1
- import type { Command } from "commander" ;
1
+ import { Command } from "commander" ;
2
2
3
3
import { checkExistingProject } from "@/commands/create-project/check-existing-project" ;
4
4
import {
@@ -14,87 +14,76 @@ import { checkEnvironment } from "@/commands/create-project/environment";
14
14
import { createNextProject } from "@/commands/create-project/next-project" ;
15
15
import { getErrorMessage , rl , runCommand } from "@/commands/create-project/utils" ;
16
16
17
- /**
18
- * Sets up the "create-project" command in the provided CLI program. This command allows users
19
- * to create a new Next.js project with a recommended configuration.
20
- *
21
- * The "create-project" command includes features such as scaffolding a Next.js project, applying
22
- * TypeScript, TailwindCSS, ESLint, Prettier, Git hooks, and other tools, ensuring a streamlined
23
- * development experience.
24
- *
25
- * @param program - The CLI program instance in which the command will be registered.
26
- */
27
- export function createProjectCommand ( program : Command ) : void {
28
- program
29
- . command ( "create-project [name]" )
30
- . description ( "Create a new Next.js project with recommended setup" )
31
- . action ( async ( projectNameArg ) => {
32
- try {
33
- // Check environment (PNPM, write permissions)
34
- checkEnvironment ( ) ;
35
-
36
- // Check if package.json exists and get the project name
37
- const { projectName, packageJsonExists } = await checkExistingProject ( projectNameArg ) ;
38
-
39
- if ( ! packageJsonExists ) {
40
- console . log ( `\n🚀 Starting project creation for ${ projectName } ...\n` ) ;
41
- createNextProject ( projectName ) ;
42
- process . chdir ( projectName ) ;
43
- console . log ( `📂 Moved to ${ projectName } ` ) ;
44
- }
45
-
46
- // Update layout.tsx to use fontVariables
47
- updateLayoutFile ( process . cwd ( ) ) ;
48
-
49
- // Update page.tsx to add JSX.Element return types
50
- updatePageFile ( process . cwd ( ) ) ;
51
-
52
- // Edit the postcss.config.mjs file
53
- updatePostcssConfig ( process . cwd ( ) ) ;
54
-
55
- // Install dependencies
56
- installDependencies ( ) ;
57
-
58
- // Remove unwanted packages
59
- cleanupPackages ( ) ;
60
-
61
- // Create configuration files
62
- createConfigFiles ( process . cwd ( ) ) ;
63
-
64
- // Update next.config.ts with experimental configuration
65
- updateNextConfig ( process . cwd ( ) ) ;
66
-
67
- // Update package.json
68
- updatePackageJson ( process . cwd ( ) ) ;
69
-
70
- // Enable git hooks
71
- console . log ( `\n🔄 Activating git hooks...` ) ;
72
- runCommand ( "pnpm simple-git-hooks" ) ;
73
-
74
- // Run Prettier to format the file
75
- console . log ( `\n📝 Formatting files with Prettier...` ) ;
76
- runCommand ( "pnpm format" ) ;
77
-
78
- // Run ESLint
79
- console . log ( `\n🔍 Running ESLint to check code style...` ) ;
80
- runCommand ( "pnpm lint" ) ;
81
-
82
- // Completion notice
83
- console . log ( `\n✅ Project ${ packageJsonExists ? "configured" : "created" } successfully!` ) ;
84
- console . log ( `- Project: ${ projectName } ` ) ;
85
- console . log ( "- Next.js with TypeScript" ) ;
86
- console . log ( "- TailwindCSS and @codefast/ui" ) ;
87
- console . log ( "- ESLint, Prettier, Commitlint, and Git Hooks" ) ;
88
- console . log ( "- Lint-staged for pre-commit checks" ) ;
89
- console . log ( `\n📁 Project directory: ${ process . cwd ( ) } ` ) ;
90
- console . log ( `\n🚀 To start development:` ) ;
91
- console . log ( `cd ${ projectName } && pnpm dev` ) ;
92
- } catch ( error ) {
93
- console . error ( `\n❌ An error occurred: ${ getErrorMessage ( error ) } ` ) ;
94
- process . exit ( 1 ) ;
95
- } finally {
96
- // Close readline interface
97
- rl . close ( ) ;
17
+ export const createProjectCommand = new Command ( )
18
+ . name ( "create-project [name]" )
19
+ . description ( "Create a new Next.js project with recommended setup" )
20
+ . action ( async ( projectNameArg ) => {
21
+ try {
22
+ // Check environment (PNPM, write permissions)
23
+ checkEnvironment ( ) ;
24
+
25
+ // Check if package.json exists and get the project name
26
+ const { projectName, packageJsonExists } = await checkExistingProject ( projectNameArg ) ;
27
+
28
+ if ( ! packageJsonExists ) {
29
+ console . log ( `\n🚀 Starting project creation for ${ projectName } ...\n` ) ;
30
+ createNextProject ( projectName ) ;
31
+ process . chdir ( projectName ) ;
32
+ console . log ( `📂 Moved to ${ projectName } ` ) ;
98
33
}
99
- } ) ;
100
- }
34
+
35
+ // Update layout.tsx to use fontVariables
36
+ updateLayoutFile ( process . cwd ( ) ) ;
37
+
38
+ // Update page.tsx to add JSX.Element return types
39
+ updatePageFile ( process . cwd ( ) ) ;
40
+
41
+ // Edit the postcss.config.mjs file
42
+ updatePostcssConfig ( process . cwd ( ) ) ;
43
+
44
+ // Install dependencies
45
+ installDependencies ( ) ;
46
+
47
+ // Remove unwanted packages
48
+ cleanupPackages ( ) ;
49
+
50
+ // Create configuration files
51
+ createConfigFiles ( process . cwd ( ) ) ;
52
+
53
+ // Update next.config.ts with experimental configuration
54
+ updateNextConfig ( process . cwd ( ) ) ;
55
+
56
+ // Update package.json
57
+ updatePackageJson ( process . cwd ( ) ) ;
58
+
59
+ // Enable git hooks
60
+ console . log ( `\n🔄 Activating git hooks...` ) ;
61
+ runCommand ( "pnpm simple-git-hooks" ) ;
62
+
63
+ // Run Prettier to format the file
64
+ console . log ( `\n📝 Formatting files with Prettier...` ) ;
65
+ runCommand ( "pnpm format" ) ;
66
+
67
+ // Run ESLint
68
+ console . log ( `\n🔍 Running ESLint to check code style...` ) ;
69
+ runCommand ( "pnpm lint" ) ;
70
+
71
+ // Completion notice
72
+ console . log ( `\n✅ Project ${ packageJsonExists ? "configured" : "created" } successfully!` ) ;
73
+ console . log ( `- Project: ${ projectName } ` ) ;
74
+ console . log ( "- Next.js with TypeScript" ) ;
75
+ console . log ( "- TailwindCSS and @codefast/ui" ) ;
76
+ console . log ( "- ESLint, Prettier, Commitlint, and Git Hooks" ) ;
77
+ console . log ( "- Lint-staged for pre-commit checks" ) ;
78
+ console . log ( `\n📁 Project directory: ${ process . cwd ( ) } ` ) ;
79
+ console . log ( `\n🚀 To start development:` ) ;
80
+ console . log ( `cd ${ projectName } && pnpm dev` ) ;
81
+ } catch ( error ) {
82
+ console . error ( `\n❌ An error occurred: ${ getErrorMessage ( error ) } ` ) ;
83
+ process . exit ( 1 ) ;
84
+ } finally {
85
+ // Close readline interface
86
+ rl . close ( ) ;
87
+ process . exit ( 0 ) ;
88
+ }
89
+ } ) ;
0 commit comments