@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @brickflow/cli
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - update multiply file in types
8
+
3
9
  ## 0.0.12
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brickflow/cli",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -10,29 +10,41 @@ if (args.includes('--help') || args.includes('-h')) {
10
10
 
11
11
  const options = parseArgs(args)
12
12
 
13
- if (!options.path || !options.typeName || !options.outputFile || !options.replacePattern) {
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 inputDir = path.resolve(process.cwd(), options.path)
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 = readdirSync(inputDir)
22
- .filter((entry) => statSync(path.join(inputDir, entry)).isFile())
23
- .sort((first, second) => first.localeCompare(second))
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: ${inputDir}`)
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: ${inputDir}`)
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
- path: null,
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
- parsedOptions.path = rawArgs[index + 1] ?? null
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 (!parsedOptions.path) {
86
- parsedOptions.path = positional[0] ?? null
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`)