@atproto/lex-cli 0.4.0 → 0.5.0-rc.0

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/src/index.ts CHANGED
@@ -20,25 +20,23 @@ program.name('lex').description('Lexicon CLI').version('0.0.0')
20
20
  program
21
21
  .command('gen-md')
22
22
  .description('Generate markdown documentation')
23
+ .option('--yes', 'skip confirmation')
23
24
  .argument('<outfile>', 'path of the file to write to', toPath)
24
25
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
25
- .action(async (outFilePath: string, lexiconPaths: string[]) => {
26
- if (!outFilePath.endsWith('.md')) {
27
- console.error('Must supply the path to a .md file as the first parameter')
28
- process.exit(1)
29
- }
30
- console.log('Writing', outFilePath)
31
- const ok = await yesno({
32
- question: 'Are you sure you want to continue? [y/N]',
33
- defaultValue: false,
34
- })
35
- if (!ok) {
36
- console.log('Aborted.')
37
- process.exit(0)
38
- }
39
- const lexicons = readAllLexicons(lexiconPaths)
40
- await mdGen.process(outFilePath, lexicons)
41
- })
26
+ .action(
27
+ async (outFile: string, lexiconPaths: string[], o: { yes?: true }) => {
28
+ if (!outFile.endsWith('.md')) {
29
+ console.error(
30
+ 'Must supply the path to a .md file as the first parameter',
31
+ )
32
+ process.exit(1)
33
+ }
34
+ if (!o?.yes) await confirmOrExit()
35
+ console.log('Writing', outFile)
36
+ const lexicons = readAllLexicons(lexiconPaths)
37
+ await mdGen.process(outFile, lexicons)
38
+ },
39
+ )
42
40
 
43
41
  program
44
42
  .command('gen-ts-obj')
@@ -52,22 +50,16 @@ program
52
50
  program
53
51
  .command('gen-api')
54
52
  .description('Generate a TS client API')
53
+ .option('--yes', 'skip confirmation')
55
54
  .argument('<outdir>', 'path of the directory to write to', toPath)
56
55
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
57
- .action(async (outDir: string, lexiconPaths: string[]) => {
56
+ .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {
58
57
  const lexicons = readAllLexicons(lexiconPaths)
59
58
  const api = await genClientApi(lexicons)
60
59
  const diff = genFileDiff(outDir, api)
61
60
  console.log('This will write the following files:')
62
61
  printFileDiff(diff)
63
- const ok = await yesno({
64
- question: 'Are you sure you want to continue? [y/N]',
65
- defaultValue: false,
66
- })
67
- if (!ok) {
68
- console.log('Aborted.')
69
- process.exit(0)
70
- }
62
+ if (!o?.yes) await confirmOrExit()
71
63
  applyFileDiff(diff)
72
64
  console.log('API generated.')
73
65
  })
@@ -75,22 +67,16 @@ program
75
67
  program
76
68
  .command('gen-server')
77
69
  .description('Generate a TS server API')
70
+ .option('--yes', 'skip confirmation')
78
71
  .argument('<outdir>', 'path of the directory to write to', toPath)
79
72
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
80
- .action(async (outDir: string, lexiconPaths: string[]) => {
73
+ .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {
81
74
  const lexicons = readAllLexicons(lexiconPaths)
82
75
  const api = await genServerApi(lexicons)
83
76
  const diff = genFileDiff(outDir, api)
84
77
  console.log('This will write the following files:')
85
78
  printFileDiff(diff)
86
- const ok = await yesno({
87
- question: 'Are you sure you want to continue? [y/N]',
88
- defaultValue: false,
89
- })
90
- if (!ok) {
91
- console.log('Aborted.')
92
- process.exit(0)
93
- }
79
+ if (!o?.yes) await confirmOrExit()
94
80
  applyFileDiff(diff)
95
81
  console.log('API generated.')
96
82
  })
@@ -106,3 +92,14 @@ function toPaths(v: string, acc: string[]) {
106
92
  acc.push(path.resolve(v))
107
93
  return acc
108
94
  }
95
+
96
+ async function confirmOrExit() {
97
+ const ok = await yesno({
98
+ question: 'Are you sure you want to continue? [y/N]',
99
+ defaultValue: false,
100
+ })
101
+ if (!ok) {
102
+ console.log('Aborted.')
103
+ process.exit(0)
104
+ }
105
+ }