ds-01 1.0.7 → 1.0.8
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/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +5 -7
- package/package.json +1 -1
- package/src/commands/add.ts +44 -125
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAuDpC,eAAO,MAAM,GAAG,SA0MZ,CAAC"}
|
package/dist/commands/add.js
CHANGED
|
@@ -84,8 +84,9 @@ export const add = new Command()
|
|
|
84
84
|
},
|
|
85
85
|
});
|
|
86
86
|
if (!response.ok) {
|
|
87
|
+
const errorData = await response.json().catch(() => null);
|
|
87
88
|
s.stop(pc.red("Component fetch failed."));
|
|
88
|
-
cancel(
|
|
89
|
+
cancel(errorData?.error || `Server returned HTTP ${response.status}`);
|
|
89
90
|
process.exit(1);
|
|
90
91
|
}
|
|
91
92
|
const componentData = await response.json();
|
|
@@ -118,8 +119,7 @@ export const add = new Command()
|
|
|
118
119
|
// --------------------------------------------------
|
|
119
120
|
// 7. Install dependencies
|
|
120
121
|
// --------------------------------------------------
|
|
121
|
-
if (componentData.dependencies &&
|
|
122
|
-
componentData.dependencies.length > 0) {
|
|
122
|
+
if (componentData.dependencies && componentData.dependencies.length > 0) {
|
|
123
123
|
const depsToInstall = componentData.dependencies.join(" ");
|
|
124
124
|
s.start(`Installing missing dependencies: ${pc.cyan(depsToInstall)}...`);
|
|
125
125
|
try {
|
|
@@ -136,16 +136,14 @@ export const add = new Command()
|
|
|
136
136
|
// --------------------------------------------------
|
|
137
137
|
// 8. Success
|
|
138
138
|
// --------------------------------------------------
|
|
139
|
-
const mainFile = bundledFileNames.find((name) => name.toLowerCase() ===
|
|
140
|
-
componentName.toLowerCase()) || bundledFileNames[0];
|
|
139
|
+
const mainFile = bundledFileNames.find((name) => name.toLowerCase() === componentName.toLowerCase()) || bundledFileNames[0];
|
|
141
140
|
outro(`${pc.white("✔")} ${pc.bold(`Component <${componentName} /> is ready!`)}\n` +
|
|
142
141
|
pc.gray("Import it: ") +
|
|
143
142
|
pc.cyan(`import { ${mainFile} } from "@/${config.componentsPath}/${componentName}/${mainFile}"`));
|
|
144
143
|
}
|
|
145
144
|
catch (error) {
|
|
146
145
|
s.stop(pc.red("An error occurred during injection."));
|
|
147
|
-
cancel(pc.gray(error?.message ||
|
|
148
|
-
"Unknown CLI Error"));
|
|
146
|
+
cancel(pc.gray(error?.message || "Unknown CLI Error"));
|
|
149
147
|
process.exit(1);
|
|
150
148
|
}
|
|
151
149
|
});
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -12,8 +12,7 @@ import machineIdPkg from "node-machine-id";
|
|
|
12
12
|
|
|
13
13
|
const { machineIdSync } = machineIdPkg;
|
|
14
14
|
|
|
15
|
-
const API_BASE_URL =
|
|
16
|
-
process.env.DS01_API_URL || "https://ds-01.vercel.app";
|
|
15
|
+
const API_BASE_URL = process.env.DS01_API_URL || "https://ds-01.vercel.app";
|
|
17
16
|
|
|
18
17
|
// Helper to verify Tailwind exists before doing anything
|
|
19
18
|
function checkTailwindInstallation() {
|
|
@@ -29,9 +28,7 @@ function checkTailwindInstallation() {
|
|
|
29
28
|
process.exit(1);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
const pkgJson = JSON.parse(
|
|
33
|
-
fs.readFileSync(pkgJsonPath, "utf-8"),
|
|
34
|
-
);
|
|
31
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
35
32
|
|
|
36
33
|
const allDeps = {
|
|
37
34
|
...pkgJson.dependencies,
|
|
@@ -40,22 +37,16 @@ function checkTailwindInstallation() {
|
|
|
40
37
|
|
|
41
38
|
if (!allDeps["tailwindcss"]) {
|
|
42
39
|
cancel(
|
|
43
|
-
pc.red(
|
|
44
|
-
"Tailwind CSS is missing from your project dependencies.\n",
|
|
45
|
-
) +
|
|
40
|
+
pc.red("Tailwind CSS is missing from your project dependencies.\n") +
|
|
46
41
|
pc.gray(
|
|
47
42
|
"DS01 components rely strictly on Tailwind CSS for styling.\n\n",
|
|
48
43
|
) +
|
|
49
44
|
pc.white(
|
|
50
45
|
"Kindly install it and configure your project, then retry:\n",
|
|
51
46
|
) +
|
|
52
|
-
pc.cyan(
|
|
53
|
-
" npm install tailwindcss @tailwindcss/postcss postcss\n\n",
|
|
54
|
-
) +
|
|
47
|
+
pc.cyan(" npm install tailwindcss @tailwindcss/postcss postcss\n\n") +
|
|
55
48
|
pc.gray("Official Setup Guide: ") +
|
|
56
|
-
pc.underline(
|
|
57
|
-
"https://tailwindcss.com/docs/installation",
|
|
58
|
-
),
|
|
49
|
+
pc.underline("https://tailwindcss.com/docs/installation"),
|
|
59
50
|
);
|
|
60
51
|
|
|
61
52
|
process.exit(1);
|
|
@@ -65,10 +56,7 @@ function checkTailwindInstallation() {
|
|
|
65
56
|
export const add = new Command()
|
|
66
57
|
.name("add")
|
|
67
58
|
.description("Add a component from DS01 to your project")
|
|
68
|
-
.argument(
|
|
69
|
-
"<component>",
|
|
70
|
-
"The name of the component (e.g., premium-section)",
|
|
71
|
-
)
|
|
59
|
+
.argument("<component>", "The name of the component (e.g., premium-section)")
|
|
72
60
|
.action(async (componentName: string) => {
|
|
73
61
|
console.log();
|
|
74
62
|
|
|
@@ -82,45 +70,28 @@ export const add = new Command()
|
|
|
82
70
|
|
|
83
71
|
const cwd = process.cwd();
|
|
84
72
|
|
|
85
|
-
const configPath = path.join(
|
|
86
|
-
cwd,
|
|
87
|
-
"ds01.config.json",
|
|
88
|
-
);
|
|
73
|
+
const configPath = path.join(cwd, "ds01.config.json");
|
|
89
74
|
|
|
90
75
|
if (!fs.existsSync(configPath)) {
|
|
91
|
-
cancel(
|
|
92
|
-
pc.red(
|
|
93
|
-
"ds01.config.json not found. Run 'npx ds-01 init' first.",
|
|
94
|
-
),
|
|
95
|
-
);
|
|
76
|
+
cancel(pc.red("ds01.config.json not found. Run 'npx ds-01 init' first."));
|
|
96
77
|
|
|
97
78
|
process.exit(1);
|
|
98
79
|
}
|
|
99
80
|
|
|
100
|
-
const config = JSON.parse(
|
|
101
|
-
fs.readFileSync(configPath, "utf-8"),
|
|
102
|
-
);
|
|
81
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
103
82
|
|
|
104
83
|
const token = getToken();
|
|
105
84
|
const machineId = machineIdSync();
|
|
106
85
|
|
|
107
86
|
if (!token || !machineId) {
|
|
108
|
-
cancel(
|
|
109
|
-
pc.red(
|
|
110
|
-
"You are not authenticated. Run 'npx ds-01 login' first.",
|
|
111
|
-
),
|
|
112
|
-
);
|
|
87
|
+
cancel(pc.red("You are not authenticated. Run 'npx ds-01 login' first."));
|
|
113
88
|
|
|
114
89
|
process.exit(1);
|
|
115
90
|
}
|
|
116
91
|
|
|
117
92
|
const s = spinner();
|
|
118
93
|
|
|
119
|
-
s.start(
|
|
120
|
-
`Fetching ${pc.cyan(
|
|
121
|
-
`<${componentName} />`,
|
|
122
|
-
)} from registry...`,
|
|
123
|
-
);
|
|
94
|
+
s.start(`Fetching ${pc.cyan(`<${componentName} />`)} from registry...`);
|
|
124
95
|
|
|
125
96
|
try {
|
|
126
97
|
// --------------------------------------------------
|
|
@@ -144,8 +115,7 @@ export const add = new Command()
|
|
|
144
115
|
new TextEncoder().encode(message),
|
|
145
116
|
);
|
|
146
117
|
|
|
147
|
-
const signatureBase64 =
|
|
148
|
-
Buffer.from(signature).toString("base64");
|
|
118
|
+
const signatureBase64 = Buffer.from(signature).toString("base64");
|
|
149
119
|
|
|
150
120
|
// --------------------------------------------------
|
|
151
121
|
// 3. Send token + machine ID + signature
|
|
@@ -169,29 +139,22 @@ export const add = new Command()
|
|
|
169
139
|
);
|
|
170
140
|
|
|
171
141
|
if (!response.ok) {
|
|
172
|
-
|
|
173
|
-
pc.red("Component fetch failed."),
|
|
174
|
-
);
|
|
142
|
+
const errorData = await response.json().catch(() => null);
|
|
175
143
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
);
|
|
144
|
+
s.stop(pc.red("Component fetch failed."));
|
|
145
|
+
|
|
146
|
+
cancel(errorData?.error || `Server returned HTTP ${response.status}`);
|
|
179
147
|
|
|
180
148
|
process.exit(1);
|
|
181
149
|
}
|
|
182
150
|
|
|
183
|
-
const componentData =
|
|
184
|
-
await response.json();
|
|
151
|
+
const componentData = await response.json();
|
|
185
152
|
|
|
186
153
|
// --------------------------------------------------
|
|
187
154
|
// 4. Create component folder
|
|
188
155
|
// --------------------------------------------------
|
|
189
156
|
|
|
190
|
-
const targetDir = path.join(
|
|
191
|
-
cwd,
|
|
192
|
-
config.componentsPath,
|
|
193
|
-
componentName,
|
|
194
|
-
);
|
|
157
|
+
const targetDir = path.join(cwd, config.componentsPath, componentName);
|
|
195
158
|
|
|
196
159
|
if (!fs.existsSync(targetDir)) {
|
|
197
160
|
fs.mkdirSync(targetDir, {
|
|
@@ -203,45 +166,29 @@ export const add = new Command()
|
|
|
203
166
|
// 5. Extract bundled file names
|
|
204
167
|
// --------------------------------------------------
|
|
205
168
|
|
|
206
|
-
const bundledFileNames =
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
file.name.replace(
|
|
210
|
-
/\.[^/.]+$/,
|
|
211
|
-
"",
|
|
212
|
-
),
|
|
213
|
-
);
|
|
169
|
+
const bundledFileNames = componentData.files.map((file: any) =>
|
|
170
|
+
file.name.replace(/\.[^/.]+$/, ""),
|
|
171
|
+
);
|
|
214
172
|
|
|
215
173
|
// --------------------------------------------------
|
|
216
174
|
// 6. Write component files
|
|
217
175
|
// --------------------------------------------------
|
|
218
176
|
|
|
219
177
|
for (const file of componentData.files) {
|
|
220
|
-
const filePath = path.join(
|
|
221
|
-
targetDir,
|
|
222
|
-
file.name,
|
|
223
|
-
);
|
|
178
|
+
const filePath = path.join(targetDir, file.name);
|
|
224
179
|
|
|
225
180
|
let content = file.content;
|
|
226
181
|
|
|
227
|
-
bundledFileNames.forEach(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
content = content.replace(
|
|
235
|
-
regex,
|
|
236
|
-
`from "./${fileName}"`,
|
|
237
|
-
);
|
|
238
|
-
},
|
|
239
|
-
);
|
|
182
|
+
bundledFileNames.forEach((fileName: string) => {
|
|
183
|
+
const regex = new RegExp(
|
|
184
|
+
`from\\s+["']\\.[^"']*?\\/${fileName}["']`,
|
|
185
|
+
"g",
|
|
186
|
+
);
|
|
240
187
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
);
|
|
188
|
+
content = content.replace(regex, `from "./${fileName}"`);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
fs.writeFileSync(filePath, content);
|
|
245
192
|
}
|
|
246
193
|
|
|
247
194
|
s.stop(
|
|
@@ -256,45 +203,28 @@ export const add = new Command()
|
|
|
256
203
|
// 7. Install dependencies
|
|
257
204
|
// --------------------------------------------------
|
|
258
205
|
|
|
259
|
-
if (
|
|
260
|
-
componentData.dependencies
|
|
261
|
-
componentData.dependencies.length > 0
|
|
262
|
-
) {
|
|
263
|
-
const depsToInstall =
|
|
264
|
-
componentData.dependencies.join(" ");
|
|
206
|
+
if (componentData.dependencies && componentData.dependencies.length > 0) {
|
|
207
|
+
const depsToInstall = componentData.dependencies.join(" ");
|
|
265
208
|
|
|
266
209
|
s.start(
|
|
267
|
-
`Installing missing dependencies: ${pc.cyan(
|
|
268
|
-
depsToInstall,
|
|
269
|
-
)}...`,
|
|
210
|
+
`Installing missing dependencies: ${pc.cyan(depsToInstall)}...`,
|
|
270
211
|
);
|
|
271
212
|
|
|
272
213
|
try {
|
|
273
|
-
execSync(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
stdio: "ignore",
|
|
277
|
-
},
|
|
278
|
-
);
|
|
214
|
+
execSync(`npm install ${depsToInstall}`, {
|
|
215
|
+
stdio: "ignore",
|
|
216
|
+
});
|
|
279
217
|
|
|
280
218
|
s.stop(
|
|
281
219
|
pc.green(
|
|
282
|
-
`Dependencies installed successfully: ${pc.gray(
|
|
283
|
-
depsToInstall,
|
|
284
|
-
)}`,
|
|
220
|
+
`Dependencies installed successfully: ${pc.gray(depsToInstall)}`,
|
|
285
221
|
),
|
|
286
222
|
);
|
|
287
223
|
} catch {
|
|
288
|
-
s.stop(
|
|
289
|
-
pc.red(
|
|
290
|
-
"Failed to auto-install dependencies.",
|
|
291
|
-
),
|
|
292
|
-
);
|
|
224
|
+
s.stop(pc.red("Failed to auto-install dependencies."));
|
|
293
225
|
|
|
294
226
|
note(
|
|
295
|
-
`Please run: ${pc.cyan(
|
|
296
|
-
`npm install ${depsToInstall}`,
|
|
297
|
-
)} manually.`,
|
|
227
|
+
`Please run: ${pc.cyan(`npm install ${depsToInstall}`)} manually.`,
|
|
298
228
|
"Manual Action Required",
|
|
299
229
|
);
|
|
300
230
|
}
|
|
@@ -306,9 +236,7 @@ export const add = new Command()
|
|
|
306
236
|
|
|
307
237
|
const mainFile =
|
|
308
238
|
bundledFileNames.find(
|
|
309
|
-
(name: string) =>
|
|
310
|
-
name.toLowerCase() ===
|
|
311
|
-
componentName.toLowerCase(),
|
|
239
|
+
(name: string) => name.toLowerCase() === componentName.toLowerCase(),
|
|
312
240
|
) || bundledFileNames[0];
|
|
313
241
|
|
|
314
242
|
outro(
|
|
@@ -321,19 +249,10 @@ export const add = new Command()
|
|
|
321
249
|
),
|
|
322
250
|
);
|
|
323
251
|
} catch (error: any) {
|
|
324
|
-
s.stop(
|
|
325
|
-
pc.red(
|
|
326
|
-
"An error occurred during injection.",
|
|
327
|
-
),
|
|
328
|
-
);
|
|
252
|
+
s.stop(pc.red("An error occurred during injection."));
|
|
329
253
|
|
|
330
|
-
cancel(
|
|
331
|
-
pc.gray(
|
|
332
|
-
error?.message ||
|
|
333
|
-
"Unknown CLI Error",
|
|
334
|
-
),
|
|
335
|
-
);
|
|
254
|
+
cancel(pc.gray(error?.message || "Unknown CLI Error"));
|
|
336
255
|
|
|
337
256
|
process.exit(1);
|
|
338
257
|
}
|
|
339
|
-
});
|
|
258
|
+
});
|