update docs

This commit is contained in:
Chen Asraf
2022-04-21 15:34:03 +03:00
parent 4e2fa01bed
commit bf10fb8ec3
7 changed files with 135 additions and 79 deletions

View File

@@ -3,3 +3,6 @@ tab_width = 2
indent_style = space indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

View File

@@ -16,21 +16,21 @@ jobs:
- run: yarn test - run: yarn test
- run: yarn build - run: yarn build
- run: cd ./dist && yarn pack --filename=../package.tgz - run: cd ./dist && yarn pack --filename=../package.tgz
if: "!contains(github.event.head_commit.message, '[skip publish]')" if: "contains(github.event.head_commit.message, '[publish]')"
- uses: Klemensas/action-autotag@stable - uses: Klemensas/action-autotag@stable
if: "!contains(github.event.head_commit.message, '[skip publish]')" if: "contains(github.event.head_commit.message, '[publish]')"
id: update_tag id: update_tag
with: with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
tag_prefix: "v" tag_prefix: "v"
- name: Publish on NPM - name: Publish on NPM
uses: JS-DevTools/npm-publish@v1 uses: JS-DevTools/npm-publish@v1
if: "!contains(github.event.head_commit.message, '[skip publish]')" if: "contains(github.event.head_commit.message, '[publish]')"
with: with:
package: ./dist/package.json package: ./dist/package.json
token: "${{ secrets.NPM_TOKEN }}" token: "${{ secrets.NPM_TOKEN }}"
- name: Create Release - name: Create Release
if: steps.update_tag.outputs.tagname && !contains(github.event.head_commit.message, '[skip publish]') if: steps.update_tag.outputs.tagname && contains(github.event.head_commit.message, '[publish]')
uses: actions/create-release@v1 uses: actions/create-release@v1
id: create_release id: create_release
env: env:
@@ -40,7 +40,7 @@ jobs:
tag_name: ${{ steps.update_tag.outputs.tagname }} tag_name: ${{ steps.update_tag.outputs.tagname }}
release_name: Release ${{ steps.update_tag.outputs.tagname }} release_name: Release ${{ steps.update_tag.outputs.tagname }}
- name: Upload Release Asset - name: Upload Release Asset
if: steps.update_tag.outputs.tagname && !contains(github.event.head_commit.message, '[skip publish]') if: steps.update_tag.outputs.tagname && contains(github.event.head_commit.message, '[publish]')
id: upload-release-asset id: upload-release-asset
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:

View File

@@ -1,8 +1,9 @@
{ {
"MD013": { "line-length": {
"line_length": 100, "line_length": 100,
"tables": false, "tables": false,
"code_blocks": false "code_blocks": false
}, },
"MD033": false "no-inline-html": false,
} "first-line-h1": false
}

10
.vscode/settings.json vendored
View File

@@ -10,5 +10,11 @@
"noext", "noext",
"nonegate", "nonegate",
"subdir" "subdir"
] ],
} "[markdown]": {
"editor.rulers": [
87,
100
],
},
}

8
.vscode/tasks.json vendored
View File

@@ -13,6 +13,12 @@
"type": "npm", "type": "npm",
"problemMatcher": [], "problemMatcher": [],
}, },
{
"command": "yarn typedoc --watch",
"label": "typedoc --watch",
"type": "shell",
"problemMatcher": [],
},
{ {
"script": "start", "script": "start",
"label": "start", "label": "start",
@@ -50,4 +56,4 @@
"problemMatcher": [], "problemMatcher": [],
}, },
], ],
} }

159
README.md
View File

@@ -1,5 +1,14 @@
<div style="text-align:center;">
# Simple Scaffold # Simple Scaffold
[GitHub](https://github.com/chenasraf/simple-scaffold) |
[Documentation](https://casraf.blog/simple-scaffold) |
[NPM](https://npmjs.com/package/simple-scaffold) |
[casraf.blog](https://casraf.blog)
</div>
Simple Scaffold allows you to generate any set of files in the easiest way possible with simple commands. Simple Scaffold allows you to generate any set of files in the easiest way possible with simple commands.
It is completely framework agnostic so you can use it for anything from a few simple files to an It is completely framework agnostic so you can use it for anything from a few simple files to an
@@ -16,25 +25,25 @@ other custom data) inside the paths or contents of the files using Handlebars.js
- [Simple Scaffold](#simple-scaffold) - [Simple Scaffold](#simple-scaffold)
- [Install](#install) - [Install](#install)
- [Use as a command line tool](#use-as-a-command-line-tool) - [Command Line Interface (CLI)](#command-line-interface-cli)
- [Command Line Options](#command-line-options) - [Available flags](#available-flags)
- [Use in Node.js](#use-in-nodejs) - [Node module](#node-module)
- [Node-specific options](#node-specific-options) - [Node-specific options](#node-specific-options)
- [Preparing files](#preparing-files) - [Preparing files](#preparing-files)
- [Template files](#template-files) - [Template files](#template-files)
- [Variable/token replacement](#variabletoken-replacement) - [Variable/token replacement](#variabletoken-replacement)
- [Built-in Helpers](#built-in-helpers) - [Helpers](#helpers)
- [Capitalization Helpers](#capitalization-helpers) - [Built-in Helpers](#built-in-helpers)
- [Date helpers](#date-helpers) - [Capitalization Helpers](#capitalization-helpers)
- [Custom Helpers](#custom-helpers) - [Date helpers](#date-helpers)
- [Custom Helpers](#custom-helpers)
- [Examples](#examples) - [Examples](#examples)
- [Command Example](#command-example) - [Run](#run)
- [Example Scaffold Input](#example-scaffold-input) - [Command Example](#command-example)
- [Input Directory structure](#input-directory-structure) - [Node Module Example](#node-module-example)
- [Contents of `project/scaffold/{{Name}}.jsx`](#contents-of-projectscaffoldnamejsx) - [Files](#files)
- [Example Scaffold Output](#example-scaffold-output) - [Input](#input)
- [Output directory structure](#output-directory-structure) - [Output](#output)
- [Contents of `project/scaffold/MyComponent/MyComponent.jsx`](#contents-of-projectscaffoldmycomponentmycomponentjsx)
- [Contributing](#contributing) - [Contributing](#contributing)
</details> </details>
@@ -54,9 +63,13 @@ yarn [global] add simple-scaffold
npx simple-scaffold@latest <...args> npx simple-scaffold@latest <...args>
``` ```
## Use as a command line tool ## Command Line Interface (CLI)
### Command Line Options ### Available flags
The following is the help text from the `simple-scaffold` binary. To see this and more
information anytime, add the `-h` or `--help` flag to your call, e.g.
`npx simple-scaffold@latest -h`.
```plaintext ```plaintext
Usage: simple-scaffold [options] Usage: simple-scaffold [options]
@@ -67,26 +80,26 @@ Options:
--help|-h Display help information --help|-h Display help information
--name|-n Name to be passed to the generated files. {{name}} and --name|-n Name to be passed to the generated files. {{name}}
{{Name}} inside contents and file names will be replaced and {{Name}} inside contents and file names will be
accordingly. replaced accordingly.
--output|-o Path to output to. If --create-sub-folder is enabled, --output|-o Path to output to. If --create-sub-folder is enabled,
the subfolder will be created inside this path. the subfolder will be created inside this path.
(default: current dir) (default: current dir)
--templates|-t Template files to use as input. You may provide multiple --templates|-t Template files to use as input. You may provide
files, each of which can be a relative or absolute path, or a multiple files, each of which can be a relative or
glob pattern for multiple file matching easily. absolute path, or a glob pattern for multiple file
matching easily.
--overwrite|-w Enable to override output files, even if they already --overwrite|-w Enable to override output files, even if they already
exist. (default: false) exist. (default: false)
--data|-d Add custom data to the templates. By default, only your --data|-d Add custom data to the templates. By default, only
app name is included. your app name is included.
--create-sub-folder|-s Create subfolder with the input name --create-sub-folder|-s Create subfolder with the input name (default: false)
(default: false)
--sub-folder-name-helper|-sh Default helper to apply to subfolder name when using --sub-folder-name-helper|-sh Default helper to apply to subfolder name when using
`--create-sub-folder true`. `--create-sub-folder true`.
@@ -101,9 +114,9 @@ Options:
2) 2)
--dry-run|-dr Don't emit files. This is good for testing your --dry-run|-dr Don't emit files. This is good for testing your
scaffolds and making sure they don't fail, without having to scaffolds and making sure they don't fail, without
write actual file contents or create directories. having to write actual file contents or create
(default: false) directories. (default: false)
``` ```
You can also add this as a script in your `package.json`: You can also add this as a script in your `package.json`:
@@ -116,7 +129,7 @@ You can also add this as a script in your `package.json`:
} }
``` ```
## Use in Node.js ## Node module
You can also build the scaffold yourself, if you want to create more complex arguments or scaffold You can also build the scaffold yourself, if you want to create more complex arguments or scaffold
groups - simply pass a config object to the Scaffold function when you are ready to start. groups - simply pass a config object to the Scaffold function when you are ready to start.
@@ -214,14 +227,16 @@ Your `data` will be pre-populated with the following:
> [Handlebars.js Language Features](https://handlebarsjs.com/guide/#language-features) for more > [Handlebars.js Language Features](https://handlebarsjs.com/guide/#language-features) for more
> information. > information.
### Built-in Helpers ### Helpers
#### Built-in Helpers
Simple-Scaffold provides some built-in text transformation filters usable by handleBars. 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 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. replace `My Name` with `my_name` when producing the final value.
#### Capitalization Helpers ##### Capitalization Helpers
| Helper name | Example code | Example output | | Helper name | Example code | Example output |
| ------------ | ----------------------- | -------------- | | ------------ | ----------------------- | -------------- |
@@ -235,7 +250,7 @@ replace `My Name` with `my_name` when producing the final value.
| `upperCase` | `{{ upperCase name }}` | MY NAME | | `upperCase` | `{{ upperCase name }}` | MY NAME |
| `lowerCase` | `{{ lowerCase name }}` | my name | | `lowerCase` | `{{ lowerCase name }}` | my name |
#### Date helpers ##### Date helpers
| Helper name | Description | Example code | Example output | | Helper name | Description | Example code | Example output |
| -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ | | -------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ------------------ |
@@ -265,7 +280,7 @@ Further details:
- **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as - **The now helper** (for current time) takes the same arguments, minus the first one (`date`) as
it is implicitly the current date. it is implicitly the current date.
### Custom Helpers #### Custom Helpers
You may also add your own custom helpers using the `helpers` options when using the JS API (rather 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 than the CLI). The `helpers` option takes an object whose keys are helper names, and values are
@@ -285,7 +300,9 @@ All of the above helpers (built in and custom) will also be available to you whe
## Examples ## Examples
### Command Example ### Run
#### Command Example
```bash ```bash
simple-scaffold MyComponent \ simple-scaffold MyComponent \
@@ -295,20 +312,35 @@ simple-scaffold MyComponent \
MyComponent MyComponent
``` ```
### Example Scaffold Input #### Node Module Example
#### Input Directory structure ```typescript
import Scaffold from 'simple-scaffold';
```plaintext async function main() {
- project await Scaffold({
- scaffold name: 'MyComponent',
- {{Name}}.js templates: ['project/scaffold/**/*'],
- src output: ['src/components'],
- components data: {
- ... className: 'myClassName',
},
});
console.log('Done.');
}
``` ```
#### Contents of `project/scaffold/{{Name}}.jsx` ### Files
#### Input
Input file path:
```plaintext
project → scaffold → {{Name}}.js → src → components
```
Input file contents:
```typescript ```typescript
import React from 'react' import React from 'react'
@@ -320,30 +352,29 @@ export default {{camelCase name}}: React.FC = (props) => {
} }
``` ```
### Example Scaffold Output #### Output
### Output directory structure Output file path:
```plaintext - With `createSubFolder = false` (default):
- project
- src
- components
- MyComponent
- MyComponent.js
- ...
```
With `createSubFolder = false`: ```plaintext
project → src → components → MyComponent.js
```
```plaintext - With `createSubFolder = true`:
- project
- src
- components
- MyComponent.js
- ...
```
#### Contents of `project/scaffold/MyComponent/MyComponent.jsx` ```plaintext
project → src → components → MyComponent → MyComponent.js
```
- With `createSubFolder = true` and `subFolderNameHelper = 'upperCase'`:
```plaintext
project → src → components → MYCOMPONENT → MyComponent.js
```
Output file contents:
```typescript ```typescript
import React from 'react' import React from 'react'

View File

@@ -111,6 +111,7 @@ export interface ScaffoldConfig {
* *
* See {@link DefaultHelperKeys} for a list of all the built-in available helpers. * See {@link DefaultHelperKeys} for a list of all the built-in available helpers.
* *
* @see https://github.com/chenasraf/simple-scaffold#helpers
* @see https://github.com/chenasraf/simple-scaffold#built-in-helpers * @see https://github.com/chenasraf/simple-scaffold#built-in-helpers
*/ */
helpers?: Record<string, Helper> helpers?: Record<string, Helper>
@@ -136,7 +137,7 @@ export interface ScaffoldConfig {
* @param rawContent The original template before token replacement * @param rawContent The original template before token replacement
* @param outputPath The final output path of the processed file * @param outputPath The final output path of the processed file
* *
* @returns `String | Buffer | undefined` The final output of the file contents-only, after further modifications - * @returns {Promise<String | Buffer | undefined> | String | Buffer | undefined} The final output of the file contents-only, after further modifications -
* or `undefined` to use the original content (i.e. `content.toString()`) * or `undefined` to use the original content (i.e. `content.toString()`)
*/ */
beforeWrite?( beforeWrite?(
@@ -219,8 +220,12 @@ export type Helper = HelperDelegate
/** /**
* The amount of information to log when generating scaffold. * The amount of information to log when generating scaffold.
* When not `None`, the selected level will be the lowest level included. For example, level `Info` (2) will include * When not `None`, the selected level will be the lowest level included.
* `Info`, `Warning` and `Error`, but not `Debug`. *
* For example, level `Info` (2) will include `Info`, `Warning` and `Error`, but not `Debug`; and `Warning` will only
* show `Warning` and `Error`.
*
* @default `2 (info)`
* *
* @category Logging * @category Logging
*/ */
@@ -229,7 +234,11 @@ export enum LogLevel {
None = 0, None = 0,
/** Debugging information. Very verbose and only recommended for troubleshooting. */ /** Debugging information. Very verbose and only recommended for troubleshooting. */
Debug = 1, Debug = 1,
/** The regular level of logging. Major actions are logged to show the scaffold progress. */ /**
* The regular level of logging. Major actions are logged to show the scaffold progress.
*
* @default
*/
Info = 2, Info = 2,
/** Warnings such as when file fails to replace token values properly in template. */ /** Warnings such as when file fails to replace token values properly in template. */
Warning = 3, Warning = 3,