Skip to content

Commit cc254b4

Browse files
committed
Merge branch 'prettier' of git://github.com/gaearon/create-react-app into gaearon-prettier
2 parents 9df3104 + 9e40909 commit cc254b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2531
-764
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"changelog": "lerna-changelog",
66
"create-react-app": "tasks/cra.sh",
77
"e2e": "tasks/e2e-simple.sh",
8+
"format": "prettier --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
89
"postinstall": "lerna bootstrap",
910
"publish": "tasks/release.sh",
1011
"start": "node packages/react-scripts/scripts/start.js",
@@ -19,6 +20,7 @@
1920
"eslint-plugin-jsx-a11y": "2.2.2",
2021
"eslint-plugin-react": "6.3.0",
2122
"lerna": "^2.0.0-beta.37",
22-
"lerna-changelog": "^0.2.3"
23+
"lerna-changelog": "^0.2.3",
24+
"prettier": "^0.17.0"
2325
}
2426
}

packages/babel-preset-react-app/index.js

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,30 @@ const plugins = [
1616
// The following two plugins use Object.assign directly, instead of Babel's
1717
// extends helper. Note that this assumes `Object.assign` is available.
1818
// { ...todo, completed: true }
19-
[require.resolve('babel-plugin-transform-object-rest-spread'), {
20-
useBuiltIns: true
21-
}],
19+
[
20+
require.resolve('babel-plugin-transform-object-rest-spread'),
21+
{
22+
useBuiltIns: true
23+
}
24+
],
2225
// Transforms JSX
23-
[require.resolve('babel-plugin-transform-react-jsx'), {
24-
useBuiltIns: true
25-
}],
26+
[
27+
require.resolve('babel-plugin-transform-react-jsx'),
28+
{
29+
useBuiltIns: true
30+
}
31+
],
2632
// Polyfills the runtime needed for async/await and generators
27-
[require.resolve('babel-plugin-transform-runtime'), {
28-
helpers: false,
29-
polyfill: false,
30-
regenerator: true,
31-
// Resolve the Babel runtime relative to the config.
32-
moduleName: path.dirname(require.resolve('babel-runtime/package'))
33-
}]
33+
[
34+
require.resolve('babel-plugin-transform-runtime'),
35+
{
36+
helpers: false,
37+
polyfill: false,
38+
regenerator: true,
39+
// Resolve the Babel runtime relative to the config.
40+
moduleName: path.dirname(require.resolve('babel-runtime/package'))
41+
}
42+
]
3443
];
3544

3645
// This is similar to how `env` works in Babel:
@@ -42,9 +51,11 @@ const plugins = [
4251
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
4352
if (env !== 'development' && env !== 'test' && env !== 'production') {
4453
throw new Error(
45-
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or '+
46-
'`BABEL_ENV` environment variables. Valid values are "development", ' +
47-
'"test", and "production". Instead, received: ' + JSON.stringify(env) + '.'
54+
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
55+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
56+
'"test", and "production". Instead, received: ' +
57+
JSON.stringify(env) +
58+
'.'
4859
);
4960
}
5061

@@ -74,11 +85,14 @@ if (env === 'test') {
7485
module.exports = {
7586
presets: [
7687
// ES features necessary for user's Node version
77-
[require('babel-preset-env').default, {
78-
targets: {
79-
node: 'current',
80-
},
81-
}],
88+
[
89+
require('babel-preset-env').default,
90+
{
91+
targets: {
92+
node: 'current'
93+
}
94+
}
95+
],
8296
// JSX, Flow
8397
require.resolve('babel-preset-react')
8498
],
@@ -88,20 +102,26 @@ if (env === 'test') {
88102
module.exports = {
89103
presets: [
90104
// Latest stable ECMAScript features
91-
[require.resolve('babel-preset-latest'), {
92-
'es2015': {
93-
modules: false
105+
[
106+
require.resolve('babel-preset-latest'),
107+
{
108+
es2015: {
109+
modules: false
110+
}
94111
}
95-
}],
112+
],
96113
// JSX, Flow
97114
require.resolve('babel-preset-react')
98115
],
99116
plugins: plugins.concat([
100117
// function* () { yield 42; yield 43; }
101-
[require.resolve('babel-plugin-transform-regenerator'), {
102-
// Async functions are converted to generators by babel-preset-latest
103-
async: false
104-
}],
118+
[
119+
require.resolve('babel-plugin-transform-regenerator'),
120+
{
121+
// Async functions are converted to generators by babel-preset-latest
122+
async: false
123+
}
124+
]
105125
])
106126
};
107127

packages/create-react-app/index.js

Lines changed: 90 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@
4040

4141
var chalk = require('chalk');
4242

43-
var currentNodeVersion = process.versions.node
43+
var currentNodeVersion = process.versions.node;
4444
if (currentNodeVersion.split('.')[0] < 4) {
4545
console.error(
4646
chalk.red(
47-
'You are running Node ' + currentNodeVersion + '.\n' +
48-
'Create React App requires Node 4 or higher. \n' +
49-
'Please update your version of Node.'
47+
'You are running Node ' +
48+
currentNodeVersion +
49+
'.\n' +
50+
'Create React App requires Node 4 or higher. \n' +
51+
'Please update your version of Node.'
5052
)
5153
);
5254
process.exit(1);
@@ -65,44 +67,78 @@ var program = commander
6567
.version(require('./package.json').version)
6668
.arguments('<project-directory>')
6769
.usage(chalk.green('<project-directory>') + ' [options]')
68-
.action(function (name) {
70+
.action(function(name) {
6971
projectName = name;
7072
})
7173
.option('--verbose', 'print additional logs')
72-
.option('--scripts-version <alternative-package>', 'use a non-standard version of react-scripts')
74+
.option(
75+
'--scripts-version <alternative-package>',
76+
'use a non-standard version of react-scripts'
77+
)
7378
.allowUnknownOption()
74-
.on('--help', function () {
75-
console.log(' Only ' + chalk.green('<project-directory>') + ' is required.');
79+
.on('--help', function() {
80+
console.log(
81+
' Only ' + chalk.green('<project-directory>') + ' is required.'
82+
);
7683
console.log();
77-
console.log(' A custom ' + chalk.cyan('--scripts-version') + ' can be one of:');
84+
console.log(
85+
' A custom ' + chalk.cyan('--scripts-version') + ' can be one of:'
86+
);
7887
console.log(' - a specific npm version: ' + chalk.green('0.8.2'));
79-
console.log(' - a custom fork published on npm: ' + chalk.green('my-react-scripts'));
80-
console.log(' - a .tgz archive: ' + chalk.green('https://mysite.com/my-react-scripts-0.8.2.tgz'));
81-
console.log(' It is not needed unless you specifically want to use a fork.');
88+
console.log(
89+
' - a custom fork published on npm: ' +
90+
chalk.green('my-react-scripts')
91+
);
92+
console.log(
93+
' - a .tgz archive: ' +
94+
chalk.green('https://mysite.com/my-react-scripts-0.8.2.tgz')
95+
);
96+
console.log(
97+
' It is not needed unless you specifically want to use a fork.'
98+
);
8299
console.log();
83-
console.log(' If you have any problems, do not hesitate to file an issue:');
84-
console.log(' ' + chalk.cyan('https://github.com/facebookincubator/create-react-app/issues/new'));
100+
console.log(
101+
' If you have any problems, do not hesitate to file an issue:'
102+
);
103+
console.log(
104+
' ' +
105+
chalk.cyan(
106+
'https://github.com/facebookincubator/create-react-app/issues/new'
107+
)
108+
);
85109
console.log();
86110
})
87111
.parse(process.argv);
88112

89113
if (typeof projectName === 'undefined') {
90114
console.error('Please specify the project directory:');
91-
console.log(' ' + chalk.cyan(program.name()) + chalk.green(' <project-directory>'));
115+
console.log(
116+
' ' + chalk.cyan(program.name()) + chalk.green(' <project-directory>')
117+
);
92118
console.log();
93119
console.log('For example:');
94120
console.log(' ' + chalk.cyan(program.name()) + chalk.green(' my-react-app'));
95121
console.log();
96-
console.log('Run ' + chalk.cyan(program.name() + ' --help') + ' to see all options.');
122+
console.log(
123+
'Run ' + chalk.cyan(program.name() + ' --help') + ' to see all options.'
124+
);
97125
process.exit(1);
98126
}
99127

100128
var hiddenProgram = new commander.Command()
101-
.option('--internal-testing-template <path-to-template>', '(internal usage only, DO NOT RELY ON THIS) ' +
102-
'use a non-standard application template')
103-
.parse(process.argv)
129+
.option(
130+
'--internal-testing-template <path-to-template>',
131+
'(internal usage only, DO NOT RELY ON THIS) ' +
132+
'use a non-standard application template'
133+
)
134+
.parse(process.argv);
104135

105-
createApp(projectName, program.verbose, program.scriptsVersion, hiddenProgram.internalTestingTemplate);
136+
createApp(
137+
projectName,
138+
program.verbose,
139+
program.scriptsVersion,
140+
hiddenProgram.internalTestingTemplate
141+
);
106142

107143
function createApp(name, verbose, version, template) {
108144
var root = path.resolve(name);
@@ -111,20 +147,22 @@ function createApp(name, verbose, version, template) {
111147
checkAppName(appName);
112148
fs.ensureDirSync(name);
113149
if (!isSafeToCreateProjectIn(root)) {
114-
console.log('The directory ' + chalk.green(name) + ' contains files that could conflict.');
150+
console.log(
151+
'The directory ' +
152+
chalk.green(name) +
153+
' contains files that could conflict.'
154+
);
115155
console.log('Try using a new directory name.');
116156
process.exit(1);
117157
}
118158

119-
console.log(
120-
'Creating a new React app in ' + chalk.green(root) + '.'
121-
);
159+
console.log('Creating a new React app in ' + chalk.green(root) + '.');
122160
console.log();
123161

124162
var packageJson = {
125163
name: appName,
126164
version: '0.1.0',
127-
private: true,
165+
private: true
128166
};
129167
fs.writeFileSync(
130168
path.join(root, 'package.json'),
@@ -142,7 +180,7 @@ function createApp(name, verbose, version, template) {
142180

143181
function shouldUseYarn() {
144182
try {
145-
execSync('yarnpkg --version', {stdio: 'ignore'});
183+
execSync('yarnpkg --version', { stdio: 'ignore' });
146184
return true;
147185
} catch (e) {
148186
return false;
@@ -154,7 +192,7 @@ function install(packageToInstall, verbose, callback) {
154192
var args;
155193
if (shouldUseYarn()) {
156194
command = 'yarnpkg';
157-
args = [ 'add', '--dev', '--exact', packageToInstall];
195+
args = ['add', '--dev', '--exact', packageToInstall];
158196
} else {
159197
command = 'npm';
160198
args = ['install', '--save-dev', '--save-exact', packageToInstall];
@@ -164,7 +202,7 @@ function install(packageToInstall, verbose, callback) {
164202
args.push('--verbose');
165203
}
166204

167-
var child = spawn(command, args, {stdio: 'inherit'});
205+
var child = spawn(command, args, { stdio: 'inherit' });
168206
child.on('close', function(code) {
169207
callback(code, command, args);
170208
});
@@ -235,8 +273,8 @@ function checkNodeVersion(packageName) {
235273
console.error(
236274
chalk.red(
237275
'You are running Node %s.\n' +
238-
'Create React App requires Node %s or higher. \n' +
239-
'Please update your version of Node.'
276+
'Create React App requires Node %s or higher. \n' +
277+
'Please update your version of Node.'
240278
),
241279
process.version,
242280
packageJson.engines.node
@@ -254,15 +292,19 @@ function checkAppName(appName) {
254292
if (allDependencies.indexOf(appName) >= 0) {
255293
console.error(
256294
chalk.red(
257-
'We cannot create a project called ' + chalk.green(appName) + ' because a dependency with the same name exists.\n' +
258-
'Due to the way npm works, the following names are not allowed:\n\n'
295+
'We cannot create a project called ' +
296+
chalk.green(appName) +
297+
' because a dependency with the same name exists.\n' +
298+
'Due to the way npm works, the following names are not allowed:\n\n'
259299
) +
260-
chalk.cyan(
261-
allDependencies.map(function(depName) {
262-
return ' ' + depName;
263-
}).join('\n')
264-
) +
265-
chalk.red('\n\nPlease choose a different project name.')
300+
chalk.cyan(
301+
allDependencies
302+
.map(function(depName) {
303+
return ' ' + depName;
304+
})
305+
.join('\n')
306+
) +
307+
chalk.red('\n\nPlease choose a different project name.')
266308
);
267309
process.exit(1);
268310
}
@@ -273,10 +315,15 @@ function checkAppName(appName) {
273315
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
274316
function isSafeToCreateProjectIn(root) {
275317
var validFiles = [
276-
'.DS_Store', 'Thumbs.db', '.git', '.gitignore', '.idea', 'README.md', 'LICENSE'
318+
'.DS_Store',
319+
'Thumbs.db',
320+
'.git',
321+
'.gitignore',
322+
'.idea',
323+
'README.md',
324+
'LICENSE'
277325
];
278-
return fs.readdirSync(root)
279-
.every(function(file) {
280-
return validFiles.indexOf(file) >= 0;
281-
});
326+
return fs.readdirSync(root).every(function(file) {
327+
return validFiles.indexOf(file) >= 0;
328+
});
282329
}

0 commit comments

Comments
 (0)