-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dominik Wilkowski <Hi@Dominik-Wilkowski.com>
- Loading branch information
1 parent
bef0e49
commit 9be302d
Showing
2 changed files
with
47 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,62 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const arg = require('arg'); | ||
|
||
const chalk = require('chalk'); | ||
const generator = require('./generator'); | ||
|
||
// Setup all the args | ||
const argSpec = { | ||
'--help': Boolean, | ||
'-h': '--help', | ||
'--version': Boolean, | ||
'-V': '--version', | ||
}; | ||
|
||
// Parse the command line args coming in | ||
const args = arg(argSpec, { | ||
// Capture the project name only | ||
permissive: false, | ||
}); | ||
let args; | ||
try { | ||
// Parse the command line args coming in | ||
args = arg(argSpec, { | ||
// Capture the project name only | ||
permissive: false, | ||
}); | ||
} catch (error) { | ||
if (error.code === 'ARG_UNKNOWN_OPTION') { | ||
console.error(chalk.red(`\nError: ${error.message}`)); | ||
console.info(generator.help()); | ||
process.exit(0); | ||
} | ||
} | ||
|
||
if (args['--version']) { | ||
console.log(generator.version()); | ||
console.info(generator.version()); | ||
process.exit(0); | ||
} | ||
|
||
if (args['--help']) { | ||
console.log(generator.help()); | ||
console.info(generator.help()); | ||
process.exit(0); | ||
} | ||
|
||
// if project name is missing print help | ||
if (args._.length === 0) { | ||
console.log(generator.help()); | ||
console.info(generator.help()); | ||
process.exit(0); | ||
} | ||
|
||
// check if folder exists and is not empty | ||
const name = generator.createAppName(args._.join(' ')); | ||
try { | ||
generator.checkEmptyDir(name); | ||
} | ||
catch (error) { | ||
console.error(chalk.red(`\n${error}`)); | ||
console.info(generator.help()); | ||
process.exit(0); | ||
} | ||
|
||
// Everything else is assumed to be a command we want to execute - more options added | ||
generator.exec(args).catch(error => { | ||
generator.exec(name).catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters