Skip to content

Commit ab77193

Browse files
author
Nick Balestra
committed
yarn compatible
1 parent 2911a66 commit ab77193

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

packages/create-cycle-app/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const VERSION = require(path.resolve(__dirname, 'package.json')).version
99

1010
const validCommands = {
1111
'verbose': true,
12-
'flavor': true
12+
'flavor': true,
13+
'noyarn': true
1314
}
1415

1516
// Command line prelude (version and usage)
@@ -34,9 +35,10 @@ Object.keys(argv)
3435
return true
3536
})
3637

37-
const flavor = argv.flavor || 'cycle-scripts@>=1.0.0 <2.0.0'
38+
const flavor = argv.flavor || 'core'
3839
const verbose = argv.verbose || false
40+
const noyarn = argv.noyarn || false
3941
const name = commands[0]
4042

4143
// Parse the command line options and run the setup
42-
createApp(name, verbose, flavor)
44+
createApp(name, verbose, flavor, noyarn)

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@
22

33
const path = require('path')
44

5-
const createProjectIn = require('./createProjectIn')
5+
const createAppDir = require('./createAppDir')
66
const initQuestions = require('./initQuestions')
77
const installScripts = require('./installScripts')
8-
const preparePackageJson = require('./preparePackageJson')
8+
const createPackageJson = require('./createPackageJson')
9+
const shouldUseYarn = require('./shouldUseYarn')
910

10-
module.exports = function createApp (name, verbose, flavor) {
11-
const appFolder = path.resolve(name)
12-
const appName = path.basename(appFolder)
13-
14-
initQuestions(flavor, options => {
15-
createProjectIn(appFolder)
16-
preparePackageJson(appFolder, appName, () => {
17-
installScripts(appFolder, appName, flavor, verbose, options)
11+
module.exports = function createApp (name, verbose, flavor, noyarn) {
12+
// The path where the cycle app will be created
13+
const appPath = path.resolve(name)
14+
// The name of the cycle app to create
15+
const appName = path.basename(appPath)
16+
// Which CLi to use (yarn or npm)
17+
let cli = 'npm'
18+
if (!noyarn && shouldUseYarn()) {
19+
cli = 'yarn'
20+
}
21+
// console.log(cli)
22+
// If no --flavor is passed (flavor === 'core')
23+
// We prompt for language and stream library
24+
// We set the flavor to be 'cycle-scripts'
25+
if (flavor === 'core') {
26+
const flavor = 'cycle-scripts'
27+
initQuestions(answers => {
28+
createAppDir(appPath)
29+
createPackageJson(appPath, appName)
30+
installScripts(appPath, appName, { flavor, verbose, answers, cli })
1831
})
19-
})
32+
// If a --flavor is passed we don't prompt the user
33+
// We delegate every task to the flavor's init() method itself.
34+
} else {
35+
createAppDir(appPath)
36+
createPackageJson(appPath, appName)
37+
installScripts(appPath, appName, { flavor, verbose, answers: false, cli })
38+
}
2039
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const execSync = require('child_process').execSync;
2+
3+
module.exports = function shouldUseYarn() {
4+
try {
5+
execSync('yarnpkg --version', { stdio: 'ignore' });
6+
return true;
7+
} catch (e) {
8+
return false;
9+
}
10+
}

0 commit comments

Comments
 (0)