simple-scaffold 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd.d.ts +2 -0
- package/cmd.js +127 -0
- package/cmd.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +24 -0
- package/index.js.map +1 -0
- package/package.json +1 -4
- package/scaffold.d.ts +34 -0
- package/scaffold.js +113 -0
- package/scaffold.js.map +1 -0
- package/types.d.ts +310 -0
- package/types.js +32 -0
- package/types.js.map +1 -0
- package/utils.d.ts +66 -0
- package/utils.js +303 -0
- package/utils.js.map +1 -0
- package/.editorconfig +0 -8
- package/.github/FUNDING.yml +0 -13
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -47
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
- package/.github/workflows/docs.yml +0 -20
- package/.github/workflows/pull_requests.yml +0 -17
- package/.github/workflows/release.yml +0 -22
- package/.markdownlint.json +0 -9
- package/.prettierrc +0 -15
- package/.vscode/launch.json +0 -27
- package/.vscode/settings.json +0 -22
- package/.vscode/tasks.json +0 -59
- package/CHANGELOG.md +0 -111
- package/LICENSE +0 -21
- package/examples/test-input/Component/.hidden-file +0 -0
- package/examples/test-input/Component/button-example.png +0 -0
- package/examples/test-input/Component/inner/inner-{{name}}.txt +0 -1
- package/examples/test-input/Component/{{Name}}.tsx +0 -17
- package/examples/test-input/scaffold.config.js +0 -13
- package/jest.config.ts +0 -205
- package/media/intro.gif +0 -0
- package/pages/README.md +0 -7
- package/pages/cli.md +0 -74
- package/pages/configuration_files.md +0 -86
- package/pages/migration.md +0 -25
- package/pages/node.md +0 -53
- package/pages/templates.md +0 -224
- package/release.config.js +0 -76
- package/src/cmd.ts +0 -131
- package/src/docs.css +0 -55
- package/src/index.ts +0 -4
- package/src/scaffold.ts +0 -140
- package/src/types.ts +0 -342
- package/src/utils.ts +0 -423
- package/tests/scaffold.test.ts +0 -502
- package/tests/utils.test.ts +0 -124
- package/tsconfig.json +0 -16
- package/typedoc.config.js +0 -63
package/cmd.d.ts
ADDED
package/cmd.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseCliArgs = void 0;
|
|
8
|
+
const massarg_1 = __importDefault(require("massarg"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const scaffold_1 = require("./scaffold");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
async function parseCliArgs(args = process.argv.slice(2)) {
|
|
16
|
+
const pkg = JSON.parse((await promises_1.default.readFile(path_1.default.join(__dirname, "package.json"))).toString());
|
|
17
|
+
const isConfig = args.includes("--config") || args.includes("-c");
|
|
18
|
+
return ((0, massarg_1.default)()
|
|
19
|
+
.main((config) => {
|
|
20
|
+
const _config = (0, utils_1.parseConfig)(config);
|
|
21
|
+
return (0, scaffold_1.Scaffold)(_config);
|
|
22
|
+
})
|
|
23
|
+
.option({
|
|
24
|
+
name: "name",
|
|
25
|
+
aliases: ["n"],
|
|
26
|
+
description: "Name to be passed to the generated files. {{name}} and {{Name}} inside contents and file names will be replaced accordingly.",
|
|
27
|
+
isDefault: true,
|
|
28
|
+
required: true,
|
|
29
|
+
})
|
|
30
|
+
.option({
|
|
31
|
+
name: "config",
|
|
32
|
+
aliases: ["c"],
|
|
33
|
+
description: "Filename to load config from instead of passing arguments to CLI or using a Node.js script. You may pass a JSON or JS file, with a relative or absolute path.",
|
|
34
|
+
})
|
|
35
|
+
.option({
|
|
36
|
+
name: "output",
|
|
37
|
+
aliases: ["o"],
|
|
38
|
+
description: `Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path. ${chalk_1.default.reset `${chalk_1.default.white `(default: current dir)`}`}`,
|
|
39
|
+
required: !isConfig,
|
|
40
|
+
})
|
|
41
|
+
.option({
|
|
42
|
+
name: "templates",
|
|
43
|
+
aliases: ["t"],
|
|
44
|
+
array: true,
|
|
45
|
+
description: "Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, " +
|
|
46
|
+
"or a glob pattern for multiple file matching easily.",
|
|
47
|
+
required: !isConfig,
|
|
48
|
+
})
|
|
49
|
+
.option({
|
|
50
|
+
name: "overwrite",
|
|
51
|
+
aliases: ["w"],
|
|
52
|
+
boolean: true,
|
|
53
|
+
defaultValue: false,
|
|
54
|
+
description: "Enable to override output files, even if they already exist.",
|
|
55
|
+
})
|
|
56
|
+
.option({
|
|
57
|
+
name: "data",
|
|
58
|
+
aliases: ["d"],
|
|
59
|
+
description: "Add custom data to the templates. By default, only your app name is included.",
|
|
60
|
+
parse: (v) => JSON.parse(v),
|
|
61
|
+
})
|
|
62
|
+
.option({
|
|
63
|
+
name: "append-data",
|
|
64
|
+
aliases: ["D"],
|
|
65
|
+
description: "Append additional custom data to the templates, which will overwrite --data, using an alternate syntax, which is easier to use with CLI: -D key1=string -D key2:=raw",
|
|
66
|
+
parse: utils_1.parseAppendData,
|
|
67
|
+
})
|
|
68
|
+
.option({
|
|
69
|
+
name: "create-sub-folder",
|
|
70
|
+
aliases: ["s"],
|
|
71
|
+
boolean: true,
|
|
72
|
+
defaultValue: false,
|
|
73
|
+
description: "Create subfolder with the input name",
|
|
74
|
+
})
|
|
75
|
+
.option({
|
|
76
|
+
name: "sub-folder-name-helper",
|
|
77
|
+
aliases: ["sh"],
|
|
78
|
+
description: "Default helper to apply to subfolder name when using `--create-sub-folder true`.",
|
|
79
|
+
})
|
|
80
|
+
.option({
|
|
81
|
+
name: "quiet",
|
|
82
|
+
aliases: ["q"],
|
|
83
|
+
boolean: true,
|
|
84
|
+
defaultValue: false,
|
|
85
|
+
description: "Suppress output logs (Same as --verbose 0)",
|
|
86
|
+
})
|
|
87
|
+
.option({
|
|
88
|
+
name: "verbose",
|
|
89
|
+
aliases: ["v"],
|
|
90
|
+
defaultValue: types_1.LogLevel.Info,
|
|
91
|
+
description: "Determine amount of logs to display. The values are: " +
|
|
92
|
+
`${chalk_1.default.bold `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`}. ` +
|
|
93
|
+
"The provided level will display messages of the same level or higher.",
|
|
94
|
+
parse: Number,
|
|
95
|
+
})
|
|
96
|
+
.option({
|
|
97
|
+
name: "dry-run",
|
|
98
|
+
aliases: ["dr"],
|
|
99
|
+
boolean: true,
|
|
100
|
+
defaultValue: false,
|
|
101
|
+
description: "Don't emit files. This is good for testing your scaffolds and making sure they " +
|
|
102
|
+
"don't fail, without having to write actual file contents or create directories.",
|
|
103
|
+
})
|
|
104
|
+
// .example({
|
|
105
|
+
// input: `yarn cmd -t examples/test-input/Component -o examples/test-output -d '{"property":"myProp","value":"10"}'`,
|
|
106
|
+
// description: "Usage",
|
|
107
|
+
// output: "",
|
|
108
|
+
// })
|
|
109
|
+
.help({
|
|
110
|
+
binName: "simple-scaffold",
|
|
111
|
+
useGlobalColumns: true,
|
|
112
|
+
usageExample: "[options]",
|
|
113
|
+
header: [`Create structured files based on templates.`].join("\n"),
|
|
114
|
+
footer: [
|
|
115
|
+
`Version: ${pkg.version}`,
|
|
116
|
+
`Copyright © Chen Asraf 2017-${new Date().getFullYear()}`,
|
|
117
|
+
``,
|
|
118
|
+
`Documentation: ${chalk_1.default.underline `https://casraf.dev/simple-scaffold`}`,
|
|
119
|
+
`NPM: ${chalk_1.default.underline `https://npmjs.com/package/simple-scaffold`}`,
|
|
120
|
+
`GitHub: ${chalk_1.default.underline `https://github.com/chenasraf/simple-scaffold`}`,
|
|
121
|
+
].join("\n"),
|
|
122
|
+
})
|
|
123
|
+
.parse(args));
|
|
124
|
+
}
|
|
125
|
+
exports.parseCliArgs = parseCliArgs;
|
|
126
|
+
parseCliArgs();
|
|
127
|
+
//# sourceMappingURL=cmd.js.map
|
package/cmd.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmd.js","sourceRoot":"","sources":["../src/cmd.ts"],"names":[],"mappings":";;;;;;;AACA,sDAA6B;AAC7B,kDAAyB;AACzB,mCAAqD;AACrD,yCAAqC;AACrC,gDAAuB;AACvB,2DAA4B;AAC5B,mCAAsD;AAE/C,KAAK,UAAU,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,kBAAE,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC5F,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAEjE,OAAO,CACL,IAAA,iBAAO,GAAqB;SACzB,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,CAAA;QACnC,OAAO,IAAA,mBAAQ,EAAC,OAAO,CAAC,CAAA;IAC1B,CAAC,CAAC;SACD,MAAM,CAAC;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,CAAC,GAAG,CAAC;QACd,WAAW,EACT,8HAA8H;QAChI,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;KACf,CAAC;SACD,MAAM,CAAC;QACN,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,GAAG,CAAC;QACd,WAAW,EACT,+JAA+J;KAClK,CAAC;SACD,MAAM,CAAC;QACN,IAAI,EAAE,QAAQ;QACd,OA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b,YAAY,EAAE,KAAK;QACnB,WAAW,EAAE,4CAA4C;KAC1D,CAAC;SACD,MAAM,CAAC;QACN,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC,GAAG,CAAC;QACd,YAAY,EAAE,gBAAQ,CAAC,IAAI;QAC3B,WAAW,EACT,uDAAuD;YACvD,GAAG,eAAK,CAAC,IAAI,CAAA,wDAAwD,IAAI;YACzE,uEAAuE;QACzE,KAAK,EAAE,MAAM;KACd,CAAC;SACD,MAAM,CAAC;QACN,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC,IAAI,CAAC;QACf,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,KAAK;QACnB,WAAW,EACT,iFAAiF;YACjF,iFAAiF;KACpF,CAAC;QACF,aAAa;QACb,wHAAwH;QACxH,0BAA0B;QAC1B,gBAAgB;QAChB,KAAK;SACJ,IAAI,CAAC;QACJ,OAAO,EAAE,iBAAiB;QAC1B,gBAAgB,EAAE,IAAI;QACtB,YAAY,EAAE,WAAW;QACzB,MAAM,EAAE,CAAC,6CAA6C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAClE,MAAM,EAAE;YACN,aAAa,GAAG,CAAC,OAAO,EAAE;YAC1B,+BAA+B,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YACzD,EAAE;YACF,kBAAkB,eAAK,CAAC,SAAS,CAAA,oCAAoC,EAAE;YACvE,QAAQ,eAAK,CAAC,SAAS,CAAA,2CAA2C,EAAE;YACpE,WAAW,eAAK,CAAC,SAAS,CAAA,8CAA8C,EAAE;SAC3E,CAAC,IAAI,CAAC,IAAI,CAAC;KACb,CAAC;SACD,KAAK,CAAC,IAAI,CAAC,CACf,CAAA;AACH,CAAC;AAtHD,oCAsHC;AAED,YAAY,EAAE,CAAA"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./scaffold"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
const scaffold_1 = __importDefault(require("./scaffold"));
|
|
23
|
+
exports.default = scaffold_1.default;
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,0CAAuB;AACvB,0DAAiC;AACjC,kBAAe,kBAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-scaffold",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "A simple command to generate any file structure, from single components to entire app boilerplates.",
|
|
5
5
|
"homepage": "https://casraf.dev/simple-scaffold",
|
|
6
6
|
"repository": "https://github.com/chenasraf/simple-scaffold.git",
|
|
@@ -63,8 +63,5 @@
|
|
|
63
63
|
"ts-node": "^10.9.1",
|
|
64
64
|
"typedoc": "^0.24.6",
|
|
65
65
|
"typescript": "^5.0.4"
|
|
66
|
-
},
|
|
67
|
-
"peerDependencies": {
|
|
68
|
-
"doc-theme": "file:./doc-theme"
|
|
69
66
|
}
|
|
70
67
|
}
|
package/scaffold.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ScaffoldConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Create a scaffold using given `options`.
|
|
4
|
+
*
|
|
5
|
+
* #### Create files
|
|
6
|
+
* To create a file structure to output, use any directory and file structure you would like.
|
|
7
|
+
* Inside folder names, file names or file contents, you may place `{{ var }}` where `var` is either
|
|
8
|
+
* `name` which is the scaffold name you provided or one of the keys you provided in the `data` option.
|
|
9
|
+
*
|
|
10
|
+
* The contents and names will be replaced with the transformed values so you can use your original structure as a
|
|
11
|
+
* boilerplate for other projects, components, modules, or even single files.
|
|
12
|
+
*
|
|
13
|
+
* The files will maintain their structure, starting from the directory containing the template (or the template itself
|
|
14
|
+
* if it is already a directory), and will output from that directory into the directory defined by `config.output`.
|
|
15
|
+
*
|
|
16
|
+
* #### Helpers
|
|
17
|
+
* Helpers are functions you can use to transform your `{{ var }}` contents into other values without having to
|
|
18
|
+
* pre-define the data and use a duplicated key.
|
|
19
|
+
*
|
|
20
|
+
* Any functions you provide in `helpers` option will also be available to you to make custom formatting as you see fit
|
|
21
|
+
* (for example, formatting a date)
|
|
22
|
+
*
|
|
23
|
+
* For available default values, see {@link DefaultHelpers}.
|
|
24
|
+
*
|
|
25
|
+
* @param {ScaffoldConfig} config The main configuration object
|
|
26
|
+
*
|
|
27
|
+
* @see {@link DefaultHelpers}
|
|
28
|
+
* @see {@link CaseHelpers}
|
|
29
|
+
* @see {@link DateHelpers}
|
|
30
|
+
*
|
|
31
|
+
* @category Main
|
|
32
|
+
*/
|
|
33
|
+
export declare function Scaffold(config: ScaffoldConfig): Promise<void>;
|
|
34
|
+
export default Scaffold;
|
package/scaffold.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Scaffold = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @module
|
|
9
|
+
* Simple Scaffold
|
|
10
|
+
*
|
|
11
|
+
* See [readme](README.md)
|
|
12
|
+
*/
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
/**
|
|
17
|
+
* Create a scaffold using given `options`.
|
|
18
|
+
*
|
|
19
|
+
* #### Create files
|
|
20
|
+
* To create a file structure to output, use any directory and file structure you would like.
|
|
21
|
+
* Inside folder names, file names or file contents, you may place `{{ var }}` where `var` is either
|
|
22
|
+
* `name` which is the scaffold name you provided or one of the keys you provided in the `data` option.
|
|
23
|
+
*
|
|
24
|
+
* The contents and names will be replaced with the transformed values so you can use your original structure as a
|
|
25
|
+
* boilerplate for other projects, components, modules, or even single files.
|
|
26
|
+
*
|
|
27
|
+
* The files will maintain their structure, starting from the directory containing the template (or the template itself
|
|
28
|
+
* if it is already a directory), and will output from that directory into the directory defined by `config.output`.
|
|
29
|
+
*
|
|
30
|
+
* #### Helpers
|
|
31
|
+
* Helpers are functions you can use to transform your `{{ var }}` contents into other values without having to
|
|
32
|
+
* pre-define the data and use a duplicated key.
|
|
33
|
+
*
|
|
34
|
+
* Any functions you provide in `helpers` option will also be available to you to make custom formatting as you see fit
|
|
35
|
+
* (for example, formatting a date)
|
|
36
|
+
*
|
|
37
|
+
* For available default values, see {@link DefaultHelpers}.
|
|
38
|
+
*
|
|
39
|
+
* @param {ScaffoldConfig} config The main configuration object
|
|
40
|
+
*
|
|
41
|
+
* @see {@link DefaultHelpers}
|
|
42
|
+
* @see {@link CaseHelpers}
|
|
43
|
+
* @see {@link DateHelpers}
|
|
44
|
+
*
|
|
45
|
+
* @category Main
|
|
46
|
+
*/
|
|
47
|
+
async function Scaffold(config) {
|
|
48
|
+
var _a;
|
|
49
|
+
(_a = config.output) !== null && _a !== void 0 ? _a : (config.output = process.cwd());
|
|
50
|
+
(0, utils_1.registerHelpers)(config);
|
|
51
|
+
try {
|
|
52
|
+
config.data = { name: config.name, Name: (0, utils_1.pascalCase)(config.name), ...config.data };
|
|
53
|
+
(0, utils_1.logInitStep)(config);
|
|
54
|
+
for (let _template of config.templates) {
|
|
55
|
+
try {
|
|
56
|
+
const { nonGlobTemplate, origTemplate, isDirOrGlob, isGlob, template } = await (0, utils_1.getTemplateGlobInfo)(config, _template);
|
|
57
|
+
const files = await (0, utils_1.getFileList)(config, template);
|
|
58
|
+
for (const inputFilePath of files) {
|
|
59
|
+
if (await (0, utils_1.isDir)(inputFilePath)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const relPath = (0, utils_1.makeRelativePath)(path_1.default.dirname((0, utils_1.removeGlob)(inputFilePath).replace(nonGlobTemplate, "")));
|
|
63
|
+
const basePath = (0, utils_1.getBasePath)(relPath);
|
|
64
|
+
(0, utils_1.logInputFile)(config, {
|
|
65
|
+
origTemplate,
|
|
66
|
+
relPath,
|
|
67
|
+
template,
|
|
68
|
+
inputFilePath,
|
|
69
|
+
nonGlobTemplate,
|
|
70
|
+
basePath,
|
|
71
|
+
isDirOrGlob,
|
|
72
|
+
isGlob,
|
|
73
|
+
});
|
|
74
|
+
await handleTemplateFile(config, {
|
|
75
|
+
templatePath: inputFilePath,
|
|
76
|
+
basePath,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
(0, utils_1.handleErr)(e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
(0, utils_1.log)(config, types_1.LogLevel.Error, e);
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Scaffold = Scaffold;
|
|
91
|
+
async function handleTemplateFile(config, { templatePath, basePath }) {
|
|
92
|
+
return new Promise(async (resolve, reject) => {
|
|
93
|
+
var _a;
|
|
94
|
+
try {
|
|
95
|
+
const { inputPath, outputPathOpt, outputDir, outputPath, exists } = await (0, utils_1.getTemplateFileInfo)(config, {
|
|
96
|
+
templatePath,
|
|
97
|
+
basePath,
|
|
98
|
+
});
|
|
99
|
+
const overwrite = (0, utils_1.getOptionValueForFile)(config, inputPath, (_a = config.overwrite) !== null && _a !== void 0 ? _a : false);
|
|
100
|
+
(0, utils_1.log)(config, types_1.LogLevel.Debug, `\nParsing ${templatePath}`, `\nBase path: ${basePath}`, `\nFull input path: ${inputPath}`, `\nOutput Path Opt: ${outputPathOpt}`, `\nFull output dir: ${outputDir}`, `\nFull output path: ${outputPath}`, `\n`);
|
|
101
|
+
await (0, utils_1.createDirIfNotExists)(path_1.default.dirname(outputPath), config);
|
|
102
|
+
(0, utils_1.log)(config, types_1.LogLevel.Info, `Writing to ${outputPath}`);
|
|
103
|
+
await (0, utils_1.copyFileTransformed)(config, { exists, overwrite, outputPath, inputPath });
|
|
104
|
+
resolve();
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
(0, utils_1.handleErr)(e);
|
|
108
|
+
reject(e);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
exports.default = Scaffold;
|
|
113
|
+
//# sourceMappingURL=scaffold.js.map
|
package/scaffold.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,gDAAu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,UAAU,EAAE,CAAC,CAAA;YACtD,MAAM,IAAA,2BAAmB,EAAC,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAA;YAC/E,OAAO,EAAE,CAAA;SACV;QAAC,OAAO,CAAM,EAAE;YACf,IAAA,iBAAS,EAAC,CAAC,CAAC,CAAA;YACZ,MAAM,CAAC,CAAC,CAAC,CAAA;SACV;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,QAAQ,CAAA"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { HelperDelegate } from "handlebars/runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The config object for defining a scaffolding group.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/chenasraf/simple-scaffold#readme
|
|
7
|
+
* @see {@link DefaultHelpers}
|
|
8
|
+
* @see {@link CaseHelpers}
|
|
9
|
+
* @see {@link DateHelpers}
|
|
10
|
+
*
|
|
11
|
+
* @category Config
|
|
12
|
+
*/
|
|
13
|
+
export interface ScaffoldConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced
|
|
16
|
+
* accordingly.
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path,
|
|
21
|
+
* or a glob pattern for multiple file matching easily.
|
|
22
|
+
*
|
|
23
|
+
* @default Current working directory
|
|
24
|
+
*/
|
|
25
|
+
templates: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Path to output to. If `createSubFolder` is `true`, the subfolder will be created inside this path.
|
|
28
|
+
*
|
|
29
|
+
* May also be a {@link FileResponseHandler} which returns a new output path to override the default one.
|
|
30
|
+
*
|
|
31
|
+
* @see {@link FileResponse}
|
|
32
|
+
* @see {@link FileResponseHandler}
|
|
33
|
+
*/
|
|
34
|
+
output: FileResponse<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to create subfolder with the input name.
|
|
37
|
+
*
|
|
38
|
+
* When `true`, you may also use {@link subFolderNameHelper} to determine a pre-process helper on
|
|
39
|
+
* the directory name.
|
|
40
|
+
*
|
|
41
|
+
* @default `false`
|
|
42
|
+
*/
|
|
43
|
+
createSubFolder?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Add custom data to the templates. By default, only your app name is included as `{{name}}` and `{{Name}}`.
|
|
46
|
+
*
|
|
47
|
+
* This can be any object that will be usable by Handlebars.
|
|
48
|
+
*/
|
|
49
|
+
data?: Record<string, any>;
|
|
50
|
+
/**
|
|
51
|
+
* Enable to override output files, even if they already exist.
|
|
52
|
+
*
|
|
53
|
+
* You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns
|
|
54
|
+
* a string, to return a dynamic path for each file.
|
|
55
|
+
*
|
|
56
|
+
* May also be a {@link FileResponseHandler} which returns a boolean value per file.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link FileResponse}
|
|
59
|
+
* @see {@link FileResponseHandler}
|
|
60
|
+
*
|
|
61
|
+
* @default `false`
|
|
62
|
+
*/
|
|
63
|
+
overwrite?: FileResponse<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Suppress output logs (Same as `verbose: 0` or `verbose: LogLevel.None`)
|
|
66
|
+
* @see {@link verbose}
|
|
67
|
+
*/
|
|
68
|
+
quiet?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Determine amount of logs to display.
|
|
71
|
+
*
|
|
72
|
+
* The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages
|
|
73
|
+
* of the same level or higher.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link LogLevel}
|
|
76
|
+
*
|
|
77
|
+
* @default `2 (info)`
|
|
78
|
+
*/
|
|
79
|
+
verbose?: LogLevel;
|
|
80
|
+
/**
|
|
81
|
+
* Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write
|
|
82
|
+
* actual file contents or create directories.
|
|
83
|
+
*
|
|
84
|
+
* @default `false`
|
|
85
|
+
*/
|
|
86
|
+
dryRun?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Additional helpers to add to the template parser. Provide an object whose keys are the name of the function to add,
|
|
89
|
+
* and the value is the helper function itself. The signature of helpers is as follows:
|
|
90
|
+
* ```typescript
|
|
91
|
+
* (text: string, ...args: any[]) => string
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* A full example might be:
|
|
95
|
+
*
|
|
96
|
+
* ```typescript
|
|
97
|
+
* Scaffold({
|
|
98
|
+
* //...
|
|
99
|
+
* helpers: {
|
|
100
|
+
* upperKebabCase: (text) => kebabCase(text).toUpperCase()
|
|
101
|
+
* }
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* Which will allow:
|
|
106
|
+
*
|
|
107
|
+
* ```
|
|
108
|
+
* {{ upperKebabCase "my value" }}
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* To transform to:
|
|
112
|
+
*
|
|
113
|
+
* ```
|
|
114
|
+
* MY-VALUE
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* See {@link DefaultHelpers} for a list of all the built-in available helpers.
|
|
118
|
+
*
|
|
119
|
+
* Simple Scaffold uses Handlebars.js, so all the syntax from there is supported. See
|
|
120
|
+
* [their docs](https://handlebarsjs.com/guide/#custom-helpers) for more information.
|
|
121
|
+
*
|
|
122
|
+
* @see {@link DefaultHelpers}
|
|
123
|
+
* @see {@link CaseHelpers}
|
|
124
|
+
* @see {@link DateHelpers}
|
|
125
|
+
* @see https://casraf.dev/simple-scaffold#helpers
|
|
126
|
+
* @see https://casraf.dev/simple-scaffold#built-in-helpers
|
|
127
|
+
* @see https://handlebarsjs.com/guide/#custom-helpers
|
|
128
|
+
*/
|
|
129
|
+
helpers?: Record<string, Helper>;
|
|
130
|
+
/**
|
|
131
|
+
* Default transformer to apply to subfolder name when using `createSubFolder: true`. Can be one of the default
|
|
132
|
+
* capitalization helpers, or a custom one you provide to `helpers`. Defaults to `undefined`, which means no
|
|
133
|
+
* transformation is done.
|
|
134
|
+
*
|
|
135
|
+
* @see {@link createSubFolder}
|
|
136
|
+
* @see {@link CaseHelpers}
|
|
137
|
+
* @see {@link DefaultHelpers}
|
|
138
|
+
*/
|
|
139
|
+
subFolderNameHelper?: DefaultHelpers | string;
|
|
140
|
+
/**
|
|
141
|
+
* This callback runs right before content is being written to the disk. If you supply this function, you may return
|
|
142
|
+
* a string that represents the final content of your file, you may process the content as you see fit. For example,
|
|
143
|
+
* you may run formatters on a file, fix output in edge-cases not supported by helpers or data, etc.
|
|
144
|
+
*
|
|
145
|
+
* If the return value of this function is `undefined`, the original content will be used.
|
|
146
|
+
*
|
|
147
|
+
* @param content The original template after token replacement
|
|
148
|
+
* @param rawContent The original template before token replacement
|
|
149
|
+
* @param outputPath The final output path of the processed file
|
|
150
|
+
*
|
|
151
|
+
* @returns {Promise<String | Buffer | undefined> | String | Buffer | undefined} The final output of the file
|
|
152
|
+
* contents-only, after further modifications - or `undefined` to use the original content (i.e. `content.toString()`)
|
|
153
|
+
*/
|
|
154
|
+
beforeWrite?(content: Buffer, rawContent: Buffer, outputPath: string): string | Buffer | undefined | Promise<string | Buffer | undefined>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The names of the available helper functions that relate to text capitalization.
|
|
158
|
+
*
|
|
159
|
+
* These are available for `subfolderNameHelper`.
|
|
160
|
+
*
|
|
161
|
+
* | Helper name | Example code | Example output |
|
|
162
|
+
* | ------------ | ----------------------- | -------------- |
|
|
163
|
+
* | [None] | `{{ name }}` | my name |
|
|
164
|
+
* | `camelCase` | `{{ camelCase name }}` | myName |
|
|
165
|
+
* | `snakeCase` | `{{ snakeCase name }}` | my_name |
|
|
166
|
+
* | `startCase` | `{{ startCase name }}` | My Name |
|
|
167
|
+
* | `kebabCase` | `{{ kebabCase name }}` | my-name |
|
|
168
|
+
* | `hyphenCase` | `{{ hyphenCase name }}` | my-name |
|
|
169
|
+
* | `pascalCase` | `{{ pascalCase name }}` | MyName |
|
|
170
|
+
* | `upperCase` | `{{ upperCase name }}` | MY NAME |
|
|
171
|
+
* | `lowerCase` | `{{ lowerCase name }}` | my name |
|
|
172
|
+
*
|
|
173
|
+
* @see {@link DefaultHelpers}
|
|
174
|
+
* @see {@link DateHelpers}
|
|
175
|
+
* @see {@link ScaffoldConfig}
|
|
176
|
+
* @see {@link ScaffoldConfig.subFolderNameHelper}
|
|
177
|
+
*
|
|
178
|
+
* @category Helpers
|
|
179
|
+
*/
|
|
180
|
+
export type CaseHelpers = "camelCase" | "hyphenCase" | "kebabCase" | "lowerCase" | "pascalCase" | "snakeCase" | "startCase" | "upperCase";
|
|
181
|
+
/**
|
|
182
|
+
* The names of the available helper functions that relate to dates.
|
|
183
|
+
*
|
|
184
|
+
* | Helper name | Description | Example code | Example output |
|
|
185
|
+
* | -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
|
|
186
|
+
* | `now` | Current date with format | `{{ now "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
|
187
|
+
* | `now` (with offset) | Current date with format, and with offset | `{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}` | `2042-01-01 14:00` |
|
|
188
|
+
* | `date` | Custom date with format | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
|
189
|
+
* | `date` (with offset) | Custom date with format, and with offset | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" -1 "days" }}` | `2041-31-12 15:00` |
|
|
190
|
+
* | `date` (with date from `--data`) | Custom date with format, with data from the `data` config option | `{{ date myCustomDate "yyyy-MM-dd HH:mm" }}` | `2042-01-01 12:00` |
|
|
191
|
+
*
|
|
192
|
+
* Further details:
|
|
193
|
+
*
|
|
194
|
+
* - We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want
|
|
195
|
+
* more information on the date tokens to use, refer to
|
|
196
|
+
* [their format documentation](https://date-fns.org/docs/format).
|
|
197
|
+
*
|
|
198
|
+
* - The date helper format takes the following arguments:
|
|
199
|
+
*
|
|
200
|
+
* ```typescript
|
|
201
|
+
* (
|
|
202
|
+
* date: string,
|
|
203
|
+
* format: string,
|
|
204
|
+
* offsetAmount?: number,
|
|
205
|
+
* offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
|
|
206
|
+
* )
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* - **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it is implicitly
|
|
210
|
+
* the current date.
|
|
211
|
+
*
|
|
212
|
+
* @see {@link DefaultHelpers}
|
|
213
|
+
* @see {@link CaseHelpers}
|
|
214
|
+
* @see {@link ScaffoldConfig}
|
|
215
|
+
*
|
|
216
|
+
* @category Helpers
|
|
217
|
+
*/
|
|
218
|
+
export type DateHelpers = "date" | "now";
|
|
219
|
+
/**
|
|
220
|
+
* The names of all the available helper functions in templates.
|
|
221
|
+
* Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.
|
|
222
|
+
*
|
|
223
|
+
* For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will
|
|
224
|
+
* replace `My Name` with `my_name` when producing the final value.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link CaseHelpers}
|
|
227
|
+
* @see {@link DateHelpers}
|
|
228
|
+
* @see {@link ScaffoldConfig}
|
|
229
|
+
*
|
|
230
|
+
* @category Helpers
|
|
231
|
+
*/
|
|
232
|
+
export type DefaultHelpers = CaseHelpers | DateHelpers;
|
|
233
|
+
/**
|
|
234
|
+
* Helper function, see https://handlebarsjs.com/guide/#custom-helpers
|
|
235
|
+
*
|
|
236
|
+
* @category Helpers
|
|
237
|
+
*/
|
|
238
|
+
export type Helper = HelperDelegate;
|
|
239
|
+
/**
|
|
240
|
+
* The amount of information to log when generating scaffold.
|
|
241
|
+
* When not `None`, the selected level will be the lowest level included.
|
|
242
|
+
*
|
|
243
|
+
* For example, level `Info` (2) will include `Info`, `Warning` and `Error`, but not `Debug`; and `Warning` will only
|
|
244
|
+
* show `Warning` and `Error`.
|
|
245
|
+
*
|
|
246
|
+
* @default `2 (info)`
|
|
247
|
+
*
|
|
248
|
+
* @category Logging
|
|
249
|
+
*/
|
|
250
|
+
export declare enum LogLevel {
|
|
251
|
+
/** Silent output */
|
|
252
|
+
None = 0,
|
|
253
|
+
/** Debugging information. Very verbose and only recommended for troubleshooting. */
|
|
254
|
+
Debug = 1,
|
|
255
|
+
/**
|
|
256
|
+
* The regular level of logging. Major actions are logged to show the scaffold progress.
|
|
257
|
+
*
|
|
258
|
+
* @default
|
|
259
|
+
*/
|
|
260
|
+
Info = 2,
|
|
261
|
+
/** Warnings such as when file fails to replace token values properly in template. */
|
|
262
|
+
Warning = 3,
|
|
263
|
+
/** Errors, such as missing files, bad replacement token syntax, or un-writable directories. */
|
|
264
|
+
Error = 4
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A function that takes path information about file, and returns a value of type `T`
|
|
268
|
+
*
|
|
269
|
+
* @template T The return type for the function
|
|
270
|
+
* @param {string} fullPath The full path of the current file
|
|
271
|
+
* @param {string} basedir The directory containing the current file
|
|
272
|
+
* @param {string} basename The name of the file
|
|
273
|
+
*
|
|
274
|
+
* @returns {T} A return value
|
|
275
|
+
*
|
|
276
|
+
* @category Config
|
|
277
|
+
*/
|
|
278
|
+
export type FileResponseHandler<T> = (fullPath: string, basedir: string, basename: string) => T;
|
|
279
|
+
/**
|
|
280
|
+
* Represents a response for file path information.
|
|
281
|
+
* Can either be:
|
|
282
|
+
*
|
|
283
|
+
* 1. `T` - static value
|
|
284
|
+
* 2. A function with the following signature which returns `T`:
|
|
285
|
+
* ```typescript
|
|
286
|
+
* (fullPath: string, basedir: string, basename: string) => T
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @typedef T The return type
|
|
290
|
+
*
|
|
291
|
+
* @see {@link FileResponseHandler}
|
|
292
|
+
*
|
|
293
|
+
* @category Config
|
|
294
|
+
* */
|
|
295
|
+
export type FileResponse<T> = T | FileResponseHandler<T>;
|
|
296
|
+
/** @internal */
|
|
297
|
+
export interface ScaffoldCmdConfig {
|
|
298
|
+
name: string;
|
|
299
|
+
templates: string[];
|
|
300
|
+
output: string;
|
|
301
|
+
createSubFolder: boolean;
|
|
302
|
+
data?: Record<string, string>;
|
|
303
|
+
appendData?: Record<string, string>;
|
|
304
|
+
overwrite: boolean;
|
|
305
|
+
quiet: boolean;
|
|
306
|
+
verbose: LogLevel;
|
|
307
|
+
dryRun: boolean;
|
|
308
|
+
config?: string;
|
|
309
|
+
}
|
|
310
|
+
export type ScaffoldConfigFile = Record<string, ScaffoldConfig>;
|