@cieloazul310/digital-go-pandacss-cli 0.2.2 → 0.2.3

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/bin/index.cjs CHANGED
@@ -1,266 +1,211 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
2
+ let commander = require("commander");
3
+ let path = require("path");
4
+ let fs_promises = require("fs/promises");
5
+ let simple_git = require("simple-git");
6
+ let os = require("os");
7
+ let fs = require("fs");
3
8
 
4
- // src/index.ts
5
- var import_commander = require("commander");
6
- var import_path5 = require("path");
7
-
8
- // src/load-catalogue.ts
9
- var import_promises = require("fs/promises");
10
- var import_path = require("path");
9
+ //#region src/load-catalogue.ts
11
10
  async function loadCatalogue() {
12
- const cataloguePath = (0, import_path.resolve)(__dirname, "..", "public", "catalogue.json");
13
- let file;
14
- try {
15
- file = await (0, import_promises.readFile)(cataloguePath, "utf8");
16
- } catch (err) {
17
- throw new Error(`Could not read ${cataloguePath}: ${getErrorMessage(err)}`);
18
- }
19
- let catalogue;
20
- try {
21
- catalogue = JSON.parse(file);
22
- } catch (err) {
23
- throw new Error(
24
- `Failed to parse JSON at ${cataloguePath}: ${getErrorMessage(err)}`
25
- );
26
- }
27
- return catalogue;
11
+ const cataloguePath = (0, path.resolve)(__dirname, "..", "public", "catalogue.json");
12
+ let file;
13
+ try {
14
+ file = await (0, fs_promises.readFile)(cataloguePath, "utf8");
15
+ } catch (err) {
16
+ throw new Error(`Could not read ${cataloguePath}: ${getErrorMessage(err)}`);
17
+ }
18
+ let catalogue;
19
+ try {
20
+ catalogue = JSON.parse(file);
21
+ } catch (err) {
22
+ throw new Error(`Failed to parse JSON at ${cataloguePath}: ${getErrorMessage(err)}`);
23
+ }
24
+ return catalogue;
28
25
  }
29
26
  function getErrorMessage(err) {
30
- if (err instanceof Error) return err.message;
31
- if (typeof err === "string") return err;
32
- try {
33
- return JSON.stringify(err);
34
- } catch {
35
- return String(err);
36
- }
27
+ if (err instanceof Error) return err.message;
28
+ if (typeof err === "string") return err;
29
+ try {
30
+ return JSON.stringify(err);
31
+ } catch {
32
+ return String(err);
33
+ }
37
34
  }
38
35
 
39
- // src/install-snippets.ts
40
- var import_simple_git = require("simple-git");
41
- var import_os = require("os");
42
- var import_promises5 = require("fs/promises");
43
- var import_path4 = require("path");
44
-
45
- // src/read-config.ts
46
- var import_promises3 = require("fs/promises");
47
- var import_path2 = require("path");
48
-
49
- // src/fs-exists.ts
50
- var import_promises2 = require("fs/promises");
51
- var import_fs = require("fs");
36
+ //#endregion
37
+ //#region src/fs-exists.ts
52
38
  async function exists(path) {
53
- try {
54
- await (0, import_promises2.access)(path, import_fs.constants.F_OK);
55
- return true;
56
- } catch {
57
- return false;
58
- }
39
+ try {
40
+ await (0, fs_promises.access)(path, fs.constants.F_OK);
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
59
45
  }
60
46
 
61
- // src/read-config.ts
47
+ //#endregion
48
+ //#region src/read-config.ts
62
49
  async function readConfig(cwd = process.cwd()) {
63
- const defaultConfig = {
64
- outDir: "src/components/ui",
65
- override: true
66
- };
67
- const configPath = (0, import_path2.join)(cwd, "components.json");
68
- if (!await exists(configPath)) {
69
- return defaultConfig;
70
- }
71
- const config = JSON.parse(
72
- await (0, import_promises3.readFile)(configPath, "utf-8")
73
- );
74
- return {
75
- ...defaultConfig,
76
- ...config
77
- };
50
+ const defaultConfig = {
51
+ outDir: "src/components/ui",
52
+ override: true
53
+ };
54
+ const configPath = (0, path.join)(cwd, "components.json");
55
+ if (!await exists(configPath)) return defaultConfig;
56
+ const config = JSON.parse(await (0, fs_promises.readFile)(configPath, "utf-8"));
57
+ return {
58
+ ...defaultConfig,
59
+ ...config
60
+ };
78
61
  }
79
62
 
80
- // src/copy-components.ts
81
- var import_promises4 = require("fs/promises");
82
- var import_path3 = require("path");
83
- async function copyComponents({
84
- templateDir,
85
- outputDir,
86
- versionComment,
87
- override = true,
88
- ids
89
- }) {
90
- if (!ids) {
91
- if (await exists(outputDir) && !override) {
92
- throw new Error(
93
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputDir}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
94
- );
95
- }
96
- await (0, import_promises4.cp)(templateDir, outputDir, { recursive: true });
97
- const dirs = await (0, import_promises4.readdir)(outputDir, { withFileTypes: true });
98
- for (const dir of dirs) {
99
- if (dir.isDirectory()) {
100
- const destDir = (0, import_path3.join)(outputDir, dir.name);
101
- const files = await (0, import_promises4.readdir)(destDir, { withFileTypes: true });
102
- for (const file of files) {
103
- if (file.isFile() && file.name.endsWith(".tsx")) {
104
- const destPath = (0, import_path3.join)(destDir, file.name);
105
- const content = await (0, import_promises4.readFile)(destPath, "utf8");
106
- if (versionComment && content.startsWith(versionComment)) continue;
107
- await (0, import_promises4.writeFile)(destPath, (versionComment || "") + content, "utf8");
108
- }
109
- }
110
- }
111
- }
112
- return;
113
- }
114
- if (await exists(outputDir) && !override) {
115
- throw new Error(
116
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputDir}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
117
- );
118
- }
119
- for (const id of ids) {
120
- const src = (0, import_path3.join)(templateDir, id);
121
- if (!await exists(src)) {
122
- throw new Error(
123
- `\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${id} (expected at ${src})`
124
- );
125
- }
126
- const dest = (0, import_path3.join)(outputDir, id);
127
- if (await exists(dest) && !override) {
128
- throw new Error(
129
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${dest}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
130
- );
131
- }
132
- await (0, import_promises4.cp)(src, dest, { recursive: true });
133
- const destFiles = await (0, import_promises4.readdir)(dest, { withFileTypes: true });
134
- for (const file of destFiles) {
135
- if (file.isFile() && file.name.endsWith(".tsx")) {
136
- const destPath = (0, import_path3.join)(dest, file.name);
137
- const content = await (0, import_promises4.readFile)(destPath, "utf8");
138
- if (versionComment && content.startsWith(versionComment)) continue;
139
- await (0, import_promises4.writeFile)(destPath, (versionComment || "") + content, "utf8");
140
- }
141
- }
142
- }
63
+ //#endregion
64
+ //#region src/copy-components.ts
65
+ async function copyComponents({ templateDir, outputDir, versionComment, override = true, ids }) {
66
+ if (!ids) {
67
+ if (await exists(outputDir) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${outputDir}. --overrideを使用して上書きしてください。`);
68
+ await (0, fs_promises.cp)(templateDir, outputDir, { recursive: true });
69
+ const dirs = await (0, fs_promises.readdir)(outputDir, { withFileTypes: true });
70
+ for (const dir of dirs) if (dir.isDirectory()) {
71
+ const destDir = (0, path.join)(outputDir, dir.name);
72
+ const files = await (0, fs_promises.readdir)(destDir, { withFileTypes: true });
73
+ for (const file of files) if (file.isFile() && file.name.endsWith(".tsx")) {
74
+ const destPath = (0, path.join)(destDir, file.name);
75
+ const content = await (0, fs_promises.readFile)(destPath, "utf8");
76
+ if (versionComment && content.startsWith(versionComment)) continue;
77
+ await (0, fs_promises.writeFile)(destPath, (versionComment || "") + content, "utf8");
78
+ }
79
+ }
80
+ return;
81
+ }
82
+ if (await exists(outputDir) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${outputDir}. --overrideを使用して上書きしてください。`);
83
+ for (const id of ids) {
84
+ const src = (0, path.join)(templateDir, id);
85
+ if (!await exists(src)) throw new Error(`テンプレートコンポーネントが見つかりません: ${id} (expected at ${src})`);
86
+ const dest = (0, path.join)(outputDir, id);
87
+ if (await exists(dest) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${dest}. --overrideを使用して上書きしてください。`);
88
+ await (0, fs_promises.cp)(src, dest, { recursive: true });
89
+ const destFiles = await (0, fs_promises.readdir)(dest, { withFileTypes: true });
90
+ for (const file of destFiles) if (file.isFile() && file.name.endsWith(".tsx")) {
91
+ const destPath = (0, path.join)(dest, file.name);
92
+ const content = await (0, fs_promises.readFile)(destPath, "utf8");
93
+ if (versionComment && content.startsWith(versionComment)) continue;
94
+ await (0, fs_promises.writeFile)(destPath, (versionComment || "") + content, "utf8");
95
+ }
96
+ }
143
97
  }
144
98
 
145
- // src/version-comment.ts
146
- function createVersionComment({
147
- tag,
148
- commit
149
- } = {}) {
150
- if (!tag || !commit) {
151
- return "// Generated from Custom Source Directory\n";
152
- }
153
- return `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})
154
- `;
99
+ //#endregion
100
+ //#region src/version-comment.ts
101
+ function createVersionComment({ tag, commit } = {}) {
102
+ if (!tag || !commit) return "// Generated from Custom Source Directory\n";
103
+ return `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})\n`;
155
104
  }
156
105
 
157
- // src/install-snippets.ts
106
+ //#endregion
107
+ //#region src/install-snippets.ts
158
108
  async function main(args) {
159
- const cwd = process.cwd();
160
- const { outDir, sourceDir, override } = await readConfig(cwd);
161
- const tmpPath = (0, import_path4.join)((0, import_os.tmpdir)(), `digital-go-pandacss-${Date.now()}`);
162
- let templateDir = void 0;
163
- let versionComment = void 0;
164
- if (sourceDir) {
165
- await (0, import_promises5.cp)((0, import_path4.join)(cwd, sourceDir), tmpPath, { recursive: true });
166
- templateDir = tmpPath;
167
- versionComment = createVersionComment();
168
- } else {
169
- const git = (0, import_simple_git.simpleGit)();
170
- const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
171
- const templateSubdir = "components/src";
172
- await git.clone(repoUrl, tmpPath);
173
- const repoGit = (0, import_simple_git.simpleGit)(tmpPath);
174
- const tag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
175
- const commit = (await repoGit.revparse(["HEAD"])).trim();
176
- templateDir = (0, import_path4.join)(tmpPath, templateSubdir);
177
- versionComment = createVersionComment({ tag, commit });
178
- }
179
- if (!await exists(templateDir)) {
180
- throw new Error(`\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${templateDir}`);
181
- }
182
- const outputDir = (0, import_path4.join)(cwd, outDir);
183
- let idsToCopy = args && args.length > 0 ? args : void 0;
184
- if (idsToCopy) {
185
- const entries = await (0, import_promises5.readdir)(templateDir, { withFileTypes: true });
186
- const available = entries.filter((e) => e.isDirectory()).map((d) => d.name);
187
- const existing = idsToCopy.filter((id) => available.includes(id));
188
- const missing = idsToCopy.filter((id) => !available.includes(id));
189
- if (missing.length > 0) {
190
- console.warn(
191
- `Warning: the following components were listed in the catalogue but are not present in the template repository and will be skipped: ${missing.join(", ")}`
192
- );
193
- }
194
- idsToCopy = existing.length > 0 ? existing : void 0;
195
- }
196
- await copyComponents({
197
- templateDir,
198
- outputDir,
199
- override,
200
- versionComment,
201
- ids: idsToCopy
202
- });
203
- console.log(`\u2705 UI\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092 ${outDir} \u306B\u751F\u6210\u3057\u307E\u3057\u305F`);
109
+ const cwd = process.cwd();
110
+ const { outDir, sourceDir, override } = await readConfig(cwd);
111
+ const tmpPath = (0, path.join)((0, os.tmpdir)(), `digital-go-pandacss-${Date.now()}`);
112
+ let templateDir = void 0;
113
+ let versionComment = void 0;
114
+ if (sourceDir) {
115
+ await (0, fs_promises.cp)((0, path.join)(cwd, sourceDir), tmpPath, { recursive: true });
116
+ templateDir = tmpPath;
117
+ versionComment = createVersionComment();
118
+ } else {
119
+ const git = (0, simple_git.simpleGit)();
120
+ const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
121
+ const templateSubdir = "components/src";
122
+ await git.clone(repoUrl, tmpPath);
123
+ const repoGit = (0, simple_git.simpleGit)(tmpPath);
124
+ const tag = (await repoGit.raw([
125
+ "describe",
126
+ "--tags",
127
+ "--abbrev=0"
128
+ ])).trim();
129
+ const commit = (await repoGit.revparse(["HEAD"])).trim();
130
+ templateDir = (0, path.join)(tmpPath, templateSubdir);
131
+ versionComment = createVersionComment({
132
+ tag,
133
+ commit
134
+ });
135
+ }
136
+ if (!await exists(templateDir)) throw new Error(`テンプレートディレクトリが見つかりません: ${templateDir}`);
137
+ const outputDir = (0, path.join)(cwd, outDir);
138
+ let idsToCopy = args && args.length > 0 ? args : void 0;
139
+ if (idsToCopy) {
140
+ const available = (await (0, fs_promises.readdir)(templateDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((d) => d.name);
141
+ const existing = idsToCopy.filter((id) => available.includes(id));
142
+ const missing = idsToCopy.filter((id) => !available.includes(id));
143
+ if (missing.length > 0) console.warn(`Warning: the following components were listed in the catalogue but are not present in the template repository and will be skipped: ${missing.join(", ")}`);
144
+ idsToCopy = existing.length > 0 ? existing : void 0;
145
+ }
146
+ await copyComponents({
147
+ templateDir,
148
+ outputDir,
149
+ override,
150
+ versionComment,
151
+ ids: idsToCopy
152
+ });
153
+ console.log(`✅ UIコンポーネントを ${outDir} に生成しました`);
204
154
  }
205
155
  async function installSnippets(args) {
206
- await main(args).then(() => process.exit(0)).catch((err) => {
207
- console.error(err);
208
- process.exit(1);
209
- });
156
+ await main(args).then(() => process.exit(0)).catch((err) => {
157
+ console.error(err);
158
+ process.exit(1);
159
+ });
210
160
  }
211
161
 
212
- // src/index.ts
213
- var program = new import_commander.Command();
214
- program.name("digital-go-pandacss").description("\u30C7\u30B8\u30BF\u30EB\u5E81\u30C7\u30B6\u30A4\u30F3\u30B7\u30B9\u30C6\u30E0 for Panda CSS");
215
- program.command("install [ids...]").description("\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u6307\u5B9A\u3057\u307E\u3059").option("--all", "\u3059\u3079\u3066\u306E\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u307E\u3059").action(async (ids = [], options) => {
216
- if (options.all && ids.length > 0) {
217
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u3068--all\u3092\u540C\u6642\u306B\u6307\u5B9A\u3059\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093");
218
- process.exit(2);
219
- }
220
- if (!options.all && ids.length === 0) {
221
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u3092\u6307\u5B9A\u3059\u308B\u304B\u3001--all\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044");
222
- process.exit(2);
223
- }
224
- const catalogue = await loadCatalogue() ?? { components: {} };
225
- const availableIds = Object.values(catalogue.components || {}).map(
226
- ({ id }) => id
227
- );
228
- const targetIds = options.all ? availableIds : ids;
229
- const unknown = targetIds.filter((id) => !availableIds.includes(id));
230
- if (unknown.length) {
231
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093:", unknown.join(", "));
232
- process.exit(2);
233
- }
234
- try {
235
- const { outDir: cfgOutDir, override: cfgOverride } = await readConfig(
236
- process.cwd()
237
- );
238
- const outputPath = (0, import_path5.join)(process.cwd(), cfgOutDir);
239
- if (await exists(outputPath) && !cfgOverride) {
240
- console.error(
241
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputPath}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
242
- );
243
- process.exit(1);
244
- }
245
- await installSnippets(targetIds);
246
- } catch (err) {
247
- console.error(err);
248
- process.exit(1);
249
- }
162
+ //#endregion
163
+ //#region src/index.ts
164
+ const program = new commander.Command();
165
+ program.name("digital-go-pandacss").description("デジタル庁デザインシステム for Panda CSS");
166
+ program.command("install [ids...]").description("インストールするコンポーネントを指定します").option("--all", "すべてのコンポーネントをインストールします").action(async (ids = [], options) => {
167
+ if (options.all && ids.length > 0) {
168
+ console.error("コンポーネントIDと--allを同時に指定することはできません");
169
+ process.exit(2);
170
+ }
171
+ if (!options.all && ids.length === 0) {
172
+ console.error("コンポーネントIDを指定するか、--allを使用してください");
173
+ process.exit(2);
174
+ }
175
+ const catalogue = await loadCatalogue() ?? { components: {} };
176
+ const availableIds = Object.values(catalogue.components || {}).map(({ id }) => id);
177
+ const targetIds = options.all ? availableIds : ids;
178
+ const unknown = targetIds.filter((id) => !availableIds.includes(id));
179
+ if (unknown.length) {
180
+ console.error("コンポーネントIDが見つかりません:", unknown.join(", "));
181
+ process.exit(2);
182
+ }
183
+ try {
184
+ const { outDir: cfgOutDir, override: cfgOverride } = await readConfig(process.cwd());
185
+ const outputPath = (0, path.join)(process.cwd(), cfgOutDir);
186
+ if (await exists(outputPath) && !cfgOverride) {
187
+ console.error(`出力先ディレクトリが既に存在します: ${outputPath}. --overrideを使用して上書きしてください。`);
188
+ process.exit(1);
189
+ }
190
+ await installSnippets(targetIds);
191
+ } catch (err) {
192
+ console.error(err);
193
+ process.exit(1);
194
+ }
250
195
  });
251
- program.command("list").description("\u5229\u7528\u53EF\u80FD\u306A\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u306E\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059").option("--json", "JSON\u5F62\u5F0F\u3067\u51FA\u529B\u3057\u307E\u3059").action(async (options) => {
252
- const catalogue = await loadCatalogue();
253
- if (!catalogue || !catalogue.components) {
254
- console.error("\u30AB\u30BF\u30ED\u30B0\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
255
- process.exit(1);
256
- }
257
- const comps = Object.values(catalogue.components);
258
- if (options.json) {
259
- console.log(JSON.stringify(comps, null, 2));
260
- return;
261
- }
262
- for (const { id, name } of comps) {
263
- console.log(`${id} \u2014 ${name}`);
264
- }
196
+ program.command("list").description("利用可能なコンポーネントIDの一覧を表示します").option("--json", "JSON形式で出力します").action(async (options) => {
197
+ const catalogue = await loadCatalogue();
198
+ if (!catalogue || !catalogue.components) {
199
+ console.error("カタログが見つかりません");
200
+ process.exit(1);
201
+ }
202
+ const comps = Object.values(catalogue.components);
203
+ if (options.json) {
204
+ console.log(JSON.stringify(comps, null, 2));
205
+ return;
206
+ }
207
+ for (const { id, name } of comps) console.log(`${id} — ${name}`);
265
208
  });
266
209
  program.parse(process.argv);
210
+
211
+ //#endregion
package/bin/index.mjs ADDED
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { join, resolve } from "path";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { access, cp, readFile, readdir, writeFile } from "fs/promises";
7
+ import { simpleGit } from "simple-git";
8
+ import { tmpdir } from "os";
9
+ import { constants } from "fs";
10
+
11
+ //#region ../../node_modules/tsdown/esm-shims.js
12
+ const getFilename = () => fileURLToPath(import.meta.url);
13
+ const getDirname = () => path.dirname(getFilename());
14
+ const __dirname = /* @__PURE__ */ getDirname();
15
+
16
+ //#endregion
17
+ //#region src/load-catalogue.ts
18
+ async function loadCatalogue() {
19
+ const cataloguePath = resolve(__dirname, "..", "public", "catalogue.json");
20
+ let file;
21
+ try {
22
+ file = await readFile(cataloguePath, "utf8");
23
+ } catch (err) {
24
+ throw new Error(`Could not read ${cataloguePath}: ${getErrorMessage(err)}`);
25
+ }
26
+ let catalogue;
27
+ try {
28
+ catalogue = JSON.parse(file);
29
+ } catch (err) {
30
+ throw new Error(`Failed to parse JSON at ${cataloguePath}: ${getErrorMessage(err)}`);
31
+ }
32
+ return catalogue;
33
+ }
34
+ function getErrorMessage(err) {
35
+ if (err instanceof Error) return err.message;
36
+ if (typeof err === "string") return err;
37
+ try {
38
+ return JSON.stringify(err);
39
+ } catch {
40
+ return String(err);
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ //#region src/fs-exists.ts
46
+ async function exists(path) {
47
+ try {
48
+ await access(path, constants.F_OK);
49
+ return true;
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/read-config.ts
57
+ async function readConfig(cwd = process.cwd()) {
58
+ const defaultConfig = {
59
+ outDir: "src/components/ui",
60
+ override: true
61
+ };
62
+ const configPath = join(cwd, "components.json");
63
+ if (!await exists(configPath)) return defaultConfig;
64
+ const config = JSON.parse(await readFile(configPath, "utf-8"));
65
+ return {
66
+ ...defaultConfig,
67
+ ...config
68
+ };
69
+ }
70
+
71
+ //#endregion
72
+ //#region src/copy-components.ts
73
+ async function copyComponents({ templateDir, outputDir, versionComment, override = true, ids }) {
74
+ if (!ids) {
75
+ if (await exists(outputDir) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${outputDir}. --overrideを使用して上書きしてください。`);
76
+ await cp(templateDir, outputDir, { recursive: true });
77
+ const dirs = await readdir(outputDir, { withFileTypes: true });
78
+ for (const dir of dirs) if (dir.isDirectory()) {
79
+ const destDir = join(outputDir, dir.name);
80
+ const files = await readdir(destDir, { withFileTypes: true });
81
+ for (const file of files) if (file.isFile() && file.name.endsWith(".tsx")) {
82
+ const destPath = join(destDir, file.name);
83
+ const content = await readFile(destPath, "utf8");
84
+ if (versionComment && content.startsWith(versionComment)) continue;
85
+ await writeFile(destPath, (versionComment || "") + content, "utf8");
86
+ }
87
+ }
88
+ return;
89
+ }
90
+ if (await exists(outputDir) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${outputDir}. --overrideを使用して上書きしてください。`);
91
+ for (const id of ids) {
92
+ const src = join(templateDir, id);
93
+ if (!await exists(src)) throw new Error(`テンプレートコンポーネントが見つかりません: ${id} (expected at ${src})`);
94
+ const dest = join(outputDir, id);
95
+ if (await exists(dest) && !override) throw new Error(`出力先ディレクトリが既に存在します: ${dest}. --overrideを使用して上書きしてください。`);
96
+ await cp(src, dest, { recursive: true });
97
+ const destFiles = await readdir(dest, { withFileTypes: true });
98
+ for (const file of destFiles) if (file.isFile() && file.name.endsWith(".tsx")) {
99
+ const destPath = join(dest, file.name);
100
+ const content = await readFile(destPath, "utf8");
101
+ if (versionComment && content.startsWith(versionComment)) continue;
102
+ await writeFile(destPath, (versionComment || "") + content, "utf8");
103
+ }
104
+ }
105
+ }
106
+
107
+ //#endregion
108
+ //#region src/version-comment.ts
109
+ function createVersionComment({ tag, commit } = {}) {
110
+ if (!tag || !commit) return "// Generated from Custom Source Directory\n";
111
+ return `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})\n`;
112
+ }
113
+
114
+ //#endregion
115
+ //#region src/install-snippets.ts
116
+ async function main(args) {
117
+ const cwd = process.cwd();
118
+ const { outDir, sourceDir, override } = await readConfig(cwd);
119
+ const tmpPath = join(tmpdir(), `digital-go-pandacss-${Date.now()}`);
120
+ let templateDir = void 0;
121
+ let versionComment = void 0;
122
+ if (sourceDir) {
123
+ await cp(join(cwd, sourceDir), tmpPath, { recursive: true });
124
+ templateDir = tmpPath;
125
+ versionComment = createVersionComment();
126
+ } else {
127
+ const git = simpleGit();
128
+ const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
129
+ const templateSubdir = "components/src";
130
+ await git.clone(repoUrl, tmpPath);
131
+ const repoGit = simpleGit(tmpPath);
132
+ const tag = (await repoGit.raw([
133
+ "describe",
134
+ "--tags",
135
+ "--abbrev=0"
136
+ ])).trim();
137
+ const commit = (await repoGit.revparse(["HEAD"])).trim();
138
+ templateDir = join(tmpPath, templateSubdir);
139
+ versionComment = createVersionComment({
140
+ tag,
141
+ commit
142
+ });
143
+ }
144
+ if (!await exists(templateDir)) throw new Error(`テンプレートディレクトリが見つかりません: ${templateDir}`);
145
+ const outputDir = join(cwd, outDir);
146
+ let idsToCopy = args && args.length > 0 ? args : void 0;
147
+ if (idsToCopy) {
148
+ const available = (await readdir(templateDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((d) => d.name);
149
+ const existing = idsToCopy.filter((id) => available.includes(id));
150
+ const missing = idsToCopy.filter((id) => !available.includes(id));
151
+ if (missing.length > 0) console.warn(`Warning: the following components were listed in the catalogue but are not present in the template repository and will be skipped: ${missing.join(", ")}`);
152
+ idsToCopy = existing.length > 0 ? existing : void 0;
153
+ }
154
+ await copyComponents({
155
+ templateDir,
156
+ outputDir,
157
+ override,
158
+ versionComment,
159
+ ids: idsToCopy
160
+ });
161
+ console.log(`✅ UIコンポーネントを ${outDir} に生成しました`);
162
+ }
163
+ async function installSnippets(args) {
164
+ await main(args).then(() => process.exit(0)).catch((err) => {
165
+ console.error(err);
166
+ process.exit(1);
167
+ });
168
+ }
169
+
170
+ //#endregion
171
+ //#region src/index.ts
172
+ const program = new Command();
173
+ program.name("digital-go-pandacss").description("デジタル庁デザインシステム for Panda CSS");
174
+ program.command("install [ids...]").description("インストールするコンポーネントを指定します").option("--all", "すべてのコンポーネントをインストールします").action(async (ids = [], options) => {
175
+ if (options.all && ids.length > 0) {
176
+ console.error("コンポーネントIDと--allを同時に指定することはできません");
177
+ process.exit(2);
178
+ }
179
+ if (!options.all && ids.length === 0) {
180
+ console.error("コンポーネントIDを指定するか、--allを使用してください");
181
+ process.exit(2);
182
+ }
183
+ const catalogue = await loadCatalogue() ?? { components: {} };
184
+ const availableIds = Object.values(catalogue.components || {}).map(({ id }) => id);
185
+ const targetIds = options.all ? availableIds : ids;
186
+ const unknown = targetIds.filter((id) => !availableIds.includes(id));
187
+ if (unknown.length) {
188
+ console.error("コンポーネントIDが見つかりません:", unknown.join(", "));
189
+ process.exit(2);
190
+ }
191
+ try {
192
+ const { outDir: cfgOutDir, override: cfgOverride } = await readConfig(process.cwd());
193
+ const outputPath = join(process.cwd(), cfgOutDir);
194
+ if (await exists(outputPath) && !cfgOverride) {
195
+ console.error(`出力先ディレクトリが既に存在します: ${outputPath}. --overrideを使用して上書きしてください。`);
196
+ process.exit(1);
197
+ }
198
+ await installSnippets(targetIds);
199
+ } catch (err) {
200
+ console.error(err);
201
+ process.exit(1);
202
+ }
203
+ });
204
+ program.command("list").description("利用可能なコンポーネントIDの一覧を表示します").option("--json", "JSON形式で出力します").action(async (options) => {
205
+ const catalogue = await loadCatalogue();
206
+ if (!catalogue || !catalogue.components) {
207
+ console.error("カタログが見つかりません");
208
+ process.exit(1);
209
+ }
210
+ const comps = Object.values(catalogue.components);
211
+ if (options.json) {
212
+ console.log(JSON.stringify(comps, null, 2));
213
+ return;
214
+ }
215
+ for (const { id, name } of comps) console.log(`${id} — ${name}`);
216
+ });
217
+ program.parse(process.argv);
218
+
219
+ //#endregion
220
+ export { };
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@cieloazul310/digital-go-pandacss-cli",
3
- "version": "0.2.2",
4
- "type": "module",
3
+ "version": "0.2.3",
5
4
  "license": "MIT",
6
5
  "homepage": "https://github.com/cieloazul310/digital-go-design-system-with-panda",
7
6
  "author": {
@@ -17,6 +16,7 @@
17
16
  "access": "public",
18
17
  "registry": "https://registry.npmjs.org/"
19
18
  },
19
+ "type": "module",
20
20
  "files": [
21
21
  "bin",
22
22
  "public"
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "scripts": {
28
28
  "prebuild": "tsx ../../scripts/generate-catalogue.ts",
29
- "build": "tsup",
29
+ "build": "tsdown",
30
30
  "dev": "npm run build -- --watch",
31
31
  "eslint": "eslint src --fix",
32
32
  "format": "prettier --parser typescript --write ."
@@ -36,11 +36,11 @@
36
36
  "simple-git": "^3.28.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@repo/eslint-config": "^0.2.2",
40
- "@repo/typescript-config": "^0.2.2",
39
+ "@repo/eslint-config": "^0.2.3",
40
+ "@repo/typescript-config": "^0.2.3",
41
41
  "eslint": "^9.37.0",
42
42
  "execa": "^9.6.0",
43
- "tsup": "8.5.0",
43
+ "tsdown": "^0.20.1",
44
44
  "tsx": "^4.20.6",
45
45
  "typescript": "^5.9.3"
46
46
  },
package/bin/index.js DELETED
@@ -1,272 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // ../../node_modules/tsup/assets/esm_shims.js
4
- import path from "path";
5
- import { fileURLToPath } from "url";
6
- var getFilename = () => fileURLToPath(import.meta.url);
7
- var getDirname = () => path.dirname(getFilename());
8
- var __dirname = /* @__PURE__ */ getDirname();
9
-
10
- // src/index.ts
11
- import { Command } from "commander";
12
- import { join as join4 } from "path";
13
-
14
- // src/load-catalogue.ts
15
- import { readFile } from "fs/promises";
16
- import { resolve } from "path";
17
- async function loadCatalogue() {
18
- const cataloguePath = resolve(__dirname, "..", "public", "catalogue.json");
19
- let file;
20
- try {
21
- file = await readFile(cataloguePath, "utf8");
22
- } catch (err) {
23
- throw new Error(`Could not read ${cataloguePath}: ${getErrorMessage(err)}`);
24
- }
25
- let catalogue;
26
- try {
27
- catalogue = JSON.parse(file);
28
- } catch (err) {
29
- throw new Error(
30
- `Failed to parse JSON at ${cataloguePath}: ${getErrorMessage(err)}`
31
- );
32
- }
33
- return catalogue;
34
- }
35
- function getErrorMessage(err) {
36
- if (err instanceof Error) return err.message;
37
- if (typeof err === "string") return err;
38
- try {
39
- return JSON.stringify(err);
40
- } catch {
41
- return String(err);
42
- }
43
- }
44
-
45
- // src/install-snippets.ts
46
- import { simpleGit } from "simple-git";
47
- import { tmpdir } from "os";
48
- import { cp as cp2, readdir as readdir2 } from "fs/promises";
49
- import { join as join3 } from "path";
50
-
51
- // src/read-config.ts
52
- import { readFile as readFile2 } from "fs/promises";
53
- import { join } from "path";
54
-
55
- // src/fs-exists.ts
56
- import { access } from "fs/promises";
57
- import { constants } from "fs";
58
- async function exists(path2) {
59
- try {
60
- await access(path2, constants.F_OK);
61
- return true;
62
- } catch {
63
- return false;
64
- }
65
- }
66
-
67
- // src/read-config.ts
68
- async function readConfig(cwd = process.cwd()) {
69
- const defaultConfig = {
70
- outDir: "src/components/ui",
71
- override: true
72
- };
73
- const configPath = join(cwd, "components.json");
74
- if (!await exists(configPath)) {
75
- return defaultConfig;
76
- }
77
- const config = JSON.parse(
78
- await readFile2(configPath, "utf-8")
79
- );
80
- return {
81
- ...defaultConfig,
82
- ...config
83
- };
84
- }
85
-
86
- // src/copy-components.ts
87
- import { readdir, readFile as readFile3, writeFile, cp } from "fs/promises";
88
- import { join as join2 } from "path";
89
- async function copyComponents({
90
- templateDir,
91
- outputDir,
92
- versionComment,
93
- override = true,
94
- ids
95
- }) {
96
- if (!ids) {
97
- if (await exists(outputDir) && !override) {
98
- throw new Error(
99
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputDir}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
100
- );
101
- }
102
- await cp(templateDir, outputDir, { recursive: true });
103
- const dirs = await readdir(outputDir, { withFileTypes: true });
104
- for (const dir of dirs) {
105
- if (dir.isDirectory()) {
106
- const destDir = join2(outputDir, dir.name);
107
- const files = await readdir(destDir, { withFileTypes: true });
108
- for (const file of files) {
109
- if (file.isFile() && file.name.endsWith(".tsx")) {
110
- const destPath = join2(destDir, file.name);
111
- const content = await readFile3(destPath, "utf8");
112
- if (versionComment && content.startsWith(versionComment)) continue;
113
- await writeFile(destPath, (versionComment || "") + content, "utf8");
114
- }
115
- }
116
- }
117
- }
118
- return;
119
- }
120
- if (await exists(outputDir) && !override) {
121
- throw new Error(
122
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputDir}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
123
- );
124
- }
125
- for (const id of ids) {
126
- const src = join2(templateDir, id);
127
- if (!await exists(src)) {
128
- throw new Error(
129
- `\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${id} (expected at ${src})`
130
- );
131
- }
132
- const dest = join2(outputDir, id);
133
- if (await exists(dest) && !override) {
134
- throw new Error(
135
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${dest}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
136
- );
137
- }
138
- await cp(src, dest, { recursive: true });
139
- const destFiles = await readdir(dest, { withFileTypes: true });
140
- for (const file of destFiles) {
141
- if (file.isFile() && file.name.endsWith(".tsx")) {
142
- const destPath = join2(dest, file.name);
143
- const content = await readFile3(destPath, "utf8");
144
- if (versionComment && content.startsWith(versionComment)) continue;
145
- await writeFile(destPath, (versionComment || "") + content, "utf8");
146
- }
147
- }
148
- }
149
- }
150
-
151
- // src/version-comment.ts
152
- function createVersionComment({
153
- tag,
154
- commit
155
- } = {}) {
156
- if (!tag || !commit) {
157
- return "// Generated from Custom Source Directory\n";
158
- }
159
- return `// Generated from digital-go-design-system-with-panda@${tag} (commit: ${commit})
160
- `;
161
- }
162
-
163
- // src/install-snippets.ts
164
- async function main(args) {
165
- const cwd = process.cwd();
166
- const { outDir, sourceDir, override } = await readConfig(cwd);
167
- const tmpPath = join3(tmpdir(), `digital-go-pandacss-${Date.now()}`);
168
- let templateDir = void 0;
169
- let versionComment = void 0;
170
- if (sourceDir) {
171
- await cp2(join3(cwd, sourceDir), tmpPath, { recursive: true });
172
- templateDir = tmpPath;
173
- versionComment = createVersionComment();
174
- } else {
175
- const git = simpleGit();
176
- const repoUrl = "https://github.com/cieloazul310/digital-go-design-system-with-panda";
177
- const templateSubdir = "components/src";
178
- await git.clone(repoUrl, tmpPath);
179
- const repoGit = simpleGit(tmpPath);
180
- const tag = (await repoGit.raw(["describe", "--tags", "--abbrev=0"])).trim();
181
- const commit = (await repoGit.revparse(["HEAD"])).trim();
182
- templateDir = join3(tmpPath, templateSubdir);
183
- versionComment = createVersionComment({ tag, commit });
184
- }
185
- if (!await exists(templateDir)) {
186
- throw new Error(`\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${templateDir}`);
187
- }
188
- const outputDir = join3(cwd, outDir);
189
- let idsToCopy = args && args.length > 0 ? args : void 0;
190
- if (idsToCopy) {
191
- const entries = await readdir2(templateDir, { withFileTypes: true });
192
- const available = entries.filter((e) => e.isDirectory()).map((d) => d.name);
193
- const existing = idsToCopy.filter((id) => available.includes(id));
194
- const missing = idsToCopy.filter((id) => !available.includes(id));
195
- if (missing.length > 0) {
196
- console.warn(
197
- `Warning: the following components were listed in the catalogue but are not present in the template repository and will be skipped: ${missing.join(", ")}`
198
- );
199
- }
200
- idsToCopy = existing.length > 0 ? existing : void 0;
201
- }
202
- await copyComponents({
203
- templateDir,
204
- outputDir,
205
- override,
206
- versionComment,
207
- ids: idsToCopy
208
- });
209
- console.log(`\u2705 UI\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092 ${outDir} \u306B\u751F\u6210\u3057\u307E\u3057\u305F`);
210
- }
211
- async function installSnippets(args) {
212
- await main(args).then(() => process.exit(0)).catch((err) => {
213
- console.error(err);
214
- process.exit(1);
215
- });
216
- }
217
-
218
- // src/index.ts
219
- var program = new Command();
220
- program.name("digital-go-pandacss").description("\u30C7\u30B8\u30BF\u30EB\u5E81\u30C7\u30B6\u30A4\u30F3\u30B7\u30B9\u30C6\u30E0 for Panda CSS");
221
- program.command("install [ids...]").description("\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u6307\u5B9A\u3057\u307E\u3059").option("--all", "\u3059\u3079\u3066\u306E\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u307E\u3059").action(async (ids = [], options) => {
222
- if (options.all && ids.length > 0) {
223
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u3068--all\u3092\u540C\u6642\u306B\u6307\u5B9A\u3059\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093");
224
- process.exit(2);
225
- }
226
- if (!options.all && ids.length === 0) {
227
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u3092\u6307\u5B9A\u3059\u308B\u304B\u3001--all\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044");
228
- process.exit(2);
229
- }
230
- const catalogue = await loadCatalogue() ?? { components: {} };
231
- const availableIds = Object.values(catalogue.components || {}).map(
232
- ({ id }) => id
233
- );
234
- const targetIds = options.all ? availableIds : ids;
235
- const unknown = targetIds.filter((id) => !availableIds.includes(id));
236
- if (unknown.length) {
237
- console.error("\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093:", unknown.join(", "));
238
- process.exit(2);
239
- }
240
- try {
241
- const { outDir: cfgOutDir, override: cfgOverride } = await readConfig(
242
- process.cwd()
243
- );
244
- const outputPath = join4(process.cwd(), cfgOutDir);
245
- if (await exists(outputPath) && !cfgOverride) {
246
- console.error(
247
- `\u51FA\u529B\u5148\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059: ${outputPath}. --override\u3092\u4F7F\u7528\u3057\u3066\u4E0A\u66F8\u304D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
248
- );
249
- process.exit(1);
250
- }
251
- await installSnippets(targetIds);
252
- } catch (err) {
253
- console.error(err);
254
- process.exit(1);
255
- }
256
- });
257
- program.command("list").description("\u5229\u7528\u53EF\u80FD\u306A\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8ID\u306E\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059").option("--json", "JSON\u5F62\u5F0F\u3067\u51FA\u529B\u3057\u307E\u3059").action(async (options) => {
258
- const catalogue = await loadCatalogue();
259
- if (!catalogue || !catalogue.components) {
260
- console.error("\u30AB\u30BF\u30ED\u30B0\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
261
- process.exit(1);
262
- }
263
- const comps = Object.values(catalogue.components);
264
- if (options.json) {
265
- console.log(JSON.stringify(comps, null, 2));
266
- return;
267
- }
268
- for (const { id, name } of comps) {
269
- console.log(`${id} \u2014 ${name}`);
270
- }
271
- });
272
- program.parse(process.argv);