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