@brickflow/cli 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/types/index.js +31 -13
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/types/index.js
CHANGED
|
@@ -10,29 +10,41 @@ if (args.includes('--help') || args.includes('-h')) {
|
|
|
10
10
|
|
|
11
11
|
const options = parseArgs(args)
|
|
12
12
|
|
|
13
|
-
if (
|
|
13
|
+
if (options.paths.length === 0 || !options.typeName || !options.outputFile || !options.replacePattern) {
|
|
14
14
|
printHelp()
|
|
15
15
|
process.exit(1)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const inputDirs = options.paths.map((inputPath) => path.resolve(process.cwd(), inputPath))
|
|
19
19
|
const outputFile = path.resolve(process.cwd(), options.outputFile)
|
|
20
20
|
const replacePattern = parseReplacePattern(options.replacePattern)
|
|
21
|
-
const entries =
|
|
22
|
-
.
|
|
23
|
-
|
|
21
|
+
const entries = inputDirs
|
|
22
|
+
.flatMap((inputDir) =>
|
|
23
|
+
readdirSync(inputDir)
|
|
24
|
+
.filter((entry) => statSync(path.join(inputDir, entry)).isFile())
|
|
25
|
+
.map((entry) => ({ entry, inputDir })),
|
|
26
|
+
)
|
|
27
|
+
.sort((first, second) => {
|
|
28
|
+
const entryComparison = first.entry.localeCompare(second.entry)
|
|
29
|
+
|
|
30
|
+
if (entryComparison !== 0) {
|
|
31
|
+
return entryComparison
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return first.inputDir.localeCompare(second.inputDir)
|
|
35
|
+
})
|
|
24
36
|
|
|
25
|
-
const typeValues = new Set(entries.map((entry) => applyReplacePattern(entry, replacePattern)).filter(Boolean))
|
|
37
|
+
const typeValues = new Set(entries.map(({ entry }) => applyReplacePattern(entry, replacePattern)).filter(Boolean))
|
|
26
38
|
|
|
27
39
|
if (typeValues.size === 0) {
|
|
28
|
-
throw new Error(`No type values generated from: ${
|
|
40
|
+
throw new Error(`No type values generated from: ${inputDirs.join(', ')}`)
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
const declaration = `declare type ${options.typeName} = ${[...typeValues].map((value) => `'${value}'`).join(' | ')}\n`
|
|
32
44
|
writeFileSync(outputFile, declaration, 'utf8')
|
|
33
45
|
|
|
34
46
|
console.log(`✅ Types generated for ${options.typeName}`)
|
|
35
|
-
console.log(` input: ${
|
|
47
|
+
console.log(` input: ${inputDirs.join(', ')}`)
|
|
36
48
|
console.log(` output: ${outputFile}`)
|
|
37
49
|
|
|
38
50
|
function applyReplacePattern(value, pattern) {
|
|
@@ -46,7 +58,7 @@ function applyReplacePattern(value, pattern) {
|
|
|
46
58
|
function parseArgs(rawArgs) {
|
|
47
59
|
const parsedOptions = {
|
|
48
60
|
outputFile: null,
|
|
49
|
-
|
|
61
|
+
paths: [],
|
|
50
62
|
replacePattern: null,
|
|
51
63
|
typeName: null,
|
|
52
64
|
}
|
|
@@ -56,7 +68,12 @@ function parseArgs(rawArgs) {
|
|
|
56
68
|
const value = rawArgs[index]
|
|
57
69
|
|
|
58
70
|
if (value === '--path') {
|
|
59
|
-
|
|
71
|
+
const inputPath = rawArgs[index + 1] ?? null
|
|
72
|
+
|
|
73
|
+
if (inputPath) {
|
|
74
|
+
parsedOptions.paths.push(inputPath)
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
index += 1
|
|
61
78
|
continue
|
|
62
79
|
}
|
|
@@ -82,8 +99,8 @@ function parseArgs(rawArgs) {
|
|
|
82
99
|
positional.push(value)
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
if (
|
|
86
|
-
parsedOptions.
|
|
102
|
+
if (parsedOptions.paths.length === 0 && positional[0]) {
|
|
103
|
+
parsedOptions.paths.push(positional[0])
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
if (!parsedOptions.typeName) {
|
|
@@ -118,9 +135,10 @@ Usage:
|
|
|
118
135
|
brick types ./path/to/files IconName ./types/icon.d.ts .svg
|
|
119
136
|
brick types ./path/to/files IconName ./types/icon.d.ts /\\.svg$/
|
|
120
137
|
brick types --path ./path/to/files --type-name IconName --output-file ./types/icon.d.ts --replace-pattern /\\.svg$/
|
|
138
|
+
brick types --path ./path/to/files --path ./path/to/more-files --type-name IconName --output-file ./types/icon.d.ts --replace-pattern /\\.svg$/
|
|
121
139
|
|
|
122
140
|
Notes:
|
|
123
|
-
path: directory with source files
|
|
141
|
+
path: directory with source files, can be passed multiple times
|
|
124
142
|
typeName: generated TypeScript type name
|
|
125
143
|
outputFile: file to write declaration into
|
|
126
144
|
replacePattern: string or regex literal used in replace(..., '') for each filename`)
|