11#!/usr/bin/env node
22import { execSync } from "child_process" ;
3- import { fileURLToPath } from "url" ;
4- import { join , dirname } from "path" ;
53import { confirm } from "@inquirer/prompts" ;
64import select from "@inquirer/select" ;
75import { Command } from "commander" ;
86import ora from "ora" ;
97import { validateRegion } from "./validators.js" ;
108import { regionConfig } from "./config.js" ;
9+ import path from "path" ;
1110
1211const program = new Command ( ) ;
1312
14- // checking to see if vals are provided as argv
15- // if not, proceed with inquirer
16- let regionProvidedAsArgv = false ;
17-
1813program
1914 . name ( "Create Radfish App" )
2015 . description ( "The CLI to bootstrap a radfish app!" )
2116 . version ( "0.0.1" ) ;
2217
2318// program options
24- program
25- . argument ( "<repository>" )
26- . option ( "-r --region <string>" , "specified region" ) ;
19+ program . argument ( "<projectDirectoryPath>" ) . option ( "-r --region <string>" , "specified region" ) ;
2720
28- program . action ( ( repository , options ) => {
21+ program . action ( ( projectDirectoryPath , options ) => {
2922 const isValidRegion = validateRegion ( options . region ) ;
3023
3124 if ( ! isValidRegion ) {
3225 const regionCodes = regionConfig
3326 . map ( ( region ) => region . code )
3427 . join ( " , " )
3528 . replace ( / , $ / , "" ) ; // remove comma from last elem
36- console . error (
37- "Invalid region code. Here are the valid regions: " ,
38- regionCodes
39- ) ;
29+ console . error ( "Invalid region code. Here are the valid regions: " , regionCodes ) ;
4030 }
4131
42- scaffoldRadFishApp ( repository ) ;
32+ scaffoldRadFishApp ( projectDirectoryPath ) ;
4333} ) ;
4434
4535// check options passed in via cli command
4636const options = program . opts ( ) ;
4737
48- if ( options && options . region ) {
49- regionProvidedAsArgv = true ;
50- }
38+ async function scaffoldRadFishApp ( projectDirectoryPath ) {
39+ const targetDirectory = path . resolve (
40+ process . cwd ( ) ,
41+ `${ projectDirectoryPath . trim ( ) . replace ( / \s + / g, "-" ) } ` , // replace whitespaces in the filepath
42+ ) ;
5143
52- async function scaffoldRadFishApp ( repository ) {
5344 async function defineRegion ( ) {
5445 return await select ( {
5546 name : "region" ,
@@ -60,19 +51,14 @@ async function scaffoldRadFishApp(repository) {
6051
6152 async function confirmConfiguration ( region ) {
6253 return await confirm ( {
63- message : `You are about to scaffold an application for the region of ${ region } in the following project directory: ../ ${ repository }
54+ message : `You are about to scaffold an application for the region of ${ region } in the following project directory: ${ targetDirectory }
6455 Okay to proceed?` ,
6556 } ) ;
6657 }
6758
6859 // this will clone the radfish app boilerplate and spin it up
6960 function bootstrapApp ( ) {
7061 const repoUrl = "git@github.com:NMFS-RADFish/boilerplate.git" ; // via ssh each user/developer will need to have ssh keypair setup in github org
71- const targetDirectory = `../${ repository . replace ( / \s + / g, "-" ) } ` ; // remove any whitespaces from filepath...just in case
72-
73- const __filename = fileURLToPath ( import . meta. url ) ;
74- const __dirname = dirname ( __filename ) ;
75-
7662 const spinner = ora ( "Setting up application" ) . start ( ) ;
7763
7864 // Clone the repository
@@ -85,8 +71,7 @@ async function scaffoldRadFishApp(repository) {
8571 }
8672
8773 // Change to the cloned repository directory
88- const repoPath = join ( __dirname , targetDirectory ) ;
89- process . chdir ( repoPath ) ;
74+ process . chdir ( targetDirectory ) ;
9075
9176 // Run an npm script (replace 'your-script-name' with the actual npm script name)
9277 try {
0 commit comments