simple-scaffold 1.1.4 → 1.2.0
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/.editorconfig +8 -0
- package/.github/FUNDING.yml +13 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- package/.github/workflows/docs.yml +20 -0
- package/.github/workflows/pull_requests.yml +17 -0
- package/.github/workflows/release.yml +24 -0
- package/.markdownlint.json +9 -0
- package/.prettierrc +15 -0
- package/.vscode/launch.json +27 -0
- package/.vscode/settings.json +22 -0
- package/.vscode/tasks.json +59 -0
- package/CHANGELOG.md +92 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +25 -0
- package/README.md +7 -1
- 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 +1 -0
- package/examples/test-input/Component/{{Name}}.tsx +17 -0
- package/jest.config.ts +205 -0
- package/media/intro.gif +0 -0
- package/package.json +22 -13
- package/release.config.js +84 -0
- package/src/cmd.ts +124 -0
- package/src/docs.css +46 -0
- package/src/index.ts +4 -0
- package/src/scaffold.ts +140 -0
- package/src/types.ts +339 -0
- package/src/utils.ts +397 -0
- package/tests/scaffold.test.ts +502 -0
- package/tests/utils.test.ts +124 -0
- package/tsconfig.json +16 -0
- package/typedoc.json +27 -0
- package/cmd.d.ts +0 -2
- package/cmd.js +0 -111
- package/cmd.js.map +0 -1
- package/index.d.ts +0 -4
- package/index.js +0 -24
- package/index.js.map +0 -1
- package/scaffold.d.ts +0 -34
- package/scaffold.js +0 -113
- package/scaffold.js.map +0 -1
- package/types.d.ts +0 -307
- package/types.js +0 -32
- package/types.js.map +0 -1
- package/utils.d.ts +0 -62
- package/utils.js +0 -266
- package/utils.js.map +0 -1
package/jest.config.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
// All imported modules in your tests should be mocked automatically
|
|
8
|
+
// automock: false,
|
|
9
|
+
|
|
10
|
+
// Stop running tests after `n` failures
|
|
11
|
+
// bail: 0,
|
|
12
|
+
|
|
13
|
+
// The directory where Jest should store its cached dependency information
|
|
14
|
+
// cacheDirectory: "/private/var/folders/q9/0mns8fgd00b4t5j5lq2wh2yh0000gn/T/jest_dx",
|
|
15
|
+
|
|
16
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
17
|
+
clearMocks: true,
|
|
18
|
+
|
|
19
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
20
|
+
collectCoverage: true,
|
|
21
|
+
|
|
22
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
23
|
+
// collectCoverageFrom: undefined,
|
|
24
|
+
|
|
25
|
+
// The directory where Jest should output its coverage files
|
|
26
|
+
coverageDirectory: "coverage",
|
|
27
|
+
|
|
28
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
29
|
+
// coveragePathIgnorePatterns: [
|
|
30
|
+
// "/node_modules/"
|
|
31
|
+
// ],
|
|
32
|
+
|
|
33
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
34
|
+
coverageProvider: "v8",
|
|
35
|
+
|
|
36
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
37
|
+
// coverageReporters: [
|
|
38
|
+
// "json",
|
|
39
|
+
// "text",
|
|
40
|
+
// "lcov",
|
|
41
|
+
// "clover"
|
|
42
|
+
// ],
|
|
43
|
+
|
|
44
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
45
|
+
// coverageThreshold: undefined,
|
|
46
|
+
|
|
47
|
+
// A path to a custom dependency extractor
|
|
48
|
+
// dependencyExtractor: undefined,
|
|
49
|
+
|
|
50
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
51
|
+
// errorOnDeprecated: false,
|
|
52
|
+
|
|
53
|
+
// The default configuration for fake timers
|
|
54
|
+
// fakeTimers: {
|
|
55
|
+
// "enableGlobally": false
|
|
56
|
+
// },
|
|
57
|
+
|
|
58
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
59
|
+
// forceCoverageMatch: [],
|
|
60
|
+
|
|
61
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
62
|
+
// globalSetup: undefined,
|
|
63
|
+
|
|
64
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
65
|
+
// globalTeardown: undefined,
|
|
66
|
+
|
|
67
|
+
// A set of global variables that need to be available in all test environments
|
|
68
|
+
// globals: {},
|
|
69
|
+
|
|
70
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
71
|
+
// maxWorkers: "50%",
|
|
72
|
+
|
|
73
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
74
|
+
// moduleDirectories: [
|
|
75
|
+
// "node_modules"
|
|
76
|
+
// ],
|
|
77
|
+
|
|
78
|
+
// An array of file extensions your modules use
|
|
79
|
+
// moduleFileExtensions: [
|
|
80
|
+
// "js",
|
|
81
|
+
// "mjs",
|
|
82
|
+
// "cjs",
|
|
83
|
+
// "jsx",
|
|
84
|
+
// "ts",
|
|
85
|
+
// "tsx",
|
|
86
|
+
// "json",
|
|
87
|
+
// "node"
|
|
88
|
+
// ],
|
|
89
|
+
|
|
90
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
91
|
+
// moduleNameMapper: {},
|
|
92
|
+
// moduleNameMapper: {
|
|
93
|
+
// chalk: "<rootDir>/node_modules/chalk/source/index.js",
|
|
94
|
+
// "#ansi-styles": "<rootDir>/node_modules/chalk/source/vendor/ansi-styles/index.js",
|
|
95
|
+
// "#supports-color": "<rootDir>/node_modules/chalk/source/vendor/supports-color/index.js",
|
|
96
|
+
// },
|
|
97
|
+
|
|
98
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
99
|
+
modulePathIgnorePatterns: ["<rootDir>/dist"],
|
|
100
|
+
|
|
101
|
+
// Activates notifications for test results
|
|
102
|
+
// notify: false,
|
|
103
|
+
|
|
104
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
105
|
+
// notifyMode: "failure-change",
|
|
106
|
+
|
|
107
|
+
// A preset that is used as a base for Jest's configuration
|
|
108
|
+
preset: "ts-jest",
|
|
109
|
+
|
|
110
|
+
// Run tests from one or more projects
|
|
111
|
+
// projects: undefined,
|
|
112
|
+
|
|
113
|
+
// Use this configuration option to add custom reporters to Jest
|
|
114
|
+
// reporters: undefined,
|
|
115
|
+
|
|
116
|
+
// Automatically reset mock state before every test
|
|
117
|
+
// resetMocks: false,
|
|
118
|
+
|
|
119
|
+
// Reset the module registry before running each individual test
|
|
120
|
+
// resetModules: false,
|
|
121
|
+
|
|
122
|
+
// A path to a custom resolver
|
|
123
|
+
// resolver: undefined,
|
|
124
|
+
|
|
125
|
+
// Automatically restore mock state and implementation before every test
|
|
126
|
+
// restoreMocks: false,
|
|
127
|
+
|
|
128
|
+
// The root directory that Jest should scan for tests and modules within
|
|
129
|
+
// rootDir: undefined,
|
|
130
|
+
|
|
131
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
132
|
+
// roots: [
|
|
133
|
+
// "<rootDir>"
|
|
134
|
+
// ],
|
|
135
|
+
|
|
136
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
137
|
+
// runner: "jest-runner",
|
|
138
|
+
|
|
139
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
140
|
+
// setupFiles: [],
|
|
141
|
+
|
|
142
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
143
|
+
// setupFilesAfterEnv: [],
|
|
144
|
+
|
|
145
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
146
|
+
// slowTestThreshold: 5,
|
|
147
|
+
|
|
148
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
149
|
+
// snapshotSerializers: [],
|
|
150
|
+
|
|
151
|
+
// The test environment that will be used for testing
|
|
152
|
+
// testEnvironment: "jest-environment-node",
|
|
153
|
+
|
|
154
|
+
// Options that will be passed to the testEnvironment
|
|
155
|
+
// testEnvironmentOptions: {},
|
|
156
|
+
|
|
157
|
+
// Adds a location field to test results
|
|
158
|
+
// testLocationInResults: false,
|
|
159
|
+
|
|
160
|
+
// The glob patterns Jest uses to detect test files
|
|
161
|
+
// testMatch: [
|
|
162
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
163
|
+
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
164
|
+
// ],
|
|
165
|
+
|
|
166
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
167
|
+
// testPathIgnorePatterns: [
|
|
168
|
+
// "/node_modules/"
|
|
169
|
+
// ],
|
|
170
|
+
|
|
171
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
172
|
+
// testRegex: [],
|
|
173
|
+
|
|
174
|
+
// This option allows the use of a custom results processor
|
|
175
|
+
// testResultsProcessor: undefined,
|
|
176
|
+
|
|
177
|
+
// This option allows use of a custom test runner
|
|
178
|
+
// testRunner: "jest-circus/runner",
|
|
179
|
+
|
|
180
|
+
// A map from regular expressions to paths to transformers
|
|
181
|
+
// transform: undefined,
|
|
182
|
+
|
|
183
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
184
|
+
// transformIgnorePatterns: [
|
|
185
|
+
// "/node_modules/",
|
|
186
|
+
// "\\.pnp\\.[^\\/]+$"
|
|
187
|
+
// ],
|
|
188
|
+
|
|
189
|
+
// transform: {
|
|
190
|
+
// "^.+\\.ts?$": "ts-jest",
|
|
191
|
+
// },
|
|
192
|
+
// transformIgnorePatterns: ["<rootDir>/node_modules/"],
|
|
193
|
+
|
|
194
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
195
|
+
// unmockedModulePathPatterns: undefined,
|
|
196
|
+
|
|
197
|
+
// Indicates whether each individual test should be reported during the run
|
|
198
|
+
// verbose: undefined,
|
|
199
|
+
|
|
200
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
201
|
+
// watchPathIgnorePatterns: [],
|
|
202
|
+
|
|
203
|
+
// Whether to use watchman for file crawling
|
|
204
|
+
// watchman: true,
|
|
205
|
+
}
|
package/media/intro.gif
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-scaffold",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A simple command to generate any file structure, from single components to entire app boilerplates.",
|
|
5
|
-
"homepage": "https://casraf.
|
|
5
|
+
"homepage": "https://casraf.dev/simple-scaffold",
|
|
6
6
|
"repository": "https://github.com/chenasraf/simple-scaffold.git",
|
|
7
7
|
"author": "Chen Asraf <inbox@casraf.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"cmd": "node --trace-warnings dist/cmd.js",
|
|
29
29
|
"build-test": "yarn build && yarn test",
|
|
30
30
|
"build-cmd": "yarn build && yarn cmd",
|
|
31
|
-
"build-docs": "
|
|
32
|
-
"build-docs-theme": "cd doc-theme && yarn install && yarn build && cd ..",
|
|
31
|
+
"build-docs": "typedoc",
|
|
33
32
|
"watch-docs": "yarn typedoc --watch",
|
|
34
|
-
"audit-fix": "npm_config_yes=true npx yarn-audit-fix --flow=convert"
|
|
33
|
+
"audit-fix": "npm_config_yes=true npx yarn-audit-fix --flow=convert",
|
|
34
|
+
"changelog": "conventional-changelog -p conventionalcommits -i CHANGELOG.md -s -r 0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"chalk": "^4.1.2",
|
|
@@ -40,21 +40,30 @@
|
|
|
40
40
|
"handlebars": "^4.7.7",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
42
|
"massarg": "^1.0.7-pre.1",
|
|
43
|
+
"semantic-release-conventional-commits": "^3.0.0",
|
|
43
44
|
"util.promisify": "^1.1.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
47
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
48
|
+
"@semantic-release/git": "^10.0.1",
|
|
49
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
50
|
+
"@types/jest": "^29.5.1",
|
|
48
51
|
"@types/lodash": "^4.14.171",
|
|
49
52
|
"@types/mock-fs": "^4.13.1",
|
|
50
|
-
"@types/node": "^18.
|
|
51
|
-
"
|
|
53
|
+
"@types/node": "^18.16.0",
|
|
54
|
+
"conventional-changelog": "^3.1.25",
|
|
55
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
56
|
+
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
52
57
|
"jest": "^29.5.0",
|
|
53
58
|
"mock-fs": "^5.2.0",
|
|
54
|
-
"rimraf": "^
|
|
55
|
-
"
|
|
59
|
+
"rimraf": "^5.0.0",
|
|
60
|
+
"semantic-release": "^21.0.1",
|
|
61
|
+
"ts-jest": "^29.1.0",
|
|
56
62
|
"ts-node": "^10.9.1",
|
|
57
|
-
"typedoc": "^0.
|
|
58
|
-
"typescript": "^
|
|
63
|
+
"typedoc": "^0.24.6",
|
|
64
|
+
"typescript": "^5.0.4"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"doc-theme": "file:./doc-theme"
|
|
59
68
|
}
|
|
60
69
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** @type {import('semantic-release').Options} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
branches: [
|
|
4
|
+
"+([0-9])?(.{+([0-9]),x}).x",
|
|
5
|
+
"master",
|
|
6
|
+
"next",
|
|
7
|
+
"next-major",
|
|
8
|
+
{ name: "beta", prerelease: true },
|
|
9
|
+
{ name: "alpha", prerelease: true },
|
|
10
|
+
],
|
|
11
|
+
analyzeCommits: {
|
|
12
|
+
path: "semantic-release-conventional-commits",
|
|
13
|
+
majorTypes: ["major", "breaking"],
|
|
14
|
+
minorTypes: ["minor", "feat", "feature"],
|
|
15
|
+
patchTypes: ["patch", "fix", "bugfix", "refactor", "perf", "revert"],
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
[
|
|
19
|
+
"@semantic-release/commit-analyzer",
|
|
20
|
+
{
|
|
21
|
+
preset: "conventionalcommits",
|
|
22
|
+
parserOpts: {
|
|
23
|
+
noteKeywords: ["breaking:", "breaking-fix:", "breaking-feat:"],
|
|
24
|
+
},
|
|
25
|
+
releaseRules: [
|
|
26
|
+
{ type: "feat", section: "Features", release: "minor" },
|
|
27
|
+
{ type: "docs", section: "Misc", release: "patch" },
|
|
28
|
+
{ type: "fix", section: "Bug Fixes", release: "patch" },
|
|
29
|
+
{ type: "refactor", section: "Misc", release: "patch" },
|
|
30
|
+
{ type: "docs", section: "Misc", release: "patch" },
|
|
31
|
+
{ type: "perf", section: "Misc", release: "patch" },
|
|
32
|
+
{ type: "build", section: "Misc", release: "patch" },
|
|
33
|
+
{ type: "chore", section: "Misc", release: "patch" },
|
|
34
|
+
{ type: "test", section: "Misc", release: "patch" },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
"@semantic-release/release-notes-generator",
|
|
40
|
+
{
|
|
41
|
+
preset: "conventionalcommits",
|
|
42
|
+
parserOpts: {
|
|
43
|
+
noteKeywords: ["breaking"],
|
|
44
|
+
types: [
|
|
45
|
+
{ type: "feat", section: "Features", release: "minor" },
|
|
46
|
+
{ type: "docs", section: "Misc", release: "patch" },
|
|
47
|
+
{ type: "fix", section: "Bug Fixes", release: "patch" },
|
|
48
|
+
{ type: "refactor", section: "Misc", release: "patch" },
|
|
49
|
+
{ type: "docs", section: "Misc", release: "patch" },
|
|
50
|
+
{ type: "perf", section: "Misc", release: "patch" },
|
|
51
|
+
{ type: "build", section: "Misc", release: "patch" },
|
|
52
|
+
{ type: "chore", section: "Misc", release: "patch" },
|
|
53
|
+
{ type: "test", section: "Misc", release: "patch" },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
"@semantic-release/changelog",
|
|
60
|
+
{
|
|
61
|
+
changelogFile: "CHANGELOG.md",
|
|
62
|
+
changelogTitle: "# Change Log",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
"@semantic-release/npm",
|
|
67
|
+
{
|
|
68
|
+
packageRoot: "dist",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"@semantic-release/github",
|
|
73
|
+
{
|
|
74
|
+
assets: ["package.tgz"],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"@semantic-release/git",
|
|
79
|
+
{
|
|
80
|
+
assets: ["CHANGELOG.md", "package.json"],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
],
|
|
84
|
+
}
|
package/src/cmd.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import massarg from "massarg"
|
|
3
|
+
import chalk from "chalk"
|
|
4
|
+
import { LogLevel, ScaffoldCmdConfig } from "./types"
|
|
5
|
+
import { Scaffold } from "./scaffold"
|
|
6
|
+
import path from "path"
|
|
7
|
+
import fs from "fs/promises"
|
|
8
|
+
import { parseAppendData } from "./utils"
|
|
9
|
+
|
|
10
|
+
export async function parseCliArgs(args = process.argv.slice(2)) {
|
|
11
|
+
const pkg = JSON.parse((await fs.readFile(path.join(__dirname, "package.json"))).toString())
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
massarg<ScaffoldCmdConfig>()
|
|
15
|
+
.main((config) => {
|
|
16
|
+
config.data = { ...config.data, ...config.appendData }
|
|
17
|
+
delete config.appendData
|
|
18
|
+
return Scaffold(config)
|
|
19
|
+
})
|
|
20
|
+
.option({
|
|
21
|
+
name: "name",
|
|
22
|
+
aliases: ["n"],
|
|
23
|
+
description:
|
|
24
|
+
"Name to be passed to the generated files. {{name}} and {{Name}} inside contents and file names will be replaced accordingly.",
|
|
25
|
+
isDefault: true,
|
|
26
|
+
required: true,
|
|
27
|
+
})
|
|
28
|
+
.option({
|
|
29
|
+
name: "output",
|
|
30
|
+
aliases: ["o"],
|
|
31
|
+
description: `Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path. ${chalk.reset`${chalk.white`(default: current dir)`}`}`,
|
|
32
|
+
required: true,
|
|
33
|
+
})
|
|
34
|
+
.option({
|
|
35
|
+
name: "templates",
|
|
36
|
+
aliases: ["t"],
|
|
37
|
+
array: true,
|
|
38
|
+
description:
|
|
39
|
+
"Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, " +
|
|
40
|
+
"or a glob pattern for multiple file matching easily.",
|
|
41
|
+
required: true,
|
|
42
|
+
})
|
|
43
|
+
.option({
|
|
44
|
+
name: "overwrite",
|
|
45
|
+
aliases: ["w"],
|
|
46
|
+
boolean: true,
|
|
47
|
+
defaultValue: false,
|
|
48
|
+
description: "Enable to override output files, even if they already exist.",
|
|
49
|
+
})
|
|
50
|
+
.option({
|
|
51
|
+
name: "data",
|
|
52
|
+
aliases: ["d"],
|
|
53
|
+
description: "Add custom data to the templates. By default, only your app name is included.",
|
|
54
|
+
parse: (v) => JSON.parse(v),
|
|
55
|
+
})
|
|
56
|
+
.option({
|
|
57
|
+
name: "append-data",
|
|
58
|
+
aliases: ["D"],
|
|
59
|
+
description:
|
|
60
|
+
"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",
|
|
61
|
+
parse: parseAppendData,
|
|
62
|
+
})
|
|
63
|
+
.option({
|
|
64
|
+
name: "create-sub-folder",
|
|
65
|
+
aliases: ["s"],
|
|
66
|
+
boolean: true,
|
|
67
|
+
defaultValue: false,
|
|
68
|
+
description: "Create subfolder with the input name",
|
|
69
|
+
})
|
|
70
|
+
.option({
|
|
71
|
+
name: "sub-folder-name-helper",
|
|
72
|
+
aliases: ["sh"],
|
|
73
|
+
description: "Default helper to apply to subfolder name when using `--create-sub-folder true`.",
|
|
74
|
+
})
|
|
75
|
+
.option({
|
|
76
|
+
name: "quiet",
|
|
77
|
+
aliases: ["q"],
|
|
78
|
+
boolean: true,
|
|
79
|
+
defaultValue: false,
|
|
80
|
+
description: "Suppress output logs (Same as --verbose 0)",
|
|
81
|
+
})
|
|
82
|
+
.option({
|
|
83
|
+
name: "verbose",
|
|
84
|
+
aliases: ["v"],
|
|
85
|
+
defaultValue: LogLevel.Info,
|
|
86
|
+
description:
|
|
87
|
+
"Determine amount of logs to display. The values are: " +
|
|
88
|
+
`${chalk.bold`0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`}. ` +
|
|
89
|
+
"The provided level will display messages of the same level or higher.",
|
|
90
|
+
parse: Number,
|
|
91
|
+
})
|
|
92
|
+
.option({
|
|
93
|
+
name: "dry-run",
|
|
94
|
+
aliases: ["dr"],
|
|
95
|
+
boolean: true,
|
|
96
|
+
defaultValue: false,
|
|
97
|
+
description:
|
|
98
|
+
"Don't emit files. This is good for testing your scaffolds and making sure they " +
|
|
99
|
+
"don't fail, without having to write actual file contents or create directories.",
|
|
100
|
+
})
|
|
101
|
+
// .example({
|
|
102
|
+
// input: `yarn cmd -t examples/test-input/Component -o examples/test-output -d '{"property":"myProp","value":"10"}'`,
|
|
103
|
+
// description: "Usage",
|
|
104
|
+
// output: "",
|
|
105
|
+
// })
|
|
106
|
+
.help({
|
|
107
|
+
binName: "simple-scaffold",
|
|
108
|
+
useGlobalColumns: true,
|
|
109
|
+
usageExample: "[options]",
|
|
110
|
+
header: [`Create structured files based on templates.`].join("\n"),
|
|
111
|
+
footer: [
|
|
112
|
+
`Version: ${pkg.version}`,
|
|
113
|
+
`Copyright © Chen Asraf 2017-${new Date().getFullYear()}`,
|
|
114
|
+
``,
|
|
115
|
+
`Documentation: ${chalk.underline`https://casraf.dev/simple-scaffold`}`,
|
|
116
|
+
`NPM: ${chalk.underline`https://npmjs.com/package/simple-scaffold`}`,
|
|
117
|
+
`GitHub: ${chalk.underline`https://github.com/chenasraf/simple-scaffold`}`,
|
|
118
|
+
].join("\n"),
|
|
119
|
+
})
|
|
120
|
+
.parse(args)
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
parseCliArgs()
|
package/src/docs.css
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
.tsd-typography table {
|
|
2
|
+
border-collapse: collapse;
|
|
3
|
+
width: 100%;
|
|
4
|
+
box-sizing
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.tsd-typography table td,
|
|
8
|
+
.tsd-typography table th {
|
|
9
|
+
vertical-align: top;
|
|
10
|
+
border: 1px solid var(--color-accent);
|
|
11
|
+
padding: 6px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tsd-typography h1 + table,
|
|
15
|
+
.tsd-typography h2 + table,
|
|
16
|
+
.tsd-typography h3 + table,
|
|
17
|
+
.tsd-typography h4 + table,
|
|
18
|
+
.tsd-typography h5 + table,
|
|
19
|
+
.tsd-typography h6 + table,
|
|
20
|
+
|
|
21
|
+
.tsd-typography h1 + pre,
|
|
22
|
+
.tsd-typography h2 + pre,
|
|
23
|
+
.tsd-typography h3 + pre,
|
|
24
|
+
.tsd-typography h4 + pre,
|
|
25
|
+
.tsd-typography h5 + pre,
|
|
26
|
+
.tsd-typography h6 + pre {
|
|
27
|
+
margin-top: 1em;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
.tsd-typography pre + a + h1,
|
|
33
|
+
.tsd-typography pre + a + h2,
|
|
34
|
+
.tsd-typography pre + a + h3,
|
|
35
|
+
.tsd-typography pre + a + h4,
|
|
36
|
+
.tsd-typography pre + a + h5,
|
|
37
|
+
.tsd-typography pre + a + h6,
|
|
38
|
+
|
|
39
|
+
.tsd-typography table + a + h1,
|
|
40
|
+
.tsd-typography table + a + h2,
|
|
41
|
+
.tsd-typography table + a + h3,
|
|
42
|
+
.tsd-typography table + a + h4,
|
|
43
|
+
.tsd-typography table + a + h5,
|
|
44
|
+
.tsd-typography table + a + h6 {
|
|
45
|
+
margin-top: 2em;
|
|
46
|
+
}
|
package/src/index.ts
ADDED
package/src/scaffold.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Simple Scaffold
|
|
4
|
+
*
|
|
5
|
+
* See [readme](README.md)
|
|
6
|
+
*/
|
|
7
|
+
import path from "path"
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
createDirIfNotExists,
|
|
11
|
+
getOptionValueForFile,
|
|
12
|
+
handleErr,
|
|
13
|
+
log,
|
|
14
|
+
pascalCase,
|
|
15
|
+
isDir,
|
|
16
|
+
removeGlob,
|
|
17
|
+
makeRelativePath,
|
|
18
|
+
registerHelpers,
|
|
19
|
+
getTemplateGlobInfo,
|
|
20
|
+
getFileList,
|
|
21
|
+
getBasePath,
|
|
22
|
+
copyFileTransformed,
|
|
23
|
+
getTemplateFileInfo,
|
|
24
|
+
logInitStep,
|
|
25
|
+
logInputFile,
|
|
26
|
+
} from "./utils"
|
|
27
|
+
import { LogLevel, ScaffoldConfig } from "./types"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a scaffold using given `options`.
|
|
31
|
+
*
|
|
32
|
+
* #### Create files
|
|
33
|
+
* To create a file structure to output, use any directory and file structure you would like.
|
|
34
|
+
* Inside folder names, file names or file contents, you may place `{{ var }}` where `var` is either
|
|
35
|
+
* `name` which is the scaffold name you provided or one of the keys you provided in the `data` option.
|
|
36
|
+
*
|
|
37
|
+
* The contents and names will be replaced with the transformed values so you can use your original structure as a
|
|
38
|
+
* boilerplate for other projects, components, modules, or even single files.
|
|
39
|
+
*
|
|
40
|
+
* The files will maintain their structure, starting from the directory containing the template (or the template itself
|
|
41
|
+
* if it is already a directory), and will output from that directory into the directory defined by `config.output`.
|
|
42
|
+
*
|
|
43
|
+
* #### Helpers
|
|
44
|
+
* Helpers are functions you can use to transform your `{{ var }}` contents into other values without having to
|
|
45
|
+
* pre-define the data and use a duplicated key.
|
|
46
|
+
*
|
|
47
|
+
* Any functions you provide in `helpers` option will also be available to you to make custom formatting as you see fit
|
|
48
|
+
* (for example, formatting a date)
|
|
49
|
+
*
|
|
50
|
+
* For available default values, see {@link DefaultHelpers}.
|
|
51
|
+
*
|
|
52
|
+
* @param {ScaffoldConfig} config The main configuration object
|
|
53
|
+
*
|
|
54
|
+
* @see {@link DefaultHelpers}
|
|
55
|
+
* @see {@link CaseHelpers}
|
|
56
|
+
* @see {@link DateHelpers}
|
|
57
|
+
*
|
|
58
|
+
* @category Main
|
|
59
|
+
*/
|
|
60
|
+
export async function Scaffold(config: ScaffoldConfig): Promise<void> {
|
|
61
|
+
config.output ??= process.cwd()
|
|
62
|
+
|
|
63
|
+
registerHelpers(config)
|
|
64
|
+
try {
|
|
65
|
+
config.data = { name: config.name, Name: pascalCase(config.name), ...config.data }
|
|
66
|
+
logInitStep(config)
|
|
67
|
+
for (let _template of config.templates) {
|
|
68
|
+
try {
|
|
69
|
+
const { nonGlobTemplate, origTemplate, isDirOrGlob, isGlob, template } = await getTemplateGlobInfo(
|
|
70
|
+
config,
|
|
71
|
+
_template,
|
|
72
|
+
)
|
|
73
|
+
const files = await getFileList(config, template)
|
|
74
|
+
for (const inputFilePath of files) {
|
|
75
|
+
if (await isDir(inputFilePath)) {
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
const relPath = makeRelativePath(path.dirname(removeGlob(inputFilePath).replace(nonGlobTemplate, "")))
|
|
79
|
+
const basePath = getBasePath(relPath)
|
|
80
|
+
logInputFile(config, {
|
|
81
|
+
origTemplate,
|
|
82
|
+
relPath,
|
|
83
|
+
template,
|
|
84
|
+
inputFilePath,
|
|
85
|
+
nonGlobTemplate,
|
|
86
|
+
basePath,
|
|
87
|
+
isDirOrGlob,
|
|
88
|
+
isGlob,
|
|
89
|
+
})
|
|
90
|
+
await handleTemplateFile(config, {
|
|
91
|
+
templatePath: inputFilePath,
|
|
92
|
+
basePath,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
} catch (e: any) {
|
|
96
|
+
handleErr(e)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (e: any) {
|
|
100
|
+
log(config, LogLevel.Error, e)
|
|
101
|
+
throw e
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function handleTemplateFile(
|
|
105
|
+
config: ScaffoldConfig,
|
|
106
|
+
{ templatePath, basePath }: { templatePath: string; basePath: string },
|
|
107
|
+
): Promise<void> {
|
|
108
|
+
return new Promise(async (resolve, reject) => {
|
|
109
|
+
try {
|
|
110
|
+
const { inputPath, outputPathOpt, outputDir, outputPath, exists } = await getTemplateFileInfo(config, {
|
|
111
|
+
templatePath,
|
|
112
|
+
basePath,
|
|
113
|
+
})
|
|
114
|
+
const overwrite = getOptionValueForFile(config, inputPath, config.overwrite ?? false)
|
|
115
|
+
|
|
116
|
+
log(
|
|
117
|
+
config,
|
|
118
|
+
LogLevel.Debug,
|
|
119
|
+
`\nParsing ${templatePath}`,
|
|
120
|
+
`\nBase path: ${basePath}`,
|
|
121
|
+
`\nFull input path: ${inputPath}`,
|
|
122
|
+
`\nOutput Path Opt: ${outputPathOpt}`,
|
|
123
|
+
`\nFull output dir: ${outputDir}`,
|
|
124
|
+
`\nFull output path: ${outputPath}`,
|
|
125
|
+
`\n`,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
await createDirIfNotExists(path.dirname(outputPath), config)
|
|
129
|
+
|
|
130
|
+
log(config, LogLevel.Info, `Writing to ${outputPath}`)
|
|
131
|
+
await copyFileTransformed(config, { exists, overwrite, outputPath, inputPath })
|
|
132
|
+
resolve()
|
|
133
|
+
} catch (e: any) {
|
|
134
|
+
handleErr(e)
|
|
135
|
+
reject(e)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export default Scaffold
|