mirror of
https://github.com/chenasraf/simple-scaffold.git
synced 2026-05-18 01:29:09 +00:00
docs: update
This commit is contained in:
@@ -18,6 +18,18 @@ show `Warning` and `Error`.
|
||||
|
||||
## Enumeration Members
|
||||
|
||||
### None
|
||||
|
||||
• **None** = ``0``
|
||||
|
||||
Silent output
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:279](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L279)
|
||||
|
||||
___
|
||||
|
||||
### Debug
|
||||
|
||||
• **Debug** = ``1``
|
||||
@@ -26,19 +38,7 @@ Debugging information. Very verbose and only recommended for troubleshooting.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:281](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L281)
|
||||
|
||||
___
|
||||
|
||||
### Error
|
||||
|
||||
• **Error** = ``4``
|
||||
|
||||
Errors, such as missing files, bad replacement token syntax, or un-writable directories.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:291](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L291)
|
||||
[types.ts:281](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L281)
|
||||
|
||||
___
|
||||
|
||||
@@ -56,19 +56,7 @@ The regular level of logging. Major actions are logged to show the scaffold prog
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:287](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L287)
|
||||
|
||||
___
|
||||
|
||||
### None
|
||||
|
||||
• **None** = ``0``
|
||||
|
||||
Silent output
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:279](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L279)
|
||||
[types.ts:287](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L287)
|
||||
|
||||
___
|
||||
|
||||
@@ -80,4 +68,16 @@ Warnings such as when file fails to replace token values properly in template.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:289](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L289)
|
||||
[types.ts:289](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L289)
|
||||
|
||||
___
|
||||
|
||||
### Error
|
||||
|
||||
• **Error** = ``4``
|
||||
|
||||
Errors, such as missing files, bad replacement token syntax, or un-writable directories.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:291](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L291)
|
||||
|
||||
@@ -14,7 +14,7 @@ custom_edit_url: null
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:337](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L337)
|
||||
[types.ts:337](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L337)
|
||||
|
||||
___
|
||||
|
||||
@@ -24,7 +24,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:342](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L342)
|
||||
[types.ts:342](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L342)
|
||||
|
||||
___
|
||||
|
||||
@@ -34,7 +34,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:335](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L335)
|
||||
[types.ts:335](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L335)
|
||||
|
||||
___
|
||||
|
||||
@@ -44,7 +44,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:336](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L336)
|
||||
[types.ts:336](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L336)
|
||||
|
||||
___
|
||||
|
||||
@@ -54,7 +54,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:341](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L341)
|
||||
[types.ts:341](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L341)
|
||||
|
||||
___
|
||||
|
||||
@@ -64,7 +64,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:345](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L345)
|
||||
[types.ts:345](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L345)
|
||||
|
||||
___
|
||||
|
||||
@@ -76,7 +76,7 @@ The key to use for the file which contains the template configurations.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:344](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L344)
|
||||
[types.ts:344](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L344)
|
||||
|
||||
___
|
||||
|
||||
@@ -89,7 +89,7 @@ accordingly.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:332](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L332)
|
||||
[types.ts:332](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L332)
|
||||
|
||||
___
|
||||
|
||||
@@ -99,7 +99,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:334](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L334)
|
||||
[types.ts:334](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L334)
|
||||
|
||||
___
|
||||
|
||||
@@ -109,7 +109,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:338](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L338)
|
||||
[types.ts:338](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L338)
|
||||
|
||||
___
|
||||
|
||||
@@ -119,7 +119,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:339](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L339)
|
||||
[types.ts:339](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L339)
|
||||
|
||||
___
|
||||
|
||||
@@ -129,7 +129,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:333](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L333)
|
||||
[types.ts:333](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L333)
|
||||
|
||||
___
|
||||
|
||||
@@ -139,4 +139,4 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:340](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L340)
|
||||
[types.ts:340](https://github.com/chenasraf/simple-scaffold/blob/8fcc7a1/src/types.ts#L340)
|
||||
|
||||
@@ -10,14 +10,65 @@ The config object for defining a scaffolding group.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [Node.js usage](https://chenasraf.github.io/simple-scaffold/pages/node.html)
|
||||
- [CLI usage](https://chenasraf.github.io/simple-scaffold/pages/cli.html)
|
||||
- [Node.js usage](https://chenasraf.github.io/simple-scaffold/docs/usage/node|)
|
||||
- [CLI usage](https://chenasraf.github.io/simple-scaffold/docs/usage/cli|)
|
||||
- [DefaultHelpers](../modules.md#defaulthelpers)
|
||||
- [CaseHelpers](../modules.md#casehelpers)
|
||||
- [DateHelpers](../modules.md#datehelpers)
|
||||
|
||||
## Properties
|
||||
|
||||
### name
|
||||
|
||||
• **name**: `string`
|
||||
|
||||
Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced
|
||||
accordingly.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:19](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L19)
|
||||
|
||||
___
|
||||
|
||||
### templates
|
||||
|
||||
• **templates**: `string`[]
|
||||
|
||||
Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path,
|
||||
or a glob pattern for multiple file matching easily.
|
||||
|
||||
**`Default`**
|
||||
|
||||
```ts
|
||||
Current working directory
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:27](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L27)
|
||||
|
||||
___
|
||||
|
||||
### output
|
||||
|
||||
• **output**: [`FileResponse`](../modules.md#fileresponse)\<`string`\>
|
||||
|
||||
Path to output to. If `createSubFolder` is `true`, the subfolder will be created inside this path.
|
||||
|
||||
May also be a [FileResponseHandler](../modules.md#fileresponsehandler) which returns a new output path to override the default one.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [FileResponse](../modules.md#fileresponse)
|
||||
- [FileResponseHandler](../modules.md#fileresponsehandler)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:37](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L37)
|
||||
|
||||
___
|
||||
|
||||
### createSubFolder
|
||||
|
||||
• `Optional` **createSubFolder**: `boolean`
|
||||
@@ -33,7 +84,7 @@ the directory name.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:47](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L47)
|
||||
[types.ts:47](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L47)
|
||||
|
||||
___
|
||||
|
||||
@@ -47,7 +98,72 @@ This can be any object that will be usable by Handlebars.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:54](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L54)
|
||||
[types.ts:54](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L54)
|
||||
|
||||
___
|
||||
|
||||
### overwrite
|
||||
|
||||
• `Optional` **overwrite**: [`FileResponse`](../modules.md#fileresponse)\<`boolean`\>
|
||||
|
||||
Enable to override output files, even if they already exist.
|
||||
|
||||
You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns
|
||||
a boolean for each file.
|
||||
|
||||
May also be a [FileResponseHandler](../modules.md#fileresponsehandler) which returns a boolean value per file.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [FileResponse](../modules.md#fileresponse)
|
||||
- [FileResponseHandler](../modules.md#fileresponsehandler)
|
||||
|
||||
**`Default`**
|
||||
|
||||
`false`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:69](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L69)
|
||||
|
||||
___
|
||||
|
||||
### quiet
|
||||
|
||||
• `Optional` **quiet**: `boolean`
|
||||
|
||||
Suppress output logs (Same as `verbose: 0` or `verbose: LogLevel.None`)
|
||||
|
||||
**`See`**
|
||||
|
||||
[verbose](ScaffoldConfig.md#verbose)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:75](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L75)
|
||||
|
||||
___
|
||||
|
||||
### verbose
|
||||
|
||||
• `Optional` **verbose**: [`LogLevel`](../enums/LogLevel.md)
|
||||
|
||||
Determine amount of logs to display.
|
||||
|
||||
The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages
|
||||
of the same level or higher.
|
||||
|
||||
**`See`**
|
||||
|
||||
[LogLevel](../enums/LogLevel.md)
|
||||
|
||||
**`Default`**
|
||||
|
||||
`2 (info)`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:87](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L87)
|
||||
|
||||
___
|
||||
|
||||
@@ -64,7 +180,7 @@ actual file contents or create directories.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:95](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L95)
|
||||
[types.ts:95](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L95)
|
||||
|
||||
___
|
||||
|
||||
@@ -115,81 +231,7 @@ Simple Scaffold uses Handlebars.js, so all the syntax from there is supported. S
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:137](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L137)
|
||||
|
||||
___
|
||||
|
||||
### name
|
||||
|
||||
• **name**: `string`
|
||||
|
||||
Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced
|
||||
accordingly.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:19](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L19)
|
||||
|
||||
___
|
||||
|
||||
### output
|
||||
|
||||
• **output**: [`FileResponse`](../modules.md#fileresponse)\<`string`\>
|
||||
|
||||
Path to output to. If `createSubFolder` is `true`, the subfolder will be created inside this path.
|
||||
|
||||
May also be a [FileResponseHandler](../modules.md#fileresponsehandler) which returns a new output path to override the default one.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [FileResponse](../modules.md#fileresponse)
|
||||
- [FileResponseHandler](../modules.md#fileresponsehandler)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:37](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L37)
|
||||
|
||||
___
|
||||
|
||||
### overwrite
|
||||
|
||||
• `Optional` **overwrite**: [`FileResponse`](../modules.md#fileresponse)\<`boolean`\>
|
||||
|
||||
Enable to override output files, even if they already exist.
|
||||
|
||||
You may supply a function to this option, which can take the arguments `(fullPath, baseDir, baseName)` and returns
|
||||
a boolean for each file.
|
||||
|
||||
May also be a [FileResponseHandler](../modules.md#fileresponsehandler) which returns a boolean value per file.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [FileResponse](../modules.md#fileresponse)
|
||||
- [FileResponseHandler](../modules.md#fileresponsehandler)
|
||||
|
||||
**`Default`**
|
||||
|
||||
`false`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:69](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L69)
|
||||
|
||||
___
|
||||
|
||||
### quiet
|
||||
|
||||
• `Optional` **quiet**: `boolean`
|
||||
|
||||
Suppress output logs (Same as `verbose: 0` or `verbose: LogLevel.None`)
|
||||
|
||||
**`See`**
|
||||
|
||||
[verbose](ScaffoldConfig.md#verbose)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:75](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L75)
|
||||
[types.ts:137](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L137)
|
||||
|
||||
___
|
||||
|
||||
@@ -209,49 +251,7 @@ transformation is done.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:148](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L148)
|
||||
|
||||
___
|
||||
|
||||
### templates
|
||||
|
||||
• **templates**: `string`[]
|
||||
|
||||
Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path,
|
||||
or a glob pattern for multiple file matching easily.
|
||||
|
||||
**`Default`**
|
||||
|
||||
```ts
|
||||
Current working directory
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:27](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L27)
|
||||
|
||||
___
|
||||
|
||||
### verbose
|
||||
|
||||
• `Optional` **verbose**: [`LogLevel`](../enums/LogLevel.md)
|
||||
|
||||
Determine amount of logs to display.
|
||||
|
||||
The values are: `0 (none) | 1 (debug) | 2 (info) | 3 (warn) | 4 (error)`. The provided level will display messages
|
||||
of the same level or higher.
|
||||
|
||||
**`See`**
|
||||
|
||||
[LogLevel](../enums/LogLevel.md)
|
||||
|
||||
**`Default`**
|
||||
|
||||
`2 (info)`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:87](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L87)
|
||||
[types.ts:148](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L148)
|
||||
|
||||
## Methods
|
||||
|
||||
@@ -282,4 +282,4 @@ contents-only, after further modifications - or `undefined` to use the original
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:164](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L164)
|
||||
[types.ts:164](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L164)
|
||||
|
||||
@@ -12,185 +12,8 @@ custom_edit_url: null
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [ScaffoldCmdConfig](interfaces/ScaffoldCmdConfig.md)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
|
||||
## Config
|
||||
|
||||
### FileResponse
|
||||
|
||||
Ƭ **FileResponse**\<`T`\>: `T` \| [`FileResponseHandler`](modules.md#fileresponsehandler)\<`T`\>
|
||||
|
||||
Represents a response for file path information.
|
||||
Can either be:
|
||||
|
||||
1. `T` - static value
|
||||
2. A function with the following signature which returns `T`:
|
||||
```typescript
|
||||
(fullPath: string, basedir: string, basename: string) => T
|
||||
```
|
||||
|
||||
**`See`**
|
||||
|
||||
[FileResponseHandler](modules.md#fileresponsehandler)
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name |
|
||||
| :------ |
|
||||
| `T` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:324](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L324)
|
||||
|
||||
___
|
||||
|
||||
### FileResponseHandler
|
||||
|
||||
Ƭ **FileResponseHandler**\<`T`\>: (`fullPath`: `string`, `basedir`: `string`, `basename`: `string`) => `T`
|
||||
|
||||
A function that takes path information about file, and returns a value of type `T`
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name | Description |
|
||||
| :------ | :------ |
|
||||
| `T` | The return type for the function |
|
||||
|
||||
#### Type declaration
|
||||
|
||||
▸ (`fullPath`, `basedir`, `basename`): `T`
|
||||
|
||||
##### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `fullPath` | `string` | The full path of the current file |
|
||||
| `basedir` | `string` | The directory containing the current file |
|
||||
| `basename` | `string` | The name of the file |
|
||||
|
||||
##### Returns
|
||||
|
||||
`T`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:306](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L306)
|
||||
|
||||
## Helpers
|
||||
|
||||
### CaseHelpers
|
||||
|
||||
Ƭ **CaseHelpers**: ``"camelCase"`` \| ``"hyphenCase"`` \| ``"kebabCase"`` \| ``"lowerCase"`` \| ``"pascalCase"`` \| ``"snakeCase"`` \| ``"startCase"`` \| ``"upperCase"``
|
||||
|
||||
The names of the available helper functions that relate to text capitalization.
|
||||
|
||||
These are available for `subfolderNameHelper`.
|
||||
|
||||
| Helper name | Example code | Example output |
|
||||
| ------------ | ----------------------- | -------------- |
|
||||
| [None] | `{{ name }}` | my name |
|
||||
| `camelCase` | `{{ camelCase name }}` | myName |
|
||||
| `snakeCase` | `{{ snakeCase name }}` | my_name |
|
||||
| `startCase` | `{{ startCase name }}` | My Name |
|
||||
| `kebabCase` | `{{ kebabCase name }}` | my-name |
|
||||
| `hyphenCase` | `{{ hyphenCase name }}` | my-name |
|
||||
| `pascalCase` | `{{ pascalCase name }}` | MyName |
|
||||
| `upperCase` | `{{ upperCase name }}` | MY NAME |
|
||||
| `lowerCase` | `{{ lowerCase name }}` | my name |
|
||||
|
||||
**`See`**
|
||||
|
||||
- [DefaultHelpers](modules.md#defaulthelpers)
|
||||
- [DateHelpers](modules.md#datehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
- [ScaffoldConfig.subFolderNameHelper](interfaces/ScaffoldConfig.md#subfoldernamehelper)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:195](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L195)
|
||||
|
||||
___
|
||||
|
||||
### DateHelpers
|
||||
|
||||
Ƭ **DateHelpers**: ``"date"`` \| ``"now"``
|
||||
|
||||
The names of the available helper functions that relate to dates.
|
||||
|
||||
| Helper name | Description | Example code | Example output |
|
||||
| -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
|
||||
| `now` | Current date with format | `{{ now "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `now` (with offset) | Current date with format, and with offset | `{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}` | `2042-01-01 14:00` |
|
||||
| `date` | Custom date with format | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `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` |
|
||||
| `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` |
|
||||
|
||||
Further details:
|
||||
|
||||
- We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want
|
||||
more information on the date tokens to use, refer to
|
||||
[their format documentation](https://date-fns.org/docs/format).
|
||||
|
||||
- The date helper format takes the following arguments:
|
||||
|
||||
```typescript
|
||||
(
|
||||
date: string,
|
||||
format: string,
|
||||
offsetAmount?: number,
|
||||
offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
|
||||
)
|
||||
```
|
||||
|
||||
- **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it is implicitly
|
||||
the current date.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [DefaultHelpers](modules.md#defaulthelpers)
|
||||
- [CaseHelpers](modules.md#casehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:242](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L242)
|
||||
|
||||
___
|
||||
|
||||
### DefaultHelpers
|
||||
|
||||
Ƭ **DefaultHelpers**: [`CaseHelpers`](modules.md#casehelpers) \| [`DateHelpers`](modules.md#datehelpers)
|
||||
|
||||
The names of all the available helper functions in templates.
|
||||
Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.
|
||||
|
||||
For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will
|
||||
replace `My Name` with `my_name` when producing the final value.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [CaseHelpers](modules.md#casehelpers)
|
||||
- [DateHelpers](modules.md#datehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:257](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L257)
|
||||
|
||||
___
|
||||
|
||||
### Helper
|
||||
|
||||
Ƭ **Helper**: `HelperDelegate`
|
||||
|
||||
Helper function, see https://handlebarsjs.com/guide/#custom-helpers
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:264](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L264)
|
||||
|
||||
## Main
|
||||
|
||||
### Scaffold
|
||||
@@ -239,96 +62,186 @@ A promise that resolves when the scaffold is complete
|
||||
|
||||
#### Defined in
|
||||
|
||||
[scaffold.ts:55](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/scaffold.ts#L55)
|
||||
[scaffold.ts:55](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/scaffold.ts#L55)
|
||||
|
||||
## Config
|
||||
|
||||
### FileResponseHandler
|
||||
|
||||
Ƭ **FileResponseHandler**\<`T`\>: (`fullPath`: `string`, `basedir`: `string`, `basename`: `string`) => `T`
|
||||
|
||||
A function that takes path information about file, and returns a value of type `T`
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name | Description |
|
||||
| :------ | :------ |
|
||||
| `T` | The return type for the function |
|
||||
|
||||
#### Type declaration
|
||||
|
||||
▸ (`fullPath`, `basedir`, `basename`): `T`
|
||||
|
||||
##### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `fullPath` | `string` | The full path of the current file |
|
||||
| `basedir` | `string` | The directory containing the current file |
|
||||
| `basename` | `string` | The name of the file |
|
||||
|
||||
##### Returns
|
||||
|
||||
`T`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:306](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L306)
|
||||
|
||||
___
|
||||
|
||||
### FileResponse
|
||||
|
||||
Ƭ **FileResponse**\<`T`\>: `T` \| [`FileResponseHandler`](modules.md#fileresponsehandler)\<`T`\>
|
||||
|
||||
Represents a response for file path information.
|
||||
Can either be:
|
||||
|
||||
1. `T` - static value
|
||||
2. A function with the following signature which returns `T`:
|
||||
```typescript
|
||||
(fullPath: string, basedir: string, basename: string) => T
|
||||
```
|
||||
|
||||
**`See`**
|
||||
|
||||
[FileResponseHandler](modules.md#fileresponsehandler)
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name |
|
||||
| :------ |
|
||||
| `T` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:324](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L324)
|
||||
|
||||
## Helpers
|
||||
|
||||
### CaseHelpers
|
||||
|
||||
Ƭ **CaseHelpers**: ``"camelCase"`` \| ``"hyphenCase"`` \| ``"kebabCase"`` \| ``"lowerCase"`` \| ``"pascalCase"`` \| ``"snakeCase"`` \| ``"startCase"`` \| ``"upperCase"``
|
||||
|
||||
The names of the available helper functions that relate to text capitalization.
|
||||
|
||||
These are available for `subfolderNameHelper`.
|
||||
|
||||
| Helper name | Example code | Example output |
|
||||
| ------------ | ----------------------- | -------------- |
|
||||
| [None] | `{{ name }}` | my name |
|
||||
| `camelCase` | `{{ camelCase name }}` | myName |
|
||||
| `snakeCase` | `{{ snakeCase name }}` | my_name |
|
||||
| `startCase` | `{{ startCase name }}` | My Name |
|
||||
| `kebabCase` | `{{ kebabCase name }}` | my-name |
|
||||
| `hyphenCase` | `{{ hyphenCase name }}` | my-name |
|
||||
| `pascalCase` | `{{ pascalCase name }}` | MyName |
|
||||
| `upperCase` | `{{ upperCase name }}` | MY NAME |
|
||||
| `lowerCase` | `{{ lowerCase name }}` | my name |
|
||||
|
||||
**`See`**
|
||||
|
||||
- [DefaultHelpers](modules.md#defaulthelpers)
|
||||
- [DateHelpers](modules.md#datehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
- [ScaffoldConfig.subFolderNameHelper](interfaces/ScaffoldConfig.md#subfoldernamehelper)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:195](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L195)
|
||||
|
||||
___
|
||||
|
||||
### DateHelpers
|
||||
|
||||
Ƭ **DateHelpers**: ``"date"`` \| ``"now"``
|
||||
|
||||
The names of the available helper functions that relate to dates.
|
||||
|
||||
| Helper name | Description | Example code | Example output |
|
||||
| -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
|
||||
| `now` | Current date with format | `{{ now "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `now` (with offset) | Current date with format, and with offset | `{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}` | `2042-01-01 14:00` |
|
||||
| `date` | Custom date with format | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `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` |
|
||||
| `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` |
|
||||
|
||||
Further details:
|
||||
|
||||
- We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want
|
||||
more information on the date tokens to use, refer to
|
||||
[their format documentation](https://date-fns.org/docs/format).
|
||||
|
||||
- The date helper format takes the following arguments:
|
||||
|
||||
```typescript
|
||||
(
|
||||
date: string,
|
||||
format: string,
|
||||
offsetAmount?: number,
|
||||
offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
|
||||
)
|
||||
```
|
||||
|
||||
- **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it is implicitly
|
||||
the current date.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [DefaultHelpers](modules.md#defaulthelpers)
|
||||
- [CaseHelpers](modules.md#casehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:242](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L242)
|
||||
|
||||
___
|
||||
|
||||
### DefaultHelpers
|
||||
|
||||
Ƭ **DefaultHelpers**: [`CaseHelpers`](modules.md#casehelpers) \| [`DateHelpers`](modules.md#datehelpers)
|
||||
|
||||
The names of all the available helper functions in templates.
|
||||
Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.js.
|
||||
|
||||
For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will
|
||||
replace `My Name` with `my_name` when producing the final value.
|
||||
|
||||
**`See`**
|
||||
|
||||
- [CaseHelpers](modules.md#casehelpers)
|
||||
- [DateHelpers](modules.md#datehelpers)
|
||||
- [ScaffoldConfig](interfaces/ScaffoldConfig.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:257](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L257)
|
||||
|
||||
___
|
||||
|
||||
### Helper
|
||||
|
||||
Ƭ **Helper**: `HelperDelegate`
|
||||
|
||||
Helper function, see https://handlebarsjs.com/guide/#custom-helpers
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:264](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L264)
|
||||
|
||||
## Other
|
||||
|
||||
### default
|
||||
|
||||
Renames and re-exports [Scaffold](modules.md#scaffold)
|
||||
|
||||
___
|
||||
|
||||
### AsyncResolver
|
||||
|
||||
Ƭ **AsyncResolver**\<`T`, `R`\>: [`Resolver`](modules.md#resolver)\<`T`, `Promise`\<`R`\> \| `R`\>
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `T` | `T` |
|
||||
| `R` | `T` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:373](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L373)
|
||||
|
||||
___
|
||||
|
||||
### ConfigLoadConfig
|
||||
|
||||
Ƭ **ConfigLoadConfig**: [`LogConfig`](modules.md#logconfig) & `Pick`\<[`ScaffoldCmdConfig`](interfaces/ScaffoldCmdConfig.md), ``"config"``\> & \{ `isRemote`: `boolean` }
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:379](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L379)
|
||||
|
||||
___
|
||||
|
||||
### LogConfig
|
||||
|
||||
Ƭ **LogConfig**: `Pick`\<[`ScaffoldConfig`](interfaces/ScaffoldConfig.md), ``"quiet"`` \| ``"verbose"``\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:376](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L376)
|
||||
|
||||
___
|
||||
|
||||
### MinimalConfig
|
||||
|
||||
Ƭ **MinimalConfig**: `Pick`\<[`ScaffoldCmdConfig`](interfaces/ScaffoldCmdConfig.md), ``"name"`` \| ``"key"``\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:382](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L382)
|
||||
|
||||
___
|
||||
|
||||
### Resolver
|
||||
|
||||
Ƭ **Resolver**\<`T`, `R`\>: `R` \| (`value`: `T`) => `R`
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `T` | `T` |
|
||||
| `R` | `T` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:370](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L370)
|
||||
|
||||
___
|
||||
|
||||
### ScaffoldConfigFile
|
||||
|
||||
Ƭ **ScaffoldConfigFile**: [`AsyncResolver`](modules.md#asyncresolver)\<[`ScaffoldCmdConfig`](interfaces/ScaffoldCmdConfig.md), [`ScaffoldConfigMap`](modules.md#scaffoldconfigmap)\>
|
||||
|
||||
The scaffold config file is either:
|
||||
- A [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A function that returns a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A promise that resolves to a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A function that returns a promise that resolves to a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:367](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L367)
|
||||
|
||||
___
|
||||
|
||||
### ScaffoldConfigMap
|
||||
|
||||
Ƭ **ScaffoldConfigMap**: `Record`\<`string`, [`ScaffoldConfig`](interfaces/ScaffoldConfig.md)\>
|
||||
@@ -347,4 +260,26 @@ When no template key is provided to the scaffold command, the "default" template
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:359](https://github.com/chenasraf/simple-scaffold/blob/3343df7/src/types.ts#L359)
|
||||
[types.ts:359](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L359)
|
||||
|
||||
___
|
||||
|
||||
### ScaffoldConfigFile
|
||||
|
||||
Ƭ **ScaffoldConfigFile**: `AsyncResolver`\<`ScaffoldCmdConfig`, [`ScaffoldConfigMap`](modules.md#scaffoldconfigmap)\>
|
||||
|
||||
The scaffold config file is either:
|
||||
- A [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A function that returns a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A promise that resolves to a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
- A function that returns a promise that resolves to a [ScaffoldConfigMap](modules.md#scaffoldconfigmap) object
|
||||
|
||||
#### Defined in
|
||||
|
||||
[types.ts:367](https://github.com/chenasraf/simple-scaffold/blob/d9508cd/src/types.ts#L367)
|
||||
|
||||
___
|
||||
|
||||
### default
|
||||
|
||||
Renames and re-exports [Scaffold](modules.md#scaffold)
|
||||
|
||||
@@ -14,7 +14,7 @@ To see this and more information anytime, add the `-h` or `--help` flag to your
|
||||
| Command \| alias | |
|
||||
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--help`\|`-h` | Display help information |
|
||||
| `--name`\|`-n` | Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced accordingly. |
|
||||
| `--name`\|`-n` | Name to be passed to the generated files. `{{name}}` and `{{Name}}` inside contents and file names will be replaced accordingly. |
|
||||
| `--config`\|`-c` | Filename or HTTPS git URL to load config from instead of passing arguments to CLI or using a Node.js script. |
|
||||
| `--github`\|`-gh` | GitHub path to load config from instead of passing arguments to CLI or using a Node.js script. |
|
||||
| `--key`\|`-k` | Key to load inside the config file. This overwrites the config key provided after the colon in --config (e.g. --config scaffold.cmd.js:component) |
|
||||
@@ -32,7 +32,7 @@ To see this and more information anytime, add the `-h` or `--help` flag to your
|
||||
## Examples:
|
||||
|
||||
> See
|
||||
> [Configuration Files](https://chenasraf.github.io/simple-scaffold/pages/docs/configuration_files.md)
|
||||
> [Configuration Files](https://chenasraf.github.io/simple-scaffold/docs/usage/configuration_files)
|
||||
> for organizing multiple scaffold types into easy-to-maintain files
|
||||
|
||||
Usage with config file
|
||||
|
||||
@@ -8,22 +8,23 @@ scaffolding configurations.
|
||||
|
||||
## Creating config files
|
||||
|
||||
Configuration files should be valid `.js`/`.json` files that contain valid Scaffold configurations.
|
||||
Configuration files should be valid `.js`/`.mjs`/`.cjs`/`.json` files that contain valid Scaffold
|
||||
configurations.
|
||||
|
||||
Each file hold multiple scaffolds. Each scaffold is a key, and its value is the configuration. For
|
||||
example:
|
||||
|
||||
```json
|
||||
{
|
||||
"component": {
|
||||
"templates": ["templates/component"],
|
||||
"output": "src/components"
|
||||
}
|
||||
```js
|
||||
module.exports = {
|
||||
component: {
|
||||
templates: ["templates/component"],
|
||||
output: "src/components",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
The configuration contents are identical to the
|
||||
[Node.js configuration structure](https://chenasraf.github.io/simple-scaffold/pages/node.md):
|
||||
[Node.js configuration structure](https://chenasraf.github.io/simple-scaffold/docs/usage/node):
|
||||
|
||||
```ts
|
||||
interface ScaffoldConfig {
|
||||
@@ -46,8 +47,8 @@ interface ScaffoldConfig {
|
||||
}
|
||||
```
|
||||
|
||||
If you want to supply functions inside the configurations, you must use a `.js` file as JSON does
|
||||
not support non-primitives.
|
||||
If you want to supply functions inside the configurations, you must use a `.js`/`.cjs`/`.mjs` file
|
||||
as JSON does not support non-primitives.
|
||||
|
||||
A `.js` file can be just like a `.json` file, make sure to export the final configuration:
|
||||
|
||||
@@ -62,7 +63,7 @@ module.exports = {
|
||||
```
|
||||
|
||||
Another feature of using a JS file is you can export a function which will be loaded with the CMD
|
||||
config provided to Simple Scaffold. The `extras` key contains any values not consumed by built-in
|
||||
config provided to Simple Scaffold. The `extra` key contains any values not consumed by built-in
|
||||
flags, so you can pre-process your args before outputting a config:
|
||||
|
||||
```js
|
||||
@@ -84,13 +85,13 @@ Once your config is created, you can use it by providing the file name to the `-
|
||||
for brevity), optionally alongside `--key` or `-k`, denoting the key to use as the config object, as
|
||||
you define in your config:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
simple-scaffold -c <file> -k <template_key>
|
||||
```
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
simple-scaffold -c scaffold.json -k component MyComponentName
|
||||
```
|
||||
|
||||
@@ -107,64 +108,55 @@ module.exports = {
|
||||
|
||||
And then:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
# will use 'default' template
|
||||
simple-scaffold -c scaffold.json MyComponentName
|
||||
```
|
||||
|
||||
- When the filename is omitted, the following files will be tried in order:
|
||||
|
||||
- `scaffold.config.*`
|
||||
- `scaffold.*`
|
||||
|
||||
Where `*` denotes any supported file extension, in the priority listed in
|
||||
[Supported file types](#supported-file-types)
|
||||
|
||||
- When the `template_key` is ommitted, `default` will be used as default.
|
||||
|
||||
### Supported file types
|
||||
|
||||
Any importable file is supported, depending on your build process.
|
||||
|
||||
Common files include:
|
||||
|
||||
- `*.json`
|
||||
- `*.js`
|
||||
- `*.mjs`
|
||||
- `*.cjs`
|
||||
- `*.js`
|
||||
- `*.json`
|
||||
|
||||
When filenames are ommited when loading configs, these are the file extensions that will be
|
||||
automatically tried, by the specified order of priority.
|
||||
|
||||
Note that you might need to find the correct extension of `.js`, `.cjs` or `.mjs` depending on your
|
||||
build process and your package type (for example, packages with `"type": "module"` in their
|
||||
`package.json` might be required to use `.mjs`.
|
||||
`package.json` might be required to use `.mjs`.)
|
||||
|
||||
## Remote Templates
|
||||
### Git/GitHub Templates
|
||||
|
||||
You can load template groups remotely, similar to how you would pass a config normally.
|
||||
You may specify a git or GitHub url to use remote templates.
|
||||
|
||||
The main difference is the templates will be hosted on a remote location such as a git server, and
|
||||
not locally in your project. This can be done to easily share & reuse templates.
|
||||
The command line option is `--git` or `-g`.
|
||||
|
||||
When passing a git URL to `--config`, you will clone that repo and use the files there as template.
|
||||
- You may specify a full git or HTTPS git URL, which will be tried
|
||||
- You may specify a git username and project if the project is on GitHub
|
||||
|
||||
The syntax is as follows:
|
||||
```sh
|
||||
# GitHub shorthand
|
||||
simple-scaffold -gh <username>/<project_name> [-c <filename>] [-k <template_key>]
|
||||
|
||||
```shell
|
||||
simple-scaffold -c <git_url>[#<git_file>] [-k <template_key>]
|
||||
```
|
||||
|
||||
For example, to use this repository's example as base:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c https://github.com/chenasraf/simple-scaffold.git#scaffold.config.js -k component
|
||||
```
|
||||
|
||||
When the `filename` is omitted, `/scaffold.config.js` will be used as default.
|
||||
|
||||
When the `template_key` is ommitted, `default` will be used as default.
|
||||
|
||||
### GitHub Templates
|
||||
|
||||
As a shorter alternative to the above example, you can use `--github` or `-gh` to reference a GitHub
|
||||
URL without specifying the whole path.
|
||||
|
||||
The syntax is as follows:
|
||||
|
||||
```shell
|
||||
simple-scaffold -gh <username>/<project_name>[#<git_file>] [-k <template_key>]
|
||||
```
|
||||
|
||||
This example is equivalent to the above, just shorter to write:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c chenasraf/simple-scaffold#scaffold.config.js -k component
|
||||
# Any git URL, git:// and https:// are supported
|
||||
simple-scaffold -g git://gitlab.com/<username>/<project_name> [-c <filename>] [-k <template_key>]
|
||||
simple-scaffold -g https://gitlab.com/<username>/<project_name>.git [-c <filename>] [-k <template_key>]
|
||||
```
|
||||
|
||||
## Use In Node.js
|
||||
|
||||
141
docs/docs/usage/examples.md
Normal file
141
docs/docs/usage/examples.md
Normal file
@@ -0,0 +1,141 @@
|
||||
---
|
||||
title: Examples
|
||||
---
|
||||
|
||||
## Example files
|
||||
|
||||
### Input
|
||||
|
||||
- Input file path:
|
||||
|
||||
```text
|
||||
project → scaffold → {{Name}}.js → src → components
|
||||
```
|
||||
|
||||
- Input file contents:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Author: {{ author }}
|
||||
* Date: {{ now "yyyy-MM-dd" }}
|
||||
*/
|
||||
import React from 'react'
|
||||
|
||||
export default {{camelCase name}}: React.FC = (props) => {
|
||||
return (
|
||||
<div className="{{className}}">{{camelCase name}} Component</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
- Output file path:
|
||||
|
||||
- With `createSubFolder = false` (default):
|
||||
|
||||
```text
|
||||
project → src → components → MyComponent.js
|
||||
```
|
||||
|
||||
- With `createSubFolder = true`:
|
||||
|
||||
```text
|
||||
project → src → components → MyComponent → MyComponent.js
|
||||
```
|
||||
|
||||
- With `createSubFolder = true` and `subFolderNameHelper = 'upperCase'`:
|
||||
|
||||
```text
|
||||
project → src → components → MYCOMPONENT → MyComponent.js
|
||||
```
|
||||
|
||||
- Output file contents:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Author: My Name
|
||||
* Date: 2077-01-01
|
||||
*/
|
||||
import React from 'react'
|
||||
|
||||
export default MyComponent: React.FC = (props) => {
|
||||
return (
|
||||
<div className="myClassName">MyComponent Component</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Example run commands
|
||||
|
||||
### Command Example
|
||||
|
||||
```bash
|
||||
simple-scaffold \
|
||||
-t project/scaffold/**/* \
|
||||
-o src/components \
|
||||
-d '{"className": "myClassName","author": "My Name"}'
|
||||
MyComponent
|
||||
```
|
||||
|
||||
### Equivalent Node Module Example
|
||||
|
||||
```typescript
|
||||
import Scaffold from "simple-scaffold"
|
||||
|
||||
async function main() {
|
||||
await Scaffold({
|
||||
name: "MyComponent",
|
||||
templates: ["project/scaffold/**/*"],
|
||||
output: ["src/components"],
|
||||
data: {
|
||||
className: "myClassName",
|
||||
author: "My Name",
|
||||
},
|
||||
})
|
||||
console.log("Done.")
|
||||
}
|
||||
```
|
||||
|
||||
### Re-usable config
|
||||
|
||||
#### Shell
|
||||
|
||||
```bash
|
||||
# cjs
|
||||
simple-scaffold -c scaffold.cjs MyComponent \
|
||||
-d '{"className": "myClassName","author": "My Name"}'
|
||||
# mjs
|
||||
simple-scaffold -c scaffold.mjs MyComponent \
|
||||
-d '{"className": "myClassName","author": "My Name"}'
|
||||
```
|
||||
|
||||
#### scaffold.cjs
|
||||
|
||||
```js
|
||||
module.exports = (config) => ({
|
||||
default: {
|
||||
templates: ["project/scaffold/**/*"],
|
||||
output: ["src/components"],
|
||||
data: {
|
||||
className: "myClassName",
|
||||
author: "My Name",
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
#### scaffold.mjs
|
||||
|
||||
```js
|
||||
export default (config) => ({
|
||||
default: {
|
||||
templates: ["project/scaffold/**/*"],
|
||||
output: ["src/components"],
|
||||
data: {
|
||||
className: "myClassName",
|
||||
author: "My Name",
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
@@ -4,18 +4,30 @@ title: Migration
|
||||
|
||||
## v1.x to v2.x
|
||||
|
||||
### CLI option changes
|
||||
|
||||
- The `:template_key` syntax has been removed. You can still use `-k template_key` to achieve the
|
||||
same result.
|
||||
- Several changes to how remote configs are loaded via CLI:
|
||||
- The `--github` (`-gh`) flag has been replaced by a generic `--git` (`-g`) one, which handles any
|
||||
git URL. Providing a partial GitHub path will default to trying to find the project on GitHub,
|
||||
e.g. `-g username/project`
|
||||
- The `#template_file` syntax has been removed, you may use `--config` or `-c` to tell Simple
|
||||
Scaffold which file to look for inside the git project. There is a default file priority list
|
||||
which can find the file for you if it is in one of the supported filenames.
|
||||
- `verbose` can now take the names `debug`, `info`, `warn`, `error` or `none` (case insensitive) or
|
||||
as usual by using the numbering from before.
|
||||
- All boolean flags no longer take a value. `-q` instead of `-q 1` or `-q true`, `-s` instead of
|
||||
`-s 1`, `-w` instead of `-w 1`, etc.
|
||||
|
||||
### Behavior changes
|
||||
|
||||
- Data is no longer auto-populated with `Name` (PascalCase) by default. You can just use the helper
|
||||
in your templates contents and file names, simply use `{{ pascalCase name }}` instead of
|
||||
`{{ Name }}`. `Name` was arbitrary and it is confusing (is it `Title Case`? `PascalCase`? only
|
||||
reading the docs can tell). Alternatively, you can inject the transformed name into your `data`
|
||||
manually using a scaffold config file, by using the Node API or by appending the data to the CLI
|
||||
invocation.
|
||||
- `verbose` can now take the names `debug`, `info`, `warn`, `error` or `none` (case insensitive) or
|
||||
as usual by using the numbering from before.
|
||||
- All boolean flags no longer take a value. `-q` instead of `-q 1` or `-q true`, `-s` instead of
|
||||
`-s 1`, `-w` instead of `-w 1`, etc.
|
||||
|
||||
## v0.x to v1.x
|
||||
|
||||
|
||||
@@ -37,6 +37,21 @@ const config: Config = {
|
||||
{
|
||||
entryPoints: ["../src/index.ts"],
|
||||
tsconfig: "../tsconfig.json",
|
||||
|
||||
// typedoc options
|
||||
watch: process.env.NODE_ENV === "development",
|
||||
excludePrivate: true,
|
||||
excludeProtected: true,
|
||||
excludeInternal: true,
|
||||
// includeVersion: true,
|
||||
categorizeByGroup: false,
|
||||
sort: ["visibility"],
|
||||
categoryOrder: ["Main", "*"],
|
||||
media: "media",
|
||||
entryPointStrategy: "expand",
|
||||
validation: {
|
||||
invalidLink: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
"cmd": "node --trace-warnings dist/cmd.js",
|
||||
"build-test": "pnpm build && pnpm test",
|
||||
"build-cmd": "pnpm build && pnpm cmd",
|
||||
"build-docs": "typedoc",
|
||||
"watch-docs": "pnpm typedoc --watch",
|
||||
"build-docs": "cd docs && pnpm build",
|
||||
"watch-docs": "cd docs && pnpm start",
|
||||
"audit-fix": "pnpm audit --fix",
|
||||
"changelog": "conventional-changelog -i CHANGELOG.md -s -r 0; echo \"# Change Log\n\n$(cat CHANGELOG.md)\" > CHANGELOG.md"
|
||||
},
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
See full documentation [here](https://chenasraf.github.io/simple-scaffold).
|
||||
|
||||
- [Command Line Interface (CLI) usage](https://chenasraf.github.io/simple-scaffold/pages/cli.html)
|
||||
- [Node.js usage](https://chenasraf.github.io/simple-scaffold/pages/node.html)
|
||||
- [Templates](https://chenasraf.github.io/simple-scaffold/pages/templates.html)
|
||||
- [Configuration Files](https://chenasraf.github.io/simple-scaffold/pages/configuration_files.html)
|
||||
- [Migrating between major versions](https://chenasraf.github.io/simple-scaffold/pages/migration.html)
|
||||
79
pages/cli.md
79
pages/cli.md
@@ -1,79 +0,0 @@
|
||||
## Available flags
|
||||
|
||||
```text
|
||||
Usage: simple-scaffold [options]
|
||||
```
|
||||
|
||||
To see this and more information anytime, add the `-h` or `--help` flag to your call, e.g.
|
||||
`npx simple-scaffold@latest -h`.
|
||||
|
||||
| Command \| alias | |
|
||||
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--help`\|`-h` | Display help information |
|
||||
| `--name`\|`-n` | Name to be passed to the generated files. {{name}} and {{Name}} inside contents and file names will be replaced accordingly. |
|
||||
| `--config`\|`-c` | Filename or HTTPS git URL to load config from instead of passing arguments to CLI or using a Node.js script. |
|
||||
| `--github`\|`-gh` | GitHub path to load config from instead of passing arguments to CLI or using a Node.js script. |
|
||||
| `--key`\|`-k` | Key to load inside the config file. This overwrites the config key provided after the colon in --config (e.g. --config scaffold.cmd.js:component) |
|
||||
| `--output`\|`-o` | Path to output to. If --create-sub-folder is enabled, the subfolder will be created inside this path. (default: current dir) |
|
||||
| `--templates`\|`-t` | Template files to use as input. You may provide multiple files, each of which can be a relative or absolute path, or a glob pattern for multiple file matching easily. |
|
||||
| `--overwrite`\|`-w` | Enable to override output files, even if they already exist. (default: false) |
|
||||
| `--data`\|`-d` | Add custom data to the templates. By default, only your app name is included. |
|
||||
| `--append-data`\|`-D` | 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 |
|
||||
| `--create-sub-folder`\|`-s` | Create subfolder with the input name (default: false) |
|
||||
| `--sub-folder-name-helper`\|`-sh` | Default helper to apply to subfolder name when using `--create-sub-folder true`. |
|
||||
| `--quiet`\|`-q` | Suppress output logs (Same as --log-level 0) (default: false) |
|
||||
| `--log-level`\|`-v` | Determine amount of logs to display. The values are: 0 (none) \| 1 (debug) \| 2 (info) \| 3 (warn) \| 4 (error). The provided level will display messages of the same level or higher. (default: 2) |
|
||||
| `--dry-run`\|`-dr` | Don't emit files. This is good for testing your scaffolds and making sure they don't fail, without having to write actual file contents or create directories. (default: false) |
|
||||
|
||||
## Examples:
|
||||
|
||||
> See
|
||||
> [Configuration Files](https://chenasraf.github.io/simple-scaffold/pages/docs/configuration_files.md)
|
||||
> for organizing multiple scaffold types into easy-to-maintain files
|
||||
|
||||
Usage with config file
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -c scaffold.cmd.js --key component
|
||||
```
|
||||
|
||||
Usage with GitHub config file
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -gh chenasraf/simple-scaffold --key component
|
||||
```
|
||||
|
||||
Usage with https git URL (for non-GitHub)
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -c \
|
||||
https://example.com/user/template.git#scaffold.cmd.js --key component
|
||||
```
|
||||
|
||||
Full syntax with config path and template key (applicable to all above methods)
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -c scaffold.cmd.js:component MyComponent
|
||||
```
|
||||
|
||||
Excluded template key, assumes 'default' key
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -c scaffold.cmd.js MyComponent
|
||||
```
|
||||
|
||||
Shortest syntax for GitHub, assumes file 'scaffold.cmd.js' and template key 'default'
|
||||
|
||||
```shell
|
||||
$ simple-scaffold -gh chenasraf/simple-scaffold MyComponent
|
||||
```
|
||||
|
||||
You can also add this as a script in your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"scaffold": "npx simple-scaffold@latest -t scaffolds/component/**/* -o src/components -d '{\"myProp\": \"propName\", \"myVal\": 123}'"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1,183 +0,0 @@
|
||||
If you want to have reusable configurations which are complex and don't fit into command lines
|
||||
easily, or just want to manage your templates easier, you can use configuration files to load your
|
||||
scaffolding configurations.
|
||||
|
||||
## Creating config files
|
||||
|
||||
Configuration files should be valid `.js`/`.json` files that contain valid Scaffold configurations.
|
||||
|
||||
Each file hold multiple scaffolds. Each scaffold is a key, and its value is the configuration. For
|
||||
example:
|
||||
|
||||
```json
|
||||
{
|
||||
"component": {
|
||||
"templates": ["templates/component"],
|
||||
"output": "src/components"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The configuration contents are identical to the [Node.js configuration structure](./node):
|
||||
|
||||
```ts
|
||||
interface ScaffoldConfig {
|
||||
name: string
|
||||
templates: string[]
|
||||
output: FileResponse<string>
|
||||
createSubFolder?: boolean
|
||||
data?: Record<string, any>
|
||||
overwrite?: FileResponse<boolean>
|
||||
logLevel?: LogLevel
|
||||
dryRun?: boolean
|
||||
helpers?: Record<string, Helper>
|
||||
subFolderNameHelper?: DefaultHelpers | string
|
||||
beforeWrite?(
|
||||
content: Buffer,
|
||||
rawContent: Buffer,
|
||||
outputPath: string,
|
||||
): string | Buffer | undefined | Promise<string | Buffer | undefined>
|
||||
}
|
||||
```
|
||||
|
||||
If you want to supply functions inside the configurations, you must use a `.js` file as JSON does
|
||||
not support non-primitives.
|
||||
|
||||
A `.js` file can be just like a `.json` file, make sure to export the final configuration:
|
||||
|
||||
```js
|
||||
/** @type {import('simple-scaffold').ScaffoldConfigFile} */
|
||||
module.exports = {
|
||||
component: {
|
||||
templates: ["templates/component"],
|
||||
output: "src/components",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
Another feature of using a JS file is you can export a function which will be loaded with the CMD
|
||||
config provided to Simple Scaffold. The `extras` key contains any values not consumed by built-in
|
||||
flags, so you can pre-process your args before outputting a config:
|
||||
|
||||
```js
|
||||
/** @type {import('simple-scaffold').ScaffoldConfigFile} */
|
||||
module.exports = (config) => {
|
||||
console.log("Config:", config)
|
||||
return {
|
||||
component: {
|
||||
templates: ["templates/component"],
|
||||
output: "src/components",
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using a config file
|
||||
|
||||
Once your config is created, you can use it by providing the file name to the `--config` (or `-c`
|
||||
for brevity), optionally alongside `--key` or `-k`, denoting the key to use as the config object, as
|
||||
you define in your config:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c <file> -k <template_key>
|
||||
```
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c scaffold.json -k component MyComponentName
|
||||
```
|
||||
|
||||
If you don't want to supply a template/config name (e.g. `component`), `default` will be used:
|
||||
|
||||
```js
|
||||
/** @type {import('simple-scaffold').ScaffoldConfigFile} */
|
||||
module.exports = {
|
||||
default: {
|
||||
// ...
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
And then:
|
||||
|
||||
```shell
|
||||
# will use 'default' template
|
||||
simple-scaffold -c scaffold.json MyComponentName
|
||||
```
|
||||
|
||||
Any importable file is supported, depending on your build process.
|
||||
|
||||
Common files include:
|
||||
|
||||
- `*.json`
|
||||
- `*.js`
|
||||
- `*.mjs`
|
||||
- `*.cjs`
|
||||
|
||||
Note that you might need to find the correct extension of `.js`, `.cjs` or `.mjs` depending on your
|
||||
build process and your package type (for example, packages with `"type": "module"` in their
|
||||
`package.json` might be required to use `.mjs`.
|
||||
|
||||
## Remote Templates
|
||||
|
||||
You can load template groups remotely, similar to how you would pass a config normally.
|
||||
|
||||
The main difference is the templates will be hosted on a remote location such as a git server, and
|
||||
not locally in your project. This can be done to easily share & reuse templates.
|
||||
|
||||
When passing a git URL to `--config`, you will clone that repo and use the files there as template.
|
||||
|
||||
The syntax is as follows:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c <git_url>[#<git_file>] [-k <template_key>]
|
||||
```
|
||||
|
||||
For example, to use this repository's example as base:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c https://github.com/chenasraf/simple-scaffold.git#scaffold.config.js -k component
|
||||
```
|
||||
|
||||
When the `filename` is omitted, `/scaffold.config.js` will be used as default.
|
||||
|
||||
When the `template_key` is ommitted, `default` will be used as default.
|
||||
|
||||
### GitHub Templates
|
||||
|
||||
As a shorter alternative to the above example, you can use `--github` or `-gh` to reference a GitHub
|
||||
URL without specifying the whole path.
|
||||
|
||||
The syntax is as follows:
|
||||
|
||||
```shell
|
||||
simple-scaffold -gh <username>/<project_name>[#<git_file>] [-k <template_key>]
|
||||
```
|
||||
|
||||
This example is equivalent to the above, just shorter to write:
|
||||
|
||||
```shell
|
||||
simple-scaffold -c chenasraf/simple-scaffold#scaffold.config.js -k component
|
||||
```
|
||||
|
||||
## Use In Node.js
|
||||
|
||||
You can also start a scaffold from Node.js with a remote file or URL config.
|
||||
|
||||
Just use the `Scaffold.fromConfig` function:
|
||||
|
||||
```ts
|
||||
Scaffold.fromConfig(
|
||||
"scaffold.config.js", // file or HTTPS git URL
|
||||
{
|
||||
// name of the generated component
|
||||
name: "My Component",
|
||||
// key to load from the config
|
||||
key: "component",
|
||||
},
|
||||
{
|
||||
// other config overrides
|
||||
},
|
||||
)
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
# v1.x to v2.x
|
||||
|
||||
- The `:template_key` syntax has been removed. You can still use `-k template_key` to achieve the
|
||||
same result.
|
||||
- Data is no longer auto-populated with `Name` (PascalCase) by default. You can just use the helper
|
||||
in your templates contents and file names, simply use `{{ pascalCase name }}` instead of
|
||||
`{{ Name }}`. `Name` was arbitrary and it is confusing (is it `Title Case`? `PascalCase`? only
|
||||
reading the docs can tell). Alternatively, you can inject the transformed name into your `data`
|
||||
manually using a scaffold config file, by using the Node API or by appending the data to the CLI
|
||||
invocation.
|
||||
- `verbose` has been renamed to `log-level`, and now takes the names `debug`, `info`, `warn`,
|
||||
`error` or `none` (case insensitive) instead of using the numbering from before.
|
||||
- All boolean flags no longer take a value. `-q` instead of `-q 1` or `-q true`, `-s` instead of
|
||||
`-s 1`, `-w` instead of `-w 1`, etc.
|
||||
|
||||
# v0.x to v1.x
|
||||
|
||||
In Simple Scaffold v1.0, the entire codebase was overhauled, yet usage remains mostly the same
|
||||
between versions. With these notable exceptions:
|
||||
|
||||
- Some of the argument names have changed
|
||||
- Template syntax has been improved
|
||||
- The command to run Scaffold has been simplified from `new SimpleScaffold(opts).run()` to
|
||||
`SimpleScaffold(opts)`, which now returns a promise that you can await to know when the process
|
||||
has been completed.
|
||||
|
||||
## Argument changes
|
||||
|
||||
- `locals` has been renamed to `data`. The appropriate command line args have been updated as well
|
||||
to `--data` | `-d`.
|
||||
- Additional options have been added to both CLI and Node interfaces. See
|
||||
[Command Line Interface (CLI) usage](https://chenasraf.github.io/simple-scaffold/pages/cli.html)
|
||||
and [Node.js usage](https://chenasraf.github.io/simple-scaffold/pages/node.html) for more
|
||||
information.
|
||||
|
||||
## Template syntax changes
|
||||
|
||||
Simple Scaffold still uses Handlebars.js to handle template content and file names. However, helpers
|
||||
have been added to remove the need for you to pre-process the template data on simple use-cases such
|
||||
as case type manipulation (converting to camel case, snake case, etc)
|
||||
|
||||
See the readme for the full information on how to use these helpers and which are available.
|
||||
@@ -1,52 +0,0 @@
|
||||
You can build the scaffold yourself, if you want to create more complex arguments, scaffold groups,
|
||||
etc - simply pass a config object to the Scaffold function when you are ready to start.
|
||||
|
||||
The config takes similar arguments to the command line. The full type definitions can be found in
|
||||
[src/types.ts](https://github.com/chenasraf/simple-scaffold/blob/develop/src/types.ts#L13).
|
||||
|
||||
See the full
|
||||
[documentation](https://chenasraf.github.io/simple-scaffold/interfaces/ScaffoldConfig.html) for the
|
||||
configuration options and their behavior.
|
||||
|
||||
```ts
|
||||
interface ScaffoldConfig {
|
||||
name: string
|
||||
templates: string[]
|
||||
output: FileResponse<string>
|
||||
createSubFolder?: boolean
|
||||
data?: Record<string, any>
|
||||
overwrite?: FileResponse<boolean>
|
||||
logLevel?: LogLevel
|
||||
dryRun?: boolean
|
||||
helpers?: Record<string, Helper>
|
||||
subFolderNameHelper?: DefaultHelpers | string
|
||||
beforeWrite?(
|
||||
content: Buffer,
|
||||
rawContent: Buffer,
|
||||
outputPath: string,
|
||||
): string | Buffer | undefined | Promise<string | Buffer | undefined>
|
||||
}
|
||||
```
|
||||
|
||||
This is an example of loading a complete scaffold via Node.js:
|
||||
|
||||
```typescript
|
||||
import Scaffold from "simple-scaffold"
|
||||
|
||||
const config = {
|
||||
name: "component",
|
||||
templates: [path.join(__dirname, "scaffolds", "component")],
|
||||
output: path.join(__dirname, "src", "components"),
|
||||
createSubFolder: true,
|
||||
subFolderNameHelper: "upperCase"
|
||||
data: {
|
||||
property: "value",
|
||||
},
|
||||
helpers: {
|
||||
twice: (text) => [text, text].join(" ")
|
||||
},
|
||||
beforeWrite: (content, rawContent, outputPath) => content.toString().toUpperCase()
|
||||
}
|
||||
|
||||
const scaffold = Scaffold(config)
|
||||
```
|
||||
@@ -1,224 +0,0 @@
|
||||
# Preparing template files
|
||||
|
||||
Put your template files anywhere, and fill them with tokens for replacement.
|
||||
|
||||
Each template (not file) in the config array is parsed individually, and copied to the output
|
||||
directory. If a single template path contains multiple files (e.g. if you use a folder path or a
|
||||
glob pattern), the first directory up the tree of that template will become the base inside the
|
||||
defined output path for that template, while copying files recursively and maintaining their
|
||||
relative structure.
|
||||
|
||||
Examples:
|
||||
|
||||
> In the following examples, the config `name` is `AppName`, and the config `output` is `src`.
|
||||
|
||||
| Input template | Files in template | Output path(s) |
|
||||
| ----------------------------- | ------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| `./templates/{{ name }}.txt` | `./templates/{{ name }}.txt` | `src/AppName.txt` |
|
||||
| `./templates/directory` | `outer/{{name}}.txt`,<br />`outer2/inner/{{name}}.txt` | `src/outer/AppName.txt`,<br />`src/outer2/inner/AppName.txt` |
|
||||
| `./templates/others/**/*.txt` | `outer/{{name}}.jpg`,<br />`outer2/inner/{{name}}.txt` | `src/outer2/inner/AppName.txt` |
|
||||
|
||||
## Variable/token replacement
|
||||
|
||||
Scaffolding will replace `{{ varName }}` in both the file name and its contents and put the
|
||||
transformed files in the output directory.
|
||||
|
||||
The data available for the template parser is the data you pass to the `data` config option (or
|
||||
`--data` argument in CLI).
|
||||
|
||||
For example, using the following command:
|
||||
|
||||
```bash
|
||||
npx simple-scaffold@latest \
|
||||
--templates templates/components/{{name}}.jsx \
|
||||
--output src/components \
|
||||
--create-sub-folder true \
|
||||
MyComponent
|
||||
```
|
||||
|
||||
Will output a file with the path:
|
||||
|
||||
```text
|
||||
<working_dir>/src/components/MyComponent.jsx
|
||||
```
|
||||
|
||||
The contents of the file will be transformed in a similar fashion.
|
||||
|
||||
Your `data` will be pre-populated with the following:
|
||||
|
||||
- `{{Name}}`: PascalCase of the component name
|
||||
- `{{name}}`: raw name of the component as you entered it
|
||||
|
||||
> Simple-Scaffold uses [Handlebars.js](https://handlebarsjs.com/) for outputting the file contents.
|
||||
> Any `data` you add in the config will be available for use with their names wrapped in `{{` and
|
||||
> `}}`. Other Handlebars built-ins such as `each`, `if` and `with` are also supported, see
|
||||
> [Handlebars.js Language Features](https://handlebarsjs.com/guide/#language-features) for more
|
||||
> information.
|
||||
|
||||
## Helpers
|
||||
|
||||
### Built-in Helpers
|
||||
|
||||
Simple-Scaffold provides some built-in text transformation filters usable by Handlebars.
|
||||
|
||||
For example, you may use `{{ snakeCase name }}` inside a template file or filename, and it will
|
||||
replace `My Name` with `my_name` when producing the final value.
|
||||
|
||||
#### Capitalization Helpers
|
||||
|
||||
| Helper name | Example code | Example output |
|
||||
| ------------ | ----------------------- | -------------- |
|
||||
| [None] | `{{ name }}` | my name |
|
||||
| `camelCase` | `{{ camelCase name }}` | myName |
|
||||
| `snakeCase` | `{{ snakeCase name }}` | my_name |
|
||||
| `startCase` | `{{ startCase name }}` | My Name |
|
||||
| `kebabCase` | `{{ kebabCase name }}` | my-name |
|
||||
| `hyphenCase` | `{{ hyphenCase name }}` | my-name |
|
||||
| `pascalCase` | `{{ pascalCase name }}` | MyName |
|
||||
| `upperCase` | `{{ upperCase name }}` | MY NAME |
|
||||
| `lowerCase` | `{{ lowerCase name }}` | my name |
|
||||
|
||||
#### Date helpers
|
||||
|
||||
| Helper name | Description | Example code | Example output |
|
||||
| -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
|
||||
| `now` | Current date with format | `{{ now "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `now` (with offset) | Current date with format, and with offset | `{{ now "yyyy-MM-dd HH:mm" -1 "hours" }}` | `2042-01-01 14:00` |
|
||||
| `date` | Custom date with format | `{{ date "2042-01-01T15:00:00Z" "yyyy-MM-dd HH:mm" }}` | `2042-01-01 15:00` |
|
||||
| `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` |
|
||||
| `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` |
|
||||
|
||||
Further details:
|
||||
|
||||
- We use [`date-fns`](https://date-fns.org/docs/) for parsing/manipulating the dates. If you want
|
||||
more information on the date tokens to use, refer to
|
||||
[their format documentation](https://date-fns.org/docs/format).
|
||||
|
||||
- The date helper format takes the following arguments:
|
||||
|
||||
```typescript
|
||||
(
|
||||
date: string,
|
||||
format: string,
|
||||
offsetAmount?: number,
|
||||
offsetType?: "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"
|
||||
)
|
||||
```
|
||||
|
||||
- **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as it
|
||||
is implicitly the current date.
|
||||
|
||||
### Custom Helpers
|
||||
|
||||
You may also add your own custom helpers using the `helpers` options when using the JS API (rather
|
||||
than the CLI). The `helpers` option takes an object whose keys are helper names, and values are the
|
||||
transformation functions. For example, `upperCase` is implemented like so:
|
||||
|
||||
```typescript
|
||||
config.helpers = {
|
||||
upperCase: (text) => text.toUpperCase(),
|
||||
}
|
||||
```
|
||||
|
||||
All of the above helpers (built in and custom) will also be available to you when using
|
||||
`subFolderNameHelper` (`--sub-folder-name-helper`/`-sh`) as a possible value.
|
||||
|
||||
> To see more information on how helpers work and more features, see
|
||||
> [Handlebars.js docs](https://handlebarsjs.com/guide/#custom-helpers).
|
||||
|
||||
# Examples
|
||||
|
||||
## Run
|
||||
|
||||
### Command Example
|
||||
|
||||
```bash
|
||||
simple-scaffold MyComponent \
|
||||
-t project/scaffold/**/* \
|
||||
-o src/components \
|
||||
-d '{"className": "myClassName","author": "Chen Asraf"}'
|
||||
MyComponent
|
||||
```
|
||||
|
||||
### Equivalent Node Module Example
|
||||
|
||||
```typescript
|
||||
import Scaffold from "simple-scaffold"
|
||||
|
||||
async function main() {
|
||||
await Scaffold({
|
||||
name: "MyComponent",
|
||||
templates: ["project/scaffold/**/*"],
|
||||
output: ["src/components"],
|
||||
data: {
|
||||
className: "myClassName",
|
||||
author: "Chen Asraf",
|
||||
},
|
||||
})
|
||||
console.log("Done.")
|
||||
}
|
||||
```
|
||||
|
||||
## Files
|
||||
|
||||
### Input
|
||||
|
||||
- Input file path:
|
||||
|
||||
```text
|
||||
project → scaffold → {{Name}}.js → src → components
|
||||
```
|
||||
|
||||
- Input file contents:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Author: {{ author }}
|
||||
* Date: {{ now "yyyy-MM-dd" }}
|
||||
*/
|
||||
import React from 'react'
|
||||
|
||||
export default {{camelCase name}}: React.FC = (props) => {
|
||||
return (
|
||||
<div className="{{className}}">{{camelCase name}} Component</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
- Output file path:
|
||||
|
||||
- With `createSubFolder = false` (default):
|
||||
|
||||
```text
|
||||
project → src → components → MyComponent.js
|
||||
```
|
||||
|
||||
- With `createSubFolder = true`:
|
||||
|
||||
```text
|
||||
project → src → components → MyComponent → MyComponent.js
|
||||
```
|
||||
|
||||
- With `createSubFolder = true` and `subFolderNameHelper = 'upperCase'`:
|
||||
|
||||
```text
|
||||
project → src → components → MYCOMPONENT → MyComponent.js
|
||||
```
|
||||
|
||||
- Output file contents:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Author: Chen Asraf
|
||||
* Date: 2077-01-01
|
||||
*/
|
||||
import React from 'react'
|
||||
|
||||
export default MyComponent: React.FC = (props) => {
|
||||
return (
|
||||
<div className="myClassName">MyComponent Component</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -3,8 +3,8 @@ import { HelperDelegate } from "handlebars/runtime"
|
||||
/**
|
||||
* The config object for defining a scaffolding group.
|
||||
*
|
||||
* @see {@link https://chenasraf.github.io/simple-scaffold/pages/node.html | Node.js usage}
|
||||
* @see {@link https://chenasraf.github.io/simple-scaffold/pages/cli.html | CLI usage}
|
||||
* @see {@link https://chenasraf.github.io/simple-scaffold/docs/usage/node| Node.js usage}
|
||||
* @see {@link https://chenasraf.github.io/simple-scaffold/docs/usage/cli| CLI usage}
|
||||
* @see {@link DefaultHelpers}
|
||||
* @see {@link CaseHelpers}
|
||||
* @see {@link DateHelpers}
|
||||
|
||||
Reference in New Issue
Block a user