mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-18 01:29:09 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a2d7c08f3 | ||
|
|
a92c471243 | ||
|
|
07b1c4b1f0 |
21
README.md
21
README.md
@@ -43,14 +43,14 @@ Any `locals` you add in the config will populate with their names wrapped in `{{
|
||||
They are all stringified, so be sure to parse them accordingly by creating a script, if necessary.
|
||||
|
||||
### Command line options
|
||||
##### `--template glob [--template glob2 [...]]` (required)
|
||||
##### `--template glob [--template glob2 [...]]` (required) (alias: -t)
|
||||
A glob pattern of template files to load.
|
||||
|
||||
A template file may be of any type and extension, and supports [Handlebars](https://handlebarsjs.com) as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.
|
||||
|
||||
You can load more than one template list by simple adding more `--template` arguments.
|
||||
|
||||
##### `--output path` (optional)
|
||||
##### `--output path` (optional) (alias -o)
|
||||
The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible.
|
||||
|
||||
Your new scaffold will be placed under a directory with the scaffold name from the argumemts.
|
||||
@@ -58,9 +58,14 @@ Your new scaffold will be placed under a directory with the scaffold name from t
|
||||
You may also pass a function to transform the output path for each file individually.
|
||||
This function takes 2 arguments: filename, and base glob path
|
||||
|
||||
##### `--locals key=value[,key=value[,...]]` (optional)
|
||||
##### `--locals key=value [--locals key=value [,...]]` (optional) (alias: -l)
|
||||
Pass a KV map to the template for parsing.
|
||||
|
||||
##### `--create-sub-folder [true|false]` (optional) (alias -S) (default: true)
|
||||
Whether to create a subfolder for the output with all the files inside, or simply dump them directly in the output folder.
|
||||
|
||||
#####
|
||||
|
||||
### Use in Node.js
|
||||
You can also build the scaffold yourself, if you want to create more complex arguments or scaffold groups.
|
||||
Simply pass a config object to the constructor, and invoke `run()` when you are ready to start.
|
||||
@@ -73,6 +78,7 @@ const scaffold = new SimpleScaffold({
|
||||
name: 'component',
|
||||
templates: [path.join(__dirname, 'scaffolds', 'component')],
|
||||
output: path.join(__dirname, 'src', 'components'),
|
||||
createSubFolder: true,
|
||||
locals: {
|
||||
property: 'value',
|
||||
}
|
||||
@@ -121,6 +127,15 @@ simple-scaffold MyComponent \
|
||||
- ...
|
||||
```
|
||||
|
||||
With `createSubfolder = false`:
|
||||
```
|
||||
- project
|
||||
- src
|
||||
- components
|
||||
- MyComponent.js
|
||||
- ...
|
||||
```
|
||||
|
||||
#### project/scaffold/MyComponent/MyComponent.js
|
||||
```js
|
||||
const React = require('react')
|
||||
|
||||
7
cmd.ts
7
cmd.ts
@@ -24,7 +24,7 @@ const defs: Def[] = [
|
||||
{ name: 'templates', alias: 't', type: filePathParser, multiple: true },
|
||||
{ name: 'output', alias: 'o', type: filePathParser, multiple: true },
|
||||
{ name: 'locals', alias: 'l', multiple: true, type: localsParser },
|
||||
{ name: 'create-sub-folder', alias: 'S', type: Boolean },
|
||||
{ name: 'create-sub-folder', alias: 'S', type: (text: string) => text && text.trim().length ? ['true', '1', 'on'].includes(text.trim()) : true },
|
||||
{ name: 'help', alias: 'h', type: Boolean, description: 'Display this help message' },
|
||||
]
|
||||
|
||||
@@ -35,7 +35,10 @@ const help = [
|
||||
{ header: 'Options', optionList: defs }
|
||||
]
|
||||
|
||||
args.locals = args.locals.reduce((all: object, cur: object) => ({ ...all, ...cur }), {} as IScaffold.Config['locals'])
|
||||
args.locals = (args.locals || []).reduce((all: object, cur: object) => ({ ...all, ...cur }), {} as IScaffold.Config['locals'])
|
||||
if (args.createSubFolder === null) {
|
||||
args.createSubFolder = true
|
||||
}
|
||||
console.info('Config:', args)
|
||||
|
||||
if (args.help || !args.name) {
|
||||
|
||||
15
dist/cmd.js
vendored
15
dist/cmd.js
vendored
@@ -8,7 +8,7 @@
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(this, function() {
|
||||
})(typeof self !== 'undefined' ? self : this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
@@ -233,9 +233,9 @@ var cliArgs = __webpack_require__(7);
|
||||
var cliUsage = __webpack_require__(8);
|
||||
var path = __webpack_require__(0);
|
||||
function localsParser(content) {
|
||||
var _a = content.split('='), key = _a[0], value = _a[1];
|
||||
return _b = {}, _b[key] = value, _b;
|
||||
var _b;
|
||||
var _a;
|
||||
var _b = content.split('='), key = _b[0], value = _b[1];
|
||||
return _a = {}, _a[key] = value, _a;
|
||||
}
|
||||
function filePathParser(content) {
|
||||
if (content.startsWith('/')) {
|
||||
@@ -248,7 +248,7 @@ var defs = [
|
||||
{ name: 'templates', alias: 't', type: filePathParser, multiple: true },
|
||||
{ name: 'output', alias: 'o', type: filePathParser, multiple: true },
|
||||
{ name: 'locals', alias: 'l', multiple: true, type: localsParser },
|
||||
{ name: 'create-sub-folder', alias: 'S', type: Boolean },
|
||||
{ name: 'create-sub-folder', alias: 'S', type: function (text) { return text && text.trim().length ? ['true', '1', 'on'].includes(text.trim()) : true; } },
|
||||
{ name: 'help', alias: 'h', type: Boolean, description: 'Display this help message' },
|
||||
];
|
||||
var args = cliArgs(defs, { camelCase: true });
|
||||
@@ -256,7 +256,10 @@ var help = [
|
||||
{ header: 'Scaffold Generator', content: 'Generate scaffolds for your project based on file templates.' },
|
||||
{ header: 'Options', optionList: defs }
|
||||
];
|
||||
args.locals = args.locals.reduce(function (all, cur) { return (__assign({}, all, cur)); }, {});
|
||||
args.locals = (args.locals || []).reduce(function (all, cur) { return (__assign({}, all, cur)); }, {});
|
||||
if (args.createSubFolder === null) {
|
||||
args.createSubFolder = true;
|
||||
}
|
||||
console.info('Config:', args);
|
||||
if (args.help || !args.name) {
|
||||
console.log(cliUsage(help));
|
||||
|
||||
2
dist/cmd.js.map
vendored
2
dist/cmd.js.map
vendored
File diff suppressed because one or more lines are too long
1
dist/dist/cmd.d.ts
vendored
1
dist/dist/cmd.d.ts
vendored
@@ -0,0 +1 @@
|
||||
export {};
|
||||
|
||||
10
dist/dist/scaffold.d.ts
vendored
10
dist/dist/scaffold.d.ts
vendored
@@ -3,11 +3,11 @@ declare class SimpleScaffold {
|
||||
config: IScaffold.Config;
|
||||
locals: IScaffold.Config['locals'];
|
||||
constructor(config: IScaffold.Config);
|
||||
private parseLocals(text);
|
||||
private fileList(input);
|
||||
private getFileContents(filePath);
|
||||
private getOutputPath(file, basePath);
|
||||
private writeFile(filePath, fileContents);
|
||||
private parseLocals;
|
||||
private fileList;
|
||||
private getFileContents;
|
||||
private getOutputPath;
|
||||
private writeFile;
|
||||
run(): void;
|
||||
}
|
||||
export default SimpleScaffold;
|
||||
|
||||
1
dist/dist/test.d.ts
vendored
1
dist/dist/test.d.ts
vendored
@@ -0,0 +1 @@
|
||||
export {};
|
||||
|
||||
2
dist/scaffold.js
vendored
2
dist/scaffold.js
vendored
@@ -7,7 +7,7 @@
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(this, function() {
|
||||
})(typeof self !== 'undefined' ? self : this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
2
dist/scaffold.js.map
vendored
2
dist/scaffold.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/test.js
vendored
2
dist/test.js
vendored
@@ -7,7 +7,7 @@
|
||||
exports["library"] = factory();
|
||||
else
|
||||
root["library"] = factory();
|
||||
})(this, function() {
|
||||
})(typeof self !== 'undefined' ? self : this, function() {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
2
dist/test.js.map
vendored
2
dist/test.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "simple-scaffold",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"description": "Create files based on templates",
|
||||
"repository": "https://github.com/chenasraf/simple-scaffold.git",
|
||||
"author": "Chen Asraf <inbox@casraf.com>",
|
||||
|
||||
Reference in New Issue
Block a user