|
2 | 2 |
|
3 | 3 | const path = require('path') |
4 | 4 |
|
5 | | -const createProjectIn = require('./createProjectIn') |
| 5 | +const createAppDir = require('./createAppDir') |
6 | 6 | const initQuestions = require('./initQuestions') |
7 | 7 | const installScripts = require('./installScripts') |
8 | | -const preparePackageJson = require('./preparePackageJson') |
| 8 | +const createPackageJson = require('./createPackageJson') |
| 9 | +const shouldUseYarn = require('./shouldUseYarn') |
9 | 10 |
|
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 }) |
18 | 31 | }) |
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 | + } |
20 | 39 | } |
0 commit comments