@codefast/cli 0.3.4 → 0.3.5-canary.0
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 +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +126 -126
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
2
|
+
import { Container, inject, injectable } from "inversify";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import external_node_process_default, { exit } from "node:process";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import external_node_path_default from "node:path";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import external_node_fs_default from "node:fs";
|
|
9
|
+
import external_node_readline_default from "node:readline";
|
|
10
|
+
import { Project } from "ts-morph";
|
|
11
|
+
import { glob } from "glob";
|
|
12
|
+
import { merge } from "lodash-es";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
14
|
const TYPES = {
|
|
15
15
|
ProjectRepository: Symbol.for("ProjectRepository"),
|
|
16
16
|
PackageRepository: Symbol.for("PackageRepository"),
|
|
@@ -47,15 +47,15 @@ class CreateProjectCommand {
|
|
|
47
47
|
this.createProjectUseCase = createProjectUseCase;
|
|
48
48
|
}
|
|
49
49
|
getCommand() {
|
|
50
|
-
return new
|
|
50
|
+
return new Command().name("create-project").description("Create a new Next.js project with TypeScript, TailwindCSS, and linting setup").argument("[project-name]", "Name of the project to create").action(async (projectName)=>{
|
|
51
51
|
await this.createProjectUseCase.execute(projectName);
|
|
52
|
-
|
|
52
|
+
external_node_process_default.exit(0);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
CreateProjectCommand = _ts_decorate([
|
|
57
|
-
|
|
58
|
-
_ts_param(0,
|
|
57
|
+
injectable(),
|
|
58
|
+
_ts_param(0, inject(TYPES.CreateProjectUseCase)),
|
|
59
59
|
_ts_metadata("design:type", Function),
|
|
60
60
|
_ts_metadata("design:paramtypes", [
|
|
61
61
|
"undefined" == typeof CreateProjectUseCase ? Object : CreateProjectUseCase
|
|
@@ -80,19 +80,19 @@ class UpdateExportsCommand {
|
|
|
80
80
|
this.updateExportsUseCase = updateExportsUseCase;
|
|
81
81
|
}
|
|
82
82
|
getCommand() {
|
|
83
|
-
return new
|
|
83
|
+
return new 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)=>{
|
|
84
84
|
await this.updateExportsUseCase.execute({
|
|
85
85
|
packageFilter: options.package,
|
|
86
86
|
dryRun: Boolean(options.dryRun),
|
|
87
87
|
configPath: options.config
|
|
88
88
|
});
|
|
89
|
-
|
|
89
|
+
exit(0);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
UpdateExportsCommand = update_exports_command_ts_decorate([
|
|
94
|
-
|
|
95
|
-
update_exports_command_ts_param(0,
|
|
94
|
+
injectable(),
|
|
95
|
+
update_exports_command_ts_param(0, inject(TYPES.UpdateExportsUseCase)),
|
|
96
96
|
update_exports_command_ts_metadata("design:type", Function),
|
|
97
97
|
update_exports_command_ts_metadata("design:paramtypes", [
|
|
98
98
|
"undefined" == typeof UpdateExportsUseCase ? Object : UpdateExportsUseCase
|
|
@@ -427,7 +427,7 @@ export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
ConfigService = config_service_ts_decorate([
|
|
430
|
-
|
|
430
|
+
injectable()
|
|
431
431
|
], ConfigService);
|
|
432
432
|
function create_project_use_case_ts_decorate(decorators, target, key, desc) {
|
|
433
433
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -508,12 +508,12 @@ class create_project_use_case_CreateProjectUseCase {
|
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
510
|
create_project_use_case_CreateProjectUseCase = create_project_use_case_ts_decorate([
|
|
511
|
-
|
|
512
|
-
create_project_use_case_ts_param(0,
|
|
513
|
-
create_project_use_case_ts_param(1,
|
|
514
|
-
create_project_use_case_ts_param(2,
|
|
515
|
-
create_project_use_case_ts_param(3,
|
|
516
|
-
create_project_use_case_ts_param(4,
|
|
511
|
+
injectable(),
|
|
512
|
+
create_project_use_case_ts_param(0, inject(TYPES.ProjectRepository)),
|
|
513
|
+
create_project_use_case_ts_param(1, inject(TYPES.FileSystemPort)),
|
|
514
|
+
create_project_use_case_ts_param(2, inject(TYPES.CommandExecutorPort)),
|
|
515
|
+
create_project_use_case_ts_param(3, inject(TYPES.PromptPort)),
|
|
516
|
+
create_project_use_case_ts_param(4, inject(TYPES.ConfigService)),
|
|
517
517
|
create_project_use_case_ts_metadata("design:type", Function),
|
|
518
518
|
create_project_use_case_ts_metadata("design:paramtypes", [
|
|
519
519
|
"undefined" == typeof ProjectRepositoryInterface ? Object : ProjectRepositoryInterface,
|
|
@@ -565,8 +565,8 @@ class update_exports_use_case_UpdateExportsUseCase {
|
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
update_exports_use_case_UpdateExportsUseCase = update_exports_use_case_ts_decorate([
|
|
568
|
-
|
|
569
|
-
update_exports_use_case_ts_param(0,
|
|
568
|
+
injectable(),
|
|
569
|
+
update_exports_use_case_ts_param(0, inject(TYPES.PackageRepository)),
|
|
570
570
|
update_exports_use_case_ts_metadata("design:type", Function),
|
|
571
571
|
update_exports_use_case_ts_metadata("design:paramtypes", [
|
|
572
572
|
"undefined" == typeof PackageRepository ? Object : PackageRepository
|
|
@@ -593,15 +593,15 @@ class CLIAdapter {
|
|
|
593
593
|
this.packageInfoService = packageInfoService;
|
|
594
594
|
}
|
|
595
595
|
initialize() {
|
|
596
|
-
const program = new
|
|
596
|
+
const program = new Command();
|
|
597
597
|
program.name("codefast").description("CodeFast CLI - A development toolkit for CodeFast.").version(this.packageInfoService.getPackageVersion(), "-v, --version", "display CLI version").addCommand(this.createProjectCommand.getCommand()).addCommand(this.updateExportsCommand.getCommand()).parse(process.argv);
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
CLIAdapter = cli_adapter_ts_decorate([
|
|
601
|
-
|
|
602
|
-
cli_adapter_ts_param(0,
|
|
603
|
-
cli_adapter_ts_param(1,
|
|
604
|
-
cli_adapter_ts_param(2,
|
|
601
|
+
injectable(),
|
|
602
|
+
cli_adapter_ts_param(0, inject(TYPES.CreateProjectCommand)),
|
|
603
|
+
cli_adapter_ts_param(1, inject(TYPES.UpdateExportsCommand)),
|
|
604
|
+
cli_adapter_ts_param(2, inject(TYPES.PackageInfoService)),
|
|
605
605
|
cli_adapter_ts_metadata("design:type", Function),
|
|
606
606
|
cli_adapter_ts_metadata("design:paramtypes", [
|
|
607
607
|
void 0 === CreateProjectCommand ? Object : CreateProjectCommand,
|
|
@@ -609,49 +609,49 @@ CLIAdapter = cli_adapter_ts_decorate([
|
|
|
609
609
|
"undefined" == typeof PackageInfoServiceInterface ? Object : PackageInfoServiceInterface
|
|
610
610
|
])
|
|
611
611
|
], CLIAdapter);
|
|
612
|
-
const packageConfigSchema =
|
|
613
|
-
cjsOutputPattern:
|
|
614
|
-
esmOutputPattern:
|
|
615
|
-
packageJsonPath:
|
|
616
|
-
srcIndexPath:
|
|
617
|
-
typesOutputCjsPattern:
|
|
618
|
-
typesOutputPattern:
|
|
619
|
-
exportPathPrefixesToRemove:
|
|
612
|
+
const packageConfigSchema = z.object({
|
|
613
|
+
cjsOutputPattern: z.string().describe("Output pattern for CommonJS format, e.g., './dist/cjs/{dir}/{name}.cjs'"),
|
|
614
|
+
esmOutputPattern: z.string().describe("Output pattern for ESM format, e.g., './dist/esm/{dir}/{name}.js'"),
|
|
615
|
+
packageJsonPath: z.string().describe("Path to the package.json file, e.g., 'package.json'"),
|
|
616
|
+
srcIndexPath: z.string().describe("Path to the source index file, e.g., 'src/index.ts'"),
|
|
617
|
+
typesOutputCjsPattern: z.string().describe("Output pattern for CommonJS type declarations, e.g., './dist/types/{dir}/{name}.d.cts'"),
|
|
618
|
+
typesOutputPattern: z.string().describe("Output pattern for type declarations, e.g., './dist/types/{dir}/{name}.d.ts'"),
|
|
619
|
+
exportPathPrefixesToRemove: z.array(z.string()).optional().describe("Prefixes to remove from export paths, e.g., ['components']")
|
|
620
620
|
});
|
|
621
|
-
const scriptConfigSchema =
|
|
622
|
-
customPackageConfigs:
|
|
621
|
+
const scriptConfigSchema = z.object({
|
|
622
|
+
customPackageConfigs: z.record(z.string(), packageConfigSchema.partial()).describe("Custom configurations for specific packages"),
|
|
623
623
|
defaultPackageConfig: packageConfigSchema.describe("Default configuration applied to all packages unless overridden"),
|
|
624
|
-
packagesGlob:
|
|
624
|
+
packagesGlob: z.string().describe("Glob pattern to find package.json files, e.g., './packages/**/package.json'")
|
|
625
625
|
});
|
|
626
|
-
|
|
627
|
-
directory:
|
|
628
|
-
exportPath:
|
|
629
|
-
name:
|
|
630
|
-
originalPath:
|
|
626
|
+
z.object({
|
|
627
|
+
directory: z.string().describe("Directory containing the import, e.g., 'components'"),
|
|
628
|
+
exportPath: z.string().describe("Resolved export path from the directory, e.g., './button'"),
|
|
629
|
+
name: z.string().describe("Name of the import, e.g., 'Button'"),
|
|
630
|
+
originalPath: z.string().describe("Original unresolved path, e.g., './components/button'")
|
|
631
631
|
});
|
|
632
|
-
const exportConfigSchema =
|
|
633
|
-
import:
|
|
634
|
-
default:
|
|
635
|
-
types:
|
|
632
|
+
const exportConfigSchema = z.object({
|
|
633
|
+
import: z.object({
|
|
634
|
+
default: z.string().describe("ESM default export path"),
|
|
635
|
+
types: z.string().describe("ESM types export path")
|
|
636
636
|
}),
|
|
637
|
-
require:
|
|
638
|
-
default:
|
|
639
|
-
types:
|
|
637
|
+
require: z.object({
|
|
638
|
+
default: z.string().describe("CommonJS default export path"),
|
|
639
|
+
types: z.string().describe("CommonJS types export path")
|
|
640
640
|
})
|
|
641
641
|
});
|
|
642
|
-
const PackageExportsSchema =
|
|
642
|
+
const PackageExportsSchema = z.record(z.string(), z.union([
|
|
643
643
|
exportConfigSchema,
|
|
644
|
-
|
|
644
|
+
z.string()
|
|
645
645
|
]));
|
|
646
|
-
const packageJsonSchema =
|
|
647
|
-
dependencies:
|
|
648
|
-
devDependencies:
|
|
646
|
+
const packageJsonSchema = z.object({
|
|
647
|
+
dependencies: z.record(z.string(), z.string()).optional().describe("List of runtime dependencies with their versions"),
|
|
648
|
+
devDependencies: z.record(z.string(), z.string()).optional().describe("List of development dependencies with their versions"),
|
|
649
649
|
exports: PackageExportsSchema.optional().describe("Export mappings for the package"),
|
|
650
|
-
name:
|
|
651
|
-
scripts:
|
|
652
|
-
"simple-git-hooks":
|
|
653
|
-
version:
|
|
654
|
-
}).catchall(
|
|
650
|
+
name: z.string().describe("Name of the package"),
|
|
651
|
+
scripts: z.record(z.string(), z.string()).describe("Script commands defined for the package"),
|
|
652
|
+
"simple-git-hooks": z.record(z.string(), z.string()).optional().describe("Git hooks configuration for the package"),
|
|
653
|
+
version: z.string().optional().describe("Version of the package")
|
|
654
|
+
}).catchall(z.unknown());
|
|
655
655
|
function node_command_executor_adapter_ts_decorate(decorators, target, key, desc) {
|
|
656
656
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
657
657
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -672,7 +672,7 @@ class NodeCommandExecutorAdapter {
|
|
|
672
672
|
this.dependencyConfigService = dependencyConfigService;
|
|
673
673
|
}
|
|
674
674
|
runCommand(command) {
|
|
675
|
-
|
|
675
|
+
execSync(command, {
|
|
676
676
|
stdio: "inherit"
|
|
677
677
|
});
|
|
678
678
|
}
|
|
@@ -695,7 +695,7 @@ class NodeCommandExecutorAdapter {
|
|
|
695
695
|
cleanupPackages() {
|
|
696
696
|
console.log(`
|
|
697
697
|
\u{1F9F9} Cleaning up unnecessary packages...`);
|
|
698
|
-
const packageJsonPath =
|
|
698
|
+
const packageJsonPath = external_node_path_default.join(process.cwd(), "package.json");
|
|
699
699
|
if (!this.fileSystemPort.exists(packageJsonPath)) return void console.warn(`\u{26A0}\u{FE0F} package.json not found, skipping cleanup.`);
|
|
700
700
|
let packageJson;
|
|
701
701
|
try {
|
|
@@ -727,9 +727,9 @@ class NodeCommandExecutorAdapter {
|
|
|
727
727
|
}
|
|
728
728
|
}
|
|
729
729
|
NodeCommandExecutorAdapter = node_command_executor_adapter_ts_decorate([
|
|
730
|
-
|
|
731
|
-
node_command_executor_adapter_ts_param(0,
|
|
732
|
-
node_command_executor_adapter_ts_param(1,
|
|
730
|
+
injectable(),
|
|
731
|
+
node_command_executor_adapter_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
732
|
+
node_command_executor_adapter_ts_param(1, inject(TYPES.DependencyConfigService)),
|
|
733
733
|
node_command_executor_adapter_ts_metadata("design:type", Function),
|
|
734
734
|
node_command_executor_adapter_ts_metadata("design:paramtypes", [
|
|
735
735
|
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
@@ -744,29 +744,29 @@ function node_file_system_adapter_ts_decorate(decorators, target, key, desc) {
|
|
|
744
744
|
}
|
|
745
745
|
class NodeFileSystemAdapter {
|
|
746
746
|
exists(filePath) {
|
|
747
|
-
return
|
|
747
|
+
return external_node_fs_default.existsSync(filePath);
|
|
748
748
|
}
|
|
749
749
|
access(filePath) {
|
|
750
|
-
|
|
750
|
+
external_node_fs_default.accessSync(filePath, external_node_fs_default.constants.W_OK);
|
|
751
751
|
}
|
|
752
752
|
readFile(filePath) {
|
|
753
753
|
try {
|
|
754
|
-
return
|
|
754
|
+
return external_node_fs_default.readFileSync(filePath, "utf8");
|
|
755
755
|
} catch (error) {
|
|
756
756
|
throw new Error(`Failed to read file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
757
757
|
}
|
|
758
758
|
}
|
|
759
759
|
writeFile(filePath, content) {
|
|
760
760
|
try {
|
|
761
|
-
const dir =
|
|
761
|
+
const dir = external_node_path_default.dirname(filePath);
|
|
762
762
|
this.createDirectory(dir);
|
|
763
|
-
|
|
763
|
+
external_node_fs_default.writeFileSync(filePath, content);
|
|
764
764
|
} catch (error) {
|
|
765
765
|
throw new Error(`Failed to write to file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
createDirectory(dirPath) {
|
|
769
|
-
if (!this.exists(dirPath))
|
|
769
|
+
if (!this.exists(dirPath)) external_node_fs_default.mkdirSync(dirPath, {
|
|
770
770
|
recursive: true
|
|
771
771
|
});
|
|
772
772
|
}
|
|
@@ -781,7 +781,7 @@ class NodeFileSystemAdapter {
|
|
|
781
781
|
console.log(`
|
|
782
782
|
\u{1F4C2} Setting up ${category} configurations:`);
|
|
783
783
|
for (const config of configs){
|
|
784
|
-
const fullPath =
|
|
784
|
+
const fullPath = external_node_path_default.join(projectDir, config.path);
|
|
785
785
|
this.writeConfigFile(fullPath, config.content);
|
|
786
786
|
if (config.description) console.log(`\u{2139}\u{FE0F} ${config.path}: ${config.description}`);
|
|
787
787
|
}
|
|
@@ -789,7 +789,7 @@ class NodeFileSystemAdapter {
|
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
NodeFileSystemAdapter = node_file_system_adapter_ts_decorate([
|
|
792
|
-
|
|
792
|
+
injectable()
|
|
793
793
|
], NodeFileSystemAdapter);
|
|
794
794
|
function node_prompt_adapter_ts_decorate(decorators, target, key, desc) {
|
|
795
795
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -802,7 +802,7 @@ function node_prompt_adapter_ts_metadata(k, v) {
|
|
|
802
802
|
}
|
|
803
803
|
class NodePromptAdapter {
|
|
804
804
|
constructor(){
|
|
805
|
-
this.rl =
|
|
805
|
+
this.rl = external_node_readline_default.createInterface({
|
|
806
806
|
input: process.stdin,
|
|
807
807
|
output: process.stdout
|
|
808
808
|
});
|
|
@@ -819,7 +819,7 @@ class NodePromptAdapter {
|
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
821
|
NodePromptAdapter = node_prompt_adapter_ts_decorate([
|
|
822
|
-
|
|
822
|
+
injectable(),
|
|
823
823
|
node_prompt_adapter_ts_metadata("design:type", Function),
|
|
824
824
|
node_prompt_adapter_ts_metadata("design:paramtypes", [])
|
|
825
825
|
], NodePromptAdapter);
|
|
@@ -831,7 +831,7 @@ function ts_morph_analysis_adapter_ts_decorate(decorators, target, key, desc) {
|
|
|
831
831
|
}
|
|
832
832
|
class TsMorphAnalysisAdapter {
|
|
833
833
|
analyzeImports(indexFilePath, packageConfig) {
|
|
834
|
-
const project = new
|
|
834
|
+
const project = new Project();
|
|
835
835
|
let sourceFile;
|
|
836
836
|
try {
|
|
837
837
|
sourceFile = project.addSourceFileAtPath(indexFilePath);
|
|
@@ -877,7 +877,7 @@ class TsMorphAnalysisAdapter {
|
|
|
877
877
|
}
|
|
878
878
|
}
|
|
879
879
|
TsMorphAnalysisAdapter = ts_morph_analysis_adapter_ts_decorate([
|
|
880
|
-
|
|
880
|
+
injectable()
|
|
881
881
|
], TsMorphAnalysisAdapter);
|
|
882
882
|
function file_system_package_repository_ts_decorate(decorators, target, key, desc) {
|
|
883
883
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -928,12 +928,12 @@ class FileSystemPackageRepository {
|
|
|
928
928
|
}
|
|
929
929
|
async findAllPackages(configPath) {
|
|
930
930
|
const config = this.getConfig(configPath);
|
|
931
|
-
return await
|
|
931
|
+
return await glob(config.packagesGlob, {
|
|
932
932
|
ignore: this.DEFAULT_IGNORE_PATTERN
|
|
933
933
|
});
|
|
934
934
|
}
|
|
935
935
|
processPackage(packageJsonPath, options) {
|
|
936
|
-
const packageDir =
|
|
936
|
+
const packageDir = external_node_path_default.dirname(packageJsonPath);
|
|
937
937
|
let packageJson;
|
|
938
938
|
try {
|
|
939
939
|
packageJson = JSON.parse(this.fileSystemPort.readFile(packageJsonPath));
|
|
@@ -949,7 +949,7 @@ class FileSystemPackageRepository {
|
|
|
949
949
|
console.info(`\u{2662}\u{2012} Processing package: ${packageName}`);
|
|
950
950
|
const config = this.getConfig(options.configPath);
|
|
951
951
|
const packageConfig = this.getPackageConfig(packageName, config);
|
|
952
|
-
const srcIndexPath =
|
|
952
|
+
const srcIndexPath = external_node_path_default.join(packageDir, packageConfig.srcIndexPath);
|
|
953
953
|
if (!this.fileSystemPort.exists(srcIndexPath)) {
|
|
954
954
|
console.error(`\u{23B9} \u{26D4}\u{FE0E} Source file not found at ${srcIndexPath}`);
|
|
955
955
|
return false;
|
|
@@ -1022,14 +1022,14 @@ class FileSystemPackageRepository {
|
|
|
1022
1022
|
getConfig(configPath) {
|
|
1023
1023
|
if (this.cachedConfig && !configPath) return this.cachedConfig;
|
|
1024
1024
|
const userConfig = this.loadConfigFile(configPath);
|
|
1025
|
-
const config =
|
|
1025
|
+
const config = merge({}, this.defaultConfig, userConfig);
|
|
1026
1026
|
if (!configPath) this.cachedConfig = config;
|
|
1027
1027
|
return config;
|
|
1028
1028
|
}
|
|
1029
1029
|
loadConfigFile(configPath) {
|
|
1030
1030
|
if (!configPath) return {};
|
|
1031
1031
|
try {
|
|
1032
|
-
const fullPath =
|
|
1032
|
+
const fullPath = external_node_path_default.resolve(configPath);
|
|
1033
1033
|
if (!this.fileSystemPort.exists(fullPath)) {
|
|
1034
1034
|
console.warn(`Configuration file not found at ${fullPath}`);
|
|
1035
1035
|
return {};
|
|
@@ -1053,21 +1053,21 @@ class FileSystemPackageRepository {
|
|
|
1053
1053
|
return pattern.replace("{dir}/", dirPart).replace("{dir}", directory).replace("{name}", name);
|
|
1054
1054
|
}
|
|
1055
1055
|
saveExportsAnalysis(packageDir, analysis) {
|
|
1056
|
-
const outputDir =
|
|
1056
|
+
const outputDir = external_node_path_default.join(packageDir, ".exports-analysis");
|
|
1057
1057
|
this.fileSystemPort.createDirectory(outputDir);
|
|
1058
|
-
this.fileSystemPort.writeFile(
|
|
1058
|
+
this.fileSystemPort.writeFile(external_node_path_default.join(outputDir, "exports-analysis.json"), JSON.stringify(analysis, null, 2));
|
|
1059
1059
|
}
|
|
1060
1060
|
saveExportsPreview(packageDir, exports) {
|
|
1061
|
-
const outputDir =
|
|
1061
|
+
const outputDir = external_node_path_default.join(packageDir, ".exports-analysis");
|
|
1062
1062
|
this.fileSystemPort.createDirectory(outputDir);
|
|
1063
|
-
this.fileSystemPort.writeFile(
|
|
1063
|
+
this.fileSystemPort.writeFile(external_node_path_default.join(outputDir, "exports-preview.json"), JSON.stringify(exports, null, 2));
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
1066
|
FileSystemPackageRepository = file_system_package_repository_ts_decorate([
|
|
1067
|
-
|
|
1068
|
-
file_system_package_repository_ts_param(0,
|
|
1069
|
-
file_system_package_repository_ts_param(1,
|
|
1070
|
-
file_system_package_repository_ts_param(2,
|
|
1067
|
+
injectable(),
|
|
1068
|
+
file_system_package_repository_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
1069
|
+
file_system_package_repository_ts_param(1, inject(TYPES.AnalysisPort)),
|
|
1070
|
+
file_system_package_repository_ts_param(2, inject(TYPES.FileSystemUtility)),
|
|
1071
1071
|
file_system_package_repository_ts_metadata("design:type", Function),
|
|
1072
1072
|
file_system_package_repository_ts_metadata("design:paramtypes", [
|
|
1073
1073
|
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
@@ -1075,16 +1075,16 @@ FileSystemPackageRepository = file_system_package_repository_ts_decorate([
|
|
|
1075
1075
|
"undefined" == typeof FileSystemUtility ? Object : FileSystemUtility
|
|
1076
1076
|
])
|
|
1077
1077
|
], FileSystemPackageRepository);
|
|
1078
|
-
const projectSchema =
|
|
1079
|
-
name:
|
|
1078
|
+
const projectSchema = z.object({
|
|
1079
|
+
name: z.string().min(1, "Project name cannot be empty").max(100, "Project name is too long (maximum 100 characters)").regex(/^[a-z0-9-~][a-z0-9-._~]*$/, {
|
|
1080
1080
|
message: "Project name must be URL-friendly (letters, numbers, hyphens, underscores, dots; no @ or scoped packages)"
|
|
1081
1081
|
}).refine((name)=>"." !== name && ".." !== name, {
|
|
1082
1082
|
message: "Project name cannot be '.' or '..'"
|
|
1083
1083
|
}).refine((name)=>!/^(?<reserved>CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name), {
|
|
1084
1084
|
message: "Project name is a reserved system name"
|
|
1085
1085
|
}),
|
|
1086
|
-
directory:
|
|
1087
|
-
packageJsonExists:
|
|
1086
|
+
directory: z.string().describe("Project directory path"),
|
|
1087
|
+
packageJsonExists: z.boolean().describe("Whether package.json exists in the project directory")
|
|
1088
1088
|
});
|
|
1089
1089
|
function file_system_project_repository_ts_decorate(decorators, target, key, desc) {
|
|
1090
1090
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1110,14 +1110,14 @@ class FileSystemProjectRepository {
|
|
|
1110
1110
|
async checkExistingProject(projectName) {
|
|
1111
1111
|
let fullPath = process.cwd();
|
|
1112
1112
|
let name = "";
|
|
1113
|
-
const packageJsonPath =
|
|
1113
|
+
const packageJsonPath = external_node_path_default.join(process.cwd(), "package.json");
|
|
1114
1114
|
const packageJsonExists = this.fileSystemPort.exists(packageJsonPath);
|
|
1115
1115
|
if (packageJsonExists) {
|
|
1116
1116
|
const result = packageJsonSchema.safeParse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
1117
1117
|
if (result.success) name = result.data.name;
|
|
1118
1118
|
} else {
|
|
1119
1119
|
name = await this.getValidProjectName(projectName);
|
|
1120
|
-
fullPath =
|
|
1120
|
+
fullPath = external_node_path_default.resolve(process.cwd(), name);
|
|
1121
1121
|
}
|
|
1122
1122
|
return {
|
|
1123
1123
|
name,
|
|
@@ -1130,7 +1130,7 @@ class FileSystemProjectRepository {
|
|
|
1130
1130
|
this.commandExecutorPort.runCommand(`npx create-next-app@latest ${projectName} ${flags}`);
|
|
1131
1131
|
}
|
|
1132
1132
|
updateLayoutFile(projectDir) {
|
|
1133
|
-
const layoutPath =
|
|
1133
|
+
const layoutPath = external_node_path_default.join(projectDir, "src", "app", "layout.tsx");
|
|
1134
1134
|
const htmlTarget = '<html className={cn(fontVariables, "antialiased")} lang="en">';
|
|
1135
1135
|
this.fileSystemUtility.updateFileIfNeeded(layoutPath, (content)=>content.includes(htmlTarget), (content)=>{
|
|
1136
1136
|
const newImports = `import type { Metadata } from "next";
|
|
@@ -1149,7 +1149,7 @@ import "@/app/globals.css";`;
|
|
|
1149
1149
|
});
|
|
1150
1150
|
}
|
|
1151
1151
|
updatePageFile(projectDir) {
|
|
1152
|
-
const pagePath =
|
|
1152
|
+
const pagePath = external_node_path_default.join(projectDir, "src", "app", "page.tsx");
|
|
1153
1153
|
this.fileSystemUtility.updateFileIfNeeded(pagePath, (content)=>content.includes("): JSX.Element"), (content)=>{
|
|
1154
1154
|
let result = content;
|
|
1155
1155
|
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}`;
|
|
@@ -1158,12 +1158,12 @@ import "@/app/globals.css";`;
|
|
|
1158
1158
|
});
|
|
1159
1159
|
}
|
|
1160
1160
|
updatePostcssConfig(projectDir) {
|
|
1161
|
-
const postcssConfigPath =
|
|
1161
|
+
const postcssConfigPath = external_node_path_default.join(projectDir, "postcss.config.mjs");
|
|
1162
1162
|
const typeComment = `/** @type {import('postcss-load-config').Config} */\n`;
|
|
1163
1163
|
this.fileSystemUtility.updateFileIfNeeded(postcssConfigPath, (content)=>content.includes(typeComment), (content)=>content.replace("const config = {", `${typeComment}const config = {`));
|
|
1164
1164
|
}
|
|
1165
1165
|
updateNextConfig(projectDir) {
|
|
1166
|
-
const nextConfigPath =
|
|
1166
|
+
const nextConfigPath = external_node_path_default.join(projectDir, "next.config.ts");
|
|
1167
1167
|
const optimizePackagesConfig = 'optimizePackageImports: ["@codefast/ui"]';
|
|
1168
1168
|
this.fileSystemUtility.updateFileIfNeeded(nextConfigPath, (content)=>content.includes(optimizePackagesConfig), (content)=>content.replace(/const nextConfig: NextConfig = \{/, `const nextConfig: NextConfig = {
|
|
1169
1169
|
experimental: {
|
|
@@ -1171,7 +1171,7 @@ import "@/app/globals.css";`;
|
|
|
1171
1171
|
},`));
|
|
1172
1172
|
}
|
|
1173
1173
|
updatePackageJson(projectDir) {
|
|
1174
|
-
const packageJsonPath =
|
|
1174
|
+
const packageJsonPath = external_node_path_default.join(projectDir, "package.json");
|
|
1175
1175
|
if (!this.fileSystemPort.exists(packageJsonPath)) return void console.warn(`\u{26A0}\u{FE0F} package.json not found, skipping update.`);
|
|
1176
1176
|
let packageJson;
|
|
1177
1177
|
try {
|
|
@@ -1209,7 +1209,7 @@ import "@/app/globals.css";`;
|
|
|
1209
1209
|
packageJsonExists: false
|
|
1210
1210
|
});
|
|
1211
1211
|
if (result.success) {
|
|
1212
|
-
const fullPath =
|
|
1212
|
+
const fullPath = external_node_path_default.resolve(process.cwd(), projectName);
|
|
1213
1213
|
if (this.fileSystemPort.exists(fullPath)) throw new Error(`A directory named "${projectName}" already exists.`);
|
|
1214
1214
|
try {
|
|
1215
1215
|
this.fileSystemPort.access(process.cwd());
|
|
@@ -1224,11 +1224,11 @@ import "@/app/globals.css";`;
|
|
|
1224
1224
|
}
|
|
1225
1225
|
}
|
|
1226
1226
|
FileSystemProjectRepository = file_system_project_repository_ts_decorate([
|
|
1227
|
-
|
|
1228
|
-
file_system_project_repository_ts_param(0,
|
|
1229
|
-
file_system_project_repository_ts_param(1,
|
|
1230
|
-
file_system_project_repository_ts_param(2,
|
|
1231
|
-
file_system_project_repository_ts_param(3,
|
|
1227
|
+
injectable(),
|
|
1228
|
+
file_system_project_repository_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
1229
|
+
file_system_project_repository_ts_param(1, inject(TYPES.CommandExecutorPort)),
|
|
1230
|
+
file_system_project_repository_ts_param(2, inject(TYPES.PromptPort)),
|
|
1231
|
+
file_system_project_repository_ts_param(3, inject(TYPES.FileSystemUtility)),
|
|
1232
1232
|
file_system_project_repository_ts_metadata("design:type", Function),
|
|
1233
1233
|
file_system_project_repository_ts_metadata("design:paramtypes", [
|
|
1234
1234
|
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
@@ -1289,7 +1289,7 @@ class DependencyConfigService {
|
|
|
1289
1289
|
}
|
|
1290
1290
|
}
|
|
1291
1291
|
DependencyConfigService = dependency_config_service_ts_decorate([
|
|
1292
|
-
|
|
1292
|
+
injectable()
|
|
1293
1293
|
], DependencyConfigService);
|
|
1294
1294
|
function node_package_info_service_ts_decorate(decorators, target, key, desc) {
|
|
1295
1295
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1311,9 +1311,9 @@ class NodePackageInfoService {
|
|
|
1311
1311
|
}
|
|
1312
1312
|
getPackageVersion() {
|
|
1313
1313
|
try {
|
|
1314
|
-
const __filename =
|
|
1315
|
-
const __dirname =
|
|
1316
|
-
const packageJsonPath =
|
|
1314
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1315
|
+
const __dirname = external_node_path_default.dirname(__filename);
|
|
1316
|
+
const packageJsonPath = external_node_path_default.resolve(__dirname, "..", "package.json");
|
|
1317
1317
|
const packageJsonResult = packageJsonSchema.parse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
1318
1318
|
return packageJsonResult.version ?? "0.0.0";
|
|
1319
1319
|
} catch (error) {
|
|
@@ -1323,8 +1323,8 @@ class NodePackageInfoService {
|
|
|
1323
1323
|
}
|
|
1324
1324
|
}
|
|
1325
1325
|
NodePackageInfoService = node_package_info_service_ts_decorate([
|
|
1326
|
-
|
|
1327
|
-
node_package_info_service_ts_param(0,
|
|
1326
|
+
injectable(),
|
|
1327
|
+
node_package_info_service_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
1328
1328
|
node_package_info_service_ts_metadata("design:type", Function),
|
|
1329
1329
|
node_package_info_service_ts_metadata("design:paramtypes", [
|
|
1330
1330
|
"undefined" == typeof FileSystemPort ? Object : FileSystemPort
|
|
@@ -1363,10 +1363,10 @@ class file_system_utility_FileSystemUtility {
|
|
|
1363
1363
|
backupFile(filePath, backupDir) {
|
|
1364
1364
|
try {
|
|
1365
1365
|
const content = this.fileSystemPort.readFile(filePath);
|
|
1366
|
-
const baseName =
|
|
1366
|
+
const baseName = external_node_path_default.basename(filePath);
|
|
1367
1367
|
const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
1368
|
-
const backupPath =
|
|
1369
|
-
this.fileSystemPort.createDirectory(
|
|
1368
|
+
const backupPath = external_node_path_default.join(external_node_path_default.dirname(filePath), backupDir, `${baseName}.backup.${timestamp}`);
|
|
1369
|
+
this.fileSystemPort.createDirectory(external_node_path_default.dirname(backupPath));
|
|
1370
1370
|
this.fileSystemPort.writeFile(backupPath, content);
|
|
1371
1371
|
} catch (error) {
|
|
1372
1372
|
console.error(`Error backing up ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
@@ -1374,14 +1374,14 @@ class file_system_utility_FileSystemUtility {
|
|
|
1374
1374
|
}
|
|
1375
1375
|
}
|
|
1376
1376
|
file_system_utility_FileSystemUtility = file_system_utility_ts_decorate([
|
|
1377
|
-
|
|
1378
|
-
file_system_utility_ts_param(0,
|
|
1377
|
+
injectable(),
|
|
1378
|
+
file_system_utility_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
1379
1379
|
file_system_utility_ts_metadata("design:type", Function),
|
|
1380
1380
|
file_system_utility_ts_metadata("design:paramtypes", [
|
|
1381
1381
|
"undefined" == typeof FileSystemPort ? Object : FileSystemPort
|
|
1382
1382
|
])
|
|
1383
1383
|
], file_system_utility_FileSystemUtility);
|
|
1384
|
-
const container = new
|
|
1384
|
+
const container = new Container();
|
|
1385
1385
|
container.bind(TYPES.ProjectRepository).to(FileSystemProjectRepository).inSingletonScope();
|
|
1386
1386
|
container.bind(TYPES.PackageRepository).to(FileSystemPackageRepository).inSingletonScope();
|
|
1387
1387
|
container.bind(TYPES.PackageInfoService).to(NodePackageInfoService).inSingletonScope();
|