A code generation tool to make adding code a scoosh
This library is in active development and APIs will change, use at your peril
sudo npm install scoosh -g
If you are using Scoosh for the first time then create a .scoosh file in your project root folder and specify the path to your code generation templates.
.scoosh
{
"snippetFolders": ["snippetFolders"]
}
Now run
scoosh preview
Previews a code generation task with interactive questions.
scoosh generate
Generates the files for the chosen template.
Each snippet has a template file in EJS syntax, and a JSON configuration file.
The extension should indicate the language for the snippet and not '.ejs'.
For example : newcomponent.js
import React, { Component } from 'react';
import Relay from 'react-relay';
class <%- ComponentName %> extends Component {
// <%- InterestingList %>
constructor() {
super();
}
render() {
return (
<div><%- SomeBoolean %></div>
);
}
}
import React, { Component } from 'react'; import Relay from 'react-relay';
In this example there are three template substitutions
<%- ComponentName %>
<%- InterestingList %>
<%- SomeBoolean %>
This file specifies how the template substitutions are fetched from user input. It should have a .json
extension.
- templateFile - This should be the filename of the template above.
- question - This is the json used by the inquirer library for fetching interactive input from users. Guide for inquirer question syntax
newcomponent.json
{
"operations": [
{
"operation": "create",
"templateFile": "newcomponent.js",
"createFile": "<%- _.kebabCase(ComponentName) %>"
}
],
"questions": [
{
"name": "ComponentName",
"type": "input",
"default": "<SPECIFYNAMEHERE>",
"message": "the component name of the blahdeblah"
},
{
"name": "InterestingList",
"type": "list",
"choices": [
"can't code", "social foibles", "doesn't like pizza"
],
"message": "the interesting of the blahdeblah"
},
{
"name": "SomeBoolean",
"type": "list",
"choices" : ["true","false"],
"message": "Select a boolean...because"
}
]
}