@codefast/cli 0.3.5 → 0.3.7-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 +6 -324
- package/README.md +301 -87
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/src/index.d.ts +3 -0
- package/dist/cjs/src/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/src/index.d.ts +3 -0
- package/dist/esm/src/index.d.ts.map +1 -0
- package/package.json +51 -21
- package/dist/index.cjs +0 -1440
- package/dist/index.cjs.map +0 -1
- package/dist/index.js +0 -1406
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,1406 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
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
|
-
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")
|
|
30
|
-
};
|
|
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;
|
|
36
|
-
}
|
|
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);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
class CreateProjectCommand {
|
|
46
|
-
constructor(createProjectUseCase){
|
|
47
|
-
this.createProjectUseCase = createProjectUseCase;
|
|
48
|
-
}
|
|
49
|
-
getCommand() {
|
|
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
|
-
await this.createProjectUseCase.execute(projectName);
|
|
52
|
-
external_node_process_default.exit(0);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
CreateProjectCommand = _ts_decorate([
|
|
57
|
-
injectable(),
|
|
58
|
-
_ts_param(0, 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);
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
class UpdateExportsCommand {
|
|
79
|
-
constructor(updateExportsUseCase){
|
|
80
|
-
this.updateExportsUseCase = updateExportsUseCase;
|
|
81
|
-
}
|
|
82
|
-
getCommand() {
|
|
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
|
-
await this.updateExportsUseCase.execute({
|
|
85
|
-
packageFilter: options.package,
|
|
86
|
-
dryRun: Boolean(options.dryRun),
|
|
87
|
-
configPath: options.config
|
|
88
|
-
});
|
|
89
|
-
exit(0);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
UpdateExportsCommand = update_exports_command_ts_decorate([
|
|
94
|
-
injectable(),
|
|
95
|
-
update_exports_command_ts_param(0, 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: `#-------------------------------------------------------------------------------
|
|
122
|
-
# Dependencies and package managers
|
|
123
|
-
#-------------------------------------------------------------------------------
|
|
124
|
-
|
|
125
|
-
# Node dependencies
|
|
126
|
-
node_modules
|
|
127
|
-
.pnpm-store
|
|
128
|
-
.yarn
|
|
129
|
-
|
|
130
|
-
#-------------------------------------------------------------------------------
|
|
131
|
-
# Development and environment
|
|
132
|
-
#-------------------------------------------------------------------------------
|
|
133
|
-
|
|
134
|
-
# Environment variables (except examples)
|
|
135
|
-
.env*
|
|
136
|
-
!.env.example
|
|
137
|
-
|
|
138
|
-
# Build artifacts
|
|
139
|
-
.next
|
|
140
|
-
build
|
|
141
|
-
dist
|
|
142
|
-
.git
|
|
143
|
-
.github
|
|
144
|
-
.turbo
|
|
145
|
-
.changeset
|
|
146
|
-
.eslintcache
|
|
147
|
-
|
|
148
|
-
# Debug logs
|
|
149
|
-
npm-debug.log*
|
|
150
|
-
yarn-debug.log*
|
|
151
|
-
|
|
152
|
-
#-------------------------------------------------------------------------------
|
|
153
|
-
# Testing
|
|
154
|
-
#-------------------------------------------------------------------------------
|
|
155
|
-
|
|
156
|
-
# Test coverage reports and config snapshots
|
|
157
|
-
coverage
|
|
158
|
-
*.test.*
|
|
159
|
-
*.e2e.*
|
|
160
|
-
|
|
161
|
-
#-------------------------------------------------------------------------------
|
|
162
|
-
# Editor and IDE configuration
|
|
163
|
-
#-------------------------------------------------------------------------------
|
|
164
|
-
|
|
165
|
-
# IDE project files
|
|
166
|
-
.idea
|
|
167
|
-
*.suo
|
|
168
|
-
*.ntvs*
|
|
169
|
-
*.njsproj
|
|
170
|
-
*.sln
|
|
171
|
-
|
|
172
|
-
#-------------------------------------------------------------------------------
|
|
173
|
-
# Operating system files
|
|
174
|
-
#-------------------------------------------------------------------------------
|
|
175
|
-
|
|
176
|
-
# System metadata files
|
|
177
|
-
.DS_Store
|
|
178
|
-
Thumbs.db
|
|
179
|
-
|
|
180
|
-
#-------------------------------------------------------------------------------
|
|
181
|
-
# Deployment
|
|
182
|
-
#-------------------------------------------------------------------------------
|
|
183
|
-
|
|
184
|
-
# Vercel deployment configuration
|
|
185
|
-
.vercel
|
|
186
|
-
`,
|
|
187
|
-
description: "Ignore files that should not be deployed to Vercel"
|
|
188
|
-
}
|
|
189
|
-
],
|
|
190
|
-
formatting: [
|
|
191
|
-
{
|
|
192
|
-
path: "prettier.config.mjs",
|
|
193
|
-
content: `/**
|
|
194
|
-
* @see https://prettier.io/docs/en/configuration.html
|
|
195
|
-
* @type {import('prettier').Config}
|
|
196
|
-
*/
|
|
197
|
-
const config = {
|
|
198
|
-
plugins: ["prettier-plugin-packagejson", "prettier-plugin-tailwindcss"],
|
|
199
|
-
printWidth: 100,
|
|
200
|
-
tailwindAttributes: ["classNames"],
|
|
201
|
-
tailwindFunctions: ["tv"],
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
export default config;
|
|
205
|
-
`,
|
|
206
|
-
description: "Prettier configuration for source code formatting"
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
path: ".editorconfig",
|
|
210
|
-
content: `# https://editorconfig.org
|
|
211
|
-
root = true
|
|
212
|
-
|
|
213
|
-
[*]
|
|
214
|
-
charset = utf-8
|
|
215
|
-
insert_final_newline = true
|
|
216
|
-
|
|
217
|
-
end_of_line = lf
|
|
218
|
-
indent_style = space
|
|
219
|
-
indent_size = 2
|
|
220
|
-
max_line_length = 120
|
|
221
|
-
|
|
222
|
-
trim_trailing_whitespace = true
|
|
223
|
-
|
|
224
|
-
[Makefile]
|
|
225
|
-
indent_style = tab
|
|
226
|
-
|
|
227
|
-
[{go.mod,go.sum,*.go}]
|
|
228
|
-
indent_style = tab
|
|
229
|
-
|
|
230
|
-
[*.rs]
|
|
231
|
-
# Keep in sync with rustfmt
|
|
232
|
-
indent_size = 4
|
|
233
|
-
`,
|
|
234
|
-
description: "Editor configuration for source code formatting"
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
path: ".prettierignore",
|
|
238
|
-
content: `# changesets
|
|
239
|
-
.changeset
|
|
240
|
-
|
|
241
|
-
# debug
|
|
242
|
-
npm-debug.log*
|
|
243
|
-
yarn-debug.log*
|
|
244
|
-
yarn-error.log*
|
|
245
|
-
.pnpm-debug.log*
|
|
246
|
-
|
|
247
|
-
# lock files
|
|
248
|
-
package-lock.json
|
|
249
|
-
yarn.lock
|
|
250
|
-
pnpm-lock.yaml
|
|
251
|
-
`,
|
|
252
|
-
description: ""
|
|
253
|
-
}
|
|
254
|
-
],
|
|
255
|
-
linting: [
|
|
256
|
-
{
|
|
257
|
-
path: "commitlint.config.mjs",
|
|
258
|
-
content: `/**
|
|
259
|
-
* @see https://commitlint.js.org/reference/configuration.html
|
|
260
|
-
* @type {import('@commitlint/types').UserConfig}
|
|
261
|
-
*/
|
|
262
|
-
const config = {
|
|
263
|
-
extends: ["@commitlint/config-conventional"],
|
|
264
|
-
rules: {
|
|
265
|
-
"body-max-line-length": [2, "always", 350],
|
|
266
|
-
"header-max-length": [2, "always", 150],
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
export default config;
|
|
271
|
-
`,
|
|
272
|
-
description: "Commitlint configuration"
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
path: "eslint.config.mjs",
|
|
276
|
-
content: `import { config } from "@codefast/eslint-config/next";
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @see https://eslint.org/docs/latest/use/configure/configuration-files
|
|
280
|
-
* @type {import('eslint').Linter.Config[]}
|
|
281
|
-
*/
|
|
282
|
-
const eslintConfig = [...config];
|
|
283
|
-
|
|
284
|
-
export default eslintConfig;
|
|
285
|
-
`,
|
|
286
|
-
description: "ESLint configuration for the project"
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
path: "lint-staged.config.mjs",
|
|
290
|
-
content: `import { relative } from "node:path";
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Builds an ESLint command with the given filenames.
|
|
294
|
-
*
|
|
295
|
-
* @param {string[]} filenames - An array of filenames to be passed to the
|
|
296
|
-
* ESLint command.
|
|
297
|
-
* @returns {string} - The generated ESLint command.
|
|
298
|
-
*/
|
|
299
|
-
function buildEslintCommand(filenames) {
|
|
300
|
-
return \`next lint --fix --max-warnings 0 --file \${filenames.map((file) => relative(import.meta.dirname, file)).
|
|
301
|
-
join(" --file ")}\`;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @see https://www.npmjs.com/package/lint-staged
|
|
306
|
-
* @type {import('lint-staged').Configuration}
|
|
307
|
-
*/
|
|
308
|
-
const config = {
|
|
309
|
-
"*.{js,mjs,jsx,ts,tsx}": [buildEslintCommand, "prettier --list-different --write"],
|
|
310
|
-
"*.{json,css,md,mdx}": ["prettier --list-different --write"],
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
export default config;
|
|
314
|
-
`,
|
|
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";
|
|
322
|
-
import { Geist, Geist_Mono as GeistMono } from "next/font/google";
|
|
323
|
-
|
|
324
|
-
const fontGeistSans = Geist({
|
|
325
|
-
subsets: ["latin"],
|
|
326
|
-
variable: "--font-geist-sans",
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
const fontGeistMono = GeistMono({
|
|
330
|
-
subsets: ["latin"],
|
|
331
|
-
variable: "--font-geist-mono",
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
export const fontVariables = cn(fontGeistSans.variable, fontGeistMono.variable);
|
|
335
|
-
`,
|
|
336
|
-
description: "Font configuration for the application"
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
path: "src/app/globals.css",
|
|
340
|
-
content: `@import "tailwindcss";
|
|
341
|
-
|
|
342
|
-
@import "@codefast/ui/styles.css";
|
|
343
|
-
|
|
344
|
-
@source '../../node_modules/@codefast/ui';
|
|
345
|
-
|
|
346
|
-
@custom-variant dark (&:where(.dark, .dark *));
|
|
347
|
-
|
|
348
|
-
@layer base {
|
|
349
|
-
:root {
|
|
350
|
-
--font-sans: var(--font-geist-sans);
|
|
351
|
-
--font-mono: var(--font-geist-mono);
|
|
352
|
-
|
|
353
|
-
--input: var(--color-neutral-200);
|
|
354
|
-
--border: var(--color-neutral-200);
|
|
355
|
-
--ring: var(--color-neutral-400);
|
|
356
|
-
--background: var(--color-white);
|
|
357
|
-
--foreground: var(--color-neutral-950);
|
|
358
|
-
--primary: var(--color-sky-500);
|
|
359
|
-
--primary-foreground: var(--color-neutral-50);
|
|
360
|
-
--secondary: var(--color-neutral-100);
|
|
361
|
-
--secondary-foreground: var(--color-neutral-900);
|
|
362
|
-
--destructive: var(--color-red-600);
|
|
363
|
-
--accent: var(--color-neutral-100);
|
|
364
|
-
--accent-foreground: var(--color-neutral-900);
|
|
365
|
-
--muted: var(--color-neutral-100);
|
|
366
|
-
--muted-foreground: var(--color-neutral-500);
|
|
367
|
-
--popover: var(--color-white);
|
|
368
|
-
--popover-foreground: var(--color-neutral-950);
|
|
369
|
-
--popover-overlay: --alpha(var(--color-neutral-900) / 20%);
|
|
370
|
-
--card: var(--color-white);
|
|
371
|
-
--card-foreground: var(--color-neutral-950);
|
|
372
|
-
--sidebar: var(--color-neutral-50);
|
|
373
|
-
--sidebar-foreground: var(--color-neutral-950);
|
|
374
|
-
--sidebar-primary: var(--color-sky-500);
|
|
375
|
-
--sidebar-primary-foreground: var(--color-neutral-50);
|
|
376
|
-
--sidebar-accent: var(--color-neutral-100);
|
|
377
|
-
--sidebar-accent-foreground: var(--color-neutral-900);
|
|
378
|
-
--sidebar-border: var(--color-neutral-200);
|
|
379
|
-
--sidebar-ring: var(--color-neutral-400);
|
|
380
|
-
--chart-1: var(--color-orange-600);
|
|
381
|
-
--chart-2: var(--color-teal-600);
|
|
382
|
-
--chart-3: var(--color-cyan-600);
|
|
383
|
-
--chart-4: var(--color-amber-600);
|
|
384
|
-
--chart-5: var(--color-amber-500);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
.dark {
|
|
388
|
-
--input: var(--color-neutral-700);
|
|
389
|
-
--border: --alpha(var(--color-neutral-700) / 50%);
|
|
390
|
-
--ring: var(--color-neutral-500);
|
|
391
|
-
--background: var(--color-neutral-950);
|
|
392
|
-
--foreground: var(--color-neutral-50);
|
|
393
|
-
--primary: var(--color-sky-700);
|
|
394
|
-
--primary-foreground: var(--color-neutral-50);
|
|
395
|
-
--secondary: var(--color-neutral-800);
|
|
396
|
-
--secondary-foreground: var(--color-neutral-50);
|
|
397
|
-
--destructive: var(--color-red-400);
|
|
398
|
-
--accent: var(--color-neutral-700);
|
|
399
|
-
--accent-foreground: var(--color-neutral-50);
|
|
400
|
-
--muted: var(--color-neutral-800);
|
|
401
|
-
--muted-foreground: var(--color-neutral-400);
|
|
402
|
-
--popover: var(--color-neutral-800);
|
|
403
|
-
--popover-foreground: var(--color-neutral-50);
|
|
404
|
-
--popover-overlay: --alpha(var(--color-neutral-900) / 80%);
|
|
405
|
-
--card: var(--color-neutral-900);
|
|
406
|
-
--card-foreground: var(--color-neutral-50);
|
|
407
|
-
--sidebar: var(--color-neutral-900);
|
|
408
|
-
--sidebar-foreground: var(--color-neutral-50);
|
|
409
|
-
--sidebar-primary: var(--color-sky-700);
|
|
410
|
-
--sidebar-primary-foreground: var(--color-neutral-50);
|
|
411
|
-
--sidebar-accent: var(--color-neutral-800);
|
|
412
|
-
--sidebar-accent-foreground: var(--color-neutral-50);
|
|
413
|
-
--sidebar-border: var(--color-neutral-800);
|
|
414
|
-
--sidebar-ring: var(--color-neutral-600);
|
|
415
|
-
--chart-1: var(--color-blue-700);
|
|
416
|
-
--chart-2: var(--color-emerald-500);
|
|
417
|
-
--chart-3: var(--color-amber-500);
|
|
418
|
-
--chart-4: var(--color-purple-500);
|
|
419
|
-
--chart-5: var(--color-rose-500);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
`,
|
|
423
|
-
description: "Global CSS variables for the application"
|
|
424
|
-
}
|
|
425
|
-
]
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
ConfigService = config_service_ts_decorate([
|
|
430
|
-
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();
|
|
467
|
-
}
|
|
468
|
-
}
|
|
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}`);
|
|
479
|
-
}
|
|
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}`);
|
|
499
|
-
console.log("- Next.js with TypeScript");
|
|
500
|
-
console.log("- TailwindCSS and @codefast/ui");
|
|
501
|
-
console.log("- ESLint, Prettier, Commitlint, and Git Hooks");
|
|
502
|
-
console.log("- Lint-staged for pre-commit checks");
|
|
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`);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
create_project_use_case_CreateProjectUseCase = create_project_use_case_ts_decorate([
|
|
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
|
-
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;
|
|
543
|
-
}
|
|
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;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
update_exports_use_case_UpdateExportsUseCase = update_exports_use_case_ts_decorate([
|
|
568
|
-
injectable(),
|
|
569
|
-
update_exports_use_case_ts_param(0, 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);
|
|
587
|
-
};
|
|
588
|
-
}
|
|
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 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
|
-
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
|
-
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 = 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
|
-
});
|
|
621
|
-
const scriptConfigSchema = z.object({
|
|
622
|
-
customPackageConfigs: z.record(z.string(), packageConfigSchema.partial()).describe("Custom configurations for specific packages"),
|
|
623
|
-
defaultPackageConfig: packageConfigSchema.describe("Default configuration applied to all packages unless overridden"),
|
|
624
|
-
packagesGlob: z.string().describe("Glob pattern to find package.json files, e.g., './packages/**/package.json'")
|
|
625
|
-
});
|
|
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
|
-
});
|
|
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
|
-
}),
|
|
637
|
-
require: z.object({
|
|
638
|
-
default: z.string().describe("CommonJS default export path"),
|
|
639
|
-
types: z.string().describe("CommonJS types export path")
|
|
640
|
-
})
|
|
641
|
-
});
|
|
642
|
-
const PackageExportsSchema = z.record(z.string(), z.union([
|
|
643
|
-
exportConfigSchema,
|
|
644
|
-
z.string()
|
|
645
|
-
]));
|
|
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
|
-
exports: PackageExportsSchema.optional().describe("Export mappings for the package"),
|
|
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
|
-
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);
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
class NodeCommandExecutorAdapter {
|
|
670
|
-
constructor(fileSystemPort, dependencyConfigService){
|
|
671
|
-
this.fileSystemPort = fileSystemPort;
|
|
672
|
-
this.dependencyConfigService = dependencyConfigService;
|
|
673
|
-
}
|
|
674
|
-
runCommand(command) {
|
|
675
|
-
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.");
|
|
684
|
-
}
|
|
685
|
-
}
|
|
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 = external_node_path_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
|
-
injectable(),
|
|
731
|
-
node_command_executor_adapter_ts_param(0, inject(TYPES.FileSystemPort)),
|
|
732
|
-
node_command_executor_adapter_ts_param(1, 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) {
|
|
747
|
-
return external_node_fs_default.existsSync(filePath);
|
|
748
|
-
}
|
|
749
|
-
access(filePath) {
|
|
750
|
-
external_node_fs_default.accessSync(filePath, external_node_fs_default.constants.W_OK);
|
|
751
|
-
}
|
|
752
|
-
readFile(filePath) {
|
|
753
|
-
try {
|
|
754
|
-
return external_node_fs_default.readFileSync(filePath, "utf8");
|
|
755
|
-
} catch (error) {
|
|
756
|
-
throw new Error(`Failed to read file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
writeFile(filePath, content) {
|
|
760
|
-
try {
|
|
761
|
-
const dir = external_node_path_default.dirname(filePath);
|
|
762
|
-
this.createDirectory(dir);
|
|
763
|
-
external_node_fs_default.writeFileSync(filePath, content);
|
|
764
|
-
} catch (error) {
|
|
765
|
-
throw new Error(`Failed to write to file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
createDirectory(dirPath) {
|
|
769
|
-
if (!this.exists(dirPath)) external_node_fs_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 = external_node_path_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
|
-
}
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
NodeFileSystemAdapter = node_file_system_adapter_ts_decorate([
|
|
792
|
-
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;
|
|
799
|
-
}
|
|
800
|
-
function node_prompt_adapter_ts_metadata(k, v) {
|
|
801
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
802
|
-
}
|
|
803
|
-
class NodePromptAdapter {
|
|
804
|
-
constructor(){
|
|
805
|
-
this.rl = external_node_readline_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
|
-
}
|
|
820
|
-
}
|
|
821
|
-
NodePromptAdapter = node_prompt_adapter_ts_decorate([
|
|
822
|
-
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;
|
|
831
|
-
}
|
|
832
|
-
class TsMorphAnalysisAdapter {
|
|
833
|
-
analyzeImports(indexFilePath, packageConfig) {
|
|
834
|
-
const project = new 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}`;
|
|
875
|
-
}
|
|
876
|
-
return modulePath;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
TsMorphAnalysisAdapter = ts_morph_analysis_adapter_ts_decorate([
|
|
880
|
-
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);
|
|
894
|
-
};
|
|
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"
|
|
914
|
-
},
|
|
915
|
-
customPackageConfigs: {
|
|
916
|
-
"@codefast/ui": {
|
|
917
|
-
exportPathPrefixesToRemove: [
|
|
918
|
-
"components"
|
|
919
|
-
]
|
|
920
|
-
},
|
|
921
|
-
"@codefast/style-guide": {
|
|
922
|
-
exportPathPrefixesToRemove: [
|
|
923
|
-
"configs"
|
|
924
|
-
]
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
async findAllPackages(configPath) {
|
|
930
|
-
const config = this.getConfig(configPath);
|
|
931
|
-
return await glob(config.packagesGlob, {
|
|
932
|
-
ignore: this.DEFAULT_IGNORE_PATTERN
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
processPackage(packageJsonPath, options) {
|
|
936
|
-
const packageDir = external_node_path_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 = external_node_path_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}`);
|
|
983
|
-
return true;
|
|
984
|
-
}
|
|
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 = 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 = external_node_path_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 = external_node_path_default.join(packageDir, ".exports-analysis");
|
|
1057
|
-
this.fileSystemPort.createDirectory(outputDir);
|
|
1058
|
-
this.fileSystemPort.writeFile(external_node_path_default.join(outputDir, "exports-analysis.json"), JSON.stringify(analysis, null, 2));
|
|
1059
|
-
}
|
|
1060
|
-
saveExportsPreview(packageDir, exports) {
|
|
1061
|
-
const outputDir = external_node_path_default.join(packageDir, ".exports-analysis");
|
|
1062
|
-
this.fileSystemPort.createDirectory(outputDir);
|
|
1063
|
-
this.fileSystemPort.writeFile(external_node_path_default.join(outputDir, "exports-preview.json"), JSON.stringify(exports, null, 2));
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
FileSystemPackageRepository = file_system_package_repository_ts_decorate([
|
|
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
|
-
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 = 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
|
-
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: z.string().describe("Project directory path"),
|
|
1087
|
-
packageJsonExists: 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);
|
|
1101
|
-
};
|
|
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;
|
|
1109
|
-
}
|
|
1110
|
-
async checkExistingProject(projectName) {
|
|
1111
|
-
let fullPath = process.cwd();
|
|
1112
|
-
let name = "";
|
|
1113
|
-
const packageJsonPath = external_node_path_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 = external_node_path_default.resolve(process.cwd(), name);
|
|
1121
|
-
}
|
|
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 = external_node_path_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 = external_node_path_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 = external_node_path_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 = external_node_path_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 = external_node_path_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 = external_node_path_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
|
-
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
|
-
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
|
-
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);
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
class NodePackageInfoService {
|
|
1309
|
-
constructor(fileSystemPort){
|
|
1310
|
-
this.fileSystemPort = fileSystemPort;
|
|
1311
|
-
}
|
|
1312
|
-
getPackageVersion() {
|
|
1313
|
-
try {
|
|
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
|
-
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
|
-
injectable(),
|
|
1327
|
-
node_package_info_service_ts_param(0, 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
|
-
};
|
|
1346
|
-
}
|
|
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 = external_node_path_default.basename(filePath);
|
|
1367
|
-
const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
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
|
-
this.fileSystemPort.writeFile(backupPath, content);
|
|
1371
|
-
} catch (error) {
|
|
1372
|
-
console.error(`Error backing up ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
file_system_utility_FileSystemUtility = file_system_utility_ts_decorate([
|
|
1377
|
-
injectable(),
|
|
1378
|
-
file_system_utility_ts_param(0, 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 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();
|
|
1400
|
-
function main() {
|
|
1401
|
-
const cliAdapter = container.get(TYPES.CLIAdapter);
|
|
1402
|
-
cliAdapter.initialize();
|
|
1403
|
-
}
|
|
1404
|
-
main();
|
|
1405
|
-
|
|
1406
|
-
//# sourceMappingURL=index.js.map
|