@srcroot/ui 0.0.34 → 0.0.36
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/index.js +75 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { Command } from "commander";
|
|
|
5
5
|
import chalk3 from "chalk";
|
|
6
6
|
|
|
7
7
|
// src/cli/services/project-initializer.ts
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import fs3 from "fs-extra";
|
|
9
|
+
import path3 from "path";
|
|
10
10
|
import ora from "ora";
|
|
11
11
|
import prompts from "prompts";
|
|
12
12
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -144,19 +144,19 @@ export default config
|
|
|
144
144
|
`;
|
|
145
145
|
|
|
146
146
|
// src/cli/utils/get-package-manager.ts
|
|
147
|
-
|
|
147
|
+
import fs2 from "fs";
|
|
148
|
+
import path2 from "path";
|
|
149
|
+
function getPackageManager(cwd) {
|
|
150
|
+
const dir = cwd || process.cwd();
|
|
151
|
+
if (fs2.existsSync(path2.join(dir, "bun.lockb"))) return "bun";
|
|
152
|
+
if (fs2.existsSync(path2.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
153
|
+
if (fs2.existsSync(path2.join(dir, "yarn.lock"))) return "yarn";
|
|
154
|
+
if (fs2.existsSync(path2.join(dir, "package-lock.json"))) return "npm";
|
|
148
155
|
const userAgent = process.env.npm_config_user_agent;
|
|
149
|
-
if (
|
|
150
|
-
return "
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return "yarn";
|
|
154
|
-
}
|
|
155
|
-
if (userAgent.startsWith("pnpm")) {
|
|
156
|
-
return "pnpm";
|
|
157
|
-
}
|
|
158
|
-
if (userAgent.startsWith("bun")) {
|
|
159
|
-
return "bun";
|
|
156
|
+
if (userAgent) {
|
|
157
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
158
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
159
|
+
if (userAgent.startsWith("bun")) return "bun";
|
|
160
160
|
}
|
|
161
161
|
return "npm";
|
|
162
162
|
}
|
|
@@ -179,7 +179,7 @@ var logger = {
|
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
// src/cli/services/project-initializer.ts
|
|
182
|
-
var __dirname3 =
|
|
182
|
+
var __dirname3 = path3.dirname(fileURLToPath2(import.meta.url));
|
|
183
183
|
var ProjectInitializer = class {
|
|
184
184
|
options;
|
|
185
185
|
config = {};
|
|
@@ -198,13 +198,13 @@ var ProjectInitializer = class {
|
|
|
198
198
|
this.printSuccess();
|
|
199
199
|
}
|
|
200
200
|
async validateEnvironment() {
|
|
201
|
-
const cwd =
|
|
202
|
-
const packageJsonPath =
|
|
203
|
-
if (!
|
|
201
|
+
const cwd = path3.resolve(this.options.cwd);
|
|
202
|
+
const packageJsonPath = path3.join(cwd, "package.json");
|
|
203
|
+
if (!fs3.existsSync(packageJsonPath)) {
|
|
204
204
|
logger.error("Error: No package.json found. Please run this in a project directory.");
|
|
205
205
|
process.exit(1);
|
|
206
206
|
}
|
|
207
|
-
const pkg = await
|
|
207
|
+
const pkg = await fs3.readJson(packageJsonPath);
|
|
208
208
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
209
209
|
if (!allDeps["react"]) {
|
|
210
210
|
logger.error("Error: React not found in dependencies. Please initialize this in a React project.");
|
|
@@ -212,33 +212,33 @@ var ProjectInitializer = class {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
async detectConfiguration() {
|
|
215
|
-
const cwd =
|
|
216
|
-
const packageManager = getPackageManager();
|
|
215
|
+
const cwd = path3.resolve(this.options.cwd);
|
|
216
|
+
const packageManager = getPackageManager(cwd);
|
|
217
217
|
const installCmd = packageManager === "npm" ? "install" : "add";
|
|
218
|
-
const pkg = await
|
|
218
|
+
const pkg = await fs3.readJson(path3.join(cwd, "package.json"));
|
|
219
219
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
220
220
|
const tailwindVersion = allDeps["tailwindcss"] || "";
|
|
221
221
|
const isTailwind4 = tailwindVersion.includes("^4") || tailwindVersion.startsWith("4") || allDeps["@tailwindcss/postcss"];
|
|
222
|
-
const hasSrc =
|
|
223
|
-
const srcPath = hasSrc ?
|
|
224
|
-
const appPath =
|
|
225
|
-
const pagesPath =
|
|
226
|
-
const hasAppDir =
|
|
227
|
-
const hasPagesDir =
|
|
228
|
-
const libDir =
|
|
229
|
-
const componentsDir =
|
|
222
|
+
const hasSrc = fs3.existsSync(path3.join(cwd, "src"));
|
|
223
|
+
const srcPath = hasSrc ? path3.join(cwd, "src") : cwd;
|
|
224
|
+
const appPath = path3.join(srcPath, "app");
|
|
225
|
+
const pagesPath = path3.join(srcPath, "pages");
|
|
226
|
+
const hasAppDir = fs3.existsSync(appPath);
|
|
227
|
+
const hasPagesDir = fs3.existsSync(pagesPath);
|
|
228
|
+
const libDir = path3.join(srcPath, "lib");
|
|
229
|
+
const componentsDir = path3.join(srcPath, "components", "ui");
|
|
230
230
|
let globalsPath = "";
|
|
231
231
|
if (hasAppDir) {
|
|
232
|
-
if (
|
|
233
|
-
else if (
|
|
234
|
-
else globalsPath =
|
|
232
|
+
if (fs3.existsSync(path3.join(appPath, "globals.css"))) globalsPath = path3.join(appPath, "globals.css");
|
|
233
|
+
else if (fs3.existsSync(path3.join(appPath, "global.css"))) globalsPath = path3.join(appPath, "global.css");
|
|
234
|
+
else globalsPath = path3.join(appPath, "globals.css");
|
|
235
235
|
} else if (hasPagesDir) {
|
|
236
|
-
const stylesPath =
|
|
237
|
-
if (
|
|
238
|
-
else if (
|
|
239
|
-
else globalsPath =
|
|
236
|
+
const stylesPath = path3.join(srcPath, "styles");
|
|
237
|
+
if (fs3.existsSync(path3.join(stylesPath, "globals.css"))) globalsPath = path3.join(stylesPath, "globals.css");
|
|
238
|
+
else if (fs3.existsSync(path3.join(stylesPath, "global.css"))) globalsPath = path3.join(stylesPath, "global.css");
|
|
239
|
+
else globalsPath = path3.join(stylesPath, "globals.css");
|
|
240
240
|
} else {
|
|
241
|
-
globalsPath =
|
|
241
|
+
globalsPath = path3.join(srcPath, "globals.css");
|
|
242
242
|
}
|
|
243
243
|
this.config = {
|
|
244
244
|
cwd,
|
|
@@ -266,7 +266,7 @@ var ProjectInitializer = class {
|
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
const themeChoices = availableThemes.map((theme) => ({
|
|
269
|
-
title:
|
|
269
|
+
title: theme.name,
|
|
270
270
|
value: theme.file.replace(".css", "")
|
|
271
271
|
}));
|
|
272
272
|
const themeResponse = await prompts({
|
|
@@ -286,13 +286,13 @@ var ProjectInitializer = class {
|
|
|
286
286
|
const spinner = ora("Creating project structure...").start();
|
|
287
287
|
const cfg = this.config;
|
|
288
288
|
try {
|
|
289
|
-
await
|
|
290
|
-
await
|
|
291
|
-
const utilsPath =
|
|
292
|
-
const registryUtilsPath =
|
|
289
|
+
await fs3.ensureDir(cfg.libDir);
|
|
290
|
+
await fs3.ensureDir(cfg.componentsDir);
|
|
291
|
+
const utilsPath = path3.join(cfg.libDir, "utils.ts");
|
|
292
|
+
const registryUtilsPath = path3.resolve(__dirname3, "..", "src", "registry", "lib", "utils.ts");
|
|
293
293
|
let utilsContent = "";
|
|
294
|
-
if (
|
|
295
|
-
utilsContent = await
|
|
294
|
+
if (fs3.existsSync(registryUtilsPath)) {
|
|
295
|
+
utilsContent = await fs3.readFile(registryUtilsPath, "utf-8");
|
|
296
296
|
} else {
|
|
297
297
|
utilsContent = `import { type ClassValue, clsx } from "clsx"
|
|
298
298
|
import { twMerge } from "tailwind-merge"
|
|
@@ -303,15 +303,15 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
303
303
|
`;
|
|
304
304
|
spinner.warn(`Could not find registry/utils.ts, using fallback content.`);
|
|
305
305
|
}
|
|
306
|
-
await
|
|
307
|
-
spinner.succeed(`Created ${
|
|
306
|
+
await fs3.writeFile(utilsPath, utilsContent);
|
|
307
|
+
spinner.succeed(`Created ${path3.relative(cfg.cwd, utilsPath)}`);
|
|
308
308
|
spinner.start(`Setting up ${cfg.selectedTheme} theme...`);
|
|
309
|
-
const stylesDir =
|
|
310
|
-
await
|
|
309
|
+
const stylesDir = path3.dirname(cfg.globalsPath);
|
|
310
|
+
await fs3.ensureDir(stylesDir);
|
|
311
311
|
try {
|
|
312
312
|
const cssContent = await this.themeService.getThemeCss(cfg.selectedTheme, cfg.isTailwind4);
|
|
313
|
-
await
|
|
314
|
-
spinner.succeed(`Updated ${
|
|
313
|
+
await fs3.writeFile(cfg.globalsPath, cssContent);
|
|
314
|
+
spinner.succeed(`Updated ${path3.relative(cfg.cwd, cfg.globalsPath)} with ${cfg.selectedTheme} theme (${cfg.isTailwind4 ? "Tailwind 4" : "Tailwind 3"})`);
|
|
315
315
|
} catch (error) {
|
|
316
316
|
spinner.fail(`Failed to load theme: ${cfg.selectedTheme}`);
|
|
317
317
|
console.error(error);
|
|
@@ -319,11 +319,9 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
319
319
|
}
|
|
320
320
|
if (!cfg.isTailwind4) {
|
|
321
321
|
spinner.start("Setting up Tailwind config...");
|
|
322
|
-
const tailwindConfigPath =
|
|
323
|
-
await
|
|
322
|
+
const tailwindConfigPath = path3.join(cfg.cwd, "tailwind.config.ts");
|
|
323
|
+
await fs3.writeFile(tailwindConfigPath, TAILWIND_CONFIG);
|
|
324
324
|
spinner.succeed(`Created tailwind.config.ts`);
|
|
325
|
-
} else {
|
|
326
|
-
spinner.info(`Tailwind 4 detected - skipping tailwind.config.ts`);
|
|
327
325
|
}
|
|
328
326
|
} catch (error) {
|
|
329
327
|
spinner.fail("Failed to initialize project");
|
|
@@ -374,8 +372,8 @@ async function init(options) {
|
|
|
374
372
|
}
|
|
375
373
|
|
|
376
374
|
// src/cli/commands/add.ts
|
|
377
|
-
import
|
|
378
|
-
import
|
|
375
|
+
import fs4 from "fs-extra";
|
|
376
|
+
import path4 from "path";
|
|
379
377
|
import ora2 from "ora";
|
|
380
378
|
import prompts2 from "prompts";
|
|
381
379
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
@@ -760,9 +758,9 @@ var REGISTRY = {
|
|
|
760
758
|
};
|
|
761
759
|
|
|
762
760
|
// src/cli/commands/add.ts
|
|
763
|
-
var __dirname4 =
|
|
761
|
+
var __dirname4 = path4.dirname(fileURLToPath3(import.meta.url));
|
|
764
762
|
async function add(components, options) {
|
|
765
|
-
const cwd =
|
|
763
|
+
const cwd = path4.resolve(options.cwd);
|
|
766
764
|
if (options.all) {
|
|
767
765
|
components = Object.keys(REGISTRY);
|
|
768
766
|
}
|
|
@@ -825,16 +823,16 @@ async function add(components, options) {
|
|
|
825
823
|
}
|
|
826
824
|
console.log();
|
|
827
825
|
const spinner = ora2("Adding components...").start();
|
|
828
|
-
const hasSrc =
|
|
829
|
-
const srcPath = hasSrc ?
|
|
830
|
-
const componentsDir =
|
|
826
|
+
const hasSrc = fs4.existsSync(path4.join(cwd, "src"));
|
|
827
|
+
const srcPath = hasSrc ? path4.join(cwd, "src") : cwd;
|
|
828
|
+
const componentsDir = path4.join(srcPath, "components", "ui");
|
|
831
829
|
try {
|
|
832
|
-
await
|
|
830
|
+
await fs4.ensureDir(componentsDir);
|
|
833
831
|
for (const name of componentsToAdd) {
|
|
834
832
|
const comp = REGISTRY[name];
|
|
835
|
-
const fileName =
|
|
836
|
-
const targetPath =
|
|
837
|
-
if (
|
|
833
|
+
const fileName = path4.basename(comp.file);
|
|
834
|
+
const targetPath = path4.join(componentsDir, fileName);
|
|
835
|
+
if (fs4.existsSync(targetPath) && !options.overwrite) {
|
|
838
836
|
spinner.stop();
|
|
839
837
|
const { overwrite } = await prompts2({
|
|
840
838
|
type: "confirm",
|
|
@@ -849,13 +847,13 @@ async function add(components, options) {
|
|
|
849
847
|
}
|
|
850
848
|
spinner.start("Adding components...");
|
|
851
849
|
}
|
|
852
|
-
const registryPath =
|
|
853
|
-
if (!
|
|
850
|
+
const registryPath = path4.resolve(__dirname4, "..", "src", "registry", comp.file);
|
|
851
|
+
if (!fs4.existsSync(registryPath)) {
|
|
854
852
|
spinner.warn(`Registry file not found for ${name}: ${registryPath}`);
|
|
855
853
|
continue;
|
|
856
854
|
}
|
|
857
|
-
const content = await
|
|
858
|
-
await
|
|
855
|
+
const content = await fs4.readFile(registryPath, "utf-8");
|
|
856
|
+
await fs4.writeFile(targetPath, content);
|
|
859
857
|
if (componentsToAdd.length > 10) {
|
|
860
858
|
spinner.text = `Adding ${fileName}...`;
|
|
861
859
|
} else {
|
|
@@ -905,19 +903,19 @@ async function list() {
|
|
|
905
903
|
}
|
|
906
904
|
|
|
907
905
|
// src/cli/utils/get-package-info.ts
|
|
908
|
-
import
|
|
909
|
-
import
|
|
906
|
+
import path5 from "path";
|
|
907
|
+
import fs5 from "fs-extra";
|
|
910
908
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
911
909
|
function getPackageInfo() {
|
|
912
910
|
const __filename2 = fileURLToPath4(import.meta.url);
|
|
913
|
-
const __dirname5 =
|
|
911
|
+
const __dirname5 = path5.dirname(__filename2);
|
|
914
912
|
const pathsToCheck = [
|
|
915
|
-
|
|
916
|
-
|
|
913
|
+
path5.resolve(__dirname5, "..", "package.json"),
|
|
914
|
+
path5.resolve(__dirname5, "..", "..", "..", "package.json")
|
|
917
915
|
];
|
|
918
916
|
for (const pkgPath of pathsToCheck) {
|
|
919
|
-
if (
|
|
920
|
-
return
|
|
917
|
+
if (fs5.existsSync(pkgPath)) {
|
|
918
|
+
return fs5.readJSONSync(pkgPath);
|
|
921
919
|
}
|
|
922
920
|
}
|
|
923
921
|
return { version: "0.0.0" };
|