ds-01 1.0.2 → 1.0.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.
@@ -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;AAkDpC,eAAO,MAAM,GAAG,SAwGZ,CAAC"}
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkDpC,eAAO,MAAM,GAAG,SAgHZ,CAAC"}
@@ -4,7 +4,7 @@ import pc from "picocolors";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
6
  import { execSync } from "child_process";
7
- import { getToken } from "../utils/config.js";
7
+ import { getToken, getMachineId } from "../utils/config.js";
8
8
  const API_BASE_URL = process.env.DS01_API_URL || "https://ds-01.vercel.app";
9
9
  // Helper to verify Tailwind exists before doing anything
10
10
  function checkTailwindInstallation() {
@@ -49,15 +49,21 @@ export const add = new Command()
49
49
  process.exit(1);
50
50
  }
51
51
  const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
52
+ // Read the GLOBAL credentials, not the local project config
52
53
  const token = getToken();
54
+ const machineId = getMachineId();
55
+ if (!token || !machineId) {
56
+ cancel(pc.red("You are not authenticated. Run 'npx ds-01 login' first."));
57
+ process.exit(1);
58
+ }
53
59
  const s = spinner();
54
60
  s.start(`Fetching ${pc.cyan(`<${componentName} />`)} from registry...`);
55
61
  try {
56
62
  // 3. Fetch component from your API
57
63
  const response = await fetch(`${API_BASE_URL}/api/registry/${componentName}`, {
58
64
  headers: {
59
- Authorization: `Bearer ${config.token}`,
60
- "X-Machine-ID": config.machineId, // <-- ADD THIS LINE
65
+ Authorization: `Bearer ${token}`,
66
+ "X-Machine-ID": machineId, // <-- TypeScript error fixed here
61
67
  },
62
68
  });
63
69
  if (!response.ok) {
@@ -1,4 +1,5 @@
1
1
  export declare function saveToken(token: string, machineId: string): void;
2
2
  export declare function getToken(): string | null;
3
+ export declare function getMachineId(): string | null;
3
4
  export declare function deleteToken(): void;
4
5
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAQA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAczD;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAWxC;AAED,wBAAgB,WAAW,SAI1B"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAQA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAczD;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAWxC;AAED,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAW5C;AAED,wBAAgB,WAAW,SAI1B"}
@@ -30,6 +30,19 @@ export function getToken() {
30
30
  }
31
31
  return null;
32
32
  }
33
+ export function getMachineId() {
34
+ if (fs.existsSync(credentialsPath)) {
35
+ try {
36
+ const data = fs.readFileSync(credentialsPath, "utf-8");
37
+ const parsed = JSON.parse(data);
38
+ return parsed.machineId || null;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ return null;
45
+ }
33
46
  export function deleteToken() {
34
47
  if (fs.existsSync(credentialsPath)) {
35
48
  fs.unlinkSync(credentialsPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ds-01",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Make your site best with DS01",
5
5
  "type": "module",
6
6
  "bin": {
@@ -4,7 +4,7 @@ import pc from "picocolors";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
6
  import { execSync } from "child_process";
7
- import { getToken } from "../utils/config.js";
7
+ import { getToken, getMachineId } from "../utils/config.js";
8
8
 
9
9
  const API_BASE_URL = process.env.DS01_API_URL || "https://ds-01.vercel.app";
10
10
 
@@ -17,8 +17,8 @@ function checkTailwindInstallation() {
17
17
  if (!fs.existsSync(pkgJsonPath)) {
18
18
  cancel(
19
19
  pc.red(
20
- "No package.json found. Please run this command inside a Node.js project.",
21
- ),
20
+ "No package.json found. Please run this command inside a Node.js project."
21
+ )
22
22
  );
23
23
  process.exit(1);
24
24
  }
@@ -35,14 +35,14 @@ function checkTailwindInstallation() {
35
35
  cancel(
36
36
  pc.red("Tailwind CSS is missing from your project dependencies.\n") +
37
37
  pc.gray(
38
- "DS01 components rely strictly on Tailwind CSS for styling.\n\n",
38
+ "DS01 components rely strictly on Tailwind CSS for styling.\n\n"
39
39
  ) +
40
40
  pc.white(
41
- "Kindly install it and configure your project, then retry:\n",
41
+ "Kindly install it and configure your project, then retry:\n"
42
42
  ) +
43
43
  pc.cyan(" npm install tailwindcss @tailwindcss/postcss postcss\n\n") +
44
44
  pc.gray("Official Setup Guide: ") +
45
- pc.underline("https://tailwindcss.com/docs/installation"),
45
+ pc.underline("https://tailwindcss.com/docs/installation")
46
46
  );
47
47
  process.exit(1);
48
48
  }
@@ -57,7 +57,7 @@ export const add = new Command()
57
57
 
58
58
  // 1. Premium Header
59
59
  intro(
60
- `${pc.bgWhite(pc.black(pc.bold(" DS01 ")))} ${pc.gray("Adding Component")}`,
60
+ `${pc.bgWhite(pc.black(pc.bold(" DS01 ")))} ${pc.gray("Adding Component")}`
61
61
  );
62
62
 
63
63
  // 2. Run Pre-Flight Tailwind Check
@@ -72,7 +72,15 @@ export const add = new Command()
72
72
  }
73
73
 
74
74
  const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
75
+
76
+ // Read the GLOBAL credentials, not the local project config
75
77
  const token = getToken();
78
+ const machineId = getMachineId();
79
+
80
+ if (!token || !machineId) {
81
+ cancel(pc.red("You are not authenticated. Run 'npx ds-01 login' first."));
82
+ process.exit(1);
83
+ }
76
84
 
77
85
  const s = spinner();
78
86
  s.start(`Fetching ${pc.cyan(`<${componentName} />`)} from registry...`);
@@ -83,10 +91,10 @@ export const add = new Command()
83
91
  `${API_BASE_URL}/api/registry/${componentName}`,
84
92
  {
85
93
  headers: {
86
- Authorization: `Bearer ${config.token}`,
87
- "X-Machine-ID": config.machineId, // <-- ADD THIS LINE
94
+ Authorization: `Bearer ${token}`,
95
+ "X-Machine-ID": machineId as string, // <-- TypeScript error fixed here
88
96
  },
89
- },
97
+ }
90
98
  );
91
99
 
92
100
  if (!response.ok) {
@@ -111,15 +119,15 @@ export const add = new Command()
111
119
 
112
120
  s.stop(
113
121
  pc.green(
114
- `Downloaded ${componentData.files.length} files into ${pc.white(`/${config.componentsPath}/${componentName}`)}`,
115
- ),
122
+ `Downloaded ${componentData.files.length} files into ${pc.white(`/${config.componentsPath}/${componentName}`)}`
123
+ )
116
124
  );
117
125
 
118
126
  // 6. Auto-install Missing Component Dependencies (e.g., framer-motion)
119
127
  if (componentData.dependencies && componentData.dependencies.length > 0) {
120
128
  const depsToInstall = componentData.dependencies.join(" ");
121
129
  s.start(
122
- `Installing missing dependencies: ${pc.cyan(depsToInstall)}...`,
130
+ `Installing missing dependencies: ${pc.cyan(depsToInstall)}...`
123
131
  );
124
132
 
125
133
  try {
@@ -127,14 +135,14 @@ export const add = new Command()
127
135
  execSync(`npm install ${depsToInstall}`, { stdio: "ignore" });
128
136
  s.stop(
129
137
  pc.green(
130
- `Dependencies installed successfully: ${pc.gray(depsToInstall)}`,
131
- ),
138
+ `Dependencies installed successfully: ${pc.gray(depsToInstall)}`
139
+ )
132
140
  );
133
141
  } catch (error) {
134
142
  s.stop(pc.red("Failed to auto-install dependencies."));
135
143
  note(
136
144
  `Please run: ${pc.cyan(`npm install ${depsToInstall}`)} manually.`,
137
- "Manual Action Required",
145
+ "Manual Action Required"
138
146
  );
139
147
  }
140
148
  }
@@ -144,12 +152,12 @@ export const add = new Command()
144
152
  `${pc.white("✔")} ${pc.bold(`Component <${componentName} /> is ready!`)}\n` +
145
153
  pc.gray(`Import it: `) +
146
154
  pc.cyan(
147
- `import { Section } from "@/${config.componentsPath}/${componentName}/Section"`,
148
- ),
155
+ `import { Section } from "@/${config.componentsPath}/${componentName}/Section"`
156
+ )
149
157
  );
150
158
  } catch (error: any) {
151
159
  s.stop(pc.red("An error occurred during injection."));
152
160
  cancel(pc.gray(error.message || "Unknown CLI Error"));
153
161
  process.exit(1);
154
162
  }
155
- });
163
+ });
@@ -35,6 +35,19 @@ export function getToken(): string | null {
35
35
  return null;
36
36
  }
37
37
 
38
+ export function getMachineId(): string | null {
39
+ if (fs.existsSync(credentialsPath)) {
40
+ try {
41
+ const data = fs.readFileSync(credentialsPath, "utf-8");
42
+ const parsed = JSON.parse(data);
43
+ return parsed.machineId || null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ return null;
49
+ }
50
+
38
51
  export function deleteToken() {
39
52
  if (fs.existsSync(credentialsPath)) {
40
53
  fs.unlinkSync(credentialsPath);