@ucdjs/cli 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Lucas Nørgård
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @ucdjs/cli
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+
6
+ A CLI for working with the Unicode Character Database (UCD).
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install -g @ucdjs/cli
12
+ ```
13
+
14
+ ## 📄 License
15
+
16
+ Published under [MIT License](./LICENSE).
17
+
18
+ [npm-version-src]: https://img.shields.io/npm/v/@ucdjs/cli?style=flat&colorA=18181B&colorB=4169E1
19
+ [npm-version-href]: https://npmjs.com/package/@ucdjs/cli
20
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs/cli?style=flat&colorA=18181B&colorB=4169E1
21
+ [npm-downloads-href]: https://npmjs.com/package/@ucdjs/cli
package/bin/ucd.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import("../dist/cli.js");
@@ -0,0 +1,174 @@
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 name = "@ucdjs/cli";
7
+ var version = "0.0.0";
8
+ var type = "module";
9
+ var author = {
10
+ "name": "Lucas Nørgård",
11
+ "email": "lucasnrgaard@gmail.com",
12
+ "url": "https://luxass.dev"
13
+ };
14
+ var packageManager = "pnpm@10.8.0";
15
+ var license = "MIT";
16
+ var homepage = "https://github.com/ucdjs/ucd";
17
+ var repository = {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ucdjs/ucd.git",
20
+ "directory": "packages/cli"
21
+ };
22
+ var bugs = { "url": "https://github.com/ucdjs/ucd/issues" };
23
+ var bin = { "ucd": "bin/ucd.js" };
24
+ var files = ["bin", "dist"];
25
+ var scripts = {
26
+ "build": "tsdown",
27
+ "clean": "git clean -xdf dist node_modules",
28
+ "lint": "eslint .",
29
+ "typecheck": "tsc --noEmit"
30
+ };
31
+ var dependencies = {
32
+ "farver": "catalog:prod",
33
+ "yargs-parser": "catalog:prod"
34
+ };
35
+ var devDependencies = {
36
+ "@luxass/eslint-config": "catalog:dev",
37
+ "@types/yargs-parser": "catalog:dev",
38
+ "eslint": "catalog:dev",
39
+ "publint": "catalog:dev",
40
+ "tsdown": "catalog:dev",
41
+ "typescript": "catalog:dev",
42
+ "vitest-testdirs": "catalog:dev"
43
+ };
44
+ var publishConfig = { "access": "public" };
45
+ var package_default = {
46
+ name,
47
+ version,
48
+ type,
49
+ author,
50
+ packageManager,
51
+ license,
52
+ homepage,
53
+ repository,
54
+ bugs,
55
+ bin,
56
+ files,
57
+ scripts,
58
+ dependencies,
59
+ devDependencies,
60
+ publishConfig
61
+ };
62
+
63
+ //#endregion
64
+ //#region src/cli-utils.ts
65
+ const SUPPORTED_COMMANDS = new Set(["generate"]);
66
+ /**
67
+ * Resolves the CLI command based on the provided arguments.
68
+ *
69
+ * If the `version` flag is present, it returns the "version" command.
70
+ * Otherwise, it checks if the third argument in the positional arguments (`flags._[2]`)
71
+ * is a supported command. If it is, it returns that command.
72
+ * If no supported command is found, it defaults to the "help" command.
73
+ *
74
+ * @param {Arguments} flags - The parsed arguments from the command line.
75
+ * @returns {CLICommand} The resolved CLI command.
76
+ */
77
+ function resolveCommand(flags) {
78
+ if (flags.version) return "version";
79
+ const cmd = flags._[2];
80
+ if (SUPPORTED_COMMANDS.has(cmd)) return cmd;
81
+ return "help";
82
+ }
83
+ function printHelp({ commandName, headline, usage, tables, description }) {
84
+ const terminalWidth = process.stdout.columns || 80;
85
+ const isTinyTerminal = terminalWidth < 60;
86
+ const indent = " ";
87
+ const linebreak = () => "";
88
+ const table = (rows, { padding }) => {
89
+ let raw = "";
90
+ for (const [command, help] of rows) if (isTinyTerminal) raw += `${indent}${indent}${bold(command)}\n${indent}${indent}${indent}${dim(help)}\n`;
91
+ else {
92
+ const paddedCommand = command.padEnd(padding);
93
+ raw += `${indent}${indent}${bold(paddedCommand)} ${dim(help)}\n`;
94
+ }
95
+ return raw.slice(0, -1);
96
+ };
97
+ const message = [];
98
+ if (headline) message.push(`\n${indent}${bgGreen(black(` ${commandName} `))} ${green(`v${package_default.version ?? "0.0.0"}`)}`, `${indent}${dim(headline)}`);
99
+ if (usage) message.push(linebreak(), `${indent}${bold("USAGE")}`, `${indent}${indent}${green(commandName)} ${usage}`);
100
+ if (description) message.push(linebreak(), `${indent}${bold("DESCRIPTION")}`, `${indent}${indent}${description}`);
101
+ if (tables) {
102
+ function calculateTablePadding(rows) {
103
+ const maxLength = rows.reduce((val, [first]) => Math.max(val, first.length), 0);
104
+ return Math.min(maxLength, 30) + 2;
105
+ }
106
+ const tableEntries = Object.entries(tables);
107
+ for (const [tableTitle, tableRows] of tableEntries) {
108
+ const padding = calculateTablePadding(tableRows);
109
+ message.push(linebreak(), `${indent}${bold(tableTitle.toUpperCase())}`, table(tableRows, { padding }));
110
+ }
111
+ }
112
+ message.push(linebreak(), `${indent}${dim(`Run with --help for more information on specific commands.`)}`);
113
+ console.log(`${message.join("\n")}\n`);
114
+ }
115
+ /**
116
+ * Runs a command based on the provided CLI command and flags.
117
+ *
118
+ * @param {CLICommand} cmd - The CLI command to execute.
119
+ * @param {Arguments} flags - The flags passed to the command.
120
+ * @returns {Promise<void>} A promise that resolves when the command has finished executing.
121
+ * @throws An error if the command is not found.
122
+ */
123
+ async function runCommand(cmd, flags) {
124
+ switch (cmd) {
125
+ case "help":
126
+ printHelp({
127
+ commandName: "ucd",
128
+ headline: "A CLI for working with the Unicode Character Database (UCD).",
129
+ usage: "[command] [...flags]",
130
+ tables: {
131
+ "Commands": [["generate", "Generate UCD data files."]],
132
+ "Global Flags": [
133
+ ["--force", "Force the operation to run, even if it's not needed."],
134
+ ["--version", "Show the version number and exit."],
135
+ ["--help", "Show this help message."]
136
+ ]
137
+ }
138
+ });
139
+ break;
140
+ case "version":
141
+ console.log(` ${bgGreen(black(` ucd `))} ${green(`v${package_default.version ?? "x.y.z"}`)}`);
142
+ break;
143
+ case "generate": {
144
+ const { runGenerate } = await import("./generate-ADwYDcJ5.js");
145
+ const versions = flags._.slice(3);
146
+ await runGenerate({
147
+ versions,
148
+ flags
149
+ });
150
+ break;
151
+ }
152
+ default: throw new Error(`Error running ${cmd} -- no command found.`);
153
+ }
154
+ }
155
+ function parseFlags(args) {
156
+ return yargs(args, {
157
+ configuration: { "parse-positional-numbers": false },
158
+ string: ["output-dir"],
159
+ default: { "output-dir": "./data" }
160
+ });
161
+ }
162
+ async function runCLI(args) {
163
+ try {
164
+ const flags = parseFlags(args);
165
+ const cmd = resolveCommand(flags);
166
+ await runCommand(cmd, flags);
167
+ } catch (err) {
168
+ console.error(err);
169
+ process.exit(1);
170
+ }
171
+ }
172
+
173
+ //#endregion
174
+ export { printHelp, runCLI };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,7 @@
1
+ import { runCLI } from "./cli-utils-C8H822Rg.js";
2
+ import process from "node:process";
3
+
4
+ //#region src/cli.ts
5
+ runCLI(process.argv);
6
+
7
+ //#endregion
@@ -0,0 +1,21 @@
1
+ import { printHelp } from "./cli-utils-C8H822Rg.js";
2
+ import { green } from "farver/fast";
3
+ import path from "node:path";
4
+
5
+ //#region src/cmd/generate.ts
6
+ async function runGenerate({ versions: providedVersions, flags }) {
7
+ if (flags?.help || flags?.h) {
8
+ printHelp({
9
+ headline: "Generate Unicode Data Files",
10
+ commandName: "ucd generate",
11
+ usage: "<...versions> [...flags]",
12
+ tables: { Flags: [["--output-dir", "Specify the output directory."], ["--help (-h)", "See all available flags."]] }
13
+ });
14
+ return;
15
+ }
16
+ const _outputDir = flags.outputDir ?? path.join(process.cwd(), "data");
17
+ console.log(green(`Generating emoji data for versions: ${providedVersions.join(", ")}`));
18
+ }
19
+
20
+ //#endregion
21
+ export { runGenerate };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ucdjs/cli",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "author": {
6
+ "name": "Lucas Nørgård",
7
+ "email": "lucasnrgaard@gmail.com",
8
+ "url": "https://luxass.dev"
9
+ },
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/ucdjs/ucd",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/ucdjs/ucd.git",
15
+ "directory": "packages/cli"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/ucdjs/ucd/issues"
19
+ },
20
+ "bin": {
21
+ "ucd": "bin/ucd.js"
22
+ },
23
+ "files": [
24
+ "bin",
25
+ "dist"
26
+ ],
27
+ "dependencies": {
28
+ "farver": "^0.4.2",
29
+ "yargs-parser": "^21.1.1"
30
+ },
31
+ "devDependencies": {
32
+ "@luxass/eslint-config": "^4.18.1",
33
+ "@types/yargs-parser": "^21.0.3",
34
+ "eslint": "^9.23.0",
35
+ "publint": "^0.3.12",
36
+ "tsdown": "v0.9.3",
37
+ "typescript": "^5.8.2",
38
+ "vitest-testdirs": "^3.0.1"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "clean": "git clean -xdf dist node_modules",
46
+ "lint": "eslint .",
47
+ "typecheck": "tsc --noEmit"
48
+ }
49
+ }