@seed-design/cli 0.0.0-alpha → 0.0.0-alpha-20241004093556

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.mjs CHANGED
@@ -1,3 +1,483 @@
1
1
  #!/usr/bin/env node
2
- import{cosmiconfig as Z}from"cosmiconfig";import T from"path";import{z as u}from"zod";var $="seed-design",ee=Z($,{searchPlaces:[`${$}.json`]}),k=u.object({$schema:u.string().optional(),rsc:u.coerce.boolean().default(!1),tsx:u.coerce.boolean().default(!0),css:u.coerce.boolean().default(!0),path:u.string()}).strict(),te=k.extend({resolvedUIPaths:u.string()});async function O(e){let t=await ne(e);return t?await oe(e,t):null}async function oe(e,t){let n=T.resolve(e,t.path);return te.parse({...t,resolvedUIPaths:T.join(n,"ui")})}async function ne(e){try{let t=await ee.search(e);return t?k.parse(t.config):null}catch(t){throw console.log(t),new Error(`Invalid configuration found in ${e}/seed-design.json.`)}}import{z as s}from"zod";var A=s.object({name:s.string(),description:s.string().optional(),dependencies:s.array(s.string()).optional(),devDependencies:s.array(s.string()).optional(),innerDependencies:s.array(s.string()).optional(),snippets:s.array(s.string()),type:s.enum(["component"])}),E=s.array(A),re=A.omit({snippets:!0}),se=re.extend({registries:s.array(s.object({name:s.string(),content:s.string()}))}),De=s.array(se);var I="https://component-seed.design.io";async function M(e){try{return await Promise.all(e.map(async n=>await(await fetch(`${I}/registry/component/${n}.json`)).json()))}catch(t){throw console.log(t),new Error(`Failed to fetch registry from ${I}.`)}}async function D(){try{let[e]=await M(["index"]);return E.parse(e)}catch(e){throw console.log(e),new Error(`Failed to fetch components from ${I}.`)}}import{detect as ae}from"@antfu/ni";async function F(e){let t=await ae({programmatic:!0,cwd:e});return t==="yarn@berry"?"yarn":t==="pnpm@6"?"pnpm":t==="bun"?"bun":t??"npm"}import{promises as le}from"fs";import{tmpdir as fe}from"os";import J from"path";import{transformFromAstSync as ie}from"@babel/core";import ce from"@babel/plugin-transform-typescript";import*as v from"recast";import{parse as pe}from"@babel/parser";var me={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},z=async({sourceFile:e,config:t})=>{let n=e.getFullText();if(t.tsx)return n;let r=v.parse(n,{parser:{parse:c=>pe(c,me)}}),o=ie(r,n,{cloneInputAst:!1,code:!1,ast:!0,plugins:[ce],configFile:!1});if(!o||!o.ast)throw new Error("Failed to transform JSX");return v.print(o.ast).code};import{SyntaxKind as de}from"ts-morph";var N=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let n=e.getFirstChildByKind(de.ExpressionStatement);return n?.getText()==='"use client";'&&n.remove(),e};var W=async({sourceFile:e,config:t})=>{if(t.css)return e;let r=e.getImportDeclarations().filter(o=>o.getModuleSpecifierValue().endsWith(".css"));for(let o of r)o.remove();return e};import{Project as ge,ScriptKind as ue}from"ts-morph";var he=[N,W],ye=new ge({compilerOptions:{}});async function xe(e){let t=await le.mkdtemp(J.join(fe(),"seed-deisgn-"));return J.join(t,e)}async function V(e){let t=await xe(e.filename),n=ye.createSourceFile(t,e.raw,{scriptKind:ue.TSX});for(let r of he)r({sourceFile:n,...e});return await z({sourceFile:n,...e})}import*as a from"@clack/prompts";import{execa as B}from"execa";import P from"fs-extra";import K from"path";import j from"picocolors";import{z as w}from"zod";function U(e,t){let n=new Set;function r(o){if(n.has(o))return;n.add(o);let c=t.find(d=>d.name===o);if(c&&c.innerDependencies)for(let d of c.innerDependencies)r(d)}for(let o of e)r(o);return Array.from(n)}var we=w.object({components:w.array(w.string()).optional(),cwd:w.string(),all:w.boolean()}),L=e=>{e.command("add [...components]","add component").option("-a, --all","Add all components",{default:!1}).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",{default:process.cwd()}).example("seed-design add box-button").example("seed-design add alert-dialog").action(async(t,n)=>{let r=we.parse({components:t,...n}),o=i=>j.cyan(i),c=r.cwd;P.existsSync(c)||(a.log.error(`The path ${c} does not exist. Please try again.`),process.exit(1));let d=await D(),f=r.all?d.map(i=>i.name):r.components;if(!r.components?.length&&!r.all){let i=await a.multiselect({message:"Select all components to add",options:d.map(l=>({label:l.name,value:l.name,hint:l.description}))});a.isCancel(i)&&(a.log.error("Aborted."),process.exit(0)),f=i}f?.length||(a.log.error("No components found."),process.exit(0));let y=U(f,d),S=y.filter(i=>!f.includes(i)),x=await O(c),H=await M(y);a.log.message(`Selection: ${o(f.join(", "))}`),S.length&&a.log.message(`Inner Dependencies: ${o(S.join(", "))} will be also added.`);for(let i of H){for(let m of i.registries){let g=x.resolvedUIPaths;P.existsSync(g)||await P.mkdir(g,{recursive:!0});let h=K.resolve(g,m.name),Q=await V({filename:m.name,config:x,raw:m.content});x.tsx||(h=h.replace(/\.tsx$/,".jsx"),h=h.replace(/\.ts$/,".js")),await P.writeFile(h,Q);let Y=K.relative(c,h);a.log.info(`Added ${o(m.name)} to ${o(Y)}`)}let l=await F(c),{start:b,stop:R}=a.spinner();if(i.dependencies?.length){b(j.gray("Installing dependencies"));let m=await B(l,[l==="npm"?"install":"add",...i.dependencies],{cwd:c});if(m.failed)console.error(m.all),process.exit(1);else{for(let g of i.dependencies)a.log.info(`- ${g}`);R("Dependencies installed.")}}if(i.devDependencies?.length){b(j.gray("Installing devDependencies"));let m=await B(l,[l==="npm"?"install":"add","-D",...i.devDependencies],{cwd:c});if(m.failed)console.error(m.all),process.exit(1);else{for(let g of i.devDependencies)a.log.info(`- ${g}`);R("Dependencies installed.")}}}a.outro("Components added.")})};import Ce from"findup-sync";import Se from"fs-extra";var ve="package.json";function Pe(){let e=Ce(ve);if(!e)throw new Error("No package.json file found in the project.");return e}function _(){return Se.readJSONSync(Pe())}import{cac as be}from"cac";import*as p from"@clack/prompts";import Ie from"fs-extra";import G from"path";import Me from"picocolors";import{z as X}from"zod";var je=X.object({cwd:X.string()}),q=e=>{e.command("init","initialize seed-design.json").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",{default:process.cwd()}).action(async t=>{let n=je.parse({...t}),r=x=>Me.cyan(x),o=await p.group({tsx:()=>p.confirm({message:`Would you like to use ${r("TypeScript")} (recommended)?`,initialValue:!0}),rsc:()=>p.confirm({message:`Are you using ${r("React Server Components")}?`,initialValue:!1}),css:()=>p.confirm({message:`Would you like to use ${r("CSS Modules")}? (If true, CSS import will be added in components)`,initialValue:!0}),path:()=>p.text({message:`Enter the path to your ${r("seed-design directory")}`,initialValue:"./seed-design",defaultValue:"./seed-design",placeholder:"./seed-design"})},{onCancel:()=>{p.cancel("Operation cancelled."),process.exit(0)}}),c={rsc:o.rsc,tsx:o.tsx,css:o.css,path:o.path},{start:d,stop:f}=p.spinner();d("Writing seed-design.json...");let y=G.resolve(n.cwd,"seed-design.json");await Ie.writeFile(y,`${JSON.stringify(c,null,2)}
3
- `,"utf-8");let S=G.relative(process.cwd(),y);f(`seed-design.json written to ${r(S)}`)})};var Re="seed-design",C=be(Re);async function Te(){let e=_();L(C),q(C),C.version(e.version||"1.0.0","-v, --version"),C.help(),C.parse()}Te();
2
+
3
+ // src/utils/get-config.ts
4
+ import { cosmiconfig } from "cosmiconfig";
5
+ import path from "path";
6
+ import { z } from "zod";
7
+ var MODULE_NAME = "seed-design";
8
+ var explorer = cosmiconfig(MODULE_NAME, {
9
+ searchPlaces: [`${MODULE_NAME}.json`]
10
+ });
11
+ var rawConfigSchema = z.object({
12
+ $schema: z.string().optional(),
13
+ rsc: z.coerce.boolean().default(false),
14
+ tsx: z.coerce.boolean().default(true),
15
+ css: z.coerce.boolean().default(true),
16
+ path: z.string()
17
+ }).strict();
18
+ var configSchema = rawConfigSchema.extend({
19
+ resolvedUIPaths: z.string()
20
+ });
21
+ async function getConfig(cwd) {
22
+ const config = await getRawConfig(cwd);
23
+ if (!config) {
24
+ return null;
25
+ }
26
+ return await resolveConfigPaths(cwd, config);
27
+ }
28
+ async function resolveConfigPaths(cwd, config) {
29
+ const seedComponentRootPath = path.resolve(cwd, config.path);
30
+ return configSchema.parse({
31
+ ...config,
32
+ resolvedUIPaths: path.join(seedComponentRootPath, "ui")
33
+ });
34
+ }
35
+ async function getRawConfig(cwd) {
36
+ try {
37
+ const configResult = await explorer.search(cwd);
38
+ if (!configResult) {
39
+ return null;
40
+ }
41
+ return rawConfigSchema.parse(configResult.config);
42
+ } catch (error) {
43
+ console.log(error);
44
+ throw new Error(`Invalid configuration found in ${cwd}/seed-design.json.`);
45
+ }
46
+ }
47
+
48
+ // src/schema.ts
49
+ import { z as z2 } from "zod";
50
+ var componentMetadataSchema = z2.object({
51
+ name: z2.string(),
52
+ description: z2.string().optional(),
53
+ dependencies: z2.array(z2.string()).optional(),
54
+ devDependencies: z2.array(z2.string()).optional(),
55
+ innerDependencies: z2.array(z2.string()).optional(),
56
+ snippets: z2.array(z2.string()),
57
+ type: z2.enum(["component"])
58
+ });
59
+ var componentMetadataIndexSchema = z2.array(componentMetadataSchema);
60
+ var omittedComponentMetadataIndexSchema = componentMetadataSchema.omit({ snippets: true });
61
+ var componentMetadataSchemaWithRegistry = omittedComponentMetadataIndexSchema.extend({
62
+ registries: z2.array(
63
+ z2.object({
64
+ name: z2.string(),
65
+ content: z2.string()
66
+ })
67
+ )
68
+ });
69
+ var componentMetadataWithRegistrySchema = z2.array(componentMetadataSchemaWithRegistry);
70
+
71
+ // src/utils/get-metadata.ts
72
+ var BASE_URL = false ? "https://component.seed-design.io" : "http://localhost:3000";
73
+ async function fetchComponentMetadatas(fileNames) {
74
+ try {
75
+ const results = await Promise.all(
76
+ fileNames.map(async (fileName) => {
77
+ const response = await fetch(`${BASE_URL}/registry/component/${fileName}.json`);
78
+ return await response.json();
79
+ })
80
+ );
81
+ return results;
82
+ } catch (error) {
83
+ console.log(error);
84
+ throw new Error(`Failed to fetch registry from ${BASE_URL}.`);
85
+ }
86
+ }
87
+ async function getMetadataIndex() {
88
+ try {
89
+ const [result] = await fetchComponentMetadatas(["index"]);
90
+ return componentMetadataIndexSchema.parse(result);
91
+ } catch (error) {
92
+ console.log(error);
93
+ throw new Error(`Failed to fetch components from ${BASE_URL}.`);
94
+ }
95
+ }
96
+
97
+ // src/utils/get-package-manager.ts
98
+ import { detect } from "@antfu/ni";
99
+ async function getPackageManager(targetDir) {
100
+ const packageManager = await detect({ programmatic: true, cwd: targetDir });
101
+ if (packageManager === "yarn@berry")
102
+ return "yarn";
103
+ if (packageManager === "pnpm@6")
104
+ return "pnpm";
105
+ if (packageManager === "bun")
106
+ return "bun";
107
+ return packageManager ?? "npm";
108
+ }
109
+
110
+ // src/utils/transformers/index.ts
111
+ import { promises as fs } from "fs";
112
+ import { tmpdir } from "os";
113
+ import path2 from "path";
114
+
115
+ // src/utils/transformers/transform-jsx.ts
116
+ import { transformFromAstSync } from "@babel/core";
117
+ import transformTypescript from "@babel/plugin-transform-typescript";
118
+ import * as recast from "recast";
119
+ import { parse as parse2 } from "@babel/parser";
120
+ var PARSE_OPTIONS = {
121
+ sourceType: "module",
122
+ allowImportExportEverywhere: true,
123
+ allowReturnOutsideFunction: true,
124
+ startLine: 1,
125
+ tokens: true,
126
+ plugins: [
127
+ "asyncGenerators",
128
+ "bigInt",
129
+ "classPrivateMethods",
130
+ "classPrivateProperties",
131
+ "classProperties",
132
+ "classStaticBlock",
133
+ "decimal",
134
+ "decorators-legacy",
135
+ "doExpressions",
136
+ "dynamicImport",
137
+ "exportDefaultFrom",
138
+ "exportNamespaceFrom",
139
+ "functionBind",
140
+ "functionSent",
141
+ "importAssertions",
142
+ "importMeta",
143
+ "nullishCoalescingOperator",
144
+ "numericSeparator",
145
+ "objectRestSpread",
146
+ "optionalCatchBinding",
147
+ "optionalChaining",
148
+ [
149
+ "pipelineOperator",
150
+ {
151
+ proposal: "minimal"
152
+ }
153
+ ],
154
+ [
155
+ "recordAndTuple",
156
+ {
157
+ syntaxType: "hash"
158
+ }
159
+ ],
160
+ "throwExpressions",
161
+ "topLevelAwait",
162
+ "v8intrinsic",
163
+ "typescript",
164
+ "jsx"
165
+ ]
166
+ };
167
+ var transformJsx = async ({ sourceFile, config }) => {
168
+ const output = sourceFile.getFullText();
169
+ if (config.tsx) {
170
+ return output;
171
+ }
172
+ const ast = recast.parse(output, {
173
+ parser: {
174
+ parse: (code) => {
175
+ return parse2(code, PARSE_OPTIONS);
176
+ }
177
+ }
178
+ });
179
+ const result = transformFromAstSync(ast, output, {
180
+ cloneInputAst: false,
181
+ code: false,
182
+ ast: true,
183
+ plugins: [transformTypescript],
184
+ configFile: false
185
+ });
186
+ if (!result || !result.ast) {
187
+ throw new Error("Failed to transform JSX");
188
+ }
189
+ return recast.print(result.ast).code;
190
+ };
191
+
192
+ // src/utils/transformers/transform-rsc.ts
193
+ import { SyntaxKind } from "ts-morph";
194
+ var transformRsc = async ({ sourceFile, config }) => {
195
+ if (config.rsc) {
196
+ return sourceFile;
197
+ }
198
+ const first = sourceFile.getFirstChildByKind(SyntaxKind.ExpressionStatement);
199
+ if (first?.getText() === `"use client";`) {
200
+ first.remove();
201
+ }
202
+ return sourceFile;
203
+ };
204
+
205
+ // src/utils/transformers/transform-css.ts
206
+ var transformCSS = async ({ sourceFile, config }) => {
207
+ if (config.css) {
208
+ return sourceFile;
209
+ }
210
+ const imports = sourceFile.getImportDeclarations();
211
+ const cssImports = imports.filter((i) => i.getModuleSpecifierValue().endsWith(".css"));
212
+ for (const cssImport of cssImports) {
213
+ cssImport.remove();
214
+ }
215
+ return sourceFile;
216
+ };
217
+
218
+ // src/utils/transformers/index.ts
219
+ import { Project, ScriptKind } from "ts-morph";
220
+ var transformers = [transformRsc, transformCSS];
221
+ var project = new Project({
222
+ compilerOptions: {}
223
+ });
224
+ async function createTempSourceFile(filename) {
225
+ const dir = await fs.mkdtemp(path2.join(tmpdir(), "seed-deisgn-"));
226
+ return path2.join(dir, filename);
227
+ }
228
+ async function transform(opts) {
229
+ const tempFile = await createTempSourceFile(opts.filename);
230
+ const sourceFile = project.createSourceFile(tempFile, opts.raw, {
231
+ scriptKind: ScriptKind.TSX
232
+ });
233
+ for (const transformer of transformers) {
234
+ transformer({ sourceFile, ...opts });
235
+ }
236
+ return await transformJsx({
237
+ sourceFile,
238
+ ...opts
239
+ });
240
+ }
241
+
242
+ // src/commands/add.ts
243
+ import * as p from "@clack/prompts";
244
+ import { execa } from "execa";
245
+ import fs2 from "fs-extra";
246
+ import path3 from "path";
247
+ import color from "picocolors";
248
+ import { z as z3 } from "zod";
249
+
250
+ // src/utils/add-relative-components.ts
251
+ function addRelativeComponents(userSelects, metadataIndex) {
252
+ const selectedComponents = /* @__PURE__ */ new Set();
253
+ function addSeedDependencies(componentName) {
254
+ if (selectedComponents.has(componentName))
255
+ return;
256
+ selectedComponents.add(componentName);
257
+ const component = metadataIndex.find((c) => c.name === componentName);
258
+ if (!component)
259
+ return;
260
+ if (component.innerDependencies) {
261
+ for (const dep of component.innerDependencies) {
262
+ addSeedDependencies(dep);
263
+ }
264
+ }
265
+ }
266
+ for (const componentName of userSelects) {
267
+ addSeedDependencies(componentName);
268
+ }
269
+ return Array.from(selectedComponents);
270
+ }
271
+
272
+ // src/commands/add.ts
273
+ var addOptionsSchema = z3.object({
274
+ components: z3.array(z3.string()).optional(),
275
+ cwd: z3.string(),
276
+ all: z3.boolean()
277
+ // yes: z.boolean(),
278
+ // overwrite: z.boolean(),
279
+ // path: z.string().optional(),
280
+ });
281
+ var addCommand = (cli) => {
282
+ cli.command("add [...components]", "add component").option("-a, --all", "Add all components", {
283
+ default: false
284
+ }).option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", {
285
+ default: process.cwd()
286
+ }).example("seed-design add box-button").example("seed-design add alert-dialog").action(async (components, opts) => {
287
+ const options = addOptionsSchema.parse({
288
+ components,
289
+ ...opts
290
+ });
291
+ const highlight = (text2) => color.cyan(text2);
292
+ const cwd = options.cwd;
293
+ if (!fs2.existsSync(cwd)) {
294
+ p.log.error(`The path ${cwd} does not exist. Please try again.`);
295
+ process.exit(1);
296
+ }
297
+ const metadataIndex = await getMetadataIndex();
298
+ let selectedComponents = options.all ? metadataIndex.map((meatadata) => meatadata.name) : options.components;
299
+ if (!options.components?.length && !options.all) {
300
+ const selects = await p.multiselect({
301
+ message: "Select all components to add",
302
+ options: metadataIndex.map((metadata) => {
303
+ return {
304
+ label: metadata.name,
305
+ value: metadata.name,
306
+ hint: metadata.description
307
+ };
308
+ })
309
+ });
310
+ if (p.isCancel(selects)) {
311
+ p.log.error("Aborted.");
312
+ process.exit(0);
313
+ }
314
+ selectedComponents = selects;
315
+ }
316
+ if (!selectedComponents?.length) {
317
+ p.log.error("No components found.");
318
+ process.exit(0);
319
+ }
320
+ const allComponents = addRelativeComponents(selectedComponents, metadataIndex);
321
+ const addedComponents = allComponents.filter((c) => !selectedComponents.includes(c));
322
+ const config = await getConfig(cwd);
323
+ const metadatas = await fetchComponentMetadatas(allComponents);
324
+ p.log.message(`Selection: ${highlight(selectedComponents.join(", "))}`);
325
+ if (addedComponents.length) {
326
+ p.log.message(
327
+ `Inner Dependencies: ${highlight(addedComponents.join(", "))} will be also added.`
328
+ );
329
+ }
330
+ for (const metadata of metadatas) {
331
+ for (const registry of metadata.registries) {
332
+ const UIFolderPath = config.resolvedUIPaths;
333
+ if (!fs2.existsSync(UIFolderPath)) {
334
+ await fs2.mkdir(UIFolderPath, { recursive: true });
335
+ }
336
+ let filePath = path3.resolve(UIFolderPath, registry.name);
337
+ const content = await transform({
338
+ filename: registry.name,
339
+ config,
340
+ raw: registry.content
341
+ });
342
+ if (!config.tsx) {
343
+ filePath = filePath.replace(/\.tsx$/, ".jsx");
344
+ filePath = filePath.replace(/\.ts$/, ".js");
345
+ }
346
+ await fs2.writeFile(filePath, content);
347
+ const relativePath = path3.relative(cwd, filePath);
348
+ p.log.info(`Added ${highlight(registry.name)} to ${highlight(relativePath)}`);
349
+ }
350
+ const packageManager = await getPackageManager(cwd);
351
+ const { start, stop } = p.spinner();
352
+ if (metadata.dependencies?.length) {
353
+ start(color.gray("Installing dependencies"));
354
+ const result = await execa(
355
+ packageManager,
356
+ [packageManager === "npm" ? "install" : "add", ...metadata.dependencies],
357
+ {
358
+ cwd
359
+ }
360
+ );
361
+ if (result.failed) {
362
+ console.error(result.all);
363
+ process.exit(1);
364
+ } else {
365
+ for (const deps of metadata.dependencies) {
366
+ p.log.info(`- ${deps}`);
367
+ }
368
+ stop("Dependencies installed.");
369
+ }
370
+ }
371
+ if (metadata.devDependencies?.length) {
372
+ start(color.gray("Installing devDependencies"));
373
+ const result = await execa(
374
+ packageManager,
375
+ [packageManager === "npm" ? "install" : "add", "-D", ...metadata.devDependencies],
376
+ {
377
+ cwd
378
+ }
379
+ );
380
+ if (result.failed) {
381
+ console.error(result.all);
382
+ process.exit(1);
383
+ } else {
384
+ for (const deps of metadata.devDependencies) {
385
+ p.log.info(`- ${deps}`);
386
+ }
387
+ stop("Dependencies installed.");
388
+ }
389
+ }
390
+ }
391
+ p.outro("Components added.");
392
+ });
393
+ };
394
+
395
+ // src/utils/get-package-info.ts
396
+ import findup from "findup-sync";
397
+ import fs3 from "fs-extra";
398
+ var PACKAGE_JSON = "package.json";
399
+ function getPackagePath() {
400
+ const packageJsonPath = findup(PACKAGE_JSON);
401
+ if (!packageJsonPath) {
402
+ throw new Error("No package.json file found in the project.");
403
+ }
404
+ return packageJsonPath;
405
+ }
406
+ function getPackageInfo() {
407
+ return fs3.readJSONSync(getPackagePath());
408
+ }
409
+
410
+ // src/index.ts
411
+ import { cac } from "cac";
412
+
413
+ // src/commands/init.ts
414
+ import * as p2 from "@clack/prompts";
415
+ import fs4 from "fs-extra";
416
+ import path4 from "path";
417
+ import color2 from "picocolors";
418
+ import { z as z4 } from "zod";
419
+ var initOptionsSchema = z4.object({
420
+ cwd: z4.string()
421
+ });
422
+ var initCommand = (cli) => {
423
+ cli.command("init", "initialize seed-design.json").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", {
424
+ default: process.cwd()
425
+ }).action(async (opts) => {
426
+ const options = initOptionsSchema.parse({ ...opts });
427
+ const highlight = (text2) => color2.cyan(text2);
428
+ const group2 = await p2.group(
429
+ {
430
+ tsx: () => p2.confirm({
431
+ message: `Would you like to use ${highlight("TypeScript")} (recommended)?`,
432
+ initialValue: true
433
+ }),
434
+ rsc: () => p2.confirm({
435
+ message: `Are you using ${highlight("React Server Components")}?`,
436
+ initialValue: false
437
+ }),
438
+ css: () => p2.confirm({
439
+ message: `Would you like to use ${highlight("CSS Modules")}? (If true, CSS import will be added in components)`,
440
+ initialValue: true
441
+ }),
442
+ path: () => p2.text({
443
+ message: `Enter the path to your ${highlight("seed-design directory")}`,
444
+ initialValue: "./seed-design",
445
+ defaultValue: "./seed-design",
446
+ placeholder: "./seed-design"
447
+ })
448
+ },
449
+ {
450
+ onCancel: () => {
451
+ p2.cancel("Operation cancelled.");
452
+ process.exit(0);
453
+ }
454
+ }
455
+ );
456
+ const config = {
457
+ rsc: group2.rsc,
458
+ tsx: group2.tsx,
459
+ css: group2.css,
460
+ path: group2.path
461
+ };
462
+ const { start, stop } = p2.spinner();
463
+ start("Writing seed-design.json...");
464
+ const targetPath = path4.resolve(options.cwd, "seed-design.json");
465
+ await fs4.writeFile(targetPath, `${JSON.stringify(config, null, 2)}
466
+ `, "utf-8");
467
+ const relativePath = path4.relative(process.cwd(), targetPath);
468
+ stop(`seed-design.json written to ${highlight(relativePath)}`);
469
+ });
470
+ };
471
+
472
+ // src/index.ts
473
+ var NAME = "seed-design";
474
+ var CLI = cac(NAME);
475
+ async function main() {
476
+ const packageInfo = getPackageInfo();
477
+ addCommand(CLI);
478
+ initCommand(CLI);
479
+ CLI.version(packageInfo.version || "1.0.0", "-v, --version");
480
+ CLI.help();
481
+ CLI.parse();
482
+ }
483
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/cli",
3
- "version": "0.0.0-alpha",
3
+ "version": "0.0.0-alpha-20241004093556",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,7 +4,7 @@ import {
4
4
  } from "@/src/schema";
5
5
 
6
6
  const BASE_URL =
7
- process.env.NODE_ENV === "prod" ? "https://component-seed.design.io" : "http://localhost:3000";
7
+ process.env.NODE_ENV === "prod" ? "https://component.seed-design.io" : "http://localhost:3000";
8
8
 
9
9
  export async function fetchComponentMetadatas(
10
10
  fileNames?: string[],