Permalink
Browse files

[dev] Only bootstrap specific pkgs in postinstall for faster installs

Summary:
This commit makes it so postinstall.es6 only bootstraps the packages we
are interested in based on a new env variable, `INSTALL_TARGET`.

`INSTALL_TARGET` can be set to `cloud`, `client` or `all`, or not set at all,
and our postinstall will bootstrap the packages accordingly. This will make
build and deploy times faster.

Test Plan: manual

Reviewers: spang, halla, evan, khamidou

Reviewed By: evan, khamidou

Differential Revision: https://phab.nylas.com/D4271
  • Loading branch information...
jstejada committed Mar 27, 2017
1 parent 08975c0 commit d165b294c60efa1f9fb9ece63ba18b6daf2bf9d5
Showing with 42 additions and 26 deletions.
  1. +2 −2 .travis.yml
  2. +1 −1 Dockerfile
  3. +1 −1 appveyor.yml
  4. +1 −1 scripts/daily.js
  5. +37 −21 scripts/postinstall.es6
@@ -28,9 +28,9 @@ branches:
matrix:
include:
- os: linux
env: NODE_VERSION=6.9 CC=gcc-4.8 CXX=g++-4.8 DEBUG="electron-packager:*" ONLY_CLIENT=true
env: NODE_VERSION=6.9 CC=gcc-4.8 CXX=g++-4.8 DEBUG="electron-packager:*" INSTALL_TARGET=client
- os: osx
env: NODE_VERSION=6.9 CC=clang CXX=clang++ SIGN_BUILD=true DEBUG="electron-packager:*" ONLY_CLIENT=true
env: NODE_VERSION=6.9 CC=clang CXX=clang++ SIGN_BUILD=true DEBUG="electron-packager:*" INSTALL_TARGET=client
before_install:
- openssl aes-256-cbc
@@ -5,7 +5,7 @@
# Use the latest Node 6 base docker image
# https://github.com/nodejs/docker-node
FROM node:6
ENV ONLY_CLIENT=false
ENV INSTALL_TARGET=cloud
# Copy everything (excluding what's in .dockerignore) into an empty dir
COPY . /home
@@ -36,7 +36,7 @@ environment:
global:
DEBUG: "electron-windows-installer:*,electron-packager:*"
SIGN_BUILD: true
ONLY_CLIENT: true
INSTALL_TARGET: "client"
CERTIFICATE_FILE: .\packages\client-private-plugins\encrypted_certificates\appveyor\win-nylas-n1.p12
DECRYPTION_PASSWORD:
secure: 48VSzDtdBd52Xlo3TZ1NeR1yRRrZ3AU6Px5XjD5RDp44cFU5GYVspecGqX6DGCV7i0D7nldGMyEbXNrjM1t1Kw==
@@ -206,7 +206,7 @@ async function main(args) {
try {
await spawn('git', ['clean', '-xdf'])
await spawn('cp', ['-r', '../n1-keys-and-certificates', 'packages/client-app/build/resources/certs'])
await spawn('npm', ['install'], {env: {ONLY_CLIENT: true}})
await spawn('npm', ['install'], {env: {INSTALL_TARGET: 'client'}})
await spawn('npm', ['run', 'build-client'], {env: {SIGN_BUILD: true}})
await spawn('codesign', ['--verify', '--deep', '--verbose=2', '"packages/client-app/dist/Nylas Mail-darwin-x64/Nylas Mail.app"'])
await spawn('npm', ['run', 'upload-client'])
@@ -2,6 +2,10 @@ import fs from 'fs-plus'
import path from 'path'
import childProcess from 'child_process'
const TARGET_ALL = 'all'
const TARGET_CLOUD = 'cloud'
const TARGET_CLIENT = 'client'
async function spawn(cmd, args, opts = {}) {
return new Promise((resolve, reject) => {
const options = Object.assign({stdio: 'inherit'}, opts);
@@ -53,15 +57,19 @@ async function installPrivateResources() {
fs.symlinkSync(clientSyncDir, destination, 'dir');
}
async function lernaBootstrap(installFor) {
async function lernaBootstrap(installTarget) {
console.log("\n---> Installing packages");
let lernaCmd = "lerna"
if (process.platform === "win32") { lernaCmd = "lerna.cmd" }
const lernaCmd = process.platform === 'win32' ? 'lerna.cmd' : 'lerna';
const args = ["bootstrap"]
if (installFor === "clientOnly") {
args.push("--ignore='cloud-*'")
} else if (installFor === "cloudOnly") {
args.push("--ignore='client-*'")
switch (installTarget) {
case TARGET_CLIENT:
args.push(`--ignore='cloud-*'`)
break
case TARGET_CLOUD:
args.push(`--ignore='client-*'`)
break
default:
break
}
await spawn(path.join('node_modules', '.bin', lernaCmd), args)
}
@@ -83,8 +91,7 @@ const npmEnvs = {
async function npm(cmd, options) {
const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options);
let npmCmd = "npm"
if (process.platform === "win32") { npmCmd = "npm.cmd" }
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
await spawn(npmCmd, [cmd], {
cwd: path.resolve(__dirname, '..', cwd),
env: npmEnvs[env],
@@ -137,27 +144,36 @@ function linkIsomorphicCoreSpecs() {
fs.symlinkSync(from, to, 'dir')
}
function getInstallTarget() {
const {INSTALL_TARGET} = process.env
if (!INSTALL_TARGET) {
return TARGET_ALL
}
if (![TARGET_ALL, TARGET_CLIENT, TARGET_CLOUD].includes(INSTALL_TARGET)) {
throw new Error(`postinstall: INSTALL_TARGET must be one of client, cloud, or all. It was set to ${INSTALL_TARGET}`)
}
return INSTALL_TARGET
}
async function main() {
try {
let installFor = "all";
if (process.env.ONLY_CLIENT === "true") installFor = "clientOnly"
if (process.env.ONLY_CLIENT === "false") installFor = "cloudOnly"
const installTarget = getInstallTarget()
console.log(`\n---> Installing for target ${installTarget}`);
if (installFor === "all" || installFor === "clientOnly") {
if ([TARGET_ALL, TARGET_CLIENT].includes(installTarget)) {
await installPrivateResources()
}
await lernaBootstrap(installFor);
await lernaBootstrap(installTarget);
if (installFor === "all" || installFor === "clientOnly") {
// Given that `lerna bootstrap` does not install optional
// dependencies, we need to manually run `npm install` inside
// `client-app` so `node-mac-notifier` get's correctly installed and
// included in the build See
// https://github.com/lerna/lerna/issues/121
if ([TARGET_ALL, TARGET_CLIENT].includes(installTarget)) {
if (process.platform === "darwin") {
// Given that `lerna bootstrap` does not install optional dependencies, we
// need to manually run `npm install` inside `client-app` so
// `node-mac-notifier` get's correctly installed and included in the build
// See https://github.com/lerna/lerna/issues/121
console.log("\n---> Reinstalling client-app dependencies to include optional dependencies");
await npm('install', {cwd: 'packages/client-app'})
await npm('install', {cwd: 'packages/client-app'})
}
await electronRebuild();
linkJasmineConfigs();

0 comments on commit d165b29

Please sign in to comment.