ds-01 1.0.3 → 1.0.4
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 +17 -2
- package/package.json +1 -1
- package/src/commands/add.ts +23 -2
|
@@ -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,
|
|
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,SAqIZ,CAAC"}
|
package/dist/commands/add.js
CHANGED
|
@@ -77,10 +77,23 @@ export const add = new Command()
|
|
|
77
77
|
if (!fs.existsSync(targetDir)) {
|
|
78
78
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
79
79
|
}
|
|
80
|
+
// 🛠️ EXTRACT NAMES FOR SMART REWRITING (e.g., ["PremiumHero", "Section", "AnimatedText"])
|
|
81
|
+
// We strip the extension (.tsx, .ts) to get the raw component name for import matching
|
|
82
|
+
const bundledFileNames = componentData.files.map((file) => file.name.replace(/\.[^/.]+$/, ""));
|
|
80
83
|
// 5. Inject the pure code files
|
|
81
84
|
for (const file of componentData.files) {
|
|
85
|
+
// Because the server sends just the basename (e.g., PremiumHero.tsx),
|
|
86
|
+
// path.join inherently flattens all files into the single targetDir folder.
|
|
82
87
|
const filePath = path.join(targetDir, file.name);
|
|
83
|
-
|
|
88
|
+
let content = file.content;
|
|
89
|
+
// 🛠️ DYNAMIC IMPORT REWRITER
|
|
90
|
+
bundledFileNames.forEach((fileName) => {
|
|
91
|
+
// Finds any relative import pointing to a bundled file (e.g., "../Section", "../../Section")
|
|
92
|
+
// and rewrites it strictly to a sibling import (e.g., "./Section")
|
|
93
|
+
const regex = new RegExp(`from\\s+["']\\.[^"']*?\\/${fileName}["']`, "g");
|
|
94
|
+
content = content.replace(regex, `from "./${fileName}"`);
|
|
95
|
+
});
|
|
96
|
+
fs.writeFileSync(filePath, content);
|
|
84
97
|
}
|
|
85
98
|
s.stop(pc.green(`Downloaded ${componentData.files.length} files into ${pc.white(`/${config.componentsPath}/${componentName}`)}`));
|
|
86
99
|
// 6. Auto-install Missing Component Dependencies (e.g., framer-motion)
|
|
@@ -98,9 +111,11 @@ export const add = new Command()
|
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
// 7. Clean Success Outro
|
|
114
|
+
// Find the main file to import (prioritize the one that matches the component name or use the first one)
|
|
115
|
+
const mainFile = bundledFileNames.find((name) => name.toLowerCase() === componentName.toLowerCase()) || bundledFileNames[0];
|
|
101
116
|
outro(`${pc.white("✔")} ${pc.bold(`Component <${componentName} /> is ready!`)}\n` +
|
|
102
117
|
pc.gray(`Import it: `) +
|
|
103
|
-
pc.cyan(`import {
|
|
118
|
+
pc.cyan(`import { ${mainFile} } from "@/${config.componentsPath}/${componentName}/${mainFile}"`));
|
|
104
119
|
}
|
|
105
120
|
catch (error) {
|
|
106
121
|
s.stop(pc.red("An error occurred during injection."));
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -111,10 +111,28 @@ export const add = new Command()
|
|
|
111
111
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
// 🛠️ EXTRACT NAMES FOR SMART REWRITING (e.g., ["PremiumHero", "Section", "AnimatedText"])
|
|
115
|
+
// We strip the extension (.tsx, .ts) to get the raw component name for import matching
|
|
116
|
+
const bundledFileNames = componentData.files.map((file: any) =>
|
|
117
|
+
file.name.replace(/\.[^/.]+$/, "")
|
|
118
|
+
);
|
|
119
|
+
|
|
114
120
|
// 5. Inject the pure code files
|
|
115
121
|
for (const file of componentData.files) {
|
|
122
|
+
// Because the server sends just the basename (e.g., PremiumHero.tsx),
|
|
123
|
+
// path.join inherently flattens all files into the single targetDir folder.
|
|
116
124
|
const filePath = path.join(targetDir, file.name);
|
|
117
|
-
|
|
125
|
+
let content = file.content;
|
|
126
|
+
|
|
127
|
+
// 🛠️ DYNAMIC IMPORT REWRITER
|
|
128
|
+
bundledFileNames.forEach((fileName: string) => {
|
|
129
|
+
// Finds any relative import pointing to a bundled file (e.g., "../Section", "../../Section")
|
|
130
|
+
// and rewrites it strictly to a sibling import (e.g., "./Section")
|
|
131
|
+
const regex = new RegExp(`from\\s+["']\\.[^"']*?\\/${fileName}["']`, "g");
|
|
132
|
+
content = content.replace(regex, `from "./${fileName}"`);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
fs.writeFileSync(filePath, content);
|
|
118
136
|
}
|
|
119
137
|
|
|
120
138
|
s.stop(
|
|
@@ -148,11 +166,14 @@ export const add = new Command()
|
|
|
148
166
|
}
|
|
149
167
|
|
|
150
168
|
// 7. Clean Success Outro
|
|
169
|
+
// Find the main file to import (prioritize the one that matches the component name or use the first one)
|
|
170
|
+
const mainFile = bundledFileNames.find((name: string) => name.toLowerCase() === componentName.toLowerCase()) || bundledFileNames[0];
|
|
171
|
+
|
|
151
172
|
outro(
|
|
152
173
|
`${pc.white("✔")} ${pc.bold(`Component <${componentName} /> is ready!`)}\n` +
|
|
153
174
|
pc.gray(`Import it: `) +
|
|
154
175
|
pc.cyan(
|
|
155
|
-
`import {
|
|
176
|
+
`import { ${mainFile} } from "@/${config.componentsPath}/${componentName}/${mainFile}"`
|
|
156
177
|
)
|
|
157
178
|
);
|
|
158
179
|
} catch (error: any) {
|