11#!/usr/bin/env node
22
33/**
4- * create-ojs -app
4+ * create-openscript -app
55 * CLI tool to scaffold new OpenScript projects
66 * Similar to create-react-app, create-vue
77 */
@@ -59,11 +59,15 @@ async function createProject(projectName, template = "basic") {
5959 logSuccess ( `Created directory: ${ projectName } ` ) ;
6060
6161 // Get template path
62- const templatesDir = path . join ( __dirname , ".." , " templates") ;
62+ const templatesDir = path . join ( __dirname , "templates" ) ;
6363 const templatePath = path . join ( templatesDir , template ) ;
6464
6565 if ( ! fs . existsSync ( templatePath ) ) {
6666 logError ( `Template "${ template } " not found!` ) ;
67+ log ( "\nAvailable templates:" , "cyan" ) ;
68+ log ( " basic - Basic OpenScript project (default)" , "cyan" ) ;
69+ log ( " tailwind - Project with TailwindCSS integration" , "cyan" ) ;
70+ log ( " bootstrap - Project with Bootstrap 5 integration\n" , "cyan" ) ;
6771 fs . rmdirSync ( projectPath ) ;
6872 process . exit ( 1 ) ;
6973 }
@@ -101,7 +105,7 @@ async function createProject(projectName, template = "basic") {
101105
102106 fs . writeFileSync (
103107 path . join ( projectPath , "package.json" ) ,
104- JSON . stringify ( packageJson , null , 2 )
108+ JSON . stringify ( packageJson , null , 2 ) ,
105109 ) ;
106110 logSuccess ( "Created package.json" ) ;
107111
@@ -163,7 +167,7 @@ function updateProjectName(projectPath, projectName) {
163167 let content = fs . readFileSync ( indexHtmlPath , "utf8" ) ;
164168 content = content . replace (
165169 / < t i t l e > .* < \/ t i t l e > / ,
166- `<title>${ projectName } </title>`
170+ `<title>${ projectName } </title>` ,
167171 ) ;
168172 fs . writeFileSync ( indexHtmlPath , content ) ;
169173 }
@@ -177,17 +181,38 @@ function updateProjectName(projectPath, projectName) {
177181 }
178182}
179183
184+ function showHelp ( ) {
185+ log (
186+ "\n📦 create-openscript-app - OpenScript Project Scaffolding Tool\n" ,
187+ "bright" ,
188+ ) ;
189+ log ( "Usage:" , "cyan" ) ;
190+ log ( " npx create-openscript-app <project-name> [template]\n" , "cyan" ) ;
191+ log ( "Arguments:" , "cyan" ) ;
192+ log ( " project-name Name of your new project (required)" , "cyan" ) ;
193+ log ( " template Template to use (optional, default: basic)\n" , "cyan" ) ;
194+ log ( "Available templates:" , "cyan" ) ;
195+ log ( " basic - Basic OpenScript project with Vite" , "cyan" ) ;
196+ log ( " tailwind - Project with TailwindCSS integration" , "cyan" ) ;
197+ log ( " bootstrap - Project with Bootstrap 5 integration\n" , "cyan" ) ;
198+ log ( "Examples:" , "cyan" ) ;
199+ log ( " npx create-openscript-app my-app" , "cyan" ) ;
200+ log ( " npx create-openscript-app my-app tailwind" , "cyan" ) ;
201+ log ( " npx create-openscript-app my-app bootstrap\n" , "cyan" ) ;
202+ }
203+
180204// Parse command line arguments
181205const args = process . argv . slice ( 2 ) ;
182206
207+ // Handle help flag
208+ if ( args . includes ( "--help" ) || args . includes ( "-h" ) ) {
209+ showHelp ( ) ;
210+ process . exit ( 0 ) ;
211+ }
212+
183213if ( args . length === 0 ) {
184214 log ( "\n❌ Please specify a project name\n" , "red" ) ;
185- log ( "Usage: npm create ojs-app <project-name> [template]\n" , "cyan" ) ;
186- log ( " or: npx create-ojs-app <project-name> [template]\n" , "cyan" ) ;
187- log ( "Available templates:" , "cyan" ) ;
188- log ( " basic - Basic OpenScript project (default)" , "cyan" ) ;
189- log ( " tailwind - Project with TailwindCSS integration" , "cyan" ) ;
190- log ( " bootstrap - Project with Bootstrap 5 integration\n" , "cyan" ) ;
215+ showHelp ( ) ;
191216 process . exit ( 1 ) ;
192217}
193218
@@ -197,7 +222,7 @@ const template = args[1] || "basic";
197222// Validate project name
198223if ( ! / ^ [ a - z 0 - 9 - _ ] + $ / . test ( projectName ) ) {
199224 logError (
200- "Project name can only contain lowercase letters, numbers, hyphens, and underscores"
225+ "Project name can only contain lowercase letters, numbers, hyphens, and underscores" ,
201226 ) ;
202227 process . exit ( 1 ) ;
203228}
0 commit comments