scas
Scaffolding console. It generates what you want by your templates.
Setup
npm install --global scas
Setup completion (auto complete)
Setup this automatically.
scas --completion-install
And restart your terminal.
If automatically setup does not work please follow steps bellow.
Setup manually
Make completion file.
scas --completion > your/cutom/path/scas.completion.sh
Add this to your bash profile. It depends on platform (OSX, Ubuntu, Linux, etc..)
## ~/.profile or ~/.bash_profile or ~/.bashrc source your/cutom/path/scas.completion.sh
And restart your terminal.
How to use
Get help
scas
It will show available commands.
Init .scas.js file
scas init
It will generate .scas.js
file with instructions.
Make your template
Create file template/class.js
with class implementation.
Its free form template with {{{ placeholder }}}
or {{{ placeholder | pipe }}}
moduleexports = class name | Camel { this name | camel = name | camel ; } // ...
Make your action
Open .scas.js
and replace or update actions
section.
// .... actions: class: title: 'Generate class - its your action' // free form title for help arguments: 'dir' 'name' // required arguments input: 'template/class.js' // path to template out: '{{{ dir }}}/{{{ name | Camel }}}.class.js' // path to generated file // ....
Generate your code
scas
It should contains your action.
$ scas [actions] <arguments> <options> Scaffolding console class Generate class - its your action....
Lets make your class
Use [TAB] it helps a lot
scas class dir tmp/example name user
It should generate class to local tmp/example
folder.
cat tmp/example/User.class.js
moduleexports = { thisuser = user; } // ...
So thats it.
Multiple actions (batch)
Ok, you have one class but you want to generate module with multiple files.
Lets make batch action in .scas.js
file.
Add to actions
// ... module: 'title': 'Generate module' // your help line arguments: 'dir' 'name' // required arguments batch: 'class' // #1 re-used: class action with same arguments - simply, generates class file. name: 'class' // #2 re-used class action with mapped arguments, generates module class file. map: dir: '{{{ dir }}}' name: '{{{ name }}}Module'
Now actions section looks like:
actions: class: title: 'Generate class - its your action' // free form title for help arguments: 'dir' 'name' // required arguments input: 'template/class.js' // path to template out: '{{{ dir }}}/{{{ name | Camel }}}.class.js' // path to generated file module: 'title': 'Generate module' // your help line arguments: 'dir' 'name' // required arguments batch: 'class' name: 'class' map: dir: '{{{ dir }}}' name: '{{{ name }}}Module'
Run your batch action.
scas
It will show your actions.
$ scas [actions] <arguments> <options> Scaffolding console class Generate class - its your action module Generate module...
Lets generate your module.
scas module dir tmp/example name auth
Your will see output like this.
scas module dir tmp/example name authclass input template/class.js out tmp/example/Auth.class.js content module.exports = class Auth
API
.scas.js
has easy structure. It contains next fields.
title
- text presentationdescription
- text overviewactions
- actions setimports
- array of imports with pathes to other.scas.js
pipes
- custom set of functions to modify your arguments{{{ name | myCustomPipe }}}
Now .scas.js
looks like:
moduleexports = title: '$ scas [actions] <arguments> <options>' // you can rewrite this for you goals description: 'Scaffolding console' // you can rewrite this for you goals // import other scas files or packages. imports: // it needs to support default help path: 'scas/.scas' actions: class: title: 'Generate class - its your action' // free form title for help description: 'Some hint' // you can rewrite this for you goals help: 'More info about your action' // you can rewrite this for you goals arguments: 'dir' 'name' // required arguments input: 'template/class.js' // path to template out: '{{{ dir }}}/{{{ name | Camel }}}.class.js' // path to generated file module: 'title': 'Generate module' // your help line arguments: 'dir' 'name' // required arguments batch: 'class' name: 'class' map: dir: '{{{ dir }}}' name: '{{{ name }}}Module' pipes: 'my-pipe-changes' + input
presentation fields
title
and description
are fields to present info about your scaffolding.
actions
Simple action
actions: myActionName: title: 'Generate class - its your action' // free form title for help description: 'Some hint' // you can rewrite this for you goals, is not required help: 'More info about your action' // you can rewrite this for you goals, is not required arguments: 'myDir' 'className' // required arguments, is not required input: 'template/class.js' // path to template, required out: '{{{ myDir }}}/{{{ className | Camel }}}.class.js' // path to generated file, required
Batch action
// action section here ... myModuleName: 'title': 'Generate my module' // your help line arguments: 'moduleDir' 'moduleName' // required arguments batch: 'myActionName' 'myOtherAction' // my custom action name: 'myAction' // myAction action requires arguments dir and name, just remap this. map: dir: '{{{ moduleDir }}}' name: '{{{ moduleName }}}Module'
imports
Imports section loads any other actions from any file like .scas.js
or from any *.js
or npm packages.
Now it loads only default help and init form scas
npm package.
imports: // it needs to support default help path: 'scas/.scas'
Lets add yours. Make your own
template/myRules.js
moduleexports = title: 'extended action' actions: component: title: 'Angular component' arguments: 'dir' 'name' input: 'ngComponent.ts' out: '{{{ dir }}}/{{{ name | kebab }}}.component.ts'
It requires: ngComponent.ts
Lets make it. template/ngComponent.ts
; Component
Lets import this to main .scas.js
imports: path: 'scas/.scas' path: 'template/myRules' as: 'angular'
Run this
scas angular component dir tmp/ng name userDetails
Output
component input ngComponent.ts out tmp/ng/user-details.component.ts content import {Component} from "@angular/core"; @Component
Result
cat tmp/ng/user-details.component.tsimport {Component} from "@angular/core"; @Componentexport class UserDetailsComponent
You can import same rule to main namespace.
imports: path: 'scas/.scas' path: 'template/myRules'
It will be same:
scas component dir tmp/ng name userDetailscomponent input ngComponent.ts out tmp/ng/user-details.component.ts content import {Component} from "@angular/core"; @Component
pipes
Pipes its awesome :)
Available pipes by default:
moduleexports = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pluralize _ pluralize _ _ _ ? array : '' + array _ _ _ _
Or you can make your custom pipes and declare in the pipe section.
pipes: 'my-pipe-changes' + input
Have a fun +1G Team