fix: remove gh flag

This commit is contained in:
2024-01-29 02:49:36 +02:00
committed by Chen Asraf
parent 96c1d5a759
commit e66d6ba86a
4 changed files with 29 additions and 33 deletions

View File

@@ -16,7 +16,6 @@ To see this and more information anytime, add the `-h` or `--help` flag to your
| `--name` \| `-n` | Name to be passed to the generated files. `{{name}}` and other data parameters inside contents and file names will be replaced accordingly. You may omit the `--name` or `-n` for this specific option. |
| `--config`\|`-c` | Filename to load config from instead of passing arguments to CLI or using a Node.js script. See examples for syntax. This can also work in conjunction with `--git` or `--github` to point to remote files, and with `--key` to denote which key to select from the file., |
| `--git`\|`-g` | Git URL to load config from instead of passing arguments to CLI or using a Node.js script. See examples for syntax. |
| `--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 is current working directory. |
| `--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. |
@@ -39,20 +38,23 @@ To see this and more information anytime, add the `-h` or `--help` flag to your
Usage with config file
```shell
$ simple-scaffold -c scaffold.cmd.js -k component
$ simple-scaffold -c scaffold.cmd.js -k component MyComponent
```
Usage with GitHub config file
```shell
$ simple-scaffold -gh chenasraf/simple-scaffold -k component
$ simple-scaffold -g chenasraf/simple-scaffold -k component MyComponent
```
Usage with https git URL (for non-GitHub)
```shell
$ simple-scaffold -g \
https://example.com/user/template.git -c scaffold.cmd.js -k component
$ simple-scaffold \
-g https://example.com/user/template.git \
-c scaffold.cmd.js \
-k component \
MyComponent
```
Full syntax with config path and template key (applicable to all above methods)
@@ -70,7 +72,7 @@ $ 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
$ simple-scaffold -g chenasraf/simple-scaffold MyComponent
```
You can also add this as a script in your `package.json`:
@@ -78,7 +80,10 @@ You can also add this as a script in your `package.json`:
```json
{
"scripts": {
"scaffold-cfg": "npx simple-scaffold -c scaffold.cmd.js -k component",
"scaffold-gh": "npx simple-scaffold -g chenasraf/simple-scaffold -k component",
"scaffold": "npx simple-scaffold@latest -t scaffolds/component/**/* -o src/components -d '{\"myProp\": \"propName\", \"myVal\": 123}'"
"scaffold-component": "npx simple-scaffold -c scaffold.cmd.js -k"
}
}
```

View File

@@ -11,7 +11,7 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
const pkgFile = await fs.readFile(path.join(__dirname, "package.json"))
const pkg = JSON.parse(pkgFile.toString())
const isConfigProvided =
args.includes("--config") || args.includes("-c") || args.includes("--github") || args.includes("-gh")
args.includes("--config") || args.includes("-c") || args.includes("--git") || args.includes("-g")
return (
massarg<ScaffoldCmdConfig>({
@@ -46,13 +46,6 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
"Git URL to load config from instead of passing arguments to CLI or using a Node.js script. See " +
"examples for syntax.",
})
.option({
name: "github",
aliases: ["gh"],
description:
"GitHub path to load config from instead of passing arguments to CLI or using a Node.js script. See " +
"examples for syntax.",
})
.option({
name: "key",
aliases: ["k"],
@@ -144,23 +137,20 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
})
.example({
description: "Usage with GitHub config file",
input: "simple-scaffold -gh chenasraf/simple-scaffold --key component",
input: "simple-scaffold -g chenasraf/simple-scaffold --key component",
})
.example({
description: "Usage with https git URL (for non-GitHub)",
input: "simple-scaffold -c https://example.com/user/template.git#scaffold.cmd.js --key component",
})
.example({
description: "Full syntax with config path and template key (applicable to all above methods)",
input: "simple-scaffold -c scaffold.cmd.js:component MyComponent",
input: "simple-scaffold -g https://example.com/user/template.git -c scaffold.cmd.js --key component",
})
.example({
description: "Excluded template key, assumes 'default' key",
input: "simple-scaffold -c scaffold.cmd.js MyComponent",
})
.example({
description: "Shortest syntax for GitHub, assumes file 'scaffold.cmd.js' and template key 'default'",
input: "simple-scaffold -gh chenasraf/simple-scaffold MyComponent",
description:
"Shortest syntax for GitHub, searches for config file automaticlly, assumes and template key 'default'",
input: "simple-scaffold -g chenasraf/simple-scaffold MyComponent",
})
.help({
bindOption: true,

View File

@@ -55,21 +55,23 @@ export async function parseConfigFile(config: ScaffoldCmdConfig): Promise<Scaffo
config.logLevel = LogLevel.none
}
if (config.github) {
log(config, LogLevel.info, `Loading config from github ${config.github}`)
config.git = githubPartToUrl(config.github)
if (config.git && !config.git.includes("://")) {
log(config, LogLevel.info, `Loading config from GitHub ${config.git}`)
config.git = githubPartToUrl(config.git)
}
if (config.config || config.git) {
const shouldLoadConfig = config.config || config.git
if (shouldLoadConfig) {
const isGit = Boolean(config.git)
const key = config.key ?? "default"
const configFile = config.config
const loadPath = isGit ? config.git : configFile
const configFilename = config.config
const configPath = isGit ? config.git : configFilename
log(config, LogLevel.info, `Loading config from ${configFile} with key ${key}`)
log(config, LogLevel.info, `Loading config from ${configFilename} with key ${key}`)
const configPromise = await (config.git
? getRemoteConfig({ git: loadPath, config: configFile, logLevel: config.logLevel })
: getLocalConfig({ config: configFile, logLevel: config.logLevel }))
? getRemoteConfig({ git: configPath, config: configFilename, logLevel: config.logLevel })
: getLocalConfig({ config: configFilename, logLevel: config.logLevel }))
// resolve the config
let configImport = await resolve(configPromise, config)
@@ -80,7 +82,7 @@ export async function parseConfigFile(config: ScaffoldCmdConfig): Promise<Scaffo
}
if (!configImport[key]) {
throw new Error(`Template "${key}" not found in ${configFile}`)
throw new Error(`Template "${key}" not found in ${configFilename}`)
}
const importedKey = configImport[key]

View File

@@ -335,7 +335,6 @@ export interface ScaffoldCmdConfig {
config?: string
key?: string
git?: string
github?: string
}
/**