Skip to content

Commit f2a6c53

Browse files
authored
Merge pull request #79 from cyclejs-community/validate-cli-params
fixes #78
2 parents 5439558 + f982cef commit f2a6c53

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

packages/create-cycle-app/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const argv = require('minimist')(process.argv.slice(2))
77
const createApp = require('./src/createApp')
88
const VERSION = require(path.resolve(__dirname, 'package.json')).version
99

10+
const validCommands = {
11+
'verbose': true,
12+
'flavor': true
13+
}
14+
1015
// Command line prelude (version and usage)
1116
const commands = argv._
1217
if (commands.length === 0) {
@@ -17,6 +22,21 @@ if (commands.length === 0) {
1722
console.error(chalk.red('Usage: create-cycle-app <project-directory> [--flavor] [--verbose]'))
1823
process.exit(1)
1924
}
20-
// Parse the command line options and run the setup
21-
createApp(commands[0], argv.verbose, argv.flavor)
2225

26+
Object.keys(argv)
27+
.filter(cmd => cmd !== '_')
28+
.every(cmd => {
29+
if (!validCommands[cmd]) {
30+
console.error(chalk.red(`Invalid command: ${cmd}`))
31+
process.exit(1)
32+
return false
33+
}
34+
return true
35+
})
36+
37+
const flavor = argv.flavor || false
38+
const verbose = argv.verbose || false
39+
const name = commands[0]
40+
41+
// Parse the command line options and run the setup
42+
createApp(name, verbose, flavor)

packages/create-cycle-app/src/createApp.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const installScripts = require('./installScripts')
77
module.exports = function createApp (name, verbose, flavor) {
88
const appFolder = path.resolve(name)
99
const appName = path.basename(appFolder)
10-
flavor = flavor || 'cycle-scripts'
1110

1211
createProjectIn(appFolder)
1312
preparePackageJson(appFolder, appName, () => {

packages/create-cycle-app/test/integration/__snapshots__/createCycleApp.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports[`create-cycle-app when invoked with the a directory it generate a correct package.json file 1`] = `
1+
exports[`create-cycle-app when invoked with the the correct arguments it generate a correct package.json file 1`] = `
22
"{
33
\"name\": \"MYCYCLEAPP\",
44
\"version\": \"0.1.0\",

packages/create-cycle-app/test/integration/createCycleApp.spec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@ const appName = path.resolve(__dirname, 'MYCYCLEAPP')
44
const spawn = require('cross-spawn')
55

66
describe('create-cycle-app', () => {
7-
describe('when invoked with the a directory', () => {
7+
describe('when invoked with the wrong arguments', () => {
8+
test('should throw an error', () => {
9+
expect(
10+
spawn.sync('node', [
11+
path.resolve(__dirname, '../../index.js'),
12+
appName,
13+
'--flavour',
14+
'cycle-scripts@1.0.3'
15+
])
16+
).toThrowError()
17+
})
18+
19+
test('should throw an error', () => {
20+
expect(
21+
spawn.sync('node', [
22+
path.resolve(__dirname, '../../index.js'),
23+
appName,
24+
'--verbos'
25+
])
26+
).toThrowError()
27+
})
28+
})
29+
30+
describe('when invoked with the the correct arguments', () => {
831
let dir
932

1033
beforeEach((done) => {

0 commit comments

Comments
 (0)