@krapwoo/ds-viewer 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/cli/main.js +38 -1
  2. package/package.json +4 -2
package/dist/cli/main.js CHANGED
@@ -1,12 +1,49 @@
1
1
  #!/usr/bin/env node
2
+ import { existsSync, readFileSync } from 'node:fs';
2
3
  import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
3
5
  import { resolveConfig } from "./config.js";
4
6
  import { initExistingProject } from "./init.js";
5
7
  import { dev } from "./dev.js";
6
8
  import { sync } from "./sync.js";
9
+ const USAGE = `Usage: ds-viewer <command>
10
+
11
+ Commands:
12
+ init Set up the viewer in this project: config, draft catalog pages, and an npm script
13
+ --yes accept the detected components and tokens without asking
14
+ sync Regenerate the component, props, token, and page data from source
15
+ dev Sync, then serve the catalog on a local web address and keep it current as files change
16
+
17
+ Options:
18
+ -h, --help Show this help
19
+ -v, --version Show the installed version`;
20
+ /** Walks up from this file (cli/ in source, dist/cli/ when installed) to the package's own package.json. */
21
+ function packageVersion() {
22
+ let dir = path.dirname(fileURLToPath(import.meta.url));
23
+ while (true) {
24
+ const candidate = path.join(dir, 'package.json');
25
+ if (existsSync(candidate)) {
26
+ const pkg = JSON.parse(readFileSync(candidate, 'utf8'));
27
+ if (pkg.name === '@krapwoo/ds-viewer' && pkg.version)
28
+ return pkg.version;
29
+ }
30
+ const parent = path.dirname(dir);
31
+ if (parent === dir)
32
+ return 'unknown';
33
+ dir = parent;
34
+ }
35
+ }
7
36
  async function main() {
8
37
  const [command, ...rest] = process.argv.slice(2);
9
38
  const projectRoot = process.cwd();
39
+ if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
40
+ console.log(USAGE);
41
+ return;
42
+ }
43
+ if (command === '--version' || command === '-v') {
44
+ console.log(packageVersion());
45
+ return;
46
+ }
10
47
  if (command === 'init') {
11
48
  const result = await initExistingProject(projectRoot, { yes: rest.includes('--yes') });
12
49
  for (const message of result.messages)
@@ -28,7 +65,7 @@ async function main() {
28
65
  await dev(config);
29
66
  return;
30
67
  }
31
- console.error(`Unknown command "${command ?? ''}". Usage: ds-viewer <init|dev|sync>`);
68
+ console.error(`Unknown command "${command}".\n\n${USAGE}`);
32
69
  process.exitCode = 1;
33
70
  }
34
71
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krapwoo/ds-viewer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A browsable, always-current catalog for an Expo / React Native design system.",
@@ -43,7 +43,9 @@
43
43
  "react-native-safe-area-context": "*"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
- "react-native-safe-area-context": { "optional": true }
46
+ "react-native-safe-area-context": {
47
+ "optional": true
48
+ }
47
49
  },
48
50
  "dependencies": {
49
51
  "typescript": "^6.0.0"