simple-scaffold 1.3.1 → 1.4.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/cmd.d.ts +2 -0
- package/cmd.js +132 -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 -1
- package/scaffold.d.ts +34 -0
- package/scaffold.js +113 -0
- package/scaffold.js.map +1 -0
- package/types.d.ts +311 -0
- package/types.js +32 -0
- package/types.js.map +1 -0
- package/utils.d.ts +66 -0
- package/utils.js +305 -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 -120
- 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 -130
- 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/src/types.ts
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { HelperDelegate } from "handlebars/runtime"
|
|
2
|
-
|
|
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
|
-
/**
|
|
21
|
-
* Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path,
|
|
22
|
-
* or a glob pattern for multiple file matching easily.
|
|
23
|
-
*
|
|
24
|
-
* @default Current working directory
|
|
25
|
-
*/
|
|
26
|
-
templates: string[]
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Path to output to. If `createSubFolder` is `true`, the subfolder will be created inside this path.
|
|
30
|
-
*
|
|
31
|
-
* May also be a {@link FileResponseHandler} which returns a new output path to override the default one.
|
|
32
|
-
*
|
|
33
|
-
* @see {@link FileResponse}
|
|
34
|
-
* @see {@link FileResponseHandler}
|
|
35
|
-
*/
|
|
36
|
-
output: FileResponse<string>
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Whether to create subfolder with the input name.
|
|
40
|
-
*
|
|
41
|
-
* When `true`, you may also use {@link subFolderNameHelper} to determine a pre-process helper on
|
|
42
|
-
* the directory name.
|
|
43
|
-
*
|
|
44
|
-
* @default `false`
|
|
45
|
-
*/
|
|
46
|
-
createSubFolder?: boolean
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Add custom data to the templates. By default, only your app name is included as `{{name}}` and `{{Name}}`.
|
|
50
|
-
*
|
|
51
|
-
* This can be any object that will be usable by Handlebars.
|
|
52
|
-
*/
|
|
53
|
-
data?: Record<string, any>
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Enable to override output files, even if they already exist.
|
|
57
|
-
*
|
|
58
|
-
* You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns
|
|
59
|
-
* a string, to return a dynamic path for each file.
|
|
60
|
-
*
|
|
61
|
-
* May also be a {@link FileResponseHandler} which returns a boolean value per file.
|
|
62
|
-
*
|
|
63
|
-
* @see {@link FileResponse}
|
|
64
|
-
* @see {@link FileResponseHandler}
|
|
65
|
-
*
|
|
66
|
-
* @default `false`
|
|
67
|
-
*/
|
|
68
|
-
overwrite?: FileResponse<boolean>
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Suppress output logs (Same as `verbose: 0` or `verbose: LogLevel.None`)
|
|
72
|
-
* @see {@link verbose}
|
|
73
|
-
*/
|
|
74
|
-
quiet?: boolean
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Determine amount of logs to display.
|
|
78
|
-
*
|
|
79
|
-
* The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages
|
|
80
|
-
* of the same level or higher.
|
|
81
|
-
*
|
|
82
|
-
* @see {@link LogLevel}
|
|
83
|
-
*
|
|
84
|
-
* @default `2 (info)`
|
|
85
|
-
*/
|
|
86
|
-
verbose?: LogLevel
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write
|
|
90
|
-
* actual file contents or create directories.
|
|
91
|
-
*
|
|
92
|
-
* @default `false`
|
|
93
|
-
*/
|
|
94
|
-
dryRun?: boolean
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Additional helpers to add to the template parser. Provide an object whose keys are the name of the function to add,
|
|
98
|
-
* and the value is the helper function itself. The signature of helpers is as follows:
|
|
99
|
-
* ```typescript
|
|
100
|
-
* (text: string, ...args: any[]) => string
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* A full example might be:
|
|
104
|
-
*
|
|
105
|
-
* ```typescript
|
|
106
|
-
* Scaffold({
|
|
107
|
-
* //...
|
|
108
|
-
* helpers: {
|
|
109
|
-
* upperKebabCase: (text) => kebabCase(text).toUpperCase()
|
|
110
|
-
* }
|
|
111
|
-
* })
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* Which will allow:
|
|
115
|
-
*
|
|
116
|
-
* ```
|
|
117
|
-
* {{ upperKebabCase "my value" }}
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* To transform to:
|
|
121
|
-
*
|
|
122
|
-
* ```
|
|
123
|
-
* MY-VALUE
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* See {@link DefaultHelpers} for a list of all the built-in available helpers.
|
|
127
|
-
*
|
|
128
|
-
* Simple Scaffold uses Handlebars.js, so all the syntax from there is supported. See
|
|
129
|
-
* [their docs](https://handlebarsjs.com/guide/#custom-helpers) for more information.
|
|
130
|
-
*
|
|
131
|
-
* @see {@link DefaultHelpers}
|
|
132
|
-
* @see {@link CaseHelpers}
|
|
133
|
-
* @see {@link DateHelpers}
|
|
134
|
-
* @see https://casraf.dev/simple-scaffold#helpers
|
|
135
|
-
* @see https://casraf.dev/simple-scaffold#built-in-helpers
|
|
136
|
-
* @see https://handlebarsjs.com/guide/#custom-helpers
|
|
137
|
-
*/
|
|
138
|
-
helpers?: Record<string, Helper>
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Default transformer to apply to subfolder name when using `createSubFolder: true`. Can be one of the default
|
|
142
|
-
* capitalization helpers, or a custom one you provide to `helpers`. Defaults to `undefined`, which means no
|
|
143
|
-
* transformation is done.
|
|
144
|
-
*
|
|
145
|
-
* @see {@link createSubFolder}
|
|
146
|
-
* @see {@link CaseHelpers}
|
|
147
|
-
* @see {@link DefaultHelpers}
|
|
148
|
-
*/
|
|
149
|
-
subFolderNameHelper?: DefaultHelpers | string
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* This callback runs right before content is being written to the disk. If you supply this function, you may return
|
|
153
|
-
* a string that represents the final content of your file, you may process the content as you see fit. For example,
|
|
154
|
-
* you may run formatters on a file, fix output in edge-cases not supported by helpers or data, etc.
|
|
155
|
-
*
|
|
156
|
-
* If the return value of this function is `undefined`, the original content will be used.
|
|
157
|
-
*
|
|
158
|
-
* @param content The original template after token replacement
|
|
159
|
-
* @param rawContent The original template before token replacement
|
|
160
|
-
* @param outputPath The final output path of the processed file
|
|
161
|
-
*
|
|
162
|
-
* @returns {Promise<String | Buffer | undefined> | String | Buffer | undefined} The final output of the file
|
|
163
|
-
* contents-only, after further modifications - or `undefined` to use the original content (i.e. `content.toString()`)
|
|
164
|
-
*/
|
|
165
|
-
beforeWrite?(
|
|
166
|
-
content: Buffer,
|
|
167
|
-
rawContent: Buffer,
|
|
168
|
-
outputPath: string,
|
|
169
|
-
): string | Buffer | undefined | Promise<string | Buffer | undefined>
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The names of the available helper functions that relate to text capitalization.
|
|
174
|
-
*
|
|
175
|
-
* These are available for `subfolderNameHelper`.
|
|
176
|
-
*
|
|
177
|
-
* | Helper name | Example code | Example output |
|
|
178
|
-
* | ------------ | ----------------------- | -------------- |
|
|
179
|
-
* | [None] | `{{ name }}` | my name |
|
|
180
|
-
* | `camelCase` | `{{ camelCase name }}` | myName |
|
|
181
|
-
* | `snakeCase` | `{{ snakeCase name }}` | my_name |
|
|
182
|
-
* | `startCase` | `{{ startCase name }}` | My Name |
|
|
183
|
-
* | `kebabCase` | `{{ kebabCase name }}` | my-name |
|
|
184
|
-
* | `hyphenCase` | `{{ hyphenCase name }}` | my-name |
|
|
185
|
-
* | `pascalCase` | `{{ pascalCase name }}` | MyName |
|
|
186
|
-
* | `upperCase` | `{{ upperCase name }}` | MY NAME |
|
|
187
|
-
* | `lowerCase` | `{{ lowerCase name }}` | my name |
|
|
188
|
-
*
|
|
189
|
-
* @see {@link DefaultHelpers}
|
|
190
|
-
* @see {@link DateHelpers}
|
|
191
|
-
* @see {@link ScaffoldConfig}
|
|
192
|
-
* @see {@link ScaffoldConfig.subFolderNameHelper}
|
|
193
|
-
*
|
|
194
|
-
* @category Helpers
|
|
195
|
-
*/
|
|
196
|
-
export type CaseHelpers =
|
|
197
|
-
| "camelCase"
|
|
198
|
-
| "hyphenCase"
|
|
199
|
-
| "kebabCase"
|
|
200
|
-
| "lowerCase"
|
|
201
|
-
| "pascalCase"
|
|
202
|
-
| "snakeCase"
|
|
203
|
-
| "startCase"
|
|
204
|
-
| "upperCase"
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* The names of the available helper functions that relate to dates.
|
|
208
|
-
*
|
|
209
|
-
* | Helper name | Description | Example code | Example output |
|
|
210
|
-
* | -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
|
|
211
|
-
* | `now` | Current date with format | `{{ now "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
|
212
|
-
* | `now` (with offset) | Current date with format, and with offset | `{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}` | `2042-01-01 14:00` |
|
|
213
|
-
* | `date` | Custom date with format | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
|
214
|
-
* | `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` |
|
|
215
|
-
* | `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` |
|
|
216
|
-
*
|
|
217
|
-
* Further details:
|
|
218
|
-
*
|
|
219
|
-
* - We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want
|
|
220
|
-
* more information on the date tokens to use, refer to
|
|
221
|
-
* [their format documentation](https://date-fns.org/docs/format).
|
|
222
|
-
*
|
|
223
|
-
* - The date helper format takes the following arguments:
|
|
224
|
-
*
|
|
225
|
-
* ```typescript
|
|
226
|
-
* (
|
|
227
|
-
* date: string,
|
|
228
|
-
* format: string,
|
|
229
|
-
* offsetAmount?: number,
|
|
230
|
-
* offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
|
|
231
|
-
* )
|
|
232
|
-
* ```
|
|
233
|
-
*
|
|
234
|
-
* - **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it is implicitly
|
|
235
|
-
* the current date.
|
|
236
|
-
*
|
|
237
|
-
* @see {@link DefaultHelpers}
|
|
238
|
-
* @see {@link CaseHelpers}
|
|
239
|
-
* @see {@link ScaffoldConfig}
|
|
240
|
-
*
|
|
241
|
-
* @category Helpers
|
|
242
|
-
*/
|
|
243
|
-
export type DateHelpers = "date" | "now"
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The names of all the available helper functions in templates.
|
|
247
|
-
* Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.
|
|
248
|
-
*
|
|
249
|
-
* For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will
|
|
250
|
-
* replace `My Name` with `my_name` when producing the final value.
|
|
251
|
-
*
|
|
252
|
-
* @see {@link CaseHelpers}
|
|
253
|
-
* @see {@link DateHelpers}
|
|
254
|
-
* @see {@link ScaffoldConfig}
|
|
255
|
-
*
|
|
256
|
-
* @category Helpers
|
|
257
|
-
*/
|
|
258
|
-
export type DefaultHelpers = CaseHelpers | DateHelpers
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Helper function, see https://handlebarsjs.com/guide/#custom-helpers
|
|
262
|
-
*
|
|
263
|
-
* @category Helpers
|
|
264
|
-
*/
|
|
265
|
-
export type Helper = HelperDelegate
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* The amount of information to log when generating scaffold.
|
|
269
|
-
* When not `None`, the selected level will be the lowest level included.
|
|
270
|
-
*
|
|
271
|
-
* For example, level `Info` (2) will include `Info`, `Warning` and `Error`, but not `Debug`; and `Warning` will only
|
|
272
|
-
* show `Warning` and `Error`.
|
|
273
|
-
*
|
|
274
|
-
* @default `2 (info)`
|
|
275
|
-
*
|
|
276
|
-
* @category Logging
|
|
277
|
-
*/
|
|
278
|
-
export enum LogLevel {
|
|
279
|
-
/** Silent output */
|
|
280
|
-
None = 0,
|
|
281
|
-
/** Debugging information. Very verbose and only recommended for troubleshooting. */
|
|
282
|
-
Debug = 1,
|
|
283
|
-
/**
|
|
284
|
-
* The regular level of logging. Major actions are logged to show the scaffold progress.
|
|
285
|
-
*
|
|
286
|
-
* @default
|
|
287
|
-
*/
|
|
288
|
-
Info = 2,
|
|
289
|
-
/** Warnings such as when file fails to replace token values properly in template. */
|
|
290
|
-
Warning = 3,
|
|
291
|
-
/** Errors, such as missing files, bad replacement token syntax, or un-writable directories. */
|
|
292
|
-
Error = 4,
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* A function that takes path information about file, and returns a value of type `T`
|
|
297
|
-
*
|
|
298
|
-
* @template T The return type for the function
|
|
299
|
-
* @param {string} fullPath The full path of the current file
|
|
300
|
-
* @param {string} basedir The directory containing the current file
|
|
301
|
-
* @param {string} basename The name of the file
|
|
302
|
-
*
|
|
303
|
-
* @returns {T} A return value
|
|
304
|
-
*
|
|
305
|
-
* @category Config
|
|
306
|
-
*/
|
|
307
|
-
export type FileResponseHandler<T> = (fullPath: string, basedir: string, basename: string) => T
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Represents a response for file path information.
|
|
311
|
-
* Can either be:
|
|
312
|
-
*
|
|
313
|
-
* 1. `T` - static value
|
|
314
|
-
* 2. A function with the following signature which returns `T`:
|
|
315
|
-
* ```typescript
|
|
316
|
-
* (fullPath: string, basedir: string, basename: string) => T
|
|
317
|
-
* ```
|
|
318
|
-
*
|
|
319
|
-
* @typedef T The return type
|
|
320
|
-
*
|
|
321
|
-
* @see {@link FileResponseHandler}
|
|
322
|
-
*
|
|
323
|
-
* @category Config
|
|
324
|
-
* */
|
|
325
|
-
export type FileResponse<T> = T | FileResponseHandler<T>
|
|
326
|
-
|
|
327
|
-
/** @internal */
|
|
328
|
-
export interface ScaffoldCmdConfig {
|
|
329
|
-
name: string
|
|
330
|
-
templates: string[]
|
|
331
|
-
output: string
|
|
332
|
-
createSubFolder: boolean
|
|
333
|
-
data?: Record<string, string>
|
|
334
|
-
appendData?: Record<string, string>
|
|
335
|
-
overwrite: boolean
|
|
336
|
-
quiet: boolean
|
|
337
|
-
verbose: LogLevel
|
|
338
|
-
dryRun: boolean
|
|
339
|
-
config?: string
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export type ScaffoldConfigFile = Record<string, ScaffoldConfig>
|