Skip to content

Commit 95079e2

Browse files
author
Nick Balestra
committed
wip scripts
1 parent ea2b644 commit 95079e2

File tree

4 files changed

+117
-77
lines changed

4 files changed

+117
-77
lines changed

packages/cycle-scripts/scripts/build.js

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/**
22
* BSD License
33
* For create-react-app software
4-
*
4+
*
55
* Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
66
* Redistribution and use in source and binary forms, with or without modification,
77
* are permitted provided that the following conditions are met:
8-
*
8+
*
99
* Redistributions of source code must retain the above copyright notice, this
1010
* list of conditions and the following disclaimer.
11-
*
11+
*
1212
* Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* Neither the name Facebook nor the names of its contributors may be used to
1717
* endorse or promote products derived from this software without specific
1818
* prior written permission.
19-
*
20-
*
19+
*
20+
*
2121
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2222
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2323
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -30,89 +30,83 @@
3030
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33-
'use strict';
33+
'use strict'
3434

35-
process.env.NODE_ENV = 'production';
35+
process.env.NODE_ENV = 'production'
3636

3737
const fs = require('fs-extra')
3838
const chalk = require('chalk')
3939
const webpack = require('webpack')
40-
const config = require('./configs/webpack.config.prod')
40+
const config = require('../configs/webpack.config.prod')
4141
const path = require('path')
4242

4343
const buildPath = path.join(process.cwd(), 'build')
4444
const publicPath = path.join(process.cwd(), 'public')
4545

46-
4746
// Remove all content but keep the directory so that
4847
// if you're in it, you don't end up in Trash
49-
fs.emptyDirSync(buildPath);
48+
fs.emptyDirSync(buildPath)
5049

5150
// Start the webpack build
52-
build();
51+
build()
5352

5453
// Merge with the public folder
55-
copyPublicFolder();
56-
54+
copyPublicFolder()
5755

5856
// Print out errors
59-
function printErrors(summary, errors) {
60-
console.log(chalk.red(summary));
61-
console.log();
57+
function printErrors (summary, errors) {
58+
console.log(chalk.red(summary))
59+
console.log()
6260
errors.forEach(err => {
63-
console.log(err.message || err);
64-
console.log();
65-
});
61+
console.log(err.message || err)
62+
console.log()
63+
})
6664
}
6765

68-
6966
// Merge with the public folder
70-
function copyPublicFolder() {
67+
function copyPublicFolder () {
7168
fs.copySync(publicPath, buildPath, {
72-
dereference: true,
69+
dereference: true
7370
// filter: file => file !== resolveApp('public/index.html'),
74-
});
71+
})
7572
}
7673

77-
78-
7974
// Create the production build and print the deployment instructions.
80-
function build() {
81-
console.log('Creating an optimized production build...');
75+
function build () {
76+
console.log('Creating an optimized production build...')
8277

83-
let compiler;
78+
let compiler
8479
try {
85-
compiler = webpack(config);
80+
compiler = webpack(config)
8681
} catch (err) {
87-
printErrors('Failed to compile.', [err]);
88-
process.exit(1);
82+
printErrors('Failed to compile.', [err])
83+
process.exit(1)
8984
}
9085

9186
compiler.run((err, stats) => {
9287
if (err) {
93-
printErrors('Failed to compile.', [err]);
94-
process.exit(1);
88+
printErrors('Failed to compile.', [err])
89+
process.exit(1)
9590
}
9691

9792
if (stats.compilation.errors.length) {
98-
printErrors('Failed to compile.', stats.compilation.errors);
99-
process.exit(1);
93+
printErrors('Failed to compile.', stats.compilation.errors)
94+
process.exit(1)
10095
}
10196

10297
if (process.env.CI && stats.compilation.warnings.length) {
10398
printErrors(
10499
'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.',
105100
stats.compilation.warnings
106-
);
107-
process.exit(1);
101+
)
102+
process.exit(1)
108103
}
109104

110-
console.log(chalk.green('Compiled successfully.'));
111-
console.log();
112-
});
105+
console.log(chalk.green('Compiled successfully.'))
106+
console.log()
107+
})
113108
}
114109

115-
116110
// const fs = require('fs-extra')
117111
// const path = require('path')
118112
// const mkdirp = require('mkdirp')

packages/cycle-scripts/scripts/eject.js

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

33
const fs = require('fs-extra')
44
const path = require('path')
5-
const mkdirp = require('mkdirp')
5+
const chalk = require('chalk')
6+
const inquirer = require('inquirer')
67

78
const ownPackageJsonPath = path.resolve(__dirname, '..', 'package.json')
89
const appPackageJsonPath = path.join(process.cwd(), 'package.json')
910
const ownPackageJson = JSON.parse(fs.readFileSync(ownPackageJsonPath))
1011
const appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath))
11-
const scriptsPath = path.join(process.cwd(), '.scripts')
12+
const scriptsPath = path.join(process.cwd(), 'scripts')
13+
14+
const ejectConfirmation = {
15+
type: 'confirm',
16+
name: 'doEject',
17+
default: false,
18+
message: 'Are you sure you want to eject? This action is permanent.'
19+
}
20+
21+
inquirer.prompt([ejectConfirmation]).then(answers => {
22+
if (!answers.doEject.value) {
23+
console.log(chalk.cyan('Eject aborted!'))
24+
return
25+
}
26+
})
1227

1328
// Declaring new scripts
1429
const scripts = {
15-
start: 'node .scripts/start.js',
16-
test: 'node .scripts/test.js',
17-
build: 'node .scripts/build.js'
30+
start: 'node scripts/start.js',
31+
test: 'node scripts/test.js',
32+
build: 'node scripts/build.js'
1833
}
1934

2035
// Declare the new dependencies, excluding self
@@ -36,18 +51,15 @@ fs.writeFileSync(
3651
JSON.stringify(newPackageJson, null, 2)
3752
)
3853

39-
mkdirp(scriptsPath, () => {
40-
function copy (script, subDir, inRoot) {
41-
subDir = subDir || ''
42-
fs.copySync(path.join(__dirname, subDir, script), path.join(inRoot ? '' : scriptsPath, script))
43-
}
44-
45-
// Copy scripts
46-
copy('start.js')
47-
copy('test.js')
48-
copy('build.js')
54+
// Copy scripts
55+
function copyScript (script) {
56+
fs.copySync(path.join(__dirname, script), path.join(scriptsPath, script))
57+
}
4958

50-
// Copy configs
51-
copy('.babelrc', 'configs', true)
52-
})
59+
fs.ensureDirSync(scriptsPath)
60+
copyScript('start.js')
61+
copyScript('test.js')
62+
copyScript('build.js')
5363

64+
// Copy configs
65+
fs.copySync(path.join(__dirname, '../', 'configs'), path.join('configs'))

packages/cycle-scripts/scripts/init.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path')
55
const chalk = require('chalk')
66
const spawn = require('cross-spawn')
77

8+
// To be moved to separate module
89
const basicDependencies = [
910
'@cycle/dom@16.0.0',
1011
'@cycle/run@3.0.0',
@@ -68,6 +69,7 @@ module.exports = function init (appPath, appName, verbose, originalDirectory) {
6869
const appPackage = require(appPackageJson)
6970

7071
// Manipulate app's package.json
72+
// To be moved to separate module
7173
appPackage.dependencies = appPackage.dependencies || {}
7274
appPackage.devDependencies = appPackage.devDependencies || {}
7375
appPackage.scripts = {
@@ -77,19 +79,19 @@ module.exports = function init (appPath, appName, verbose, originalDirectory) {
7779
'eject': 'cycle-scripts eject'
7880
}
7981

80-
appPackage.babel = {
81-
presets: [
82-
[ 'env', {
83-
'targets': {
84-
'browsers': ['last 2 versions'],
85-
uglify: true
86-
}
87-
}]
88-
],
89-
plugins: [
90-
['transform-react-jsx', { pragma: 'Snabbdom.createElement' }]
91-
]
92-
}
82+
// appPackage.babel = {
83+
// presets: [
84+
// [ 'env', {
85+
// 'targets': {
86+
// 'browsers': ['last 2 versions'],
87+
// uglify: true
88+
// }
89+
// }]
90+
// ],
91+
// plugins: [
92+
// ['transform-react-jsx', { pragma: 'Snabbdom.createElement' }]
93+
// ]
94+
// }
9395

9496
fs.writeFileSync(
9597
appPackageJson,

packages/cycle-scripts/scripts/start.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
1+
/**
2+
* BSD License
3+
* For create-react-app software
4+
*
5+
* Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
6+
* Redistribution and use in source and binary forms, with or without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* Neither the name Facebook nor the names of its contributors may be used to
17+
* endorse or promote products derived from this software without specific
18+
* prior written permission.
19+
*
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
133
'use strict'
234

335
const WebpackDevServer = require('webpack-dev-server')
436
const chalk = require('chalk')
537

6-
const config = require('./configs/webpack.config.dev')
7-
const devServerConfig = require('./configs/webpackDevServer.config')
8-
const createWebpackCompiler = require('./utils/createWebpackCompiler')
9-
const openBrowser = require('./utils/openBrowser')
38+
const config = require('../configs/webpack.config.dev')
39+
const devServerConfig = require('../configs/webpackDevServer.config')
40+
const createWebpackCompiler = require('cycle-dev-utils/createWebpackCompiler')
41+
const openBrowser = require('cycle-dev-utils/openBrowser')
1042

1143
process.env.NODE_ENV = 'development'
1244

0 commit comments

Comments
 (0)