Skip to content

Commit 90ba9f7

Browse files
committed
feat!: rename createSubFolder and subFolderNameHelper
1 parent 09d330a commit 90ba9f7

File tree

12 files changed

+92
-52
lines changed

12 files changed

+92
-52
lines changed

docs/docs/usage/configuration_files.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ interface ScaffoldConfig {
3131
name: string
3232
templates: string[]
3333
output: FileResponse<string>
34-
createSubFolder?: boolean
34+
subdir?: boolean
35+
git?: string
36+
config?: string
37+
key?: string
3538
data?: Record<string, any>
3639
overwrite?: FileResponse<boolean>
3740
quiet?: boolean
3841
verbose?: LogLevel
3942
dryRun?: boolean
4043
helpers?: Record<string, Helper>
41-
subFolderNameHelper?: DefaultHelpers | string
44+
subdirHelper?: DefaultHelpers | string
4245
beforeWrite?(
4346
content: Buffer,
4447
rawContent: Buffer,

docs/docs/usage/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ title: Examples
3232

3333
- Output file path:
3434

35-
- With `createSubFolder = false` (default):
35+
- With `subdir = false` (default):
3636

3737
```text
3838
project → src → components → MyComponent.js
3939
```
4040
41-
- With `createSubFolder = true`:
41+
- With `subdir = true`:
4242
4343
```text
4444
project → src → components → MyComponent → MyComponent.js
4545
```
4646
47-
- With `createSubFolder = true` and `subFolderNameHelper = 'upperCase'`:
47+
- With `subdir = true` and `subdirHelper = 'upperCase'`:
4848
4949
```text
5050
project → src → components → MYCOMPONENT → MyComponent.js

docs/docs/usage/migration.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ title: Migration
66

77
### CLI option changes
88

9-
- The `:template_key` syntax has been removed. You can still use `-k template_key` to achieve the
10-
same result.
119
- Several changes to how remote configs are loaded via CLI:
10+
- The `:template_key` syntax has been removed. You can still use `-k template_key` to achieve the
11+
same result.
1212
- The `--github` (`-gh`) flag has been replaced by a generic `--git` (`-g`) one, which handles any
1313
git URL. Providing a partial GitHub path will default to trying to find the project on GitHub,
1414
e.g. `-g username/project`
@@ -17,6 +17,10 @@ title: Migration
1717
which can find the file for you if it is in one of the supported filenames.
1818
- `verbose` can now take the names `debug`, `info`, `warn`, `error` or `none` (case insensitive) or
1919
as usual by using the numbering from before.
20+
- `--create-sub-folder` (`-s`) has been renamed to `--subdir` (`-s`) in the CLI. The Node.js names
21+
have been changed as well.
22+
- `--sub-folder-name-helper` (`-sh`) has been renamed to `--subdir-helper` (`-sh`). The Node.js
23+
names have been changed as well.
2024
- All boolean flags no longer take a value. `-q` instead of `-q 1` or `-q true`, `-s` instead of
2125
`-s 1`, `-w` instead of `-w 1`, etc.
2226

docs/docs/usage/templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ config.helpers = {
125125
```
126126

127127
All of the above helpers (built in and custom) will also be available to you when using
128-
`subFolderNameHelper` (`--sub-folder-name-helper`/`-sh`) as a possible value.
128+
`subdirHelper` (`--sub-dir-helper`/`-H`) as a possible value.
129129

130130
> To see more information on how helpers work and more features, see
131131
> [Handlebars.js docs](https://handlebarsjs.com/guide/#custom-helpers).

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
"clean": "rm -rf dist/",
2525
"build": "pnpm clean && tsc && chmod -R +x ./dist && cp ./package.json ./README.md ./dist/",
2626
"dev": "tsc --watch",
27-
"start": "node dist/scaffold.js",
27+
"start": "ts-node src/scaffold.ts",
2828
"test": "jest",
29-
"cmd": "node --trace-warnings dist/cmd.js",
30-
"build-test": "pnpm build && pnpm test",
31-
"build-cmd": "pnpm build && pnpm cmd",
29+
"cmd": "ts-node src/cmd.ts",
3230
"docs:build": "cd docs && pnpm build",
3331
"docs:watch": "cd docs && pnpm start",
3432
"audit-fix": "pnpm audit --fix",
@@ -39,7 +37,7 @@
3937
"date-fns": "^3.3.1",
4038
"glob": "^10.3.10",
4139
"handlebars": "^4.7.8",
42-
"massarg": "2.0.0-pre.11"
40+
"massarg": "2.0.0-pre.12"
4341
},
4442
"devDependencies": {
4543
"@semantic-release/changelog": "^6.0.3",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import fs from "node:fs/promises"
88
import { parseAppendData, parseConfigFile } from "./config"
99

1010
export async function parseCliArgs(args = process.argv.slice(2)) {
11-
const pkgFile = await fs.readFile(path.join(__dirname, "package.json"))
11+
const isProjectRoot = Boolean(await fs.stat(path.join(__dirname, "package.json")).catch(() => false))
12+
const pkgFile = await fs.readFile(path.resolve(__dirname, isProjectRoot ? "." : "..", "package.json"))
1213
const pkg = JSON.parse(pkgFile.toString())
1314
const isConfigProvided =
1415
args.includes("--config") || args.includes("-c") || args.includes("--git") || args.includes("-g")
@@ -56,7 +57,7 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
5657
name: "output",
5758
aliases: ["o"],
5859
description:
59-
"Path to output to. If `--create-sub-folder` is enabled, the subfolder will be created inside " +
60+
"Path to output to. If `--subdir` is enabled, the subfolder will be created inside " +
6061
"this path. Default is current working directory.",
6162
required: !isConfigProvided,
6263
})
@@ -75,6 +76,7 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
7576
aliases: ["w"],
7677
defaultValue: false,
7778
description: "Enable to override output files, even if they already exist.",
79+
negatable: true,
7880
})
7981
.option({
8082
name: "data",
@@ -91,15 +93,17 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
9193
parse: parseAppendData,
9294
})
9395
.flag({
94-
name: "create-sub-folder",
96+
name: "subdir",
9597
aliases: ["s"],
9698
defaultValue: false,
97-
description: "Create subfolder with the input name",
99+
description: "Create a parent directory with the input name (and possibly `--subdir-helper`",
100+
negatable: true,
101+
negationName: "no-subdir",
98102
})
99103
.option({
100-
name: "sub-folder-name-helper",
101-
aliases: ["sh"],
102-
description: "Default helper to apply to subfolder name when using `--create-sub-folder true`.",
104+
name: "subdir-helper",
105+
aliases: ["H"],
106+
description: "Default helper to apply to subfolder name when using `--subdir`.",
103107
})
104108
.flag({
105109
name: "quiet",
@@ -150,16 +154,17 @@ export async function parseCliArgs(args = process.argv.slice(2)) {
150154
bindOption: true,
151155
lineLength: 100,
152156
useGlobalTableColumns: true,
153-
// optionOptions: {
154-
// displayNegations: true,
155-
// },
157+
usageText: [chalk.yellow`simple-scaffold`, chalk.gray`[options]`, chalk.cyan`<name>`].join(" "),
158+
optionOptions: {
159+
displayNegations: true,
160+
},
156161
footerText: [
157162
`Version: ${pkg.version}`,
158163
`Copyright © Chen Asraf 2017-${new Date().getFullYear()}`,
159164
``,
160-
`Documentation:\n ${chalk.underline`https://chenasraf.github.io/simple-scaffold`}`,
161-
`NPM:\n ${chalk.underline`https://npmjs.com/package/simple-scaffold`}`,
162-
`GitHub:\n ${chalk.underline`https://github.com/chenasraf/simple-scaffold`}`,
165+
`Documentation: ${chalk.underline`https://chenasraf.github.io/simple-scaffold`}`,
166+
`NPM: ${chalk.underline`https://npmjs.com/package/simple-scaffold`}`,
167+
`GitHub: ${chalk.underline`https://github.com/chenasraf/simple-scaffold`}`,
163168
].join("\n"),
164169
})
165170
.parse(args)

src/file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export function getOutputDir(config: ScaffoldConfig, outputPathOpt: string, base
165165
...([
166166
outputPathOpt,
167167
basePath,
168-
config.createSubFolder
169-
? config.subFolderNameHelper
170-
? handlebarsParse(config, `{{ ${config.subFolderNameHelper} name }}`).toString()
168+
config.subdir
169+
? config.subdirHelper
170+
? handlebarsParse(config, `{{ ${config.subdirHelper} name }}`).toString()
171171
: config.name
172172
: undefined,
173173
].filter(Boolean) as string[]),

src/logger.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { LogConfig, LogLevel, ScaffoldConfig } from "./types"
22
import chalk from "chalk"
33

44
export function log(config: LogConfig, level: LogLevel, ...obj: any[]): void {
5-
if (config.logLevel === LogLevel.none || level < (config.logLevel ?? LogLevel.info)) {
5+
const priority: Record<LogLevel, number> = {
6+
[LogLevel.none]: 0,
7+
[LogLevel.debug]: 1,
8+
[LogLevel.info]: 2,
9+
[LogLevel.warning]: 3,
10+
[LogLevel.error]: 4,
11+
}
12+
13+
if (config.logLevel === LogLevel.none || priority[level] < priority[config.logLevel ?? LogLevel.info]) {
614
return
715
}
816

@@ -49,10 +57,10 @@ export function logInitStep(config: ScaffoldConfig): void {
4957
name: config.name,
5058
templates: config.templates,
5159
output: config.output,
52-
createSubFolder: config.createSubFolder,
60+
subdir: config.subdir,
5361
data: config.data,
5462
overwrite: config.overwrite,
55-
subFolderNameHelper: config.subFolderNameHelper,
63+
subdirHelper: config.subdirHelper,
5664
helpers: Object.keys(config.helpers ?? {}),
5765
logLevel: config.logLevel,
5866
dryRun: config.dryRun,

src/scaffold.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Scaffold.fromConfig = async function (
123123
logLevel: LogLevel.info,
124124
overwrite: false,
125125
templates: [],
126-
createSubFolder: false,
126+
subdir: false,
127127
quiet: false,
128128
config: pathOrUrl,
129129
...config,

0 commit comments

Comments
 (0)