@ucdjs/cli 0.3.0 → 0.3.1-beta.2

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.
@@ -0,0 +1,114 @@
1
+ import { _ as output, c as bold, p as green, t as printHelp, u as dim, v as red, y as yellow } from "./cli.mjs";
2
+ import process from "node:process";
3
+ import { readFile } from "node:fs/promises";
4
+ import { resolve } from "node:path";
5
+ import { safeJsonParse } from "@ucdjs-internal/shared";
6
+ import { getLockfilePath, validateLockfile } from "@ucdjs/lockfile";
7
+
8
+ //#region src/cmd/lockfile/validate.ts
9
+ async function runLockfileValidate({ flags }) {
10
+ if (flags?.help || flags?.h) {
11
+ printHelp({
12
+ headline: "Validate lockfile against the expected schema",
13
+ commandName: "ucd lockfile validate",
14
+ usage: "[...flags]",
15
+ description: "Parse and validate the UCD store lockfile, reporting any schema violations or structural issues.",
16
+ tables: { Flags: [
17
+ ["--store-dir", "Directory where the UCD store is located (defaults to current directory)."],
18
+ ["--json", "Output validation results as JSON."],
19
+ ["--help (-h)", "See all available flags."]
20
+ ] }
21
+ });
22
+ return;
23
+ }
24
+ const { storeDir, json } = flags;
25
+ const lockfilePath = resolve(storeDir ? resolve(storeDir) : process.cwd(), getLockfilePath());
26
+ try {
27
+ let rawContent;
28
+ try {
29
+ rawContent = await readFile(lockfilePath, "utf-8");
30
+ } catch {
31
+ if (json) output.json({
32
+ valid: false,
33
+ lockfilePath,
34
+ error: "LOCKFILE_NOT_FOUND",
35
+ message: `Lockfile not found at "${lockfilePath}"`
36
+ });
37
+ else {
38
+ output.error(red(`\n❌ Error: Lockfile not found at "${lockfilePath}".`));
39
+ output.error(`\n Run ${green("ucd store init")} to create a new store.`);
40
+ }
41
+ return;
42
+ }
43
+ const jsonData = safeJsonParse(rawContent);
44
+ if (!jsonData) {
45
+ if (json) output.json({
46
+ valid: false,
47
+ lockfilePath,
48
+ error: "INVALID_JSON",
49
+ message: "Lockfile is not valid JSON"
50
+ });
51
+ else {
52
+ output.error(red(`\n❌ Validation failed: Lockfile is not valid JSON.`));
53
+ output.error(` ${dim(`Path: ${lockfilePath}`)}`);
54
+ }
55
+ return;
56
+ }
57
+ const result = validateLockfile(jsonData);
58
+ if (!result.valid) {
59
+ const issues = result.errors ?? [];
60
+ if (json) output.json({
61
+ valid: false,
62
+ lockfilePath,
63
+ error: "SCHEMA_VALIDATION_FAILED",
64
+ issues
65
+ });
66
+ else {
67
+ output.error(red(`\n❌ Validation failed: Lockfile does not match expected schema.`));
68
+ output.error(` ${dim(`Path: ${lockfilePath}`)}\n`);
69
+ output.log(` ${bold("Issues:")}`);
70
+ for (const issue of issues) output.log(` ${yellow("•")} ${bold(issue.path || "(root)")}: ${issue.message}`);
71
+ }
72
+ return;
73
+ }
74
+ const warnings = [];
75
+ const lockfile = result.data;
76
+ const versionCount = Object.keys(lockfile.versions).length;
77
+ if (versionCount === 0) warnings.push("Lockfile has no versions tracked.");
78
+ for (const [version, entry] of Object.entries(lockfile.versions)) {
79
+ if (entry.fileCount === 0) warnings.push(`Version "${version}" has 0 files.`);
80
+ if (entry.totalSize === 0 && entry.fileCount > 0) warnings.push(`Version "${version}" has files but totalSize is 0.`);
81
+ }
82
+ if (json) output.json({
83
+ valid: true,
84
+ lockfilePath,
85
+ lockfileVersion: lockfile.lockfileVersion,
86
+ versionCount,
87
+ warnings: warnings.length > 0 ? warnings : void 0
88
+ });
89
+ else {
90
+ output.log(green(`\n✅ Lockfile is valid.`));
91
+ output.log(` ${dim(`Path: ${lockfilePath}`)}`);
92
+ output.log(` ${bold("Lockfile Version:")} ${lockfile.lockfileVersion}`);
93
+ output.log(` ${bold("Tracked Versions:")} ${versionCount}`);
94
+ if (warnings.length > 0) {
95
+ output.log(`\n ${yellow(bold("Warnings:"))}`);
96
+ for (const warning of warnings) output.log(` ${yellow("•")} ${warning}`);
97
+ }
98
+ }
99
+ } catch (err) {
100
+ if (json) output.json({
101
+ valid: false,
102
+ lockfilePath,
103
+ error: "UNKNOWN_ERROR",
104
+ message: err instanceof Error ? err.message : String(err)
105
+ });
106
+ else {
107
+ output.error(red(`\n❌ Validation error:`));
108
+ if (err instanceof Error) output.error(` ${err.message}`);
109
+ }
110
+ }
111
+ }
112
+
113
+ //#endregion
114
+ export { runLockfileValidate };
@@ -0,0 +1,114 @@
1
+ import { _ as output, p as green, t as printHelp, v as red, y as yellow } from "./cli.mjs";
2
+ import { a as assertRemoteOrStoreDir, n as REMOTE_CAPABLE_FLAGS, o as createStoreFromFlags, r as SHARED_FLAGS } from "./_shared-CgcKJJFf.mjs";
3
+ import { createUCDClient } from "@ucdjs/client";
4
+ import { UCDJS_API_BASE_URL } from "@ucdjs/env";
5
+ import { createDebugger } from "@ucdjs-internal/shared";
6
+ import { getLockfilePath, readLockfile } from "@ucdjs/lockfile";
7
+
8
+ //#region src/cmd/store/verify.ts
9
+ const debug = createDebugger("ucdjs:cli:store:verify");
10
+ async function runVerifyStore({ flags }) {
11
+ if (flags?.help || flags?.h) {
12
+ printHelp({
13
+ headline: "Verify UCD Store integrity",
14
+ commandName: "ucd store verify",
15
+ usage: "[...versions] [...flags]",
16
+ tables: { Flags: [
17
+ ...REMOTE_CAPABLE_FLAGS,
18
+ ...SHARED_FLAGS,
19
+ ["--json", "Output verification results in JSON format."],
20
+ ["--help (-h)", "See all available flags."]
21
+ ] }
22
+ });
23
+ return;
24
+ }
25
+ const { storeDir, remote, baseUrl, include: patterns, exclude: excludePatterns, json } = flags;
26
+ assertRemoteOrStoreDir(flags);
27
+ const store = await createStoreFromFlags({
28
+ baseUrl,
29
+ storeDir,
30
+ remote,
31
+ include: patterns,
32
+ exclude: excludePatterns,
33
+ requireExistingStore: true
34
+ });
35
+ const lockfilePath = getLockfilePath();
36
+ const bridge = store.fs;
37
+ let lockfile;
38
+ try {
39
+ lockfile = await readLockfile(bridge, lockfilePath);
40
+ } catch (err) {
41
+ debug?.("Error reading lockfile:", err);
42
+ if (remote) {
43
+ output.error(red(`\n❌ Error: Could not read lockfile from remote store.`));
44
+ output.error("Verify operation requires a lockfile. For remote stores, the lockfile must be accessible via the API.");
45
+ } else {
46
+ output.error(red(`\n❌ Error: Lockfile not found at ${lockfilePath}`));
47
+ output.error("Run 'ucd store init' to create a new store.");
48
+ }
49
+ return;
50
+ }
51
+ const lockfileVersions = Object.keys(lockfile.versions);
52
+ const client = await createUCDClient(baseUrl || UCDJS_API_BASE_URL);
53
+ const configResult = await client.config.get();
54
+ let availableVersions = [];
55
+ if (configResult.error || !configResult.data) {
56
+ const apiResult = await client.versions.list();
57
+ if (apiResult.error) {
58
+ output.error(red(`\n❌ Error fetching versions: ${apiResult.error.message}`));
59
+ return;
60
+ }
61
+ if (!apiResult.data) {
62
+ output.error(red(`\n❌ Error: No versions data returned from API.`));
63
+ return;
64
+ }
65
+ availableVersions = apiResult.data.map(({ version }) => version);
66
+ } else {
67
+ availableVersions = configResult.data.versions ?? [];
68
+ if (availableVersions.length === 0) {
69
+ const apiResult = await client.versions.list();
70
+ if (apiResult.error) {
71
+ output.error(red(`\n❌ Error fetching versions: ${apiResult.error.message}`));
72
+ return;
73
+ }
74
+ if (!apiResult.data) {
75
+ output.error(red(`\n❌ Error: No versions data returned from API.`));
76
+ return;
77
+ }
78
+ availableVersions = apiResult.data.map(({ version }) => version);
79
+ }
80
+ }
81
+ const availableVersionsSet = new Set(availableVersions);
82
+ const lockfileVersionsSet = new Set(lockfileVersions);
83
+ const missingVersions = lockfileVersions.filter((v) => !availableVersionsSet.has(v));
84
+ const extraVersions = availableVersions.filter((v) => !lockfileVersionsSet.has(v));
85
+ const validVersions = lockfileVersions.filter((v) => availableVersionsSet.has(v));
86
+ const isValid = missingVersions.length === 0;
87
+ if (json) {
88
+ output.json({
89
+ valid: isValid,
90
+ lockfileVersions,
91
+ availableVersions,
92
+ missingVersions,
93
+ extraVersions,
94
+ validVersions
95
+ });
96
+ return;
97
+ }
98
+ if (isValid) {
99
+ output.log(green("\n✓ Store verification passed\n"));
100
+ output.log(`All ${lockfileVersions.length} version(s) in lockfile are available in API.`);
101
+ } else {
102
+ output.error(red("\n❌ Store verification failed\n"));
103
+ output.error(`Found ${missingVersions.length} version(s) in lockfile that are not available in API:`);
104
+ for (const version of missingVersions) output.error(` - ${version}`);
105
+ }
106
+ if (extraVersions.length > 0) {
107
+ output.log(yellow(`\n⚠ Note: ${extraVersions.length} version(s) available in API but not in lockfile:`));
108
+ for (const version of extraVersions) output.log(` + ${version}`);
109
+ output.log("Run 'ucd store sync' to update the lockfile.");
110
+ }
111
+ }
112
+
113
+ //#endregion
114
+ export { runVerifyStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucdjs/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-beta.2",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Lucas Nørgård",
@@ -18,12 +18,10 @@
18
18
  "url": "https://github.com/ucdjs/ucd/issues"
19
19
  },
20
20
  "exports": {
21
- ".": "./dist/cli.js",
21
+ ".": "./dist/cli.mjs",
22
22
  "./package.json": "./package.json"
23
23
  },
24
- "main": "./dist/cli.js",
25
- "module": "./dist/cli.js",
26
- "types": "./dist/cli.d.ts",
24
+ "types": "./dist/cli.d.mts",
27
25
  "bin": {
28
26
  "ucd": "bin/ucd.js"
29
27
  },
@@ -35,22 +33,28 @@
35
33
  "node": ">=22.18"
36
34
  },
37
35
  "dependencies": {
38
- "@clack/prompts": "1.0.0-alpha.5",
39
- "@luxass/utils": "2.7.2",
40
- "@unicode-utils/core": "0.12.0-beta.18",
36
+ "@clack/prompts": "1.0.0",
37
+ "@luxass/utils": "2.7.3",
38
+ "@unicode-utils/core": "0.12.0-beta.19",
41
39
  "farver": "0.4.2",
42
40
  "yargs-parser": "22.0.0",
43
- "@ucdjs/schema-gen": "0.2.2",
44
- "@ucdjs/ucd-store": "0.1.0"
41
+ "@ucdjs-internal/shared": "0.1.1-beta.2",
42
+ "@ucdjs/client": "0.1.1-beta.2",
43
+ "@ucdjs/env": "0.1.1-beta.3",
44
+ "@ucdjs/lockfile": "0.1.1-beta.2",
45
+ "@ucdjs/fs-bridge": "0.1.1-beta.2",
46
+ "@ucdjs/schemas": "0.1.1-beta.2",
47
+ "@ucdjs/ucd-store": "1.0.1-beta.2",
48
+ "@ucdjs/schema-gen": "0.2.3-beta.2"
45
49
  },
46
50
  "devDependencies": {
47
- "@luxass/eslint-config": "6.0.1",
51
+ "@luxass/eslint-config": "7.2.0",
48
52
  "@types/yargs-parser": "21.0.3",
49
- "eslint": "9.38.0",
50
- "publint": "0.3.15",
51
- "tsdown": "0.15.9",
53
+ "eslint": "10.0.0",
54
+ "publint": "0.3.17",
55
+ "tsdown": "0.20.3",
52
56
  "typescript": "5.9.3",
53
- "vitest-testdirs": "4.2.1",
57
+ "vitest-testdirs": "4.4.2",
54
58
  "@ucdjs-tooling/tsconfig": "1.0.0",
55
59
  "@ucdjs-tooling/tsdown-config": "1.0.0"
56
60
  },
@@ -62,6 +66,6 @@
62
66
  "dev": "tsdown --watch",
63
67
  "clean": "git clean -xdf dist node_modules",
64
68
  "lint": "eslint .",
65
- "typecheck": "tsc --noEmit"
69
+ "typecheck": "tsc --noEmit -p tsconfig.build.json"
66
70
  }
67
71
  }
@@ -1,59 +0,0 @@
1
- import { createHTTPUCDStore, createNodeUCDStore } from "@ucdjs/ucd-store";
2
- import { isCancel, multiselect } from "@clack/prompts";
3
- import { UNICODE_VERSION_METADATA } from "@unicode-utils/core";
4
-
5
- //#region src/cmd/store/_shared.ts
6
- const SHARED_FLAGS = [
7
- ["--remote", "Use a Remote UCD Store."],
8
- ["--store-dir", "Directory where the UCD files are stored."],
9
- ["--include", "Patterns to include files in the store."],
10
- ["--exclude", "Patterns to exclude files from the store."],
11
- ["--base-url", "Base URL for the UCD Store."]
12
- ];
13
- function assertRemoteOrStoreDir(flags) {
14
- if (!flags.remote && !flags.storeDir) throw new Error("Either --remote or --store-dir must be specified.");
15
- }
16
- /**
17
- * Creates a UCD store instance based on the provided CLI flags.
18
- *
19
- * @param {CLIStoreCmdSharedFlags} flags - Configuration flags for creating the store
20
- * @returns {Promise<UCDStore | null>} A promise that resolves to a UCDStore instance or null
21
- * @throws {Error} When store directory is not specified for local stores
22
- */
23
- async function createStoreFromFlags(flags) {
24
- const { storeDir, remote, baseUrl, include, exclude } = flags;
25
- if (remote) return createHTTPUCDStore({
26
- baseUrl,
27
- globalFilters: {
28
- include,
29
- exclude
30
- }
31
- });
32
- if (!storeDir) throw new Error("Store directory must be specified when not using remote store.");
33
- return createNodeUCDStore({
34
- basePath: storeDir,
35
- baseUrl,
36
- globalFilters: {
37
- include,
38
- exclude
39
- },
40
- versions: flags.versions || []
41
- });
42
- }
43
- async function runVersionPrompt({ input, output } = {}) {
44
- const selectedVersions = await multiselect({
45
- options: UNICODE_VERSION_METADATA.map(({ version }) => ({
46
- value: version,
47
- label: version
48
- })),
49
- message: "Select Unicode versions to initialize the store with:",
50
- required: true,
51
- input,
52
- output
53
- });
54
- if (isCancel(selectedVersions)) return [];
55
- return selectedVersions;
56
- }
57
-
58
- //#endregion
59
- export { runVersionPrompt as i, assertRemoteOrStoreDir as n, createStoreFromFlags as r, SHARED_FLAGS as t };
@@ -1,78 +0,0 @@
1
- import { t as printHelp } from "./cli-utils-dAbyq59_.js";
2
- import { n as assertRemoteOrStoreDir, r as createStoreFromFlags, t as SHARED_FLAGS } from "./_shared-DlzCE5mE.js";
3
- import { green, red } from "farver/fast";
4
- import { UCDStoreUnsupportedFeature } from "@ucdjs/ucd-store";
5
-
6
- //#region src/cmd/store/analyze.ts
7
- async function runAnalyzeStore({ flags, versions }) {
8
- if (flags?.help || flags?.h) {
9
- printHelp({
10
- headline: "Analyze UCD Store",
11
- commandName: "ucd store analyze",
12
- usage: "[...versions] [...flags]",
13
- tables: { Flags: [
14
- ...SHARED_FLAGS,
15
- ["--check-orphaned", "Check for orphaned files in the store."],
16
- ["--json", "Output analyze information in JSON format."],
17
- ["--help (-h)", "See all available flags."]
18
- ] }
19
- });
20
- return;
21
- }
22
- if (!versions || versions.length === 0) console.info("No specific versions provided. Analyzing all versions in the store.");
23
- const { storeDir, json, remote, baseUrl, include: patterns, checkOrphaned } = flags;
24
- try {
25
- assertRemoteOrStoreDir(flags);
26
- const store = await createStoreFromFlags({
27
- baseUrl,
28
- storeDir,
29
- remote,
30
- include: patterns
31
- });
32
- if (store == null) {
33
- console.error("Error: Failed to create UCD store.");
34
- return;
35
- }
36
- const [analyzeData, analyzeError] = await store.analyze({
37
- checkOrphaned: !!checkOrphaned,
38
- versions: versions || []
39
- });
40
- if (analyzeError != null) {
41
- console.error(red(`\n❌ Error analyzing store:`));
42
- console.error(` ${analyzeError.message}`);
43
- return;
44
- }
45
- if (json) {
46
- console.info(JSON.stringify(analyzeData, null, 2));
47
- return;
48
- }
49
- for (const { version, fileCount, isComplete, missingFiles, orphanedFiles, expectedFileCount } of analyzeData) {
50
- console.info(`Version: ${version}`);
51
- if (isComplete) console.info(` Status: ${green("complete")}`);
52
- else console.warn(` Status: ${red("incomplete")}`);
53
- console.info(` Files: ${fileCount}`);
54
- if (missingFiles && missingFiles.length > 0) console.warn(` Missing files: ${missingFiles.length}`);
55
- if (orphanedFiles && orphanedFiles.length > 0) console.warn(` Orphaned files: ${orphanedFiles.length}`);
56
- if (expectedFileCount) console.info(` Total files expected: ${expectedFileCount}`);
57
- }
58
- } catch (err) {
59
- if (err instanceof UCDStoreUnsupportedFeature) {
60
- console.error(red(`\n❌ Error: Unsupported feature:`));
61
- console.error(` ${err.message}`);
62
- console.error("");
63
- console.error("This store does not support the analyze operation.");
64
- console.error("Please check the store capabilities or use a different store type.");
65
- return;
66
- }
67
- let message = "Unknown error";
68
- if (err instanceof Error) message = err.message;
69
- else if (typeof err === "string") message = err;
70
- console.error(red(`\n❌ Error analyzing store:`));
71
- console.error(` ${message}`);
72
- console.error("Please check the store configuration and try again.");
73
- console.error("If you believe this is a bug, please report it at https://github.com/ucdjs/ucd/issues");
74
- }
75
- }
76
-
77
- //#endregion
78
- export { runAnalyzeStore };
@@ -1,23 +0,0 @@
1
- import { t as printHelp } from "./cli-utils-dAbyq59_.js";
2
- import { t as SHARED_FLAGS } from "./_shared-DlzCE5mE.js";
3
-
4
- //#region src/cmd/store/clean.ts
5
- async function runCleanStore({ flags }) {
6
- if (flags?.help || flags?.h) {
7
- printHelp({
8
- headline: "Clean an UCD Store",
9
- commandName: "ucd store clean",
10
- usage: "[...flags]",
11
- tables: { Flags: [
12
- ...SHARED_FLAGS,
13
- ["--dry-run", "Show what would be deleted without actually deleting."],
14
- ["--help (-h)", "See all available flags."]
15
- ] }
16
- });
17
- return;
18
- }
19
- const { storeDir, dryRun, remote, baseUrl, include: patterns } = flags;
20
- }
21
-
22
- //#endregion
23
- export { runCleanStore };
@@ -1,129 +0,0 @@
1
- import process from "node:process";
2
- import { bgGreen, black, bold, dim, green } from "farver/fast";
3
- import yargs from "yargs-parser";
4
-
5
- //#region package.json
6
- var version = "0.3.0";
7
-
8
- //#endregion
9
- //#region src/cli-utils.ts
10
- const SUPPORTED_COMMANDS = new Set(["codegen", "store"]);
11
- /**
12
- * Resolves the CLI command based on the provided arguments.
13
- *
14
- * If the `version` flag is present, it returns the "version" command.
15
- * Otherwise, it checks if the third argument in the positional arguments (`flags._[2]`)
16
- * is a supported command. If it is, it returns that command.
17
- * If no supported command is found, it defaults to the "help" command.
18
- *
19
- * @param {Arguments} flags - The parsed arguments from the command line.
20
- * @returns {CLICommand} The resolved CLI command.
21
- */
22
- function resolveCommand(flags) {
23
- if (flags.version) return "version";
24
- const cmd = flags._[0];
25
- if (SUPPORTED_COMMANDS.has(cmd)) return cmd;
26
- return "help";
27
- }
28
- function printHelp({ commandName, headline, usage, tables, description }) {
29
- const isTinyTerminal = (process.stdout.columns || 80) < 60;
30
- const indent = " ";
31
- const linebreak = () => "";
32
- const table = (rows, { padding }) => {
33
- let raw = "";
34
- for (const [command, help] of rows) if (isTinyTerminal) raw += `${indent}${indent}${bold(command)}\n${indent}${indent}${indent}${dim(help)}\n`;
35
- else {
36
- const paddedCommand = command.padEnd(padding);
37
- raw += `${indent}${indent}${bold(paddedCommand)} ${dim(help)}\n`;
38
- }
39
- return raw.slice(0, -1);
40
- };
41
- const message = [];
42
- if (headline) message.push(`\n${indent}${bgGreen(black(` ${commandName} `))} ${green(`v${version ?? "0.0.0"}`)}`, `${indent}${dim(headline)}`);
43
- if (usage) message.push(linebreak(), `${indent}${bold("USAGE")}`, `${indent}${indent}${green(commandName)} ${usage}`);
44
- if (description) message.push(linebreak(), `${indent}${bold("DESCRIPTION")}`, `${indent}${indent}${description}`);
45
- if (tables) {
46
- function calculateTablePadding(rows) {
47
- const maxLength = rows.reduce((val, [first]) => Math.max(val, first.length), 0);
48
- return Math.min(maxLength, 30) + 2;
49
- }
50
- const tableEntries = Object.entries(tables);
51
- for (const [tableTitle, tableRows] of tableEntries) {
52
- const padding = calculateTablePadding(tableRows);
53
- message.push(linebreak(), `${indent}${bold(tableTitle.toUpperCase())}`, table(tableRows, { padding }));
54
- }
55
- }
56
- message.push(linebreak(), `${indent}${dim(`Run with --help for more information on specific commands.`)}`);
57
- console.log(`${message.join("\n")}\n`);
58
- }
59
- /**
60
- * Runs a command based on the provided CLI command and flags.
61
- *
62
- * @param {CLICommand} cmd - The CLI command to execute.
63
- * @param {Arguments} flags - The flags passed to the command.
64
- * @returns {Promise<void>} A promise that resolves when the command has finished executing.
65
- * @throws An error if the command is not found.
66
- */
67
- async function runCommand(cmd, flags) {
68
- switch (cmd) {
69
- case "help":
70
- printHelp({
71
- commandName: "ucd",
72
- headline: "A CLI for working with the Unicode Character Database (UCD).",
73
- usage: "[command] [...flags]",
74
- tables: {
75
- "Commands": [["download", "Download Unicode data files."], ["codegen", "Generate TypeScript code from UCD data."]],
76
- "Global Flags": [
77
- ["--force", "Force the operation to run, even if it's not needed."],
78
- ["--version", "Show the version number and exit."],
79
- ["--help", "Show this help message."]
80
- ]
81
- }
82
- });
83
- break;
84
- case "version":
85
- console.log(` ${bgGreen(black(` ucd `))} ${green(`v${version ?? "x.y.z"}`)}`);
86
- break;
87
- case "codegen": {
88
- const { runCodegenRoot } = await import("./root-jW0s7hem.js");
89
- await runCodegenRoot(flags._[1]?.toString() ?? "", { flags });
90
- break;
91
- }
92
- case "store": {
93
- const { runStoreRoot } = await import("./root-D1JJ1qhM.js");
94
- await runStoreRoot(flags._[1]?.toString() ?? "", { flags });
95
- break;
96
- }
97
- default: throw new Error(`Error running ${cmd} -- no command found.`);
98
- }
99
- }
100
- function parseFlags(args) {
101
- return yargs(args, {
102
- configuration: { "parse-positional-numbers": false },
103
- default: { force: false },
104
- boolean: [
105
- "force",
106
- "help",
107
- "h",
108
- "dry-run"
109
- ],
110
- string: [
111
- "output-dir",
112
- "input-dir",
113
- "output-file"
114
- ]
115
- });
116
- }
117
- async function runCLI(args) {
118
- try {
119
- const flags = parseFlags(args);
120
- process.title = "ucd-cli";
121
- await runCommand(resolveCommand(flags), flags);
122
- } catch (err) {
123
- console.error(err);
124
- process.exit(1);
125
- }
126
- }
127
-
128
- //#endregion
129
- export { runCLI as n, printHelp as t };
package/dist/cli.js DELETED
@@ -1,8 +0,0 @@
1
- import { n as runCLI } from "./cli-utils-dAbyq59_.js";
2
- import process from "node:process";
3
-
4
- //#region src/cli.ts
5
- runCLI(process.argv.slice(2));
6
-
7
- //#endregion
8
- export { };
@@ -1,75 +0,0 @@
1
- import { t as printHelp } from "./cli-utils-dAbyq59_.js";
2
- import { i as runVersionPrompt, n as assertRemoteOrStoreDir, r as createStoreFromFlags, t as SHARED_FLAGS } from "./_shared-DlzCE5mE.js";
3
- import { red } from "farver/fast";
4
- import { UCDStoreUnsupportedFeature } from "@ucdjs/ucd-store";
5
-
6
- //#region src/cmd/store/init.ts
7
- async function runInitStore({ flags, versions }) {
8
- if (flags?.help || flags?.h) {
9
- printHelp({
10
- headline: "Initialize an UCD Store",
11
- commandName: "ucd store init",
12
- usage: "[...versions] [...flags]",
13
- tables: { Flags: [
14
- ...SHARED_FLAGS,
15
- ["--force", "Overwrite existing files if they already exist."],
16
- ["--help (-h)", "See all available flags."]
17
- ] }
18
- });
19
- return;
20
- }
21
- const { storeDir, force, remote, baseUrl, include: patterns, dryRun } = flags;
22
- try {
23
- assertRemoteOrStoreDir(flags);
24
- let selectedVersions = versions;
25
- if (!selectedVersions || selectedVersions.length === 0) {
26
- const pickedVersions = await runVersionPrompt();
27
- if (pickedVersions.length === 0) {
28
- console.error("No versions selected. Operation cancelled.");
29
- return;
30
- }
31
- selectedVersions = pickedVersions;
32
- }
33
- const store = await createStoreFromFlags({
34
- baseUrl,
35
- storeDir,
36
- remote,
37
- include: patterns,
38
- versions: selectedVersions
39
- });
40
- await store.init({
41
- force,
42
- dryRun
43
- });
44
- if (!store.initialized) {
45
- console.error(red(`\n❌ Error: Store initialization failed.`));
46
- console.error("Please check the store configuration and try again.");
47
- console.error("This output may help you debug the issue:");
48
- return;
49
- }
50
- if (dryRun) {
51
- console.info("Store initialized successfully in dry-run mode.");
52
- console.info("No files have been written to disk.");
53
- } else console.info("Store initialized successfully.");
54
- } catch (err) {
55
- if (err instanceof UCDStoreUnsupportedFeature) {
56
- console.error(red(`\n❌ Error: Unsupported feature:`));
57
- console.error(` ${err.message}`);
58
- console.error("");
59
- console.error("This store does not support the init operation.");
60
- console.error("Please check the store capabilities or use a different store type.");
61
- return;
62
- }
63
- let message = "Unknown error";
64
- if (err instanceof Error) message = err.message;
65
- else if (typeof err === "string") message = err;
66
- console.error(red(`\n❌ Error initializing store:`));
67
- console.error(` ${message}`);
68
- console.error("Please check the store configuration and try again.");
69
- console.error("If the issue persists, consider running with --dry-run to see more details.");
70
- console.error("If you believe this is a bug, please report it at https://github.com/ucdjs/ucd/issues");
71
- }
72
- }
73
-
74
- //#endregion
75
- export { runInitStore };