Skip to content

Commit 0fb974a

Browse files
author
Nick Balestra
committed
initial iniquirer for core flavor
1 parent db78706 commit 0fb974a

File tree

12 files changed

+111
-31
lines changed

12 files changed

+111
-31
lines changed

packages/create-cycle-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"dependencies": {
2525
"chalk": "^1.1.3",
2626
"cross-spawn": "^4.0.2",
27+
"inquirer": "^3.0.6",
2728
"minimist": "^1.2.0"
2829
},
2930
"devDependencies": {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use strict'
2+
23
const path = require('path')
3-
const preparePackageJson = require('./preparePackageJson')
4+
45
const createProjectIn = require('./createProjectIn')
6+
const initQuestions = require('./initQuestions')
57
const installScripts = require('./installScripts')
8+
const preparePackageJson = require('./preparePackageJson')
69

710
module.exports = function createApp (name, verbose, flavor) {
811
const appFolder = path.resolve(name)
912
const appName = path.basename(appFolder)
1013

11-
createProjectIn(appFolder)
12-
preparePackageJson(appFolder, appName, () => {
13-
installScripts(appFolder, appName, flavor, verbose)
14+
initQuestions(flavor, options => {
15+
createProjectIn(appFolder)
16+
preparePackageJson(appFolder, appName, () => {
17+
installScripts(appFolder, appName, flavor, verbose, options)
18+
})
1419
})
1520
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
2-
const fs = require('fs')
2+
33
const chalk = require('chalk')
44
const console = require('console')
5+
const fs = require('fs')
6+
57
const isSafeToCreateProjectIn = require('./isSafeToCreateProjectIn')
68

79
module.exports = function createProjectIn (appFolder) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
23
const path = require('path')
34

45
module.exports = function getPackageName (installPackage) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
3+
const inquirer = require('inquirer')
4+
5+
const initQuestions = [
6+
{
7+
type: 'list',
8+
name: 'language',
9+
default: 0,
10+
choices: ['JavaScript', 'TypeScript'],
11+
message: 'Which language do you want to use to write your cycle app?'
12+
},
13+
{
14+
type: 'list',
15+
name: 'streamLib',
16+
default: 0,
17+
choices: [
18+
{
19+
name: 'XStream, tailored for Cycle.js',
20+
value: 'xstream'
21+
},
22+
{
23+
name: 'Most.js, a blazing fast stream library',
24+
value: 'most'
25+
},
26+
{
27+
name: 'RxJS',
28+
value: 'rxjs'
29+
}
30+
],
31+
message: 'Which reactive stream library do you want to use?'
32+
}
33+
]
34+
35+
module.exports = (flavor, cb) => {
36+
if (flavor) {
37+
return cb(false)
38+
}
39+
inquirer.prompt(initQuestions).then(answers => {
40+
return cb(answers)
41+
})
42+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict'
2-
const path = require('path')
2+
33
const chalk = require('chalk')
44
const spawn = require('cross-spawn')
5-
const getPackageName = require('./getPackageName')
65
const console = require('console')
6+
const path = require('path')
77
const process = require('process')
88

9-
module.exports = function installScripts (appFolder, appName, flavor, verbose) {
9+
const getPackageName = require('./getPackageName')
10+
11+
module.exports = function installScripts (appFolder, appName, flavor, verbose, options) {
1012
const originalDirectory = process.cwd()
1113
process.chdir(appFolder)
1214

@@ -45,6 +47,6 @@ module.exports = function installScripts (appFolder, appName, flavor, verbose) {
4547
const init = require(initScriptPath)
4648

4749
// Execute the cycle-scripts's specific initialization
48-
init(appFolder, appName, verbose, originalDirectory)
50+
init(appFolder, appName, verbose, originalDirectory, options)
4951
})
5052
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
23
const fs = require('fs')
34

45
module.exports = function isSafeToCreateProjectIn (appFolder) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict'
2+
3+
const chalk = require('chalk')
24
const fs = require('fs')
35
const path = require('path')
4-
const chalk = require('chalk')
56

67
module.exports = function preparePackageJson (appFolder, appName, cb) {
78
// Start creating the new app

packages/create-cycle-app/test/unit/createApp.spec.js

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const initQuestions = require('../../src/initQuestions')
2+
jest.mock('inquirer')
3+
const inquirer = require('inquirer')
4+
5+
describe('initQuedstion module', () => {
6+
describe('when calling it', () => {
7+
test('should not prompt for question if a custom flavor is provided', () => {
8+
const callback = jest.fn()
9+
initQuestions('customFlavor', callback)
10+
expect(callback).toBeCalledWith(false)
11+
expect(inquirer.prompt).not.toBeCalled()
12+
})
13+
test('should prompt for question if no custom flavor is provided', () => {
14+
const callback = jest.fn()
15+
const answer = {language: 'JavaScript', streamLib: 'xstream'}
16+
inquirer.prompt.mockReturnValue({
17+
then: jest.fn(answers => callback(answer))
18+
})
19+
initQuestions(undefined, callback)
20+
expect(callback).toBeCalledWith(answer)
21+
expect(inquirer.prompt).toBeCalled()
22+
})
23+
})
24+
})

0 commit comments

Comments
 (0)