@codefast/cli 0.3.1-canary.11 ā 0.3.1-canary.13
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/CHANGELOG.md +24 -0
- package/dist/index.cjs +166 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +166 -144
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @codefast/cli
|
|
2
2
|
|
|
3
|
+
## 0.3.1-canary.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`cd28e81`](https://github.com/codefastlabs/codefast/commit/cd28e81b34be31b1c73abbdaabe47e27952bd5df) Thanks [@thevuong](https://github.com/thevuong)! - feat: add eslint-import-resolver-typescript dependency and format import rules
|
|
8
|
+
|
|
9
|
+
- [`1990579`](https://github.com/codefastlabs/codefast/commit/19905793ee89b2223402592c753e35e81ed46182) Thanks [@thevuong](https://github.com/thevuong)! - chore(deps): update package dependencies
|
|
10
|
+
|
|
11
|
+
- [`40d05e8`](https://github.com/codefastlabs/codefast/commit/40d05e8b33a0189ce4f7d942e18b6f43daa18756) Thanks [@thevuong](https://github.com/thevuong)! - refactor(cli): simplify command registration and improve import statements
|
|
12
|
+
|
|
13
|
+
- [`952e0a3`](https://github.com/codefastlabs/codefast/commit/952e0a349defcda5c62409c39b751ebd30e78c52) Thanks [@thevuong](https://github.com/thevuong)! - feat(cli): add type-checking script to generated projects
|
|
14
|
+
|
|
15
|
+
## 0.3.1-canary.12
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`0841266`](https://github.com/codefastlabs/codefast/commit/0841266536570b017099fd32b6f0b732cc562932) Thanks [@thevuong](https://github.com/thevuong)! - fix(cli): remove redundant default action from CLI
|
|
20
|
+
|
|
21
|
+
- [`5d33972`](https://github.com/codefastlabs/codefast/commit/5d339720048479b37ce3ded253d5182364df6762) Thanks [@thevuong](https://github.com/thevuong)! - refactor(cli): update styles and constants for project creation
|
|
22
|
+
|
|
23
|
+
- [`109a2a5`](https://github.com/codefastlabs/codefast/commit/109a2a5cf4a205d4c5ceb5c3ac7afa95ca69a51d) Thanks [@thevuong](https://github.com/thevuong)! - feat(cli): improve ReactNode handling and RootLayout typings
|
|
24
|
+
|
|
25
|
+
- [`e873ddc`](https://github.com/codefastlabs/codefast/commit/e873ddcdabb110655e39aa7a69a0850c9050186e) Thanks [@thevuong](https://github.com/thevuong)! - refactor(cli): centralize file operations and error handling
|
|
26
|
+
|
|
3
27
|
## 0.3.1-canary.11
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -49,9 +49,38 @@ function runCommand(command) {
|
|
|
49
49
|
stdio: "inherit"
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const FileUtils = {
|
|
53
|
+
exists (filePath) {
|
|
54
|
+
return external_node_fs_default().existsSync(filePath);
|
|
55
|
+
},
|
|
56
|
+
readFile (filePath) {
|
|
57
|
+
try {
|
|
58
|
+
return external_node_fs_default().readFileSync(filePath, "utf8");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error(`Failed to read file ${filePath}: ${getErrorMessage(error)}`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
writeFile (filePath, content) {
|
|
64
|
+
try {
|
|
65
|
+
external_node_fs_default().writeFileSync(filePath, content);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Failed to write to file ${filePath}: ${getErrorMessage(error)}`);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
writeConfigFile (filePath, content) {
|
|
71
|
+
external_node_fs_default().writeFileSync(filePath, content);
|
|
72
|
+
console.log(`š Created ${filePath}`);
|
|
73
|
+
},
|
|
74
|
+
validatePath (filePath, filename) {
|
|
75
|
+
if (!this.exists(filePath)) {
|
|
76
|
+
console.warn(`ā ļø ${filename} not found, skipping update.`);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function getErrorMessage(error) {
|
|
83
|
+
return error instanceof Error ? error.message : "Unknown error occurred";
|
|
55
84
|
}
|
|
56
85
|
function validateProjectName(name) {
|
|
57
86
|
if (!name || /^\s*$/.test(name)) return {
|
|
@@ -290,7 +319,6 @@ yarn-error.log*
|
|
|
290
319
|
package-lock.json
|
|
291
320
|
yarn.lock
|
|
292
321
|
pnpm-lock.yaml
|
|
293
|
-
src/app/globals.css
|
|
294
322
|
`,
|
|
295
323
|
description: ""
|
|
296
324
|
}
|
|
@@ -316,6 +344,7 @@ export default config;
|
|
|
316
344
|
{
|
|
317
345
|
path: "eslint.config.mjs",
|
|
318
346
|
content: `import { config } from "@codefast/eslint-config/next";
|
|
347
|
+
|
|
319
348
|
/**
|
|
320
349
|
* @see https://eslint.org/docs/latest/use/configure/configuration-files
|
|
321
350
|
* @type {import('eslint').Linter.Config[]}
|
|
@@ -390,6 +419,7 @@ export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
|
390
419
|
:root {
|
|
391
420
|
--font-sans: var(--font-geist-sans);
|
|
392
421
|
--font-mono: var(--font-geist-mono);
|
|
422
|
+
|
|
393
423
|
--input: var(--color-neutral-200);
|
|
394
424
|
--border: var(--color-neutral-200);
|
|
395
425
|
--ring: var(--color-neutral-400);
|
|
@@ -423,6 +453,7 @@ export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
|
423
453
|
--chart-4: var(--color-amber-600);
|
|
424
454
|
--chart-5: var(--color-amber-500);
|
|
425
455
|
}
|
|
456
|
+
|
|
426
457
|
.dark {
|
|
427
458
|
--input: var(--color-neutral-700);
|
|
428
459
|
--border: --alpha(var(--color-neutral-700) / 50%);
|
|
@@ -463,87 +494,87 @@ export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
|
463
494
|
}
|
|
464
495
|
]
|
|
465
496
|
};
|
|
497
|
+
function updateFileIfNeeded(filePath, filename, checkFn, updateFn, successMessage, alreadyUpdatedMessage) {
|
|
498
|
+
if (!FileUtils.validatePath(filePath, filename)) return;
|
|
499
|
+
const content = FileUtils.readFile(filePath);
|
|
500
|
+
if (checkFn(content)) return void console.log(`š ${alreadyUpdatedMessage}`);
|
|
501
|
+
try {
|
|
502
|
+
const updatedContent = updateFn(content);
|
|
503
|
+
FileUtils.writeFile(filePath, updatedContent);
|
|
504
|
+
console.log(`š ${successMessage}`);
|
|
505
|
+
} catch (error) {
|
|
506
|
+
console.warn(`ā ļø Failed to update ${filename}: ${getErrorMessage(error)}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
466
509
|
function updatePostcssConfig(projectDir) {
|
|
467
510
|
const postcssConfigPath = external_node_path_default().join(projectDir, "postcss.config.mjs");
|
|
468
|
-
if (!external_node_fs_default().existsSync(postcssConfigPath)) return void console.warn(`ā ļø postcss.config.mjs not found, skipping update.`);
|
|
469
|
-
let content = external_node_fs_default().readFileSync(postcssConfigPath, "utf8");
|
|
470
511
|
const typeComment = `/** @type {import('postcss-load-config').Config} */\n`;
|
|
471
|
-
|
|
472
|
-
else {
|
|
473
|
-
content = content.replace("const config = {", `${typeComment}const config = {`);
|
|
474
|
-
external_node_fs_default().writeFileSync(postcssConfigPath, content);
|
|
475
|
-
console.log(`š Updated postcss.config.mjs with type comment.`);
|
|
476
|
-
}
|
|
512
|
+
updateFileIfNeeded(postcssConfigPath, "postcss.config.mjs", (content)=>content.includes(typeComment), (content)=>content.replace("const config = {", `${typeComment}const config = {`), "Updated postcss.config.mjs with type comment.", "postcss.config.mjs already contains type comment, no changes made.");
|
|
477
513
|
}
|
|
478
514
|
function updateLayoutFile(projectDir) {
|
|
479
515
|
const layoutPath = external_node_path_default().join(projectDir, "src/app/layout.tsx");
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
516
|
+
const htmlTarget = '<html className={cn(fontVariables, "antialiased")} lang="en">';
|
|
517
|
+
updateFileIfNeeded(layoutPath, "src/app/layout.tsx", (content)=>content.includes(htmlTarget), (content)=>{
|
|
518
|
+
const newImports = `import type { Metadata } from "next";
|
|
519
|
+
import type { JSX, ReactNode } from "react";
|
|
485
520
|
import { cn } from "@codefast/ui";
|
|
486
|
-
|
|
487
521
|
import { fontVariables } from "@/lib/fonts";
|
|
488
522
|
import "@/app/globals.css";`;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
try {
|
|
499
|
-
external_node_fs_default().writeFileSync(layoutPath, content);
|
|
500
|
-
console.log(`š Updated src/app/layout.tsx to use fontVariables in html tag and removed className from body`);
|
|
501
|
-
} catch (error) {
|
|
502
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
503
|
-
console.warn(`ā ļø Failed to update src/app/layout.tsx: ${errorMessage}`);
|
|
504
|
-
}
|
|
523
|
+
let result = content;
|
|
524
|
+
result = result.replaceAll(/import\s+{[^}]+}\s+from\s+["']next\/font\/google["'];\s*/g, "");
|
|
525
|
+
result = result.replace(/const\s+geistSans\s*=[^;]+;\s*const\s+geistMono\s*=[^;]+;\s*/, "");
|
|
526
|
+
result = result.replace(/import\s+type\s+{[^}]+}\s+from\s+["']next["'];\s*import\s+["']\.\/globals\.css["'];\s*/, newImports);
|
|
527
|
+
result = result.replace(/export default function RootLayout\({\s*children,\s*}\s*:\s*Readonly<{\s*children:\s*React\.ReactNode;\s*}>\)\s*{/, "export default function RootLayout({ children }: Readonly<{ children: ReactNode }>): JSX.Element {");
|
|
528
|
+
result = result.replace(/<html\s+lang="en"\s*>/, htmlTarget);
|
|
529
|
+
result = result.replace(/<body\s+className={`[^`]*`}\s*>/, "<body>");
|
|
530
|
+
return result;
|
|
531
|
+
}, "Updated src/app/layout.tsx to use fontVariables in html tag, removed className from body, modified ReactNode import, and added return type to RootLayout", "src/app/layout.tsx already uses fontVariables in html tag, no changes made.");
|
|
505
532
|
}
|
|
506
533
|
function updatePackageJson(projectDir) {
|
|
507
534
|
const packageJsonPath = external_node_path_default().join(projectDir, "package.json");
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
535
|
+
if (!FileUtils.validatePath(packageJsonPath, "package.json")) return;
|
|
536
|
+
try {
|
|
537
|
+
const packageJson = JSON.parse(FileUtils.readFile(packageJsonPath));
|
|
538
|
+
packageJson.scripts = {
|
|
539
|
+
...packageJson.scripts,
|
|
540
|
+
"check-types": "tsc --noEmit",
|
|
541
|
+
"deploy:preview": "vercel deploy --archive=tgz",
|
|
542
|
+
"deploy:prod": "vercel deploy --archive=tgz --prod",
|
|
543
|
+
format: "prettier --write --ignore-unknown .",
|
|
544
|
+
"format:check": "prettier --check --ignore-unknown .",
|
|
545
|
+
lint: "next lint --fix --max-warnings 0",
|
|
546
|
+
"lint:check": "next lint --max-warnings 0",
|
|
547
|
+
"package:install": "pnpm install",
|
|
548
|
+
"package:outdated": "pnpm outdated",
|
|
549
|
+
"package:upgrade": "pnpm update --latest",
|
|
550
|
+
preview: "pnpm build && pnpm start"
|
|
551
|
+
};
|
|
552
|
+
packageJson["simple-git-hooks"] = {
|
|
553
|
+
"pre-commit": "pnpm lint-staged",
|
|
554
|
+
"commit-msg": "pnpm commitlint --edit"
|
|
555
|
+
};
|
|
556
|
+
FileUtils.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
557
|
+
console.log(`š Updated package.json`);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
console.warn(`ā ļø Failed to update package.json: ${getErrorMessage(error)}`);
|
|
560
|
+
}
|
|
528
561
|
}
|
|
529
562
|
function updateNextConfig(projectDir) {
|
|
530
563
|
const nextConfigPath = external_node_path_default().join(projectDir, "next.config.ts");
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (content.includes('optimizePackageImports: ["@codefast/ui"]')) return void console.log(`š next.config.ts already contains optimizePackageImports configuration, no changes made.`);
|
|
534
|
-
const configPattern = /const nextConfig: NextConfig = \{/;
|
|
535
|
-
const experimentalConfig = `const nextConfig: NextConfig = {
|
|
564
|
+
const optimizePackagesConfig = 'optimizePackageImports: ["@codefast/ui"]';
|
|
565
|
+
updateFileIfNeeded(nextConfigPath, "next.config.ts", (content)=>content.includes(optimizePackagesConfig), (content)=>content.replace(/const nextConfig: NextConfig = \{/, `const nextConfig: NextConfig = {
|
|
536
566
|
experimental: {
|
|
537
567
|
optimizePackageImports: ["@codefast/ui"],
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
568
|
+
},`), "Updated next.config.ts with optimizePackageImports configuration.", "next.config.ts already contains optimizePackageImports configuration, no changes made.");
|
|
569
|
+
}
|
|
570
|
+
function updatePageFile(projectDir) {
|
|
571
|
+
const pagePath = external_node_path_default().join(projectDir, "src/app/page.tsx");
|
|
572
|
+
updateFileIfNeeded(pagePath, "src/app/page.tsx", (content)=>content.includes("): JSX.Element"), (content)=>{
|
|
573
|
+
let result = content;
|
|
574
|
+
if (!result.includes("import type { JSX }")) result = result.includes("import type {") ? result.replace(/import type {(?<types>[^}]+)} from "react";/, 'import type {$1, JSX } from "react";') : result.includes("import {") ? result.replace(/import {/, 'import type { JSX } from "react";\n\nimport {') : `import type { JSX } from "react";\n\n${result}`;
|
|
575
|
+
result = result.replace(/export default function Home\(\) {/, "export default function Home(): JSX.Element {");
|
|
576
|
+
return result;
|
|
577
|
+
}, "Updated src/app/page.tsx to add JSX.Element return type to Home component", "src/app/page.tsx already has JSX.Element return type, no changes made.");
|
|
547
578
|
}
|
|
548
579
|
function createConfigFiles(projectDir) {
|
|
549
580
|
console.log(`\nš Creating configuration files...`);
|
|
@@ -552,10 +583,10 @@ function createConfigFiles(projectDir) {
|
|
|
552
583
|
for (const { path: filePath, content, description } of configs){
|
|
553
584
|
const fullPath = external_node_path_default().join(projectDir, filePath);
|
|
554
585
|
const dir = external_node_path_default().dirname(fullPath);
|
|
555
|
-
if (!
|
|
586
|
+
if (!FileUtils.exists(dir)) external_node_fs_default().mkdirSync(dir, {
|
|
556
587
|
recursive: true
|
|
557
588
|
});
|
|
558
|
-
writeConfigFile(fullPath, content);
|
|
589
|
+
FileUtils.writeConfigFile(fullPath, content);
|
|
559
590
|
if (description) console.log(` ā¹ļø ${filePath}: ${description}`);
|
|
560
591
|
}
|
|
561
592
|
}
|
|
@@ -574,8 +605,7 @@ function cleanupPackages() {
|
|
|
574
605
|
try {
|
|
575
606
|
packageJson = JSON.parse(external_node_fs_namespaceObject.readFileSync(packageJsonPath, "utf8"));
|
|
576
607
|
} catch (error) {
|
|
577
|
-
|
|
578
|
-
console.warn(`ā ļø Error reading package.json: ${errorMessage}, skipping cleanup.`);
|
|
608
|
+
console.warn(`ā ļø Error reading package.json: ${getErrorMessage(error)}, skipping cleanup.`);
|
|
579
609
|
return;
|
|
580
610
|
}
|
|
581
611
|
const dependencies = packageJson.dependencies ?? {};
|
|
@@ -599,46 +629,47 @@ function createNextProject(projectName) {
|
|
|
599
629
|
const flags = '--ts --tailwind --eslint --app --turbo --use-pnpm --src-dir --turbopack --import-alias "@/*"';
|
|
600
630
|
runCommand(`npx create-next-app@latest ${projectName} ${flags}`);
|
|
601
631
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
console.log(`š Moved to ${projectName}`);
|
|
612
|
-
}
|
|
613
|
-
updateLayoutFile(process.cwd());
|
|
614
|
-
updatePostcssConfig(process.cwd());
|
|
615
|
-
installDependencies();
|
|
616
|
-
cleanupPackages();
|
|
617
|
-
createConfigFiles(process.cwd());
|
|
618
|
-
updateNextConfig(process.cwd());
|
|
619
|
-
updatePackageJson(process.cwd());
|
|
620
|
-
console.log(`\nš Activating git hooks...`);
|
|
621
|
-
runCommand("pnpm simple-git-hooks");
|
|
622
|
-
console.log(`\nš Formatting files with Prettier...`);
|
|
623
|
-
runCommand("pnpm format");
|
|
624
|
-
console.log(`\nā
Project ${packageJsonExists ? "configured" : "created"} successfully!`);
|
|
625
|
-
console.log(`- Project: ${projectName}`);
|
|
626
|
-
console.log("- Next.js with TypeScript");
|
|
627
|
-
console.log("- TailwindCSS and @codefast/ui");
|
|
628
|
-
console.log("- ESLint, Prettier, Commitlint, and Git Hooks");
|
|
629
|
-
console.log("- Lint-staged for pre-commit checks");
|
|
630
|
-
console.log(`\nš Project directory: ${process.cwd()}`);
|
|
631
|
-
console.log(`\nš To start development:`);
|
|
632
|
-
console.log(`cd ${projectName} && pnpm dev`);
|
|
633
|
-
} catch (error) {
|
|
634
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
635
|
-
console.error(`\nā An error occurred: ${errorMessage}`);
|
|
636
|
-
process.exit(1);
|
|
637
|
-
} finally{
|
|
638
|
-
rl.close();
|
|
632
|
+
const createProjectCommand = new external_commander_namespaceObject.Command().name("create-project [name]").description("Create a new Next.js project with recommended setup").action(async (projectNameArg)=>{
|
|
633
|
+
try {
|
|
634
|
+
checkEnvironment();
|
|
635
|
+
const { projectName, packageJsonExists } = await checkExistingProject(projectNameArg);
|
|
636
|
+
if (!packageJsonExists) {
|
|
637
|
+
console.log(`\nš Starting project creation for ${projectName}...\n`);
|
|
638
|
+
createNextProject(projectName);
|
|
639
|
+
process.chdir(projectName);
|
|
640
|
+
console.log(`š Moved to ${projectName}`);
|
|
639
641
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
+
updateLayoutFile(process.cwd());
|
|
643
|
+
updatePageFile(process.cwd());
|
|
644
|
+
updatePostcssConfig(process.cwd());
|
|
645
|
+
installDependencies();
|
|
646
|
+
cleanupPackages();
|
|
647
|
+
createConfigFiles(process.cwd());
|
|
648
|
+
updateNextConfig(process.cwd());
|
|
649
|
+
updatePackageJson(process.cwd());
|
|
650
|
+
console.log(`\nš Activating git hooks...`);
|
|
651
|
+
runCommand("pnpm simple-git-hooks");
|
|
652
|
+
console.log(`\nš Formatting files with Prettier...`);
|
|
653
|
+
runCommand("pnpm format");
|
|
654
|
+
console.log(`\nš Running ESLint to check code style...`);
|
|
655
|
+
runCommand("pnpm lint");
|
|
656
|
+
console.log(`\nā
Project ${packageJsonExists ? "configured" : "created"} successfully!`);
|
|
657
|
+
console.log(`- Project: ${projectName}`);
|
|
658
|
+
console.log("- Next.js with TypeScript");
|
|
659
|
+
console.log("- TailwindCSS and @codefast/ui");
|
|
660
|
+
console.log("- ESLint, Prettier, Commitlint, and Git Hooks");
|
|
661
|
+
console.log("- Lint-staged for pre-commit checks");
|
|
662
|
+
console.log(`\nš Project directory: ${process.cwd()}`);
|
|
663
|
+
console.log(`\nš To start development:`);
|
|
664
|
+
console.log(`cd ${projectName} && pnpm dev`);
|
|
665
|
+
} catch (error) {
|
|
666
|
+
console.error(`\nā An error occurred: ${getErrorMessage(error)}`);
|
|
667
|
+
process.exit(1);
|
|
668
|
+
} finally{
|
|
669
|
+
rl.close();
|
|
670
|
+
process.exit(0);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
642
673
|
const external_glob_namespaceObject = require("glob");
|
|
643
674
|
const external_ts_morph_namespaceObject = require("ts-morph");
|
|
644
675
|
function makeRegexPrefixesToRemove(prefixes) {
|
|
@@ -771,7 +802,7 @@ const EXPORTS_PREVIEW_FILE = "exports-preview.json";
|
|
|
771
802
|
const EXPORTS_ANALYSIS_FILE = "exports-analysis.json";
|
|
772
803
|
const ENCODING = "utf8";
|
|
773
804
|
const JSON_INDENT = 2;
|
|
774
|
-
const
|
|
805
|
+
const file_utils_FileUtils = {
|
|
775
806
|
exists (filePath) {
|
|
776
807
|
return external_node_fs_default().existsSync(filePath);
|
|
777
808
|
},
|
|
@@ -809,19 +840,19 @@ const FileUtils = {
|
|
|
809
840
|
}
|
|
810
841
|
};
|
|
811
842
|
function fileExists(filePath) {
|
|
812
|
-
return
|
|
843
|
+
return file_utils_FileUtils.exists(filePath);
|
|
813
844
|
}
|
|
814
845
|
function readPackageJson(filePath) {
|
|
815
|
-
return
|
|
846
|
+
return file_utils_FileUtils.readJsonFile(filePath);
|
|
816
847
|
}
|
|
817
848
|
function backupPackageJson(filePath) {
|
|
818
849
|
try {
|
|
819
850
|
const content = external_node_fs_default().readFileSync(filePath, ENCODING);
|
|
820
851
|
const dir = external_node_path_default().dirname(filePath);
|
|
821
852
|
const backupDir = external_node_path_default().join(dir, EXPORTS_ANALYSIS_DIR);
|
|
822
|
-
|
|
853
|
+
file_utils_FileUtils.ensureDirectoryExists(backupDir);
|
|
823
854
|
const baseName = external_node_path_default().basename(filePath);
|
|
824
|
-
const backupPath = external_node_path_default().join(backupDir,
|
|
855
|
+
const backupPath = external_node_path_default().join(backupDir, file_utils_FileUtils.createBackupFilename(baseName));
|
|
825
856
|
external_node_fs_default().writeFileSync(backupPath, content, ENCODING);
|
|
826
857
|
return true;
|
|
827
858
|
} catch (error) {
|
|
@@ -830,11 +861,11 @@ function backupPackageJson(filePath) {
|
|
|
830
861
|
}
|
|
831
862
|
}
|
|
832
863
|
function savePackageJson(filePath, content) {
|
|
833
|
-
return
|
|
864
|
+
return file_utils_FileUtils.writeJsonFile(filePath, content);
|
|
834
865
|
}
|
|
835
866
|
function saveJsonToFile(packageDir, fileName, content) {
|
|
836
|
-
const outputDir =
|
|
837
|
-
|
|
867
|
+
const outputDir = file_utils_FileUtils.getAnalysisDir(packageDir);
|
|
868
|
+
file_utils_FileUtils.writeJsonFile(external_node_path_default().join(outputDir, fileName), content);
|
|
838
869
|
}
|
|
839
870
|
function saveExportsAnalysis(packageDir, analysis) {
|
|
840
871
|
saveJsonToFile(packageDir, EXPORTS_ANALYSIS_FILE, analysis);
|
|
@@ -964,21 +995,21 @@ async function processAllPackages(options) {
|
|
|
964
995
|
throw error;
|
|
965
996
|
}
|
|
966
997
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
}
|
|
998
|
+
const updateExportsCommand = new external_commander_namespaceObject.Command().name("update-exports").description("Updates exports for all packages").option("-p, --package <package>", "Filter by package name").option("-d, --dry-run", "Run without making changes").option("-c, --config <path>", "Path to configuration file").action(async (options)=>{
|
|
999
|
+
const processorOptions = {
|
|
1000
|
+
packageFilter: options.package,
|
|
1001
|
+
dryRun: Boolean(options.dryRun),
|
|
1002
|
+
configPath: options.config
|
|
1003
|
+
};
|
|
1004
|
+
try {
|
|
1005
|
+
await processAllPackages(processorOptions);
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
console.error("Error processing packages:", error);
|
|
1008
|
+
process.exit(1);
|
|
1009
|
+
} finally{
|
|
1010
|
+
process.exit(0);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
982
1013
|
const external_node_url_namespaceObject = require("node:url");
|
|
983
1014
|
function getPackageInfo() {
|
|
984
1015
|
const __filename1 = (0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
|
|
@@ -991,16 +1022,7 @@ function getPackageVersion() {
|
|
|
991
1022
|
}
|
|
992
1023
|
function main() {
|
|
993
1024
|
const program = new external_commander_namespaceObject.Command();
|
|
994
|
-
program.name("codefast").description("CodeFast CLI - A development toolkit for CodeFast.").version(getPackageVersion(), "-v, --version", "display CLI version");
|
|
995
|
-
createUpdateExportsCommand(program);
|
|
996
|
-
createProjectCommand(program);
|
|
997
|
-
program.action(()=>{
|
|
998
|
-
console.log('Use "codefast create-project" to create a new Next.js project.');
|
|
999
|
-
console.log('Use "codefast update-exports" to update exports.');
|
|
1000
|
-
console.log('Run "codefast --help" to see all available commands.');
|
|
1001
|
-
program.help();
|
|
1002
|
-
});
|
|
1003
|
-
program.parse(process.argv);
|
|
1025
|
+
program.name("codefast").description("CodeFast CLI - A development toolkit for CodeFast.").version(getPackageVersion(), "-v, --version", "display CLI version").addCommand(updateExportsCommand).addCommand(createProjectCommand).parse(process.argv);
|
|
1004
1026
|
}
|
|
1005
1027
|
main();
|
|
1006
1028
|
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|