Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean publish and eject #257

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/babel.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

module.exports = {
// Don't try to find .babelrc because we want to force this configuration.
Expand Down
2 changes: 2 additions & 0 deletions config/babel.prod.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

module.exports = {
// Don't try to find .babelrc because we want to force this configuration.
Expand Down
2 changes: 2 additions & 0 deletions config/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
// injected into the application via DefinePlugin in Webpack configuration.
Expand Down
2 changes: 2 additions & 0 deletions config/eslint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

// Inspired by https://github.com/airbnb/javascript but less opinionated.

Expand Down
2 changes: 2 additions & 0 deletions config/jest/CSSStub.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
Expand All @@ -7,5 +8,6 @@
*
* @flow
*/
// @remove-on-eject-end

module.exports = {};
2 changes: 2 additions & 0 deletions config/jest/FileStub.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
Expand All @@ -7,5 +8,6 @@
*
* @flow
*/
// @remove-on-eject-end

module.exports = "test-file-stub";
2 changes: 2 additions & 0 deletions config/jest/transform.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

const babelDev = require('../babel.dev');
const babelJest = require('babel-jest');
Expand Down
84 changes: 36 additions & 48 deletions config/paths.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,60 +7,47 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

// TODO: we can split this file into several files (pre-eject, post-eject, test)
// and use those instead. This way we don't need to branch here.
// @remove-on-eject-end

var path = require('path');

// True after ejecting, false when used as a dependency
var isEjected = (
path.resolve(path.join(__dirname, '..')) ===
path.resolve(process.cwd())
);
function resolveApp(relativePath) {
return path.resolve(relativePath);
}

// Are we developing create-react-app locally?
var isInCreateReactAppSource = (
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
);
// config after eject: we're in ./config/
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
ownNodeModules: resolveApp('node_modules')
};

// @remove-on-eject-begin
function resolveOwn(relativePath) {
return path.resolve(__dirname, relativePath);
}
// config before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules: resolveOwn('../node_modules')
};
// @remove-on-eject-end

function resolveApp(relativePath) {
return path.resolve(relativePath);
}

if (isInCreateReactAppSource) {
// create-react-app development: we're in ./config/
module.exports = {
appBuild: resolveOwn('../build'),
appHtml: resolveOwn('../template/index.html'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
appNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('../node_modules')
};
} else if (!isEjected) {
// before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules: resolveOwn('../node_modules')
};
} else {
// after eject: we're in ./config/
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
ownNodeModules: resolveApp('node_modules')
};
}
// @remove-on-publish-begin
module.exports = {
appBuild: resolveOwn('../build'),
appHtml: resolveOwn('../template/index.html'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
appNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('../node_modules')
};
// @remove-on-publish-end
11 changes: 11 additions & 0 deletions config/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
Expand Down
2 changes: 2 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

var path = require('path');
var autoprefixer = require('autoprefixer');
Expand Down
2 changes: 2 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

var path = require('path');
var autoprefixer = require('autoprefixer');
Expand Down
2 changes: 1 addition & 1 deletion global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var pathExists = require('path-exists');
* Example of valid values:
* - a specific npm version: "0.22.0-rc1"
* - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz"
* - a package prepared with `npm pack`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
* - a package prepared with `tasks/clean_pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
*/
var commands = argv._;
if (commands.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"scripts": {
"build": "node scripts/build.js --debug-template",
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`tasks/clean_pack.sh`\"",
"e2e": "tasks/e2e.sh",
"start": "node scripts/start.js --debug-template",
"test": "node scripts/test.js --debug-template"
Expand Down
2 changes: 2 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

// Do this as the first thing so that any code reading it knows the right env.
process.env.NODE_ENV = 'production';
Expand Down
8 changes: 4 additions & 4 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ prompt(
console.log('Copying ' + file + ' to ' + appPath);
var content = fs
.readFileSync(path.join(ownPath, file), 'utf8')
// Remove license header from JS
.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '')
// Remove license header from AppleScript
.replace(/^--.*\n/gm, '')
// Remove dead code from .js files on eject
.replace(/\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, '')
// Remove dead code from .applescript files on eject
.replace(/-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/mg, '')
.trim() + '\n';
fs.writeFileSync(path.join(appPath, file), content);
});
Expand Down
2 changes: 2 additions & 0 deletions scripts/start.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

process.env.NODE_ENV = 'development';

Expand Down
2 changes: 2 additions & 0 deletions scripts/utils/WatchMissingNodeModulesPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

// This Webpack plugin ensures `npm install <library>` forces a project rebuild.
// We’re not sure why this isn't Webpack's default behavior.
Expand Down
15 changes: 10 additions & 5 deletions scripts/utils/chrome.applescript
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
-- Copyright (c) 2015-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- @remove-on-eject-begin
(*
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.

This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
of patent rights can be found in the PATENTS file in the same directory.
*)
-- @remove-on-eject-end

on run argv
set theURL to item 1 of argv

Expand Down
2 changes: 2 additions & 0 deletions scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

module.exports = (resolve, rootDir) => {
const config = {
Expand Down
2 changes: 2 additions & 0 deletions scripts/utils/prompt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -6,6 +7,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// @remove-on-eject-end

var rl = require('readline');

Expand Down
Loading