notionsoft-ui 1.0.26 → 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.
Files changed (2) hide show
  1. package/cli/index.cjs +50 -62
  2. 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,70 +136,59 @@ program
138
136
  return;
139
137
  }
140
138
 
141
- // Copy as a flat file into user's project
142
- // const destFile = path.join(config.componentDir, component + ".tsx");
143
- // fs.ensureDirSync(config.componentDir);
144
- // fs.copyFileSync(templateFile, destFile);
145
-
146
- // console.log(
147
- // chalk.green(`✓ Installed ${component} component as ${destFile}`)
148
- // );
149
- const utilsDir = path.join(cwd, "src/utils");
150
- fs.ensureDirSync(utilsDir);
151
-
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
- );
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
- if (!mergeSuccess) {
195
- console.log(
196
- chalk.red(
197
- "❌ Failed to merge required files. Component installation aborted."
198
- )
199
- );
200
- return;
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
- // --- Step 2: Copy remaining files flat into componentDir ---
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" ||
@@ -215,6 +202,7 @@ program
215
202
 
216
203
  const srcFile = path.join(templateDir, file);
217
204
  const destFile = path.join(config.componentDir, file); // flat copy
205
+ fs.ensureDirSync(config.componentDir);
218
206
  fs.copyFileSync(srcFile, destFile);
219
207
  });
220
208
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notionsoft-ui",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A React UI component installer (shadcn-style). Installs components directly into your project.",
5
5
  "bin": {
6
6
  "notionsoft-ui": "./cli/index.cjs"