@codefast/cli 0.3.1-canary.13 → 0.3.1-canary.15
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 +16 -0
- package/dist/index.cjs +1076 -669
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1081 -675
- package/dist/index.js.map +1 -1
- package/package.json +9 -7
package/dist/index.js
CHANGED
|
@@ -1,171 +1,124 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_inversify__ from "inversify";
|
|
2
3
|
import * as __WEBPACK_EXTERNAL_MODULE_commander__ from "commander";
|
|
3
|
-
import * as
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
6
9
|
import * as __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__ from "node:readline";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE_glob__ from "glob";
|
|
8
10
|
import * as __WEBPACK_EXTERNAL_MODULE_ts_morph_07c7ce60__ from "ts-morph";
|
|
11
|
+
import * as __WEBPACK_EXTERNAL_MODULE_glob__ from "glob";
|
|
9
12
|
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
10
|
-
import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
|
|
11
13
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const FileUtils = {
|
|
29
|
-
exists (filePath) {
|
|
30
|
-
return __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(filePath);
|
|
31
|
-
},
|
|
32
|
-
readFile (filePath) {
|
|
33
|
-
try {
|
|
34
|
-
return __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(filePath, "utf8");
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw new Error(`Failed to read file ${filePath}: ${getErrorMessage(error)}`);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
writeFile (filePath, content) {
|
|
40
|
-
try {
|
|
41
|
-
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(filePath, content);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
throw new Error(`Failed to write to file ${filePath}: ${getErrorMessage(error)}`);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
writeConfigFile (filePath, content) {
|
|
47
|
-
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(filePath, content);
|
|
48
|
-
console.log(`📝 Created ${filePath}`);
|
|
49
|
-
},
|
|
50
|
-
validatePath (filePath, filename) {
|
|
51
|
-
if (!this.exists(filePath)) {
|
|
52
|
-
console.warn(`⚠️ ${filename} not found, skipping update.`);
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
14
|
+
const TYPES = {
|
|
15
|
+
ProjectRepository: Symbol.for("ProjectRepository"),
|
|
16
|
+
PackageRepository: Symbol.for("PackageRepository"),
|
|
17
|
+
FileSystemPort: Symbol.for("FileSystemPort"),
|
|
18
|
+
CommandExecutorPort: Symbol.for("CommandExecutorPort"),
|
|
19
|
+
PromptPort: Symbol.for("PromptPort"),
|
|
20
|
+
AnalysisPort: Symbol.for("AnalysisPort"),
|
|
21
|
+
PackageInfoService: Symbol.for("PackageInfoService"),
|
|
22
|
+
DependencyConfigService: Symbol.for("DependencyConfigService"),
|
|
23
|
+
ConfigService: Symbol.for("ConfigService"),
|
|
24
|
+
FileSystemUtility: Symbol.for("FileSystemUtility"),
|
|
25
|
+
CreateProjectUseCase: Symbol.for("CreateProjectUseCase"),
|
|
26
|
+
UpdateExportsUseCase: Symbol.for("UpdateExportsUseCase"),
|
|
27
|
+
CreateProjectCommand: Symbol.for("CreateProjectCommand"),
|
|
28
|
+
UpdateExportsCommand: Symbol.for("UpdateExportsCommand"),
|
|
29
|
+
CLIAdapter: Symbol.for("CLIAdapter")
|
|
57
30
|
};
|
|
58
|
-
function
|
|
59
|
-
|
|
31
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
32
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
33
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
34
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
35
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
60
36
|
}
|
|
61
|
-
function
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
valid: false,
|
|
68
|
-
error: "Project name is too long (maximum 100 characters)."
|
|
69
|
-
};
|
|
70
|
-
const npmNameRegex = /^[a-z0-9-~][a-z0-9-._~]*$/;
|
|
71
|
-
if (!npmNameRegex.test(name)) return {
|
|
72
|
-
valid: false,
|
|
73
|
-
error: "Project name must be URL-friendly (letters, numbers, hyphens, underscores, dots; no @ or scoped packages)."
|
|
74
|
-
};
|
|
75
|
-
if ("." === name || ".." === name) return {
|
|
76
|
-
valid: false,
|
|
77
|
-
error: "Project name cannot be '.' or '..'."
|
|
78
|
-
};
|
|
79
|
-
const reservedNames = /^(?<reserved>CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i;
|
|
80
|
-
if (reservedNames.test(name)) return {
|
|
81
|
-
valid: false,
|
|
82
|
-
error: `Project name "${name}" is a reserved system name.`
|
|
83
|
-
};
|
|
84
|
-
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(process.cwd(), name);
|
|
85
|
-
if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(fullPath)) return {
|
|
86
|
-
valid: false,
|
|
87
|
-
error: `A directory named "${name}" already exists.`
|
|
37
|
+
function _ts_metadata(k, v) {
|
|
38
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
39
|
+
}
|
|
40
|
+
function _ts_param(paramIndex, decorator) {
|
|
41
|
+
return function(target, key) {
|
|
42
|
+
decorator(target, key, paramIndex);
|
|
88
43
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
44
|
+
}
|
|
45
|
+
class CreateProjectCommand {
|
|
46
|
+
constructor(createProjectUseCase){
|
|
47
|
+
this.createProjectUseCase = createProjectUseCase;
|
|
48
|
+
}
|
|
49
|
+
getCommand() {
|
|
50
|
+
return new __WEBPACK_EXTERNAL_MODULE_commander__.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
|
+
await this.createProjectUseCase.execute(projectName);
|
|
52
|
+
__WEBPACK_EXTERNAL_MODULE_node_process_786449bf__["default"].exit(0);
|
|
53
|
+
});
|
|
96
54
|
}
|
|
97
|
-
|
|
98
|
-
|
|
55
|
+
}
|
|
56
|
+
CreateProjectCommand = _ts_decorate([
|
|
57
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
58
|
+
_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.CreateProjectUseCase)),
|
|
59
|
+
_ts_metadata("design:type", Function),
|
|
60
|
+
_ts_metadata("design:paramtypes", [
|
|
61
|
+
"undefined" == typeof CreateProjectUseCase ? Object : CreateProjectUseCase
|
|
62
|
+
])
|
|
63
|
+
], CreateProjectCommand);
|
|
64
|
+
function update_exports_command_ts_decorate(decorators, target, key, desc) {
|
|
65
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
66
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
67
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
68
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
69
|
+
}
|
|
70
|
+
function update_exports_command_ts_metadata(k, v) {
|
|
71
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
72
|
+
}
|
|
73
|
+
function update_exports_command_ts_param(paramIndex, decorator) {
|
|
74
|
+
return function(target, key) {
|
|
75
|
+
decorator(target, key, paramIndex);
|
|
99
76
|
};
|
|
100
77
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const confirm = await utils_prompt("Do you want to continue configuring this existing project? [Y/n]: ");
|
|
115
|
-
if ("" === confirm || "y" === confirm.toLowerCase()) {
|
|
116
|
-
const packageJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(packageJsonPath, "utf8"));
|
|
117
|
-
const projectName = packageJson.name ?? await getValidProjectName(projectNameArg);
|
|
118
|
-
return {
|
|
119
|
-
projectName,
|
|
120
|
-
packageJsonExists
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
console.log("Aborting...");
|
|
124
|
-
throw new Error("User aborted the operation.");
|
|
78
|
+
class UpdateExportsCommand {
|
|
79
|
+
constructor(updateExportsUseCase){
|
|
80
|
+
this.updateExportsUseCase = updateExportsUseCase;
|
|
81
|
+
}
|
|
82
|
+
getCommand() {
|
|
83
|
+
return new __WEBPACK_EXTERNAL_MODULE_commander__.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
|
+
await this.updateExportsUseCase.execute({
|
|
85
|
+
packageFilter: options.package,
|
|
86
|
+
dryRun: Boolean(options.dryRun),
|
|
87
|
+
configPath: options.config
|
|
88
|
+
});
|
|
89
|
+
__WEBPACK_EXTERNAL_MODULE_node_process_786449bf__.exit(0);
|
|
90
|
+
});
|
|
125
91
|
}
|
|
126
|
-
const projectName = await getValidProjectName(projectNameArg);
|
|
127
|
-
return {
|
|
128
|
-
projectName,
|
|
129
|
-
packageJsonExists
|
|
130
|
-
};
|
|
131
92
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"@eslint/eslintrc",
|
|
162
|
-
"eslint-config-next"
|
|
163
|
-
];
|
|
164
|
-
const configGroups = {
|
|
165
|
-
deployment: [
|
|
166
|
-
{
|
|
167
|
-
path: ".vercelignore",
|
|
168
|
-
content: `#-------------------------------------------------------------------------------
|
|
93
|
+
UpdateExportsCommand = update_exports_command_ts_decorate([
|
|
94
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
95
|
+
update_exports_command_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.UpdateExportsUseCase)),
|
|
96
|
+
update_exports_command_ts_metadata("design:type", Function),
|
|
97
|
+
update_exports_command_ts_metadata("design:paramtypes", [
|
|
98
|
+
"undefined" == typeof UpdateExportsUseCase ? Object : UpdateExportsUseCase
|
|
99
|
+
])
|
|
100
|
+
], UpdateExportsCommand);
|
|
101
|
+
function handleError(error, defaultMessage) {
|
|
102
|
+
const message = error instanceof Error ? error.message : defaultMessage;
|
|
103
|
+
console.error(`
|
|
104
|
+
\u{274C} ${message}`);
|
|
105
|
+
}
|
|
106
|
+
function config_service_ts_decorate(decorators, target, key, desc) {
|
|
107
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
108
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
109
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
110
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
111
|
+
}
|
|
112
|
+
class ConfigService {
|
|
113
|
+
getConfigGroups() {
|
|
114
|
+
return this.configGroups;
|
|
115
|
+
}
|
|
116
|
+
constructor(){
|
|
117
|
+
this.configGroups = {
|
|
118
|
+
deployment: [
|
|
119
|
+
{
|
|
120
|
+
path: ".vercelignore",
|
|
121
|
+
content: `#-------------------------------------------------------------------------------
|
|
169
122
|
# Dependencies and package managers
|
|
170
123
|
#-------------------------------------------------------------------------------
|
|
171
124
|
|
|
@@ -231,13 +184,13 @@ Thumbs.db
|
|
|
231
184
|
# Vercel deployment configuration
|
|
232
185
|
.vercel
|
|
233
186
|
`,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
187
|
+
description: "Ignore files that should not be deployed to Vercel"
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
formatting: [
|
|
191
|
+
{
|
|
192
|
+
path: "prettier.config.mjs",
|
|
193
|
+
content: `/**
|
|
241
194
|
* @see https://prettier.io/docs/en/configuration.html
|
|
242
195
|
* @type {import('prettier').Config}
|
|
243
196
|
*/
|
|
@@ -250,11 +203,11 @@ const config = {
|
|
|
250
203
|
|
|
251
204
|
export default config;
|
|
252
205
|
`,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
206
|
+
description: "Prettier configuration for source code formatting"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
path: ".editorconfig",
|
|
210
|
+
content: `# https://editorconfig.org
|
|
258
211
|
root = true
|
|
259
212
|
|
|
260
213
|
[*]
|
|
@@ -278,11 +231,11 @@ indent_style = tab
|
|
|
278
231
|
# Keep in sync with rustfmt
|
|
279
232
|
indent_size = 4
|
|
280
233
|
`,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
234
|
+
description: "Editor configuration for source code formatting"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
path: ".prettierignore",
|
|
238
|
+
content: `# changesets
|
|
286
239
|
.changeset
|
|
287
240
|
|
|
288
241
|
# debug
|
|
@@ -296,13 +249,13 @@ package-lock.json
|
|
|
296
249
|
yarn.lock
|
|
297
250
|
pnpm-lock.yaml
|
|
298
251
|
`,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
252
|
+
description: ""
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
linting: [
|
|
256
|
+
{
|
|
257
|
+
path: "commitlint.config.mjs",
|
|
258
|
+
content: `/**
|
|
306
259
|
* @see https://commitlint.js.org/reference/configuration.html
|
|
307
260
|
* @type {import('@commitlint/types').UserConfig}
|
|
308
261
|
*/
|
|
@@ -310,16 +263,17 @@ const config = {
|
|
|
310
263
|
extends: ["@commitlint/config-conventional"],
|
|
311
264
|
rules: {
|
|
312
265
|
"body-max-line-length": [2, "always", 350],
|
|
266
|
+
"header-max-length": [2, "always", 150],
|
|
313
267
|
},
|
|
314
268
|
};
|
|
315
269
|
|
|
316
270
|
export default config;
|
|
317
271
|
`,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
272
|
+
description: "Commitlint configuration"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
path: "eslint.config.mjs",
|
|
276
|
+
content: `import { config } from "@codefast/eslint-config/next";
|
|
323
277
|
|
|
324
278
|
/**
|
|
325
279
|
* @see https://eslint.org/docs/latest/use/configure/configuration-files
|
|
@@ -329,11 +283,11 @@ const eslintConfig = [...config];
|
|
|
329
283
|
|
|
330
284
|
export default eslintConfig;
|
|
331
285
|
`,
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
286
|
+
description: "ESLint configuration for the project"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
path: "lint-staged.config.mjs",
|
|
290
|
+
content: `import { relative } from "node:path";
|
|
337
291
|
|
|
338
292
|
/**
|
|
339
293
|
* Builds an ESLint command with the given filenames.
|
|
@@ -358,13 +312,13 @@ const config = {
|
|
|
358
312
|
|
|
359
313
|
export default config;
|
|
360
314
|
`,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
315
|
+
description: "Configure lint-staged for pre-commit checks"
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
styles: [
|
|
319
|
+
{
|
|
320
|
+
path: "src/lib/fonts.ts",
|
|
321
|
+
content: `import { cn } from "@codefast/ui";
|
|
368
322
|
import { Geist, Geist_Mono as GeistMono } from "next/font/google";
|
|
369
323
|
|
|
370
324
|
const fontGeistSans = Geist({
|
|
@@ -379,11 +333,11 @@ const fontGeistMono = GeistMono({
|
|
|
379
333
|
|
|
380
334
|
export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
381
335
|
`,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
336
|
+
description: "Font configuration for the application"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
path: "src/app/globals.css",
|
|
340
|
+
content: `@import "tailwindcss";
|
|
387
341
|
|
|
388
342
|
@import "@codefast/ui/styles.css";
|
|
389
343
|
|
|
@@ -466,534 +420,986 @@ export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
|
466
420
|
}
|
|
467
421
|
}
|
|
468
422
|
`,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
};
|
|
473
|
-
function updateFileIfNeeded(filePath, filename, checkFn, updateFn, successMessage, alreadyUpdatedMessage) {
|
|
474
|
-
if (!FileUtils.validatePath(filePath, filename)) return;
|
|
475
|
-
const content = FileUtils.readFile(filePath);
|
|
476
|
-
if (checkFn(content)) return void console.log(`📝 ${alreadyUpdatedMessage}`);
|
|
477
|
-
try {
|
|
478
|
-
const updatedContent = updateFn(content);
|
|
479
|
-
FileUtils.writeFile(filePath, updatedContent);
|
|
480
|
-
console.log(`📝 ${successMessage}`);
|
|
481
|
-
} catch (error) {
|
|
482
|
-
console.warn(`⚠️ Failed to update ${filename}: ${getErrorMessage(error)}`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
function updatePostcssConfig(projectDir) {
|
|
486
|
-
const postcssConfigPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "postcss.config.mjs");
|
|
487
|
-
const typeComment = `/** @type {import('postcss-load-config').Config} */\n`;
|
|
488
|
-
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.");
|
|
489
|
-
}
|
|
490
|
-
function updateLayoutFile(projectDir) {
|
|
491
|
-
const layoutPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "src/app/layout.tsx");
|
|
492
|
-
const htmlTarget = '<html className={cn(fontVariables, "antialiased")} lang="en">';
|
|
493
|
-
updateFileIfNeeded(layoutPath, "src/app/layout.tsx", (content)=>content.includes(htmlTarget), (content)=>{
|
|
494
|
-
const newImports = `import type { Metadata } from "next";
|
|
495
|
-
import type { JSX, ReactNode } from "react";
|
|
496
|
-
import { cn } from "@codefast/ui";
|
|
497
|
-
import { fontVariables } from "@/lib/fonts";
|
|
498
|
-
import "@/app/globals.css";`;
|
|
499
|
-
let result = content;
|
|
500
|
-
result = result.replaceAll(/import\s+{[^}]+}\s+from\s+["']next\/font\/google["'];\s*/g, "");
|
|
501
|
-
result = result.replace(/const\s+geistSans\s*=[^;]+;\s*const\s+geistMono\s*=[^;]+;\s*/, "");
|
|
502
|
-
result = result.replace(/import\s+type\s+{[^}]+}\s+from\s+["']next["'];\s*import\s+["']\.\/globals\.css["'];\s*/, newImports);
|
|
503
|
-
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 {");
|
|
504
|
-
result = result.replace(/<html\s+lang="en"\s*>/, htmlTarget);
|
|
505
|
-
result = result.replace(/<body\s+className={`[^`]*`}\s*>/, "<body>");
|
|
506
|
-
return result;
|
|
507
|
-
}, "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.");
|
|
508
|
-
}
|
|
509
|
-
function updatePackageJson(projectDir) {
|
|
510
|
-
const packageJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "package.json");
|
|
511
|
-
if (!FileUtils.validatePath(packageJsonPath, "package.json")) return;
|
|
512
|
-
try {
|
|
513
|
-
const packageJson = JSON.parse(FileUtils.readFile(packageJsonPath));
|
|
514
|
-
packageJson.scripts = {
|
|
515
|
-
...packageJson.scripts,
|
|
516
|
-
"check-types": "tsc --noEmit",
|
|
517
|
-
"deploy:preview": "vercel deploy --archive=tgz",
|
|
518
|
-
"deploy:prod": "vercel deploy --archive=tgz --prod",
|
|
519
|
-
format: "prettier --write --ignore-unknown .",
|
|
520
|
-
"format:check": "prettier --check --ignore-unknown .",
|
|
521
|
-
lint: "next lint --fix --max-warnings 0",
|
|
522
|
-
"lint:check": "next lint --max-warnings 0",
|
|
523
|
-
"package:install": "pnpm install",
|
|
524
|
-
"package:outdated": "pnpm outdated",
|
|
525
|
-
"package:upgrade": "pnpm update --latest",
|
|
526
|
-
preview: "pnpm build && pnpm start"
|
|
527
|
-
};
|
|
528
|
-
packageJson["simple-git-hooks"] = {
|
|
529
|
-
"pre-commit": "pnpm lint-staged",
|
|
530
|
-
"commit-msg": "pnpm commitlint --edit"
|
|
423
|
+
description: "Global CSS variables for the application"
|
|
424
|
+
}
|
|
425
|
+
]
|
|
531
426
|
};
|
|
532
|
-
FileUtils.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
533
|
-
console.log(`📝 Updated package.json`);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
console.warn(`⚠️ Failed to update package.json: ${getErrorMessage(error)}`);
|
|
536
427
|
}
|
|
537
428
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
429
|
+
ConfigService = config_service_ts_decorate([
|
|
430
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)()
|
|
431
|
+
], ConfigService);
|
|
432
|
+
function create_project_use_case_ts_decorate(decorators, target, key, desc) {
|
|
433
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
434
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
435
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
436
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
437
|
+
}
|
|
438
|
+
function create_project_use_case_ts_metadata(k, v) {
|
|
439
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
440
|
+
}
|
|
441
|
+
function create_project_use_case_ts_param(paramIndex, decorator) {
|
|
442
|
+
return function(target, key) {
|
|
443
|
+
decorator(target, key, paramIndex);
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
class create_project_use_case_CreateProjectUseCase {
|
|
447
|
+
constructor(projectRepository, fileSystemPort, commandExecutorPort, promptPort, configService){
|
|
448
|
+
this.projectRepository = projectRepository;
|
|
449
|
+
this.fileSystemPort = fileSystemPort;
|
|
450
|
+
this.commandExecutorPort = commandExecutorPort;
|
|
451
|
+
this.promptPort = promptPort;
|
|
452
|
+
this.configService = configService;
|
|
453
|
+
}
|
|
454
|
+
async execute(projectName) {
|
|
455
|
+
try {
|
|
456
|
+
this.commandExecutorPort.checkEnvironment();
|
|
457
|
+
const project = await this.checkExistingProject(projectName);
|
|
458
|
+
const configGroups = this.configService.getConfigGroups();
|
|
459
|
+
this.createOrConfigureProject(project, configGroups);
|
|
460
|
+
this.displaySuccessMessage(project);
|
|
461
|
+
return project;
|
|
462
|
+
} catch (error) {
|
|
463
|
+
handleError(error, "Failed to create or configure project");
|
|
464
|
+
throw error;
|
|
465
|
+
} finally{
|
|
466
|
+
this.promptPort.close();
|
|
567
467
|
}
|
|
568
468
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.existsSync(packageJsonPath)) return void console.warn(`⚠️ package.json not found, skipping cleanup.`);
|
|
580
|
-
let packageJson;
|
|
581
|
-
try {
|
|
582
|
-
packageJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.readFileSync(packageJsonPath, "utf8"));
|
|
583
|
-
} catch (error) {
|
|
584
|
-
console.warn(`⚠️ Error reading package.json: ${getErrorMessage(error)}, skipping cleanup.`);
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const dependencies = packageJson.dependencies ?? {};
|
|
588
|
-
const devDependencies = packageJson.devDependencies ?? {};
|
|
589
|
-
const packagesToRemove = PACKAGES_TO_REMOVE.filter((pkg)=>pkg in dependencies || pkg in devDependencies);
|
|
590
|
-
if (packagesToRemove.length > 0) runCommand(`pnpm remove ${packagesToRemove.join(" ")}`);
|
|
591
|
-
else console.log(`ℹ️ No unnecessary packages found in package.json to remove.`);
|
|
592
|
-
}
|
|
593
|
-
function checkEnvironment() {
|
|
594
|
-
try {
|
|
595
|
-
(0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.execSync)("pnpm --version", {
|
|
596
|
-
stdio: "ignore"
|
|
597
|
-
});
|
|
598
|
-
} catch {
|
|
599
|
-
console.error(`❌ PNPM chưa được cài đặt. Vui lòng cài đặt PNPM trước.`);
|
|
600
|
-
process.exit(1);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
function createNextProject(projectName) {
|
|
604
|
-
console.log(`📦 Creating Next.js project...`);
|
|
605
|
-
const flags = '--ts --tailwind --eslint --app --turbo --use-pnpm --src-dir --turbopack --import-alias "@/*"';
|
|
606
|
-
runCommand(`npx create-next-app@latest ${projectName} ${flags}`);
|
|
607
|
-
}
|
|
608
|
-
const createProjectCommand = new __WEBPACK_EXTERNAL_MODULE_commander__.Command().name("create-project [name]").description("Create a new Next.js project with recommended setup").action(async (projectNameArg)=>{
|
|
609
|
-
try {
|
|
610
|
-
checkEnvironment();
|
|
611
|
-
const { projectName, packageJsonExists } = await checkExistingProject(projectNameArg);
|
|
612
|
-
if (!packageJsonExists) {
|
|
613
|
-
console.log(`\n🚀 Starting project creation for ${projectName}...\n`);
|
|
614
|
-
createNextProject(projectName);
|
|
615
|
-
process.chdir(projectName);
|
|
616
|
-
console.log(`📂 Moved to ${projectName}`);
|
|
469
|
+
async checkExistingProject(projectNameArg) {
|
|
470
|
+
return await this.projectRepository.checkExistingProject(projectNameArg);
|
|
471
|
+
}
|
|
472
|
+
createOrConfigureProject(project, configGroups) {
|
|
473
|
+
if (!project.packageJsonExists) {
|
|
474
|
+
console.log(`
|
|
475
|
+
\u{1F680} Starting project creation for ${project.name}...\n`);
|
|
476
|
+
this.projectRepository.createNextProject(project.name);
|
|
477
|
+
process.chdir(project.name);
|
|
478
|
+
console.log(`\u{1F4C2} Moved to ${project.name}`);
|
|
617
479
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
480
|
+
this.updateProjectFiles(project.directory);
|
|
481
|
+
this.commandExecutorPort.installDependencies();
|
|
482
|
+
this.commandExecutorPort.cleanupPackages();
|
|
483
|
+
this.fileSystemPort.createConfigFiles(project.directory, configGroups);
|
|
484
|
+
this.projectRepository.updateNextConfig(project.directory);
|
|
485
|
+
this.projectRepository.updatePackageJson(project.directory);
|
|
486
|
+
this.commandExecutorPort.enableGitHooks();
|
|
487
|
+
this.commandExecutorPort.runFormatter();
|
|
488
|
+
this.commandExecutorPort.runLinter();
|
|
489
|
+
}
|
|
490
|
+
updateProjectFiles(projectDir) {
|
|
491
|
+
this.projectRepository.updateLayoutFile(projectDir);
|
|
492
|
+
this.projectRepository.updatePageFile(projectDir);
|
|
493
|
+
this.projectRepository.updatePostcssConfig(projectDir);
|
|
494
|
+
}
|
|
495
|
+
displaySuccessMessage(project) {
|
|
496
|
+
console.log(`
|
|
497
|
+
\u{2705} Project ${project.packageJsonExists ? "configured" : "created"} successfully!`);
|
|
498
|
+
console.log(`- Project: ${project.name}`);
|
|
634
499
|
console.log("- Next.js with TypeScript");
|
|
635
500
|
console.log("- TailwindCSS and @codefast/ui");
|
|
636
501
|
console.log("- ESLint, Prettier, Commitlint, and Git Hooks");
|
|
637
502
|
console.log("- Lint-staged for pre-commit checks");
|
|
638
|
-
console.log(
|
|
639
|
-
|
|
640
|
-
console.log(`
|
|
641
|
-
|
|
642
|
-
console.
|
|
643
|
-
process.exit(1);
|
|
644
|
-
} finally{
|
|
645
|
-
rl.close();
|
|
646
|
-
process.exit(0);
|
|
503
|
+
console.log(`
|
|
504
|
+
\u{1F4C1} Project directory: ${process.cwd()}`);
|
|
505
|
+
console.log(`
|
|
506
|
+
\u{1F680} To start development:`);
|
|
507
|
+
console.log(`${project.packageJsonExists ? `cd ${project.name} && ` : ""}pnpm dev`);
|
|
647
508
|
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
509
|
+
}
|
|
510
|
+
create_project_use_case_CreateProjectUseCase = create_project_use_case_ts_decorate([
|
|
511
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
512
|
+
create_project_use_case_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.ProjectRepository)),
|
|
513
|
+
create_project_use_case_ts_param(1, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
514
|
+
create_project_use_case_ts_param(2, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.CommandExecutorPort)),
|
|
515
|
+
create_project_use_case_ts_param(3, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.PromptPort)),
|
|
516
|
+
create_project_use_case_ts_param(4, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.ConfigService)),
|
|
517
|
+
create_project_use_case_ts_metadata("design:type", Function),
|
|
518
|
+
create_project_use_case_ts_metadata("design:paramtypes", [
|
|
519
|
+
"undefined" == typeof ProjectRepositoryInterface ? Object : ProjectRepositoryInterface,
|
|
520
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
521
|
+
"undefined" == typeof CommandExecutorPort ? Object : CommandExecutorPort,
|
|
522
|
+
"undefined" == typeof PromptPort ? Object : PromptPort,
|
|
523
|
+
void 0 === ConfigService ? Object : ConfigService
|
|
524
|
+
])
|
|
525
|
+
], create_project_use_case_CreateProjectUseCase);
|
|
526
|
+
function update_exports_use_case_ts_decorate(decorators, target, key, desc) {
|
|
527
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
528
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
529
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
530
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
531
|
+
}
|
|
532
|
+
function update_exports_use_case_ts_metadata(k, v) {
|
|
533
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
534
|
+
}
|
|
535
|
+
function update_exports_use_case_ts_param(paramIndex, decorator) {
|
|
536
|
+
return function(target, key) {
|
|
537
|
+
decorator(target, key, paramIndex);
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
class update_exports_use_case_UpdateExportsUseCase {
|
|
541
|
+
constructor(packageRepository){
|
|
542
|
+
this.packageRepository = packageRepository;
|
|
672
543
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
544
|
+
async execute(options) {
|
|
545
|
+
try {
|
|
546
|
+
console.info("\u2662\u2012 Searching for packages...");
|
|
547
|
+
const packageJsonPaths = await this.packageRepository.findAllPackages(options.configPath);
|
|
548
|
+
if (0 === packageJsonPaths.length) return void console.warn("No packages found.");
|
|
549
|
+
console.log(` Found ${packageJsonPaths.length} packages.`);
|
|
550
|
+
let successCount = 0;
|
|
551
|
+
let skipCount = 0;
|
|
552
|
+
let errorCount = 0;
|
|
553
|
+
for (const packageJsonPath of packageJsonPaths){
|
|
554
|
+
const result = this.packageRepository.processPackage(packageJsonPath, options);
|
|
555
|
+
if (result) successCount++;
|
|
556
|
+
else if (options.packageFilter) skipCount++;
|
|
557
|
+
else errorCount++;
|
|
558
|
+
}
|
|
559
|
+
console.log("\u2662\u2012 Completed exports update.\n");
|
|
560
|
+
console.info(`Stats: ${successCount} succeeded, ${skipCount} skipped, ${errorCount} failed`);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
handleError(error, "Error processing packages");
|
|
563
|
+
throw error;
|
|
689
564
|
}
|
|
690
|
-
const name = parts.at(-1) ?? "";
|
|
691
|
-
const importPath = {
|
|
692
|
-
originalPath: moduleSpecifier,
|
|
693
|
-
directory,
|
|
694
|
-
name,
|
|
695
|
-
exportPath: processExportPath(moduleSpecifier, regexPattern)
|
|
696
|
-
};
|
|
697
|
-
imports.push(importPath);
|
|
698
565
|
}
|
|
699
|
-
|
|
700
|
-
|
|
566
|
+
}
|
|
567
|
+
update_exports_use_case_UpdateExportsUseCase = update_exports_use_case_ts_decorate([
|
|
568
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
569
|
+
update_exports_use_case_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.PackageRepository)),
|
|
570
|
+
update_exports_use_case_ts_metadata("design:type", Function),
|
|
571
|
+
update_exports_use_case_ts_metadata("design:paramtypes", [
|
|
572
|
+
"undefined" == typeof PackageRepository ? Object : PackageRepository
|
|
573
|
+
])
|
|
574
|
+
], update_exports_use_case_UpdateExportsUseCase);
|
|
575
|
+
function cli_adapter_ts_decorate(decorators, target, key, desc) {
|
|
576
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
577
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
578
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
579
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
580
|
+
}
|
|
581
|
+
function cli_adapter_ts_metadata(k, v) {
|
|
582
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
583
|
+
}
|
|
584
|
+
function cli_adapter_ts_param(paramIndex, decorator) {
|
|
585
|
+
return function(target, key) {
|
|
586
|
+
decorator(target, key, paramIndex);
|
|
701
587
|
};
|
|
702
588
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
589
|
+
class CLIAdapter {
|
|
590
|
+
constructor(createProjectCommand, updateExportsCommand, packageInfoService){
|
|
591
|
+
this.createProjectCommand = createProjectCommand;
|
|
592
|
+
this.updateExportsCommand = updateExportsCommand;
|
|
593
|
+
this.packageInfoService = packageInfoService;
|
|
594
|
+
}
|
|
595
|
+
initialize() {
|
|
596
|
+
const program = new __WEBPACK_EXTERNAL_MODULE_commander__.Command();
|
|
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
|
+
}
|
|
599
|
+
}
|
|
600
|
+
CLIAdapter = cli_adapter_ts_decorate([
|
|
601
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
602
|
+
cli_adapter_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.CreateProjectCommand)),
|
|
603
|
+
cli_adapter_ts_param(1, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.UpdateExportsCommand)),
|
|
604
|
+
cli_adapter_ts_param(2, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.PackageInfoService)),
|
|
605
|
+
cli_adapter_ts_metadata("design:type", Function),
|
|
606
|
+
cli_adapter_ts_metadata("design:paramtypes", [
|
|
607
|
+
void 0 === CreateProjectCommand ? Object : CreateProjectCommand,
|
|
608
|
+
void 0 === UpdateExportsCommand ? Object : UpdateExportsCommand,
|
|
609
|
+
"undefined" == typeof PackageInfoServiceInterface ? Object : PackageInfoServiceInterface
|
|
610
|
+
])
|
|
611
|
+
], CLIAdapter);
|
|
612
|
+
const packageConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
613
|
+
cjsOutputPattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Output pattern for CommonJS format, e.g., './dist/cjs/{dir}/{name}.cjs'"),
|
|
614
|
+
esmOutputPattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Output pattern for ESM format, e.g., './dist/esm/{dir}/{name}.js'"),
|
|
615
|
+
packageJsonPath: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Path to the package.json file, e.g., 'package.json'"),
|
|
616
|
+
srcIndexPath: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Path to the source index file, e.g., 'src/index.ts'"),
|
|
617
|
+
typesOutputCjsPattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Output pattern for CommonJS type declarations, e.g., './dist/types/{dir}/{name}.d.cts'"),
|
|
618
|
+
typesOutputPattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Output pattern for type declarations, e.g., './dist/types/{dir}/{name}.d.ts'"),
|
|
619
|
+
exportPathPrefixesToRemove: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().describe("Prefixes to remove from export paths, e.g., ['components']")
|
|
711
620
|
});
|
|
712
|
-
const
|
|
713
|
-
customPackageConfigs: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
|
|
714
|
-
defaultPackageConfig:
|
|
715
|
-
packagesGlob: __WEBPACK_EXTERNAL_MODULE_zod__.z.string()
|
|
621
|
+
const scriptConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
622
|
+
customPackageConfigs: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), packageConfigSchema.partial()).describe("Custom configurations for specific packages"),
|
|
623
|
+
defaultPackageConfig: packageConfigSchema.describe("Default configuration applied to all packages unless overridden"),
|
|
624
|
+
packagesGlob: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Glob pattern to find package.json files, e.g., './packages/**/package.json'")
|
|
716
625
|
});
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
626
|
+
__WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
627
|
+
directory: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Directory containing the import, e.g., 'components'"),
|
|
628
|
+
exportPath: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Resolved export path from the directory, e.g., './button'"),
|
|
629
|
+
name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Name of the import, e.g., 'Button'"),
|
|
630
|
+
originalPath: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Original unresolved path, e.g., './components/button'")
|
|
631
|
+
});
|
|
632
|
+
const exportConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
633
|
+
import: __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
634
|
+
default: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("ESM default export path"),
|
|
635
|
+
types: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("ESM types export path")
|
|
636
|
+
}),
|
|
637
|
+
require: __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
638
|
+
default: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("CommonJS default export path"),
|
|
639
|
+
types: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("CommonJS types export path")
|
|
640
|
+
})
|
|
641
|
+
});
|
|
642
|
+
const PackageExportsSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), __WEBPACK_EXTERNAL_MODULE_zod__.z.union([
|
|
643
|
+
exportConfigSchema,
|
|
644
|
+
__WEBPACK_EXTERNAL_MODULE_zod__.z.string()
|
|
645
|
+
]));
|
|
646
|
+
const packageJsonSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
647
|
+
dependencies: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), __WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().describe("List of runtime dependencies with their versions"),
|
|
648
|
+
devDependencies: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), __WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().describe("List of development dependencies with their versions"),
|
|
649
|
+
exports: PackageExportsSchema.optional().describe("Export mappings for the package"),
|
|
650
|
+
name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Name of the package"),
|
|
651
|
+
scripts: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), __WEBPACK_EXTERNAL_MODULE_zod__.z.string()).describe("Script commands defined for the package"),
|
|
652
|
+
"simple-git-hooks": __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.string(), __WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().describe("Git hooks configuration for the package"),
|
|
653
|
+
version: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional().describe("Version of the package")
|
|
654
|
+
}).catchall(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown());
|
|
655
|
+
function node_command_executor_adapter_ts_decorate(decorators, target, key, desc) {
|
|
656
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
657
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
658
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
659
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
660
|
+
}
|
|
661
|
+
function node_command_executor_adapter_ts_metadata(k, v) {
|
|
662
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
663
|
+
}
|
|
664
|
+
function node_command_executor_adapter_ts_param(paramIndex, decorator) {
|
|
665
|
+
return function(target, key) {
|
|
666
|
+
decorator(target, key, paramIndex);
|
|
747
667
|
};
|
|
748
668
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
},
|
|
765
|
-
"@codefast/style-guide": {
|
|
766
|
-
exportPathPrefixesToRemove: [
|
|
767
|
-
"configs"
|
|
768
|
-
]
|
|
669
|
+
class NodeCommandExecutorAdapter {
|
|
670
|
+
constructor(fileSystemPort, dependencyConfigService){
|
|
671
|
+
this.fileSystemPort = fileSystemPort;
|
|
672
|
+
this.dependencyConfigService = dependencyConfigService;
|
|
673
|
+
}
|
|
674
|
+
runCommand(command) {
|
|
675
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__.execSync)(command, {
|
|
676
|
+
stdio: "inherit"
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
checkEnvironment() {
|
|
680
|
+
try {
|
|
681
|
+
this.runCommand("pnpm --version");
|
|
682
|
+
} catch {
|
|
683
|
+
throw new Error("PNPM is not installed. Please install PNPM first.");
|
|
769
684
|
}
|
|
770
685
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
|
|
686
|
+
installDependencies() {
|
|
687
|
+
console.log(`
|
|
688
|
+
\u{1F4DA} Installing dependencies...`);
|
|
689
|
+
const mainDependencies = this.dependencyConfigService.getMainDependencies();
|
|
690
|
+
if (mainDependencies.length > 0) this.runCommand(`pnpm add ${mainDependencies.join(" ")}`);
|
|
691
|
+
const devDependencies = this.dependencyConfigService.getDevDependencies();
|
|
692
|
+
const allDevDependencies = Object.values(devDependencies).flat().join(" ");
|
|
693
|
+
if (allDevDependencies) this.runCommand(`pnpm add -D ${allDevDependencies}`);
|
|
694
|
+
}
|
|
695
|
+
cleanupPackages() {
|
|
696
|
+
console.log(`
|
|
697
|
+
\u{1F9F9} Cleaning up unnecessary packages...`);
|
|
698
|
+
const packageJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), "package.json");
|
|
699
|
+
if (!this.fileSystemPort.exists(packageJsonPath)) return void console.warn(`\u{26A0}\u{FE0F} package.json not found, skipping cleanup.`);
|
|
700
|
+
let packageJson;
|
|
701
|
+
try {
|
|
702
|
+
packageJson = packageJsonSchema.parse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
703
|
+
} catch (error) {
|
|
704
|
+
console.warn(`\u{26A0}\u{FE0F} Error reading package.json: ${error instanceof Error ? error.message : "Unknown error"}, skipping cleanup.`);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const dependencies = packageJson.dependencies ?? {};
|
|
708
|
+
const devDependencies = packageJson.devDependencies ?? {};
|
|
709
|
+
const packagesToRemove = this.dependencyConfigService.getPackagesToRemove().filter((pkg)=>pkg in dependencies || pkg in devDependencies);
|
|
710
|
+
if (packagesToRemove.length > 0) this.runCommand(`pnpm remove ${packagesToRemove.join(" ")}`);
|
|
711
|
+
else console.log(`\u{2139}\u{FE0F} No unnecessary packages found in package.json to remove.`);
|
|
712
|
+
}
|
|
713
|
+
enableGitHooks() {
|
|
714
|
+
console.log(`
|
|
715
|
+
\u{1F504} Activating git hooks...`);
|
|
716
|
+
this.runCommand("pnpm simple-git-hooks");
|
|
717
|
+
}
|
|
718
|
+
runFormatter() {
|
|
719
|
+
console.log(`
|
|
720
|
+
\u{1F4DD} Formatting files with Prettier...`);
|
|
721
|
+
this.runCommand("pnpm format");
|
|
722
|
+
}
|
|
723
|
+
runLinter() {
|
|
724
|
+
console.log(`
|
|
725
|
+
\u{1F50D} Running ESLint to check code style...`);
|
|
726
|
+
this.runCommand("pnpm lint");
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
NodeCommandExecutorAdapter = node_command_executor_adapter_ts_decorate([
|
|
730
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
731
|
+
node_command_executor_adapter_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
732
|
+
node_command_executor_adapter_ts_param(1, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.DependencyConfigService)),
|
|
733
|
+
node_command_executor_adapter_ts_metadata("design:type", Function),
|
|
734
|
+
node_command_executor_adapter_ts_metadata("design:paramtypes", [
|
|
735
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
736
|
+
"undefined" == typeof DependencyConfigServiceInterface ? Object : DependencyConfigServiceInterface
|
|
737
|
+
])
|
|
738
|
+
], NodeCommandExecutorAdapter);
|
|
739
|
+
function node_file_system_adapter_ts_decorate(decorators, target, key, desc) {
|
|
740
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
741
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
742
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
743
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
744
|
+
}
|
|
745
|
+
class NodeFileSystemAdapter {
|
|
746
|
+
exists(filePath) {
|
|
779
747
|
return __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(filePath);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
},
|
|
786
|
-
readJsonFile (filePath) {
|
|
748
|
+
}
|
|
749
|
+
access(filePath) {
|
|
750
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].accessSync(filePath, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].constants.W_OK);
|
|
751
|
+
}
|
|
752
|
+
readFile(filePath) {
|
|
787
753
|
try {
|
|
788
|
-
|
|
789
|
-
return JSON.parse(content);
|
|
754
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(filePath, "utf8");
|
|
790
755
|
} catch (error) {
|
|
791
|
-
|
|
792
|
-
return null;
|
|
756
|
+
throw new Error(`Failed to read file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
793
757
|
}
|
|
794
|
-
}
|
|
795
|
-
|
|
758
|
+
}
|
|
759
|
+
writeFile(filePath, content) {
|
|
796
760
|
try {
|
|
797
|
-
|
|
798
|
-
|
|
761
|
+
const dir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(filePath);
|
|
762
|
+
this.createDirectory(dir);
|
|
763
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(filePath, content);
|
|
799
764
|
} catch (error) {
|
|
800
|
-
|
|
801
|
-
return false;
|
|
765
|
+
throw new Error(`Failed to write to file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
802
766
|
}
|
|
803
|
-
},
|
|
804
|
-
getAnalysisDir (packageDir) {
|
|
805
|
-
const outputDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(packageDir, EXPORTS_ANALYSIS_DIR);
|
|
806
|
-
this.ensureDirectoryExists(outputDir);
|
|
807
|
-
return outputDir;
|
|
808
|
-
},
|
|
809
|
-
createBackupFilename (baseFilename) {
|
|
810
|
-
const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
811
|
-
return `${baseFilename}.backup.${timestamp}`;
|
|
812
767
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
768
|
+
createDirectory(dirPath) {
|
|
769
|
+
if (!this.exists(dirPath)) __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(dirPath, {
|
|
770
|
+
recursive: true
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
writeConfigFile(filePath, content) {
|
|
774
|
+
this.writeFile(filePath, content);
|
|
775
|
+
console.log(`\u{1F4DD} Created ${filePath}`);
|
|
776
|
+
}
|
|
777
|
+
createConfigFiles(projectDir, configGroups) {
|
|
778
|
+
console.log(`
|
|
779
|
+
\u{1F4DD} Creating configuration files...`);
|
|
780
|
+
for (const [category, configs] of Object.entries(configGroups)){
|
|
781
|
+
console.log(`
|
|
782
|
+
\u{1F4C2} Setting up ${category} configurations:`);
|
|
783
|
+
for (const config of configs){
|
|
784
|
+
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, config.path);
|
|
785
|
+
this.writeConfigFile(fullPath, config.content);
|
|
786
|
+
if (config.description) console.log(`\u{2139}\u{FE0F} ${config.path}: ${config.description}`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
833
789
|
}
|
|
834
790
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
function
|
|
839
|
-
|
|
840
|
-
|
|
791
|
+
NodeFileSystemAdapter = node_file_system_adapter_ts_decorate([
|
|
792
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)()
|
|
793
|
+
], NodeFileSystemAdapter);
|
|
794
|
+
function node_prompt_adapter_ts_decorate(decorators, target, key, desc) {
|
|
795
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
796
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
797
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
798
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
841
799
|
}
|
|
842
|
-
function
|
|
843
|
-
|
|
800
|
+
function node_prompt_adapter_ts_metadata(k, v) {
|
|
801
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
844
802
|
}
|
|
845
|
-
|
|
846
|
-
|
|
803
|
+
class NodePromptAdapter {
|
|
804
|
+
constructor(){
|
|
805
|
+
this.rl = __WEBPACK_EXTERNAL_MODULE_node_readline_91c31510__["default"].createInterface({
|
|
806
|
+
input: process.stdin,
|
|
807
|
+
output: process.stdout
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
async prompt(message) {
|
|
811
|
+
return new Promise((resolve)=>{
|
|
812
|
+
this.rl.question(message, (answer)=>{
|
|
813
|
+
resolve(answer.trim());
|
|
814
|
+
});
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
close() {
|
|
818
|
+
this.rl.close();
|
|
819
|
+
}
|
|
847
820
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
821
|
+
NodePromptAdapter = node_prompt_adapter_ts_decorate([
|
|
822
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
823
|
+
node_prompt_adapter_ts_metadata("design:type", Function),
|
|
824
|
+
node_prompt_adapter_ts_metadata("design:paramtypes", [])
|
|
825
|
+
], NodePromptAdapter);
|
|
826
|
+
function ts_morph_analysis_adapter_ts_decorate(decorators, target, key, desc) {
|
|
827
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
828
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
829
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
830
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
851
831
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
832
|
+
class TsMorphAnalysisAdapter {
|
|
833
|
+
analyzeImports(indexFilePath, packageConfig) {
|
|
834
|
+
const project = new __WEBPACK_EXTERNAL_MODULE_ts_morph_07c7ce60__.Project();
|
|
835
|
+
let sourceFile;
|
|
836
|
+
try {
|
|
837
|
+
sourceFile = project.addSourceFileAtPath(indexFilePath);
|
|
838
|
+
} catch (error) {
|
|
839
|
+
console.error(`Error loading source file at ${indexFilePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
840
|
+
return {
|
|
841
|
+
imports: []
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
const imports = [];
|
|
845
|
+
const prefixesToRemove = packageConfig.exportPathPrefixesToRemove ?? [];
|
|
846
|
+
const regexPattern = new RegExp(`^.?\\/?(?:${prefixesToRemove.join("|")})\\/(.*)$`);
|
|
847
|
+
for (const exportDecl of sourceFile.getExportDeclarations()){
|
|
848
|
+
let moduleSpecifier = exportDecl.getModuleSpecifierValue();
|
|
849
|
+
if (!moduleSpecifier) continue;
|
|
850
|
+
if (moduleSpecifier.startsWith("@/")) moduleSpecifier = `./${moduleSpecifier.slice(2)}`;
|
|
851
|
+
const isExternal = !moduleSpecifier.startsWith(".");
|
|
852
|
+
if (isExternal) continue;
|
|
853
|
+
const parts = moduleSpecifier.split("/").filter(Boolean);
|
|
854
|
+
if (parts.length < 2) continue;
|
|
855
|
+
let directory = parts.length <= 1 ? "." : parts.slice(0, -1).join("/");
|
|
856
|
+
if (directory.startsWith("./")) directory = directory.slice(2);
|
|
857
|
+
const name = parts.at(-1) ?? "";
|
|
858
|
+
const exportPath = this.processExportPath(moduleSpecifier, regexPattern);
|
|
859
|
+
imports.push({
|
|
860
|
+
originalPath: moduleSpecifier,
|
|
861
|
+
directory,
|
|
862
|
+
name,
|
|
863
|
+
exportPath
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
imports
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
processExportPath(modulePath, regexPattern) {
|
|
871
|
+
const match = modulePath.match(regexPattern);
|
|
872
|
+
if (match) {
|
|
873
|
+
const remainingPath = match[1];
|
|
874
|
+
return remainingPath.startsWith("./") ? remainingPath : `./${remainingPath}`;
|
|
864
875
|
}
|
|
876
|
+
return modulePath;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
TsMorphAnalysisAdapter = ts_morph_analysis_adapter_ts_decorate([
|
|
880
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)()
|
|
881
|
+
], TsMorphAnalysisAdapter);
|
|
882
|
+
function file_system_package_repository_ts_decorate(decorators, target, key, desc) {
|
|
883
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
884
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
885
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
886
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
887
|
+
}
|
|
888
|
+
function file_system_package_repository_ts_metadata(k, v) {
|
|
889
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
890
|
+
}
|
|
891
|
+
function file_system_package_repository_ts_param(paramIndex, decorator) {
|
|
892
|
+
return function(target, key) {
|
|
893
|
+
decorator(target, key, paramIndex);
|
|
865
894
|
};
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
895
|
+
}
|
|
896
|
+
class FileSystemPackageRepository {
|
|
897
|
+
constructor(fileSystemPort, analysisPort, fileSystemUtility){
|
|
898
|
+
this.fileSystemPort = fileSystemPort;
|
|
899
|
+
this.analysisPort = analysisPort;
|
|
900
|
+
this.fileSystemUtility = fileSystemUtility;
|
|
901
|
+
this.DEFAULT_IGNORE_PATTERN = [
|
|
902
|
+
"**/node_modules/**"
|
|
903
|
+
];
|
|
904
|
+
this.cachedConfig = null;
|
|
905
|
+
this.defaultConfig = {
|
|
906
|
+
packagesGlob: "./packages/**/package.json",
|
|
907
|
+
defaultPackageConfig: {
|
|
908
|
+
cjsOutputPattern: "./dist/cjs/{dir}/{name}.cjs",
|
|
909
|
+
esmOutputPattern: "./dist/esm/{dir}/{name}.js",
|
|
910
|
+
packageJsonPath: "package.json",
|
|
911
|
+
srcIndexPath: "src/index.ts",
|
|
912
|
+
typesOutputCjsPattern: "./dist/types/{dir}/{name}.d.ts",
|
|
913
|
+
typesOutputPattern: "./dist/types/{dir}/{name}.d.ts"
|
|
877
914
|
},
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
915
|
+
customPackageConfigs: {
|
|
916
|
+
"@codefast/ui": {
|
|
917
|
+
exportPathPrefixesToRemove: [
|
|
918
|
+
"components"
|
|
919
|
+
]
|
|
920
|
+
},
|
|
921
|
+
"@codefast/style-guide": {
|
|
922
|
+
exportPathPrefixesToRemove: [
|
|
923
|
+
"configs"
|
|
924
|
+
]
|
|
925
|
+
}
|
|
881
926
|
}
|
|
882
927
|
};
|
|
883
928
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
console.
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
console.
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
console.
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
console.
|
|
932
|
-
|
|
929
|
+
async findAllPackages(configPath) {
|
|
930
|
+
const config = this.getConfig(configPath);
|
|
931
|
+
return await (0, __WEBPACK_EXTERNAL_MODULE_glob__.glob)(config.packagesGlob, {
|
|
932
|
+
ignore: this.DEFAULT_IGNORE_PATTERN
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
processPackage(packageJsonPath, options) {
|
|
936
|
+
const packageDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(packageJsonPath);
|
|
937
|
+
let packageJson;
|
|
938
|
+
try {
|
|
939
|
+
packageJson = JSON.parse(this.fileSystemPort.readFile(packageJsonPath));
|
|
940
|
+
} catch (error) {
|
|
941
|
+
console.error(`Failed to parse ${packageJsonPath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
const packageName = packageJson.name;
|
|
945
|
+
if (options.packageFilter && packageName !== options.packageFilter) {
|
|
946
|
+
console.debug(`Skipping ${packageName} (does not match filter)`);
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
console.info(`\u{2662}\u{2012} Processing package: ${packageName}`);
|
|
950
|
+
const config = this.getConfig(options.configPath);
|
|
951
|
+
const packageConfig = this.getPackageConfig(packageName, config);
|
|
952
|
+
const srcIndexPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(packageDir, packageConfig.srcIndexPath);
|
|
953
|
+
if (!this.fileSystemPort.exists(srcIndexPath)) {
|
|
954
|
+
console.error(`\u{23B9} \u{26D4}\u{FE0E} Source file not found at ${srcIndexPath}`);
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
console.info(`\u{23B9} Analyzing imports from ${srcIndexPath}...`);
|
|
958
|
+
const analysis = this.analyzeImports(srcIndexPath, packageConfig);
|
|
959
|
+
if (0 === analysis.imports.length) {
|
|
960
|
+
console.warn(`\u{23B9} \u{26D4}\u{FE0E} No imports found to analyze in ${packageName}`);
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
console.log(`\u{23B9} Analysis complete. Found ${analysis.imports.length} subpath exports.`);
|
|
964
|
+
this.saveExportsAnalysis(packageDir, analysis);
|
|
965
|
+
const newExports = this.generateExports(packageName, analysis.imports, packageJson.exports ?? {}, config);
|
|
966
|
+
const currentExportsCount = packageJson.exports ? Object.keys(packageJson.exports).length : 0;
|
|
967
|
+
const newExportsCount = Object.keys(newExports).length;
|
|
968
|
+
console.info(`\u{23B9} Exports: ${currentExportsCount} -> ${newExportsCount}`);
|
|
969
|
+
if (options.dryRun) {
|
|
970
|
+
this.saveExportsPreview(packageDir, newExports);
|
|
971
|
+
console.warn(`\u{23B9} Saved exports preview to .exports-analysis`);
|
|
972
|
+
console.warn(`\u{23B9} Dry run: no changes saved for ${packageName}`);
|
|
973
|
+
return true;
|
|
974
|
+
}
|
|
975
|
+
this.fileSystemUtility.backupFile(packageJsonPath, ".exports-analysis");
|
|
976
|
+
console.log(`\u{23B9} Backed up ${packageJsonPath}`);
|
|
977
|
+
const updatedPackageJson = {
|
|
978
|
+
...packageJson,
|
|
979
|
+
exports: newExports
|
|
980
|
+
};
|
|
981
|
+
this.fileSystemPort.writeFile(packageJsonPath, `${JSON.stringify(updatedPackageJson, null, 2)}\n`);
|
|
982
|
+
console.log(`\u{23B9} Updated exports for ${packageName}`);
|
|
933
983
|
return true;
|
|
934
984
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
985
|
+
analyzeImports(indexFilePath, packageConfig) {
|
|
986
|
+
return this.analysisPort.analyzeImports(indexFilePath, packageConfig);
|
|
987
|
+
}
|
|
988
|
+
generateExports(packageName, imports, existingExports, config) {
|
|
989
|
+
const packageConfig = this.getPackageConfig(packageName, config);
|
|
990
|
+
const exports = {
|
|
991
|
+
".": existingExports["."] ?? {
|
|
992
|
+
import: {
|
|
993
|
+
default: "./dist/esm/index.js",
|
|
994
|
+
types: "./dist/types/index.d.ts"
|
|
995
|
+
},
|
|
996
|
+
require: {
|
|
997
|
+
default: "./dist/cjs/index.cjs",
|
|
998
|
+
types: "./dist/types/index.d.cts"
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
if (existingExports["./styles.css"]) exports["./styles.css"] = existingExports["./styles.css"];
|
|
1003
|
+
for (const importPath of imports){
|
|
1004
|
+
const { directory, name, exportPath } = importPath;
|
|
1005
|
+
const esmOutput = this.formatOutputPath(packageConfig.esmOutputPattern, directory, name);
|
|
1006
|
+
const cjsOutput = this.formatOutputPath(packageConfig.cjsOutputPattern, directory, name);
|
|
1007
|
+
const typesOutput = this.formatOutputPath(packageConfig.typesOutputPattern, directory, name);
|
|
1008
|
+
const typesCjsOutput = this.formatOutputPath(packageConfig.typesOutputCjsPattern, directory, name);
|
|
1009
|
+
exports[exportPath] = {
|
|
1010
|
+
import: {
|
|
1011
|
+
default: esmOutput,
|
|
1012
|
+
types: typesOutput
|
|
1013
|
+
},
|
|
1014
|
+
require: {
|
|
1015
|
+
default: cjsOutput,
|
|
1016
|
+
types: typesCjsOutput
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
return exports;
|
|
1021
|
+
}
|
|
1022
|
+
getConfig(configPath) {
|
|
1023
|
+
if (this.cachedConfig && !configPath) return this.cachedConfig;
|
|
1024
|
+
const userConfig = this.loadConfigFile(configPath);
|
|
1025
|
+
const config = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.merge)({}, this.defaultConfig, userConfig);
|
|
1026
|
+
if (!configPath) this.cachedConfig = config;
|
|
1027
|
+
return config;
|
|
1028
|
+
}
|
|
1029
|
+
loadConfigFile(configPath) {
|
|
1030
|
+
if (!configPath) return {};
|
|
1031
|
+
try {
|
|
1032
|
+
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(configPath);
|
|
1033
|
+
if (!this.fileSystemPort.exists(fullPath)) {
|
|
1034
|
+
console.warn(`Configuration file not found at ${fullPath}`);
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
const configContent = this.fileSystemPort.readFile(fullPath);
|
|
1038
|
+
return scriptConfigSchema.parse(JSON.parse(configContent));
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
console.error(`Error reading configuration file: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1041
|
+
return {};
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
getPackageConfig(packageName, config) {
|
|
1045
|
+
const customConfig = config.customPackageConfigs[packageName] ?? {};
|
|
1046
|
+
return {
|
|
1047
|
+
...config.defaultPackageConfig,
|
|
1048
|
+
...customConfig
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
formatOutputPath(pattern, directory, name) {
|
|
1052
|
+
const dirPart = "." === directory ? "" : `${directory}/`;
|
|
1053
|
+
return pattern.replace("{dir}/", dirPart).replace("{dir}", directory).replace("{name}", name);
|
|
1054
|
+
}
|
|
1055
|
+
saveExportsAnalysis(packageDir, analysis) {
|
|
1056
|
+
const outputDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(packageDir, ".exports-analysis");
|
|
1057
|
+
this.fileSystemPort.createDirectory(outputDir);
|
|
1058
|
+
this.fileSystemPort.writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(outputDir, "exports-analysis.json"), JSON.stringify(analysis, null, 2));
|
|
1059
|
+
}
|
|
1060
|
+
saveExportsPreview(packageDir, exports) {
|
|
1061
|
+
const outputDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(packageDir, ".exports-analysis");
|
|
1062
|
+
this.fileSystemPort.createDirectory(outputDir);
|
|
1063
|
+
this.fileSystemPort.writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(outputDir, "exports-preview.json"), JSON.stringify(exports, null, 2));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
FileSystemPackageRepository = file_system_package_repository_ts_decorate([
|
|
1067
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
1068
|
+
file_system_package_repository_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
1069
|
+
file_system_package_repository_ts_param(1, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.AnalysisPort)),
|
|
1070
|
+
file_system_package_repository_ts_param(2, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemUtility)),
|
|
1071
|
+
file_system_package_repository_ts_metadata("design:type", Function),
|
|
1072
|
+
file_system_package_repository_ts_metadata("design:paramtypes", [
|
|
1073
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
1074
|
+
"undefined" == typeof AnalysisPort ? Object : AnalysisPort,
|
|
1075
|
+
"undefined" == typeof FileSystemUtility ? Object : FileSystemUtility
|
|
1076
|
+
])
|
|
1077
|
+
], FileSystemPackageRepository);
|
|
1078
|
+
const projectSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
|
|
1079
|
+
name: __WEBPACK_EXTERNAL_MODULE_zod__.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
|
+
message: "Project name must be URL-friendly (letters, numbers, hyphens, underscores, dots; no @ or scoped packages)"
|
|
1081
|
+
}).refine((name)=>"." !== name && ".." !== name, {
|
|
1082
|
+
message: "Project name cannot be '.' or '..'"
|
|
1083
|
+
}).refine((name)=>!/^(?<reserved>CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name), {
|
|
1084
|
+
message: "Project name is a reserved system name"
|
|
1085
|
+
}),
|
|
1086
|
+
directory: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().describe("Project directory path"),
|
|
1087
|
+
packageJsonExists: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().describe("Whether package.json exists in the project directory")
|
|
1088
|
+
});
|
|
1089
|
+
function file_system_project_repository_ts_decorate(decorators, target, key, desc) {
|
|
1090
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1091
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
1092
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1093
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1094
|
+
}
|
|
1095
|
+
function file_system_project_repository_ts_metadata(k, v) {
|
|
1096
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
1097
|
+
}
|
|
1098
|
+
function file_system_project_repository_ts_param(paramIndex, decorator) {
|
|
1099
|
+
return function(target, key) {
|
|
1100
|
+
decorator(target, key, paramIndex);
|
|
939
1101
|
};
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1102
|
+
}
|
|
1103
|
+
class FileSystemProjectRepository {
|
|
1104
|
+
constructor(fileSystemPort, commandExecutorPort, promptPort, fileSystemUtility){
|
|
1105
|
+
this.fileSystemPort = fileSystemPort;
|
|
1106
|
+
this.commandExecutorPort = commandExecutorPort;
|
|
1107
|
+
this.promptPort = promptPort;
|
|
1108
|
+
this.fileSystemUtility = fileSystemUtility;
|
|
943
1109
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
let skipCount = 0;
|
|
956
|
-
let errorCount = 0;
|
|
957
|
-
for (const packageJsonPath of packageJsonPaths){
|
|
958
|
-
const result = processPackage(packageJsonPath, options);
|
|
959
|
-
if (result) successCount++;
|
|
960
|
-
else if (options.packageFilter) skipCount++;
|
|
961
|
-
else errorCount++;
|
|
1110
|
+
async checkExistingProject(projectName) {
|
|
1111
|
+
let fullPath = process.cwd();
|
|
1112
|
+
let name = "";
|
|
1113
|
+
const packageJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), "package.json");
|
|
1114
|
+
const packageJsonExists = this.fileSystemPort.exists(packageJsonPath);
|
|
1115
|
+
if (packageJsonExists) {
|
|
1116
|
+
const result = packageJsonSchema.safeParse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
1117
|
+
if (result.success) name = result.data.name;
|
|
1118
|
+
} else {
|
|
1119
|
+
name = await this.getValidProjectName(projectName);
|
|
1120
|
+
fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(process.cwd(), name);
|
|
962
1121
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1122
|
+
return {
|
|
1123
|
+
name,
|
|
1124
|
+
directory: fullPath,
|
|
1125
|
+
packageJsonExists
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
createNextProject(projectName) {
|
|
1129
|
+
const flags = '--ts --tailwind --eslint --app --turbo --use-pnpm --src-dir --turbopack --import-alias "@/*"';
|
|
1130
|
+
this.commandExecutorPort.runCommand(`npx create-next-app@latest ${projectName} ${flags}`);
|
|
1131
|
+
}
|
|
1132
|
+
updateLayoutFile(projectDir) {
|
|
1133
|
+
const layoutPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "src", "app", "layout.tsx");
|
|
1134
|
+
const htmlTarget = '<html className={cn(fontVariables, "antialiased")} lang="en">';
|
|
1135
|
+
this.fileSystemUtility.updateFileIfNeeded(layoutPath, (content)=>content.includes(htmlTarget), (content)=>{
|
|
1136
|
+
const newImports = `import type { Metadata } from "next";
|
|
1137
|
+
import type { JSX, ReactNode } from "react";
|
|
1138
|
+
import { cn } from "@codefast/ui";
|
|
1139
|
+
import { fontVariables } from "@/lib/fonts";
|
|
1140
|
+
import "@/app/globals.css";`;
|
|
1141
|
+
let result = content;
|
|
1142
|
+
result = result.replaceAll(/import\s+{[^}]+}\s+from\s+["']next\/font\/google["'];\s*/g, "");
|
|
1143
|
+
result = result.replace(/const\s+geistSans\s*=[^;]+;\s*const\s+geistMono\s*=[^;]+;\s*/, "");
|
|
1144
|
+
result = result.replace(/import\s+type\s+{[^}]+}\s+from\s+["']next["'];\s*import\s+["']\.\/globals\.css["'];\s*/, newImports);
|
|
1145
|
+
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 {");
|
|
1146
|
+
result = result.replace(/<html\s+lang="en"\s*>/, htmlTarget);
|
|
1147
|
+
result = result.replace(/<body\s+className={`[^`]*`}\s*>/, "<body>");
|
|
1148
|
+
return result;
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
updatePageFile(projectDir) {
|
|
1152
|
+
const pagePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "src", "app", "page.tsx");
|
|
1153
|
+
this.fileSystemUtility.updateFileIfNeeded(pagePath, (content)=>content.includes("): JSX.Element"), (content)=>{
|
|
1154
|
+
let result = content;
|
|
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}`;
|
|
1156
|
+
result = result.replace(/export default function Home\(\) {/, "export default function Home(): JSX.Element {");
|
|
1157
|
+
return result;
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
updatePostcssConfig(projectDir) {
|
|
1161
|
+
const postcssConfigPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "postcss.config.mjs");
|
|
1162
|
+
const typeComment = `/** @type {import('postcss-load-config').Config} */\n`;
|
|
1163
|
+
this.fileSystemUtility.updateFileIfNeeded(postcssConfigPath, (content)=>content.includes(typeComment), (content)=>content.replace("const config = {", `${typeComment}const config = {`));
|
|
1164
|
+
}
|
|
1165
|
+
updateNextConfig(projectDir) {
|
|
1166
|
+
const nextConfigPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "next.config.ts");
|
|
1167
|
+
const optimizePackagesConfig = 'optimizePackageImports: ["@codefast/ui"]';
|
|
1168
|
+
this.fileSystemUtility.updateFileIfNeeded(nextConfigPath, (content)=>content.includes(optimizePackagesConfig), (content)=>content.replace(/const nextConfig: NextConfig = \{/, `const nextConfig: NextConfig = {
|
|
1169
|
+
experimental: {
|
|
1170
|
+
optimizePackageImports: ["@codefast/ui"],
|
|
1171
|
+
},`));
|
|
1172
|
+
}
|
|
1173
|
+
updatePackageJson(projectDir) {
|
|
1174
|
+
const packageJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(projectDir, "package.json");
|
|
1175
|
+
if (!this.fileSystemPort.exists(packageJsonPath)) return void console.warn(`\u{26A0}\u{FE0F} package.json not found, skipping update.`);
|
|
1176
|
+
let packageJson;
|
|
1177
|
+
try {
|
|
1178
|
+
packageJson = packageJsonSchema.parse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
1179
|
+
} catch {
|
|
1180
|
+
console.warn(`Failed to parse ${packageJsonPath}, skipping update.`);
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
packageJson.scripts = {
|
|
1184
|
+
...packageJson.scripts,
|
|
1185
|
+
"check-types": "tsc --noEmit",
|
|
1186
|
+
"deploy:preview": "vercel deploy --archive=tgz",
|
|
1187
|
+
"deploy:prod": "vercel deploy --archive=tgz --prod",
|
|
1188
|
+
format: "prettier --write --ignore-unknown .",
|
|
1189
|
+
"format:check": "prettier --check --ignore-unknown .",
|
|
1190
|
+
lint: "next lint --fix --max-warnings 0",
|
|
1191
|
+
"lint:check": "next lint --max-warnings 0",
|
|
1192
|
+
"package:install": "pnpm install",
|
|
1193
|
+
"package:outdated": "pnpm outdated",
|
|
1194
|
+
"package:upgrade": "pnpm update --latest",
|
|
1195
|
+
preview: "pnpm build && pnpm start"
|
|
1196
|
+
};
|
|
1197
|
+
packageJson["simple-git-hooks"] = {
|
|
1198
|
+
"pre-commit": "pnpm lint-staged",
|
|
1199
|
+
"commit-msg": "pnpm commitlint --edit"
|
|
1200
|
+
};
|
|
1201
|
+
this.fileSystemPort.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
1202
|
+
console.log(`\u{1F4DD} Updated ${packageJsonPath}`);
|
|
1203
|
+
}
|
|
1204
|
+
async getValidProjectName(initialName, attempts = 0, maxAttempts = 3) {
|
|
1205
|
+
const projectName = initialName ?? await this.promptPort.prompt("Enter project name: ");
|
|
1206
|
+
const result = projectSchema.safeParse({
|
|
1207
|
+
name: projectName,
|
|
1208
|
+
directory: "",
|
|
1209
|
+
packageJsonExists: false
|
|
1210
|
+
});
|
|
1211
|
+
if (result.success) {
|
|
1212
|
+
const fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(process.cwd(), projectName);
|
|
1213
|
+
if (this.fileSystemPort.exists(fullPath)) throw new Error(`A directory named "${projectName}" already exists.`);
|
|
1214
|
+
try {
|
|
1215
|
+
this.fileSystemPort.access(process.cwd());
|
|
1216
|
+
} catch {
|
|
1217
|
+
throw new Error("Cannot create project: No write permission in current directory.");
|
|
1218
|
+
}
|
|
1219
|
+
return projectName;
|
|
1220
|
+
}
|
|
1221
|
+
if (attempts >= maxAttempts - 1) throw new Error("Exceeded maximum attempts to enter a valid project name.");
|
|
1222
|
+
console.error(`\u{274C} ${result.error.message} (${maxAttempts - attempts - 1} attempts remaining)`);
|
|
1223
|
+
return this.getValidProjectName(void 0, attempts + 1, maxAttempts);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
FileSystemProjectRepository = file_system_project_repository_ts_decorate([
|
|
1227
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
1228
|
+
file_system_project_repository_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
1229
|
+
file_system_project_repository_ts_param(1, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.CommandExecutorPort)),
|
|
1230
|
+
file_system_project_repository_ts_param(2, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.PromptPort)),
|
|
1231
|
+
file_system_project_repository_ts_param(3, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemUtility)),
|
|
1232
|
+
file_system_project_repository_ts_metadata("design:type", Function),
|
|
1233
|
+
file_system_project_repository_ts_metadata("design:paramtypes", [
|
|
1234
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort,
|
|
1235
|
+
"undefined" == typeof CommandExecutorPort ? Object : CommandExecutorPort,
|
|
1236
|
+
"undefined" == typeof PromptPort ? Object : PromptPort,
|
|
1237
|
+
"undefined" == typeof FileSystemUtility ? Object : FileSystemUtility
|
|
1238
|
+
])
|
|
1239
|
+
], FileSystemProjectRepository);
|
|
1240
|
+
function dependency_config_service_ts_decorate(decorators, target, key, desc) {
|
|
1241
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1242
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
1243
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1244
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1245
|
+
}
|
|
1246
|
+
class DependencyConfigService {
|
|
1247
|
+
getMainDependencies() {
|
|
1248
|
+
return this.MAIN_DEPENDENCIES;
|
|
1249
|
+
}
|
|
1250
|
+
getDevDependencies() {
|
|
1251
|
+
return this.DEV_DEPENDENCIES;
|
|
1252
|
+
}
|
|
1253
|
+
getPackagesToRemove() {
|
|
1254
|
+
return this.PACKAGES_TO_REMOVE;
|
|
1255
|
+
}
|
|
1256
|
+
constructor(){
|
|
1257
|
+
this.MAIN_DEPENDENCIES = [
|
|
1258
|
+
"@codefast/ui",
|
|
1259
|
+
"@codefast/hooks",
|
|
1260
|
+
"recharts",
|
|
1261
|
+
"react-hook-form",
|
|
1262
|
+
"next-themes",
|
|
1263
|
+
"date-fns",
|
|
1264
|
+
"lucide-react"
|
|
1265
|
+
];
|
|
1266
|
+
this.DEV_DEPENDENCIES = {
|
|
1267
|
+
commitLint: [
|
|
1268
|
+
"@commitlint/cli",
|
|
1269
|
+
"@commitlint/config-conventional",
|
|
1270
|
+
"@commitlint/types"
|
|
1271
|
+
],
|
|
1272
|
+
gitTools: [
|
|
1273
|
+
"simple-git-hooks"
|
|
1274
|
+
],
|
|
1275
|
+
formatting: [
|
|
1276
|
+
"prettier",
|
|
1277
|
+
"prettier-plugin-packagejson",
|
|
1278
|
+
"prettier-plugin-tailwindcss",
|
|
1279
|
+
"lint-staged"
|
|
1280
|
+
],
|
|
1281
|
+
linting: [
|
|
1282
|
+
"@codefast/eslint-config"
|
|
1283
|
+
]
|
|
1284
|
+
};
|
|
1285
|
+
this.PACKAGES_TO_REMOVE = [
|
|
1286
|
+
"@eslint/eslintrc",
|
|
1287
|
+
"eslint-config-next"
|
|
1288
|
+
];
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
DependencyConfigService = dependency_config_service_ts_decorate([
|
|
1292
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)()
|
|
1293
|
+
], DependencyConfigService);
|
|
1294
|
+
function node_package_info_service_ts_decorate(decorators, target, key, desc) {
|
|
1295
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1296
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
1297
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1298
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1299
|
+
}
|
|
1300
|
+
function node_package_info_service_ts_metadata(k, v) {
|
|
1301
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
1302
|
+
}
|
|
1303
|
+
function node_package_info_service_ts_param(paramIndex, decorator) {
|
|
1304
|
+
return function(target, key) {
|
|
1305
|
+
decorator(target, key, paramIndex);
|
|
975
1306
|
};
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
process.exit(1);
|
|
981
|
-
} finally{
|
|
982
|
-
process.exit(0);
|
|
1307
|
+
}
|
|
1308
|
+
class NodePackageInfoService {
|
|
1309
|
+
constructor(fileSystemPort){
|
|
1310
|
+
this.fileSystemPort = fileSystemPort;
|
|
983
1311
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1312
|
+
getPackageVersion() {
|
|
1313
|
+
try {
|
|
1314
|
+
const __filename = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url);
|
|
1315
|
+
const __dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(__filename);
|
|
1316
|
+
const packageJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(__dirname, "..", "package.json");
|
|
1317
|
+
const packageJsonResult = packageJsonSchema.parse(JSON.parse(this.fileSystemPort.readFile(packageJsonPath)));
|
|
1318
|
+
return packageJsonResult.version ?? "0.0.0";
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
console.warn(`Failed to read package version: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1321
|
+
return "unknown";
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
NodePackageInfoService = node_package_info_service_ts_decorate([
|
|
1326
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
1327
|
+
node_package_info_service_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
1328
|
+
node_package_info_service_ts_metadata("design:type", Function),
|
|
1329
|
+
node_package_info_service_ts_metadata("design:paramtypes", [
|
|
1330
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort
|
|
1331
|
+
])
|
|
1332
|
+
], NodePackageInfoService);
|
|
1333
|
+
function file_system_utility_ts_decorate(decorators, target, key, desc) {
|
|
1334
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1335
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
1336
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1337
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1338
|
+
}
|
|
1339
|
+
function file_system_utility_ts_metadata(k, v) {
|
|
1340
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
1341
|
+
}
|
|
1342
|
+
function file_system_utility_ts_param(paramIndex, decorator) {
|
|
1343
|
+
return function(target, key) {
|
|
1344
|
+
decorator(target, key, paramIndex);
|
|
1345
|
+
};
|
|
990
1346
|
}
|
|
991
|
-
|
|
992
|
-
|
|
1347
|
+
class file_system_utility_FileSystemUtility {
|
|
1348
|
+
constructor(fileSystemPort){
|
|
1349
|
+
this.fileSystemPort = fileSystemPort;
|
|
1350
|
+
}
|
|
1351
|
+
updateFileIfNeeded(filePath, checkFn, updateFn) {
|
|
1352
|
+
if (!this.fileSystemPort.exists(filePath)) return;
|
|
1353
|
+
const currentContent = this.fileSystemPort.readFile(filePath);
|
|
1354
|
+
if (checkFn(currentContent)) return void console.log(`\u{2139}\u{FE0F} ${filePath} is already up to date`);
|
|
1355
|
+
try {
|
|
1356
|
+
const updatedContent = updateFn(currentContent);
|
|
1357
|
+
this.fileSystemPort.writeFile(filePath, updatedContent);
|
|
1358
|
+
console.log(`\u{1F4DD} Updated ${filePath}`);
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
console.warn(`\u{26A0}\u{FE0F} Failed to update ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
backupFile(filePath, backupDir) {
|
|
1364
|
+
try {
|
|
1365
|
+
const content = this.fileSystemPort.readFile(filePath);
|
|
1366
|
+
const baseName = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(filePath);
|
|
1367
|
+
const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
1368
|
+
const backupPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(filePath), backupDir, `${baseName}.backup.${timestamp}`);
|
|
1369
|
+
this.fileSystemPort.createDirectory(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(backupPath));
|
|
1370
|
+
this.fileSystemPort.writeFile(backupPath, content);
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
console.error(`Error backing up ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
993
1375
|
}
|
|
1376
|
+
file_system_utility_FileSystemUtility = file_system_utility_ts_decorate([
|
|
1377
|
+
(0, __WEBPACK_EXTERNAL_MODULE_inversify__.injectable)(),
|
|
1378
|
+
file_system_utility_ts_param(0, (0, __WEBPACK_EXTERNAL_MODULE_inversify__.inject)(TYPES.FileSystemPort)),
|
|
1379
|
+
file_system_utility_ts_metadata("design:type", Function),
|
|
1380
|
+
file_system_utility_ts_metadata("design:paramtypes", [
|
|
1381
|
+
"undefined" == typeof FileSystemPort ? Object : FileSystemPort
|
|
1382
|
+
])
|
|
1383
|
+
], file_system_utility_FileSystemUtility);
|
|
1384
|
+
const container = new __WEBPACK_EXTERNAL_MODULE_inversify__.Container();
|
|
1385
|
+
container.bind(TYPES.ProjectRepository).to(FileSystemProjectRepository).inSingletonScope();
|
|
1386
|
+
container.bind(TYPES.PackageRepository).to(FileSystemPackageRepository).inSingletonScope();
|
|
1387
|
+
container.bind(TYPES.PackageInfoService).to(NodePackageInfoService).inSingletonScope();
|
|
1388
|
+
container.bind(TYPES.DependencyConfigService).to(DependencyConfigService).inSingletonScope();
|
|
1389
|
+
container.bind(TYPES.ConfigService).to(ConfigService).inSingletonScope();
|
|
1390
|
+
container.bind(TYPES.FileSystemPort).to(NodeFileSystemAdapter).inSingletonScope();
|
|
1391
|
+
container.bind(TYPES.CommandExecutorPort).to(NodeCommandExecutorAdapter).inSingletonScope();
|
|
1392
|
+
container.bind(TYPES.PromptPort).to(NodePromptAdapter).inSingletonScope();
|
|
1393
|
+
container.bind(TYPES.AnalysisPort).to(TsMorphAnalysisAdapter).inSingletonScope();
|
|
1394
|
+
container.bind(TYPES.CreateProjectUseCase).to(create_project_use_case_CreateProjectUseCase).inSingletonScope();
|
|
1395
|
+
container.bind(TYPES.UpdateExportsUseCase).to(update_exports_use_case_UpdateExportsUseCase).inSingletonScope();
|
|
1396
|
+
container.bind(TYPES.CreateProjectCommand).to(CreateProjectCommand).inSingletonScope();
|
|
1397
|
+
container.bind(TYPES.UpdateExportsCommand).to(UpdateExportsCommand).inSingletonScope();
|
|
1398
|
+
container.bind(TYPES.CLIAdapter).to(CLIAdapter).inSingletonScope();
|
|
1399
|
+
container.bind(TYPES.FileSystemUtility).to(file_system_utility_FileSystemUtility).inSingletonScope();
|
|
994
1400
|
function main() {
|
|
995
|
-
const
|
|
996
|
-
|
|
1401
|
+
const cliAdapter = container.get(TYPES.CLIAdapter);
|
|
1402
|
+
cliAdapter.initialize();
|
|
997
1403
|
}
|
|
998
1404
|
main();
|
|
999
1405
|
|