@ucdjs/cli 0.0.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.
@@ -4,7 +4,7 @@ import yargs from "yargs-parser";
4
4
 
5
5
  //#region package.json
6
6
  var name = "@ucdjs/cli";
7
- var version = "0.0.0";
7
+ var version = "0.1.1";
8
8
  var type = "module";
9
9
  var author = {
10
10
  "name": "Lucas Nørgård",
@@ -29,6 +29,7 @@ var scripts = {
29
29
  "typecheck": "tsc --noEmit"
30
30
  };
31
31
  var dependencies = {
32
+ "@luxass/unicode-utils": "catalog:prod",
32
33
  "farver": "catalog:prod",
33
34
  "yargs-parser": "catalog:prod"
34
35
  };
@@ -141,7 +142,7 @@ async function runCommand(cmd, flags) {
141
142
  console.log(` ${bgGreen(black(` ucd `))} ${green(`v${package_default.version ?? "x.y.z"}`)}`);
142
143
  break;
143
144
  case "generate": {
144
- const { runGenerate } = await import("./generate-ADwYDcJ5.js");
145
+ const { runGenerate } = await import("./generate-CGxUT7N8.js");
145
146
  const versions = flags._.slice(3);
146
147
  await runGenerate({
147
148
  versions,
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { runCLI } from "./cli-utils-C8H822Rg.js";
1
+ import { runCLI } from "./cli-utils-gCMcRvvP.js";
2
2
  import process from "node:process";
3
3
 
4
4
  //#region src/cli.ts
@@ -0,0 +1,103 @@
1
+ import { printHelp } from "./cli-utils-gCMcRvvP.js";
2
+ import { green, yellow } from "farver/fast";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import path, { dirname, join } from "node:path";
5
+ import { UNICODE_VERSIONS, UNICODE_VERSIONS_WITH_UCD } from "@luxass/unicode-utils";
6
+
7
+ //#region src/cmd/generate.ts
8
+ const BASE_URL = "https://unicode-proxy.ucdjs.dev/proxy";
9
+ async function runGenerate({ versions: providedVersions, flags }) {
10
+ if (flags?.help || flags?.h) {
11
+ printHelp({
12
+ headline: "Generate Unicode Data Files",
13
+ commandName: "ucd generate",
14
+ usage: "<...versions> [...flags]",
15
+ tables: { Flags: [["--output-dir", "Specify the output directory."], ["--help (-h)", "See all available flags."]] }
16
+ });
17
+ return;
18
+ }
19
+ if (providedVersions.length === 0) {
20
+ console.error("No versions provided. Please provide at least one version.");
21
+ return;
22
+ }
23
+ if (providedVersions[0] === "all") providedVersions = UNICODE_VERSIONS_WITH_UCD;
24
+ const invalidVersions = providedVersions.filter((version) => !UNICODE_VERSIONS.includes(version));
25
+ if (invalidVersions.length > 0) {
26
+ console.error(`Invalid version(s) provided: ${invalidVersions.join(", ")}. Please provide valid Unicode versions.`);
27
+ return;
28
+ }
29
+ const outputDir = flags.outputDir ?? path.join(process.cwd(), "data");
30
+ await mkdir(outputDir, { recursive: true });
31
+ async function processDirectory(entry, basePath, version, baseOutputDir, downloadedFiles) {
32
+ const dirPath = `${BASE_URL}/${version}/ucd/${entry.path}`;
33
+ const dirResponse = await fetch(dirPath);
34
+ if (!dirResponse.ok) {
35
+ console.error(`failed to fetch directory: ${entry.path}`);
36
+ return;
37
+ }
38
+ const dirEntries = await dirResponse.json();
39
+ if (!Array.isArray(dirEntries)) {
40
+ console.error(`invalid response format for directory: ${entry.path}`);
41
+ return;
42
+ }
43
+ const fileEntries = dirEntries.filter((e) => e.type === "file" && e.name !== "ReadMe.txt" && !e.path.includes("latest") && !e.path.includes("draft"));
44
+ await Promise.all(fileEntries.map(async (fileEntry) => {
45
+ const fullPath = `${basePath}/${entry.path}/${fileEntry.path}`;
46
+ const pathParts = fullPath.replace(/^\//, "").split("/");
47
+ const filePath = join(baseOutputDir, pathParts.slice(2).join("/"));
48
+ await mkdir(dirname(filePath), { recursive: true });
49
+ try {
50
+ const content = await fetch(`${BASE_URL}${fullPath}`).then((res) => res.text());
51
+ await writeFile(filePath, content);
52
+ downloadedFiles.push(filePath);
53
+ } catch {
54
+ console.error(`failed to process file: ${fullPath}`);
55
+ }
56
+ }));
57
+ const dirEntriesToProcess = dirEntries.filter((e) => e.type === "directory");
58
+ await Promise.all(dirEntriesToProcess.map((dir) => processDirectory(dir, `${basePath}/${entry.path}`, version, baseOutputDir, downloadedFiles)));
59
+ }
60
+ for (const version of providedVersions) {
61
+ console.info(`Starting the generation process for data files for ${green(`Unicode ${version}`)}!`);
62
+ const downloadedFilesForVersion = [];
63
+ const versionPath = `/${version}/ucd`;
64
+ const rootResponse = await fetch(`${BASE_URL}${versionPath}`);
65
+ if (!rootResponse.ok) {
66
+ console.error(`failed to fetch data for version ${version}`);
67
+ continue;
68
+ }
69
+ const rootEntries = await rootResponse.json();
70
+ if (!Array.isArray(rootEntries)) {
71
+ console.error(`invalid response format for version ${version}`);
72
+ continue;
73
+ }
74
+ const versionOutputDir = path.join(outputDir, `v${version}`);
75
+ await mkdir(versionOutputDir, { recursive: true });
76
+ const rootFiles = rootEntries.filter((e) => e.type === "file" && e.name !== "ReadMe.txt" && !e.path.includes("latest") && !e.path.includes("draft"));
77
+ await Promise.all(rootFiles.map(async (fileEntry) => {
78
+ const fileUrl = `${versionPath}/${fileEntry.path}`;
79
+ const outputFilePath = path.join(versionOutputDir, fileEntry.name);
80
+ try {
81
+ const content = await fetch(`${BASE_URL}${fileUrl}`).then((res) => res.text());
82
+ await writeFile(outputFilePath, content);
83
+ downloadedFilesForVersion.push(outputFilePath);
84
+ } catch {
85
+ console.error(`failed to process file: ${fileUrl}`);
86
+ }
87
+ }));
88
+ const directories = rootEntries.filter((e) => e.type === "directory");
89
+ await Promise.all(directories.map((dir) => processDirectory(dir, versionPath, version, versionOutputDir, downloadedFilesForVersion)));
90
+ if (downloadedFilesForVersion.length === 0) {
91
+ console.warn(yellow(`No files were downloaded for Unicode ${version}.`));
92
+ continue;
93
+ }
94
+ console.info(green(`✓ Generated ${downloadedFilesForVersion.length} for Unicode ${version}`));
95
+ for (const file of downloadedFilesForVersion) {
96
+ const relativePath = path.relative(versionOutputDir, file);
97
+ console.info(green(` - ${relativePath}`));
98
+ }
99
+ }
100
+ }
101
+
102
+ //#endregion
103
+ export { runGenerate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucdjs/cli",
3
- "version": "0.0.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Lucas Nørgård",
@@ -25,6 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
+ "@luxass/unicode-utils": "^0.0.0",
28
29
  "farver": "^0.4.2",
29
30
  "yargs-parser": "^21.1.1"
30
31
  },
@@ -1,21 +0,0 @@
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 };