Skip to content

Commit e22441c

Browse files
author
Nick Balestra
committed
cca cleanup
1 parent ab77193 commit e22441c

File tree

8 files changed

+82
-77
lines changed

8 files changed

+82
-77
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const chalk = require('chalk')
4+
const console = require('console')
5+
const fs = require('fs')
6+
7+
const isSafeToCreateApp = require('./isSafeToCreateApp')
8+
9+
module.exports = function createProjectIn (appPath) {
10+
if (!fs.existsSync(appPath)) {
11+
fs.mkdirSync(appPath)
12+
return
13+
}
14+
15+
if (isSafeToCreateApp(appPath)) {
16+
return
17+
} else {
18+
console.log(chalk.red(`The directory \`${appPath}\` contains file(s) that could conflict. Aborting.`))
19+
process.exit(1)
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
const chalk = require('chalk')
4+
const console = require('console')
5+
const fs = require('fs')
6+
const path = require('path')
7+
8+
module.exports = function createPackageJson (appPath, appName) {
9+
// Prepare package.json
10+
const content = {
11+
name: appName,
12+
version: '0.1.0',
13+
private: true
14+
}
15+
const packageJsonContent = JSON.stringify(content, null, 2)
16+
17+
// Write package.json in the app folder
18+
console.log(chalk.green(`Creating a new Cycle.js app in ${appPath}.`))
19+
console.log()
20+
fs.writeFileSync(
21+
path.join(appPath, 'package.json'),
22+
packageJsonContent
23+
)
24+
}

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ const initQuestions = [
4141
}
4242
]
4343

44-
module.exports = (flavor, cb) => {
45-
if (flavor) {
46-
return cb(false)
47-
}
48-
inquirer.prompt(initQuestions).then(answers => {
49-
return cb(answers)
50-
})
44+
module.exports = cb => {
45+
inquirer.prompt(initQuestions).then(cb)
5146
}

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,58 @@ const chalk = require('chalk')
44
const spawn = require('cross-spawn')
55
const console = require('console')
66
const path = require('path')
7-
const process = require('process')
87

98
const getPackageName = require('./getPackageName')
109

11-
module.exports = function installScripts (appFolder, appName, flavor, verbose, options) {
12-
const originalDirectory = process.cwd()
13-
process.chdir(appFolder)
10+
module.exports = function installScripts (appFolder, appName, options) {
11+
const verbose = options.verbose
12+
const flavor = options.flavor
13+
const cli = options.cli
1414

15-
// Find the right version
15+
// Check if the the the flavor to be used is local
1616
const local = /^\.\/|^\//.test(flavor)
17+
// Get the right name of the flavor package
1718
const packageName = getPackageName(flavor)
18-
1919
// Install dependencies
20+
const args = {
21+
npm: [
22+
'install',
23+
verbose && '--verbose',
24+
'--save-dev',
25+
'--save-exact',
26+
flavor
27+
].filter(a => a),
28+
yarn: [
29+
'add',
30+
'--exact',
31+
verbose && '--verbose',
32+
local ? 'file:' + flavor : flavor
33+
].filter(a => a)
34+
}
35+
36+
// Trigger npm installation
2037
console.log(chalk.green('Installing packages. This might take a couple minutes.'))
2138
console.log(chalk.green(`Installing ${packageName} from ${(local ? 'local' : 'npm')} ...`))
2239
console.log()
2340

24-
const args = [
25-
'install',
26-
verbose && '--verbose',
27-
'--save-dev',
28-
'--save-exact',
29-
local ? path.resolve(originalDirectory, flavor) : flavor
30-
].filter(function (a) { return a })
31-
32-
// Trigger npm installation
33-
const proc = spawn('npm', args, {stdio: 'inherit'})
41+
const proc = spawn(cli, args[cli], {stdio: 'inherit', cwd: appFolder})
42+
proc.on('error', (e) => console.log(e))
3443
proc.on('close', function (code) {
3544
if (code !== 0) {
36-
console.error(chalk.red(`npm \`${args.join(' ')}\` failed`))
45+
console.error(chalk.red(`${cli} \`${args[cli].join(' ')}\` failed`))
3746
return
3847
}
3948

4049
const initScriptPath = path.resolve(
41-
process.cwd(),
50+
appFolder,
4251
'node_modules',
4352
packageName,
4453
'scripts',
4554
'init.js'
4655
)
4756
const init = require(initScriptPath)
4857

49-
// Execute the cycle-scripts's specific initialization
50-
init(appFolder, appName, verbose, originalDirectory, options)
58+
// Execute the flavor's specific initialization
59+
init(appFolder, appName, options)
5160
})
5261
}

packages/create-cycle-app/src/isSafeToCreateProjectIn.js renamed to packages/create-cycle-app/src/isSafeToCreateApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('fs')
44

5-
module.exports = function isSafeToCreateProjectIn (appFolder) {
5+
module.exports = function isSafeToCreateApp (appFolder) {
66
const whitelist = [
77
'.DS_Store',
88
'Thumbs.db',

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

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const execSync = require('child_process').execSync;
1+
const execSync = require('child_process').execSync
22

3-
module.exports = function shouldUseYarn() {
3+
module.exports = function shouldUseYarn () {
44
try {
5-
execSync('yarnpkg --version', { stdio: 'ignore' });
6-
return true;
5+
execSync('yarnpkg --version', { stdio: 'ignore' })
6+
return true
77
} catch (e) {
8-
return false;
8+
return false
99
}
1010
}

0 commit comments

Comments
 (0)