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.
Files changed (2) hide show
  1. package/cli/index.cjs +73 -79
  2. 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
- if (!fs.existsSync(templateFile)) {
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
- try {
148
- const templateDir = path.join(__dirname, "../src/notion-ui", component);
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
- // --- Step 1: Merge to utils ---
157
- const utilsDir = path.join(cwd, "src/utils");
158
- fs.ensureDirSync(utilsDir);
159
-
160
- let mergeSuccess = true;
161
-
162
- fs.readdirSync(templateDir).forEach((file) => {
163
- const filePath = path.join(templateDir, file);
164
- const content = fs.readFileSync(filePath, "utf-8").trim();
165
-
166
- try {
167
- let targetPath;
168
- if (file.endsWith("-data.ts"))
169
- targetPath = path.join(utilsDir, "dt.ts");
170
- else if (file === "type.ts")
171
- targetPath = path.join(utilsDir, "type.ts");
172
- else if (file.startsWith("use-") && file.endsWith(".ts"))
173
- targetPath = path.join(utilsDir, "hook.ts");
174
- else return; // skip other files
175
-
176
- let targetContent = "";
177
- if (fs.existsSync(targetPath))
178
- targetContent = fs.readFileSync(targetPath, "utf-8");
179
-
180
- // Append only if content not already in the target file
181
- if (!targetContent.includes(content)) {
182
- if (targetContent.length > 0) targetContent += "\n\n";
183
- targetContent += content;
184
- fs.writeFileSync(targetPath, targetContent);
185
- console.log(
186
- chalk.green(
187
- `✓ Merged ${file} → ${path.relative(cwd, targetPath)}`
188
- )
189
- );
190
- } else {
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
- if (!mergeSuccess) {
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
- // --- Step 2: Copy component files ---
216
- fs.copySync(templateDir, destDir, {
217
- filter: (src) => {
218
- const filename = path.basename(src);
219
- if (filename === "index.ts") return false;
220
- if (filename.endsWith(".stories.tsx")) return false;
221
- return true;
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
  /* ------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notionsoft-ui",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
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"