notionsoft-ui 1.0.25 → 1.0.27
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 +52 -63
- package/package.json +1 -1
package/cli/index.cjs
CHANGED
|
@@ -129,8 +129,6 @@ program
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
const config = fs.readJSONSync(configFile);
|
|
132
|
-
|
|
133
|
-
// Make sure templateDir is defined here
|
|
134
132
|
const templateDir = path.join(__dirname, "../src/notion-ui", component);
|
|
135
133
|
|
|
136
134
|
if (!fs.existsSync(templateDir)) {
|
|
@@ -138,82 +136,73 @@ program
|
|
|
138
136
|
return;
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
);
|
|
187
|
-
}
|
|
188
|
-
} catch (err) {
|
|
189
|
-
mergeSuccess = false;
|
|
190
|
-
console.log(chalk.red(`❌ Failed merging ${file}: ${err.message}`));
|
|
139
|
+
// Utility function to append content if not exists
|
|
140
|
+
const appendIfNotExist = (srcFile, destFile) => {
|
|
141
|
+
const srcContent = fs.readFileSync(srcFile, "utf-8");
|
|
142
|
+
|
|
143
|
+
if (fs.existsSync(destFile)) {
|
|
144
|
+
const destContent = fs.readFileSync(destFile, "utf-8");
|
|
145
|
+
const newLines = srcContent
|
|
146
|
+
.split("\n")
|
|
147
|
+
.filter((line) => !destContent.includes(line))
|
|
148
|
+
.join("\n");
|
|
149
|
+
if (newLines.trim()) fs.appendFileSync(destFile, "\n" + newLines);
|
|
150
|
+
} else {
|
|
151
|
+
fs.writeFileSync(destFile, srcContent);
|
|
191
152
|
}
|
|
192
|
-
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Handle type.ts → src/utils/type.ts
|
|
156
|
+
const typeFile = path.join(templateDir, "type.ts");
|
|
157
|
+
if (fs.existsSync(typeFile)) {
|
|
158
|
+
const destTypeFile = path.join(cwd, "src/utils/type.ts");
|
|
159
|
+
appendIfNotExist(typeFile, destTypeFile);
|
|
160
|
+
console.log(chalk.green("✓ type.ts merged to src/utils/type.ts"));
|
|
161
|
+
}
|
|
193
162
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
|
|
163
|
+
// Handle *-data.ts → src/utils/dt.ts
|
|
164
|
+
fs.readdirSync(templateDir)
|
|
165
|
+
.filter((f) => f.endsWith("-data.ts"))
|
|
166
|
+
.forEach((dataFile) => {
|
|
167
|
+
const srcDataFile = path.join(templateDir, dataFile);
|
|
168
|
+
const destDataFile = path.join(cwd, "src/utils/dt.ts");
|
|
169
|
+
appendIfNotExist(srcDataFile, destDataFile);
|
|
170
|
+
console.log(chalk.green(`✓ ${dataFile} merged to src/utils/dt.ts`));
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Handle use-*.ts → src/utils/hook.ts
|
|
174
|
+
fs.readdirSync(templateDir)
|
|
175
|
+
.filter((f) => f.startsWith("use-") && f.endsWith(".ts"))
|
|
176
|
+
.forEach((hookFile) => {
|
|
177
|
+
const srcHookFile = path.join(templateDir, hookFile);
|
|
178
|
+
const destHookFile = path.join(cwd, "src/utils/hook.ts");
|
|
179
|
+
appendIfNotExist(srcHookFile, destHookFile);
|
|
180
|
+
console.log(chalk.green(`✓ ${hookFile} merged to src/utils/hook.ts`));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Handle utils.ts → src/utils/helper.ts
|
|
184
|
+
const utilsFile = path.join(templateDir, "utils.ts");
|
|
185
|
+
if (fs.existsSync(utilsFile)) {
|
|
186
|
+
const destUtilsFile = path.join(cwd, "src/utils/helper.ts");
|
|
187
|
+
appendIfNotExist(utilsFile, destUtilsFile);
|
|
188
|
+
console.log(chalk.green("✓ utils.ts merged to src/utils/helper.ts"));
|
|
201
189
|
}
|
|
202
190
|
|
|
203
|
-
//
|
|
204
|
-
fs.ensureDirSync(config.componentDir);
|
|
191
|
+
// Copy remaining files (exclude index.ts, *.stories.tsx, type.ts, *-data.ts, use-*.ts, utils.ts)
|
|
205
192
|
fs.readdirSync(templateDir).forEach((file) => {
|
|
206
193
|
if (
|
|
207
194
|
file === "index.ts" ||
|
|
208
195
|
file === "type.ts" ||
|
|
209
196
|
file.endsWith("-data.ts") ||
|
|
210
197
|
file.endsWith(".stories.tsx") ||
|
|
211
|
-
(file.startsWith("use-") && file.endsWith(".ts"))
|
|
198
|
+
(file.startsWith("use-") && file.endsWith(".ts")) ||
|
|
199
|
+
file === "utils.ts"
|
|
212
200
|
)
|
|
213
201
|
return;
|
|
214
202
|
|
|
215
203
|
const srcFile = path.join(templateDir, file);
|
|
216
204
|
const destFile = path.join(config.componentDir, file); // flat copy
|
|
205
|
+
fs.ensureDirSync(config.componentDir);
|
|
217
206
|
fs.copyFileSync(srcFile, destFile);
|
|
218
207
|
});
|
|
219
208
|
|