@poetora/cli 0.1.10 → 0.1.11

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.
@@ -1,10 +1,9 @@
1
- import chalk from 'chalk';
2
1
  import yargs from 'yargs';
3
2
  import { hideBin } from 'yargs/helpers';
4
3
  import { CheckCommand, DevCommand, InitCommand, LinkCommand, UpdateCommand, } from './commands/index.js';
5
4
  import { checkNodeVersion, suppressConsoleWarnings } from './middlewares.js';
6
5
  import { AccessibilityCheckService, LinkService, OpenApiCheckService, PortService, TemplateService, UpdateService, VersionService, } from './services/index.js';
7
- import { ConsoleLogger } from './utils/index.js';
6
+ import { ConsoleLogger, terminate } from './utils/index.js';
8
7
  export class CliBuilder {
9
8
  packageName;
10
9
  logger;
@@ -67,7 +66,7 @@ export class CliBuilder {
67
66
  }
68
67
  catch (error) {
69
68
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
70
- process.exit(1);
69
+ await terminate(1);
71
70
  }
72
71
  })
73
72
  .command(['new [directory]', 'init [directory]'], 'Create a new Poetora documentation site', (yargs) => yargs.positional('directory', {
@@ -80,7 +79,7 @@ export class CliBuilder {
80
79
  }
81
80
  catch (error) {
82
81
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
83
- process.exit(1);
82
+ await terminate(1);
84
83
  }
85
84
  })
86
85
  .command('openapi-check <filename>', 'check if an OpenAPI spec is valid', (yargs) => yargs
@@ -99,32 +98,47 @@ export class CliBuilder {
99
98
  filename: argv.filename,
100
99
  localSchema: argv.localSchema,
101
100
  });
102
- process.exit(0);
101
+ await terminate(0);
103
102
  }
104
103
  catch (error) {
105
104
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
106
- process.exit(1);
105
+ await terminate(1);
107
106
  }
108
107
  })
109
108
  .command(['a11y', 'accessibility-check', 'a11y-check', 'accessibility'], 'check for accessibility issues in documentation', () => undefined, async () => {
110
109
  try {
111
110
  const exitCode = await checkCommand.checkAccessibility();
112
- process.exit(exitCode);
111
+ await terminate(exitCode);
113
112
  }
114
113
  catch (error) {
115
114
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
116
- process.exit(1);
115
+ await terminate(1);
117
116
  }
118
117
  })
119
118
  .command('broken-links', 'check for invalid internal links', () => undefined, async () => {
120
119
  try {
121
120
  const brokenLinks = await linkCommand.checkBrokenLinks();
122
121
  const hasBrokenLinks = Object.keys(brokenLinks).length > 0;
123
- process.exit(hasBrokenLinks ? 1 : 0);
122
+ if (!hasBrokenLinks) {
123
+ this.logger.success('no broken links found');
124
+ await terminate(0);
125
+ }
126
+ const linkCount = Object.values(brokenLinks).flat().length;
127
+ const fileCount = Object.keys(brokenLinks).length;
128
+ this.logger.log(`found ${this.logger.highlight?.(linkCount.toString()) ?? linkCount} broken link${linkCount === 1 ? '' : 's'} in ${this.logger.highlight?.(fileCount.toString()) ?? fileCount} file${fileCount === 1 ? '' : 's'}`);
129
+ this.logger.logNewLine();
130
+ for (const [filename, links] of Object.entries(brokenLinks)) {
131
+ this.logger.logColor(filename, 'cyan');
132
+ links.forEach((link) => {
133
+ this.logger.logColor(` ⎿ ${link}`, 'gray');
134
+ });
135
+ this.logger.logNewLine();
136
+ }
137
+ await terminate(1);
124
138
  }
125
139
  catch (error) {
126
140
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
127
- process.exit(1);
141
+ await terminate(1);
128
142
  }
129
143
  })
130
144
  .command('rename <from> <to>', 'rename a file and update all internal link references', (yargs) => yargs
@@ -149,28 +163,28 @@ export class CliBuilder {
149
163
  to: argv.to,
150
164
  force: argv.force,
151
165
  });
152
- process.exit(0);
166
+ await terminate(0);
153
167
  }
154
168
  catch (error) {
155
169
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
156
- process.exit(1);
170
+ await terminate(1);
157
171
  }
158
172
  })
159
173
  .command('update', 'update the CLI to the latest version', () => undefined, async () => {
160
174
  try {
161
175
  await updateCommand.run({});
162
- process.exit(0);
176
+ await terminate(0);
163
177
  }
164
178
  catch (error) {
165
179
  this.logger.error(error instanceof Error ? error.message : 'Unknown error');
166
- process.exit(1);
180
+ await terminate(1);
167
181
  }
168
182
  })
169
183
  .command(['version', 'v'], 'display the current version of the CLI and client', () => undefined, async () => {
170
184
  const versions = versionService.getVersions();
171
- console.log(`${chalk.bold.green('cli version')} ${versions.cli}`);
172
- console.log(`${chalk.bold.green('client version')} ${versions.client}`);
173
- process.exit(0);
185
+ this.logger.logBold(`cli version ${versions.cli}`, 'green');
186
+ this.logger.logBold(`client version ${versions.client}`, 'green');
187
+ await terminate(0);
174
188
  })
175
189
  .strictCommands()
176
190
  .demandCommand(1, 'unknown command. see above for the list of supported commands.')
@@ -8,7 +8,6 @@ export class LinkService {
8
8
  async checkBrokenLinks() {
9
9
  const brokenLinks = await getBrokenInternalLinks();
10
10
  if (brokenLinks.length === 0) {
11
- this.logger.success('no broken links found');
12
11
  return {};
13
12
  }
14
13
  const brokenLinksByFile = {};
@@ -22,16 +21,6 @@ export class LinkService {
22
21
  brokenLinksByFile[filename] = [mdxPath.originalPath];
23
22
  }
24
23
  });
25
- const fileCount = Object.keys(brokenLinksByFile).length;
26
- this.logger.log(`found ${this.logger.highlight?.(brokenLinks.length.toString()) ?? brokenLinks.length} broken link${brokenLinks.length === 1 ? '' : 's'} in ${this.logger.highlight?.(fileCount.toString()) ?? fileCount} file${fileCount === 1 ? '' : 's'}`);
27
- this.logger.logNewLine();
28
- for (const [filename, links] of Object.entries(brokenLinksByFile)) {
29
- this.logger.logColor(filename, 'cyan');
30
- links.forEach((link) => {
31
- this.logger.logColor(` ⎿ ${link}`, 'gray');
32
- });
33
- this.logger.logNewLine();
34
- }
35
24
  return brokenLinksByFile;
36
25
  }
37
26
  async renameFile(from, to, force = false) {
@@ -1,2 +1,3 @@
1
1
  export * from './console-logger.js';
2
2
  export * from './logger.interface.js';
3
+ export * from './terminate.js';
@@ -1,2 +1,3 @@
1
1
  export * from './console-logger.js';
2
2
  export * from './logger.interface.js';
3
+ export * from './terminate.js';
@@ -0,0 +1 @@
1
+ export declare const terminate: (code: number) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ export const terminate = async (code) => {
2
+ await new Promise((resolve) => setTimeout(resolve, 50));
3
+ process.exit(code);
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poetora/cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "The CLI for Poetora documentation Engine",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -49,8 +49,8 @@
49
49
  "@poetora/link-rot": "0.0.7",
50
50
  "@poetora/prebuild": "0.1.6",
51
51
  "@poetora/previewing": "0.1.9",
52
- "@poetora/validation": "0.1.6",
53
- "@poetora/shared": "0.1.6"
52
+ "@poetora/shared": "0.1.6",
53
+ "@poetora/validation": "0.1.6"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@tsconfig/recommended": "1.0.2",