From 29f8ef6b72fa0b1663f48ab4e9d1361ee7b164bd Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:04:49 -0700 Subject: [PATCH 1/7] Replace deprecated `react-tools` with `babel` - Switch to babel, since react-tools has been deprecated since June 12, 2015. See https://facebook.github.io/react/blog/2015/06/12/deprecating-jstransform -and-react-tools.html - Move babel command to "npm run build" - Move commands for package into "bin/package.js" --- .babelrc | 5 +++++ bin/check-deps.js | 2 +- bin/package.js | 7 +++++++ package.json | 8 +++++--- 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..2e9146fe --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "react" + ] +} diff --git a/bin/check-deps.js b/bin/check-deps.js index f5e9e42c..fa8dd38a 100755 --- a/bin/check-deps.js +++ b/bin/check-deps.js @@ -45,7 +45,7 @@ var BUILT_IN_ELECTRON_MODULES = [ 'electron' ] var BUILT_IN_DEPS = [].concat(BUILT_IN_NODE_MODULES, BUILT_IN_ELECTRON_MODULES) -var EXECUTABLE_DEPS = ['gh-release', 'standard', 'react-tools'] +var EXECUTABLE_DEPS = ['gh-release', 'standard', 'babel-cli', 'babel-preset-react'] main() diff --git a/bin/package.js b/bin/package.js index 20f037ee..b91c39f1 100755 --- a/bin/package.js +++ b/bin/package.js @@ -19,6 +19,7 @@ var config = require('../src/config') var pkg = require('../package.json') var BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION +var BUILD_PATH = path.join(config.ROOT_PATH, 'build') var DIST_PATH = path.join(config.ROOT_PATH, 'dist') var argv = minimist(process.argv.slice(2), { @@ -36,6 +37,12 @@ var argv = minimist(process.argv.slice(2), { function build () { rimraf.sync(DIST_PATH) + rimraf.sync(BUILD_PATH) + + console.log('Babel: Building JSX...') + cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' }) + console.log('Babel: Built JSX.') + var platform = argv._[0] if (platform === 'darwin') { buildDarwin(printDone) diff --git a/package.json b/package.json index fc34ac6d..18c74357 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,8 @@ "zero-fill": "^2.2.3" }, "devDependencies": { + "babel-cli": "^6.11.4", + "babel-preset-react": "^6.11.1", "cross-zip": "^2.0.1", "electron-osx-sign": "^0.3.0", "electron-packager": "^7.0.0", @@ -55,7 +57,6 @@ "nobin-debian-installer": "^0.0.10", "open": "0.0.5", "plist": "^1.2.0", - "react-tools": "^0.13.3", "rimraf": "^2.5.2", "run-series": "^1.1.4", "standard": "^7.0.0" @@ -85,10 +86,11 @@ "url": "git://github.com/feross/webtorrent-desktop.git" }, "scripts": { + "build": "babel src -d build", "clean": "node ./bin/clean.js", "open-config": "node ./bin/open-config.js", - "package": "rimraf build/ && jsx --es6module src/ build/ && node ./bin/package.js", - "start": "jsx --es6module src/ build/ && electron .", + "package": "node ./bin/package.js", + "start": "npm run build && electron .", "test": "standard && node ./bin/check-deps.js", "update-authors": "./bin/update-authors.sh" } From 9b36f9cb220ab43364bc150b15dfeef9eec1f77f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:05:03 -0700 Subject: [PATCH 2/7] Ensure that build folder gets generated before npm publish So users using `npm install -g webtorrent-desktop` will always get a working version. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 18c74357..cef10d6f 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "clean": "node ./bin/clean.js", "open-config": "node ./bin/open-config.js", "package": "node ./bin/package.js", + "prepublish": "npm run build", "start": "npm run build && electron .", "test": "standard && node ./bin/check-deps.js", "update-authors": "./bin/update-authors.sh" From 7531ab46237227c53c781662fe2340a29513be46 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:37:53 -0700 Subject: [PATCH 3/7] Simplify babel integration further The "react" preset is composed of a bunch of plugins. https://babeljs.io/docs/plugins/preset-react/ Turns out, we only need 2 of them, not all 5. --- .babelrc | 5 +++-- bin/check-deps.js | 8 +++++++- package.json | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.babelrc b/.babelrc index 2e9146fe..9d3c6b01 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,6 @@ { - "presets": [ - "react" + "plugins": [ + "syntax-jsx", + "transform-react-jsx" ] } diff --git a/bin/check-deps.js b/bin/check-deps.js index fa8dd38a..f4a2dafc 100755 --- a/bin/check-deps.js +++ b/bin/check-deps.js @@ -45,7 +45,13 @@ var BUILT_IN_ELECTRON_MODULES = [ 'electron' ] var BUILT_IN_DEPS = [].concat(BUILT_IN_NODE_MODULES, BUILT_IN_ELECTRON_MODULES) -var EXECUTABLE_DEPS = ['gh-release', 'standard', 'babel-cli', 'babel-preset-react'] +var EXECUTABLE_DEPS = [ + 'gh-release', + 'standard', + 'babel-cli', + 'babel-plugin-syntax-jsx', + 'babel-plugin-transform-react-jsx' +] main() diff --git a/package.json b/package.json index cef10d6f..8f30bf96 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,8 @@ }, "devDependencies": { "babel-cli": "^6.11.4", - "babel-preset-react": "^6.11.1", + "babel-plugin-syntax-jsx": "^6.13.0", + "babel-plugin-transform-react-jsx": "^6.8.0", "cross-zip": "^2.0.1", "electron-osx-sign": "^0.3.0", "electron-packager": "^7.0.0", From a8239895c6bd491de50198697584e336d6e70885 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:41:37 -0700 Subject: [PATCH 4/7] babel: Add --quiet option --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f30bf96..d4724f6d 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "url": "git://github.com/feross/webtorrent-desktop.git" }, "scripts": { - "build": "babel src -d build", + "build": "babel --quiet src --out-dir build", "clean": "node ./bin/clean.js", "open-config": "node ./bin/open-config.js", "package": "node ./bin/package.js", From 9afed7fb1b7f3e6c794539dc5f6d58ef52184978 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:58:34 -0700 Subject: [PATCH 5/7] Remove --dev flag, Run React in production mode when Electron is in production mode --- src/main/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/index.js b/src/main/index.js index 20b5a3fe..898f977a 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -23,7 +23,11 @@ var windows = require('./windows') var shouldQuit = false var argv = sliceArgv(process.argv) -if (!argv.includes('--dev')) process.env.NODE_ENV = 'production' +if (config.IS_PRODUCTION) { + // When Electron is running in produdtion mode (packaged app), then run React + // in production mode too. + process.env.NODE_ENV = 'production' +} if (process.platform === 'win32') { shouldQuit = squirrelWin32.handleEvent(argv[0]) From c1dd0b31cf4e914930e82cc149a2c23c55fe1a07 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 4 Aug 2016 21:59:01 -0700 Subject: [PATCH 6/7] package: Ignore src/ directory since only build/ is used @dcposch -- does this look reasonable? --- bin/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/package.js b/bin/package.js index b91c39f1..9f72e190 100755 --- a/bin/package.js +++ b/bin/package.js @@ -89,7 +89,7 @@ var all = { // Pattern which specifies which files to ignore when copying files to create the // package(s). - ignore: /^\/dist|\/(appveyor.yml|\.appveyor.yml|\.github|appdmg|AUTHORS|CONTRIBUTORS|bench|benchmark|benchmark\.js|bin|bower\.json|component\.json|coverage|doc|docs|docs\.mli|dragdrop\.min\.js|example|examples|example\.html|example\.js|externs|ipaddr\.min\.js|Makefile|min|minimist|perf|rusha|simplepeer\.min\.js|simplewebsocket\.min\.js|static\/screenshot\.png|test|tests|test\.js|tests\.js|webtorrent\.min\.js|\.[^\/]*|.*\.md|.*\.markdown)$/, + ignore: /^\/src|^\/dist|\/(appveyor.yml|\.appveyor.yml|\.github|appdmg|AUTHORS|CONTRIBUTORS|bench|benchmark|benchmark\.js|bin|bower\.json|component\.json|coverage|doc|docs|docs\.mli|dragdrop\.min\.js|example|examples|example\.html|example\.js|externs|ipaddr\.min\.js|Makefile|min|minimist|perf|rusha|simplepeer\.min\.js|simplewebsocket\.min\.js|static\/screenshot\.png|test|tests|test\.js|tests\.js|webtorrent\.min\.js|\.[^\/]*|.*\.md|.*\.markdown)$/, // The application name. name: config.APP_NAME, From c42eb789df3a01b288291266ca7947203e9e3746 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 5 Aug 2016 16:37:25 -0700 Subject: [PATCH 7/7] fix typo --- src/main/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/index.js b/src/main/index.js index 898f977a..63a67b95 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -24,7 +24,7 @@ var shouldQuit = false var argv = sliceArgv(process.argv) if (config.IS_PRODUCTION) { - // When Electron is running in produdtion mode (packaged app), then run React + // When Electron is running in production mode (packaged app), then run React // in production mode too. process.env.NODE_ENV = 'production' }