notionsoft-ui 1.0.23 → 1.0.25
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/cli/index.cjs +73 -79
- package/package.json +1 -1
package/cli/index.cjs
CHANGED
|
@@ -129,9 +129,11 @@ program
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const config = fs.readJSONSync(configFile);
|
|
132
|
-
const templateFile = getTemplateFile(component);
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
// Make sure templateDir is defined here
|
|
134
|
+
const templateDir = path.join(__dirname, "../src/notion-ui", component);
|
|
135
|
+
|
|
136
|
+
if (!fs.existsSync(templateDir)) {
|
|
135
137
|
console.log(chalk.red(`❌ Component '${component}' does not exist.`));
|
|
136
138
|
return;
|
|
137
139
|
}
|
|
@@ -144,88 +146,80 @@ program
|
|
|
144
146
|
// console.log(
|
|
145
147
|
// chalk.green(`✓ Installed ${component} component as ${destFile}`)
|
|
146
148
|
// );
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const destDir = path.join(config.componentDir, component);
|
|
150
|
-
|
|
151
|
-
if (!fs.existsSync(templateDir)) {
|
|
152
|
-
console.log(chalk.red(`❌ Component '${component}' does not exist.`));
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
149
|
+
const utilsDir = path.join(cwd, "src/utils");
|
|
150
|
+
fs.ensureDirSync(utilsDir);
|
|
155
151
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
console.log(
|
|
192
|
-
chalk.yellow(
|
|
193
|
-
`⚠ ${file} already exists in ${path.relative(
|
|
194
|
-
cwd,
|
|
195
|
-
targetPath
|
|
196
|
-
)}, skipping`
|
|
197
|
-
)
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
} catch (err) {
|
|
201
|
-
mergeSuccess = false;
|
|
202
|
-
console.log(chalk.red(`❌ Failed merging ${file}: ${err.message}`));
|
|
152
|
+
let mergeSuccess = true;
|
|
153
|
+
|
|
154
|
+
// --- Step 1: Merge utils ---
|
|
155
|
+
fs.readdirSync(templateDir).forEach((file) => {
|
|
156
|
+
const filePath = path.join(templateDir, file);
|
|
157
|
+
const content = fs.readFileSync(filePath, "utf-8").trim();
|
|
158
|
+
|
|
159
|
+
let targetPath;
|
|
160
|
+
if (file.endsWith("-data.ts")) targetPath = path.join(utilsDir, "dt.ts");
|
|
161
|
+
else if (file === "type.ts") targetPath = path.join(utilsDir, "type.ts");
|
|
162
|
+
else if (file.startsWith("use-") && file.endsWith(".ts"))
|
|
163
|
+
targetPath = path.join(utilsDir, "hook.ts");
|
|
164
|
+
else return; // skip other files
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
let targetContent = "";
|
|
168
|
+
if (fs.existsSync(targetPath))
|
|
169
|
+
targetContent = fs.readFileSync(targetPath, "utf-8");
|
|
170
|
+
|
|
171
|
+
if (!targetContent.includes(content)) {
|
|
172
|
+
if (targetContent.length > 0) targetContent += "\n\n";
|
|
173
|
+
targetContent += content;
|
|
174
|
+
fs.writeFileSync(targetPath, targetContent);
|
|
175
|
+
console.log(
|
|
176
|
+
chalk.green(`✓ Merged ${file} → ${path.relative(cwd, targetPath)}`)
|
|
177
|
+
);
|
|
178
|
+
} else {
|
|
179
|
+
console.log(
|
|
180
|
+
chalk.yellow(
|
|
181
|
+
`⚠ ${file} already exists in ${path.relative(
|
|
182
|
+
cwd,
|
|
183
|
+
targetPath
|
|
184
|
+
)}, skipping`
|
|
185
|
+
)
|
|
186
|
+
);
|
|
203
187
|
}
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
console.log(
|
|
208
|
-
chalk.red(
|
|
209
|
-
"❌ Failed to merge required files. Component installation aborted."
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
return;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
mergeSuccess = false;
|
|
190
|
+
console.log(chalk.red(`❌ Failed merging ${file}: ${err.message}`));
|
|
213
191
|
}
|
|
192
|
+
});
|
|
214
193
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
console.log(chalk.green(`✓ Installed ${component} to ${destDir}`));
|
|
226
|
-
} catch (err) {
|
|
227
|
-
console.log(chalk.red(`❌ Installation failed: ${err.message}`));
|
|
194
|
+
if (!mergeSuccess) {
|
|
195
|
+
console.log(
|
|
196
|
+
chalk.red(
|
|
197
|
+
"❌ Failed to merge required files. Component installation aborted."
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
return;
|
|
228
201
|
}
|
|
202
|
+
|
|
203
|
+
// --- Step 2: Copy remaining files flat into componentDir ---
|
|
204
|
+
fs.ensureDirSync(config.componentDir);
|
|
205
|
+
fs.readdirSync(templateDir).forEach((file) => {
|
|
206
|
+
if (
|
|
207
|
+
file === "index.ts" ||
|
|
208
|
+
file === "type.ts" ||
|
|
209
|
+
file.endsWith("-data.ts") ||
|
|
210
|
+
file.endsWith(".stories.tsx") ||
|
|
211
|
+
(file.startsWith("use-") && file.endsWith(".ts"))
|
|
212
|
+
)
|
|
213
|
+
return;
|
|
214
|
+
|
|
215
|
+
const srcFile = path.join(templateDir, file);
|
|
216
|
+
const destFile = path.join(config.componentDir, file); // flat copy
|
|
217
|
+
fs.copyFileSync(srcFile, destFile);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
console.log(
|
|
221
|
+
chalk.green(`✓ Installed ${component} to ${config.componentDir}`)
|
|
222
|
+
);
|
|
229
223
|
});
|
|
230
224
|
|
|
231
225
|
/* ------------------------------
|