Mailspring/script/bootstrap
2016-11-21 13:49:05 -08:00

73 lines
2.3 KiB
JavaScript
Executable file

#!/usr/bin/env node
/* eslint global-require: 0 */
/* eslint quote-props: 0 */
const path = require('path');
const safeExec = require('./utils/child-process-wrapper.js').safeExec;
const npmEnvs = {
system: process.env,
apm: Object.assign({}, process.env, {
'npm_config_target': '0.10.40',
}),
electron: Object.assign({}, process.env, {
'npm_config_target': '1.4.1',
'npm_config_arch': process.arch,
'npm_config_target_arch': process.arch,
'npm_config_disturl': 'https://atom.io/download/atom-shell',
'npm_config_runtime': 'electron',
'npm_config_build_from_source': true,
}),
};
function npm(cmd, options) {
const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options);
return new Promise((resolve, reject) => {
console.log(`\n-- Running npm ${cmd} in ./${cwd} with ${env} config --`)
safeExec(`npm ${cmd}`, {
cwd: path.resolve(__dirname, '..', cwd),
env: npmEnvs[env],
}, (err) => {
return err ? reject(err) : resolve(null);
});
});
}
function installPrivateResources() {
console.log("\n-- Linking Nylas submodule resources --")
const fs = require('fs-plus');
const proDir = path.resolve(path.join('src', 'pro'))
const canaryFileExists = fs.existsSync(path.join(proDir, "README.md"))
if (!canaryFileExists) {
console.log(`Could not find pro submodule at ${proDir}. Skipping...`)
return;
}
const unlinkIfExistsSync = (p) => {
try { if (fs.lstatSync(p)) { fs.removeSync(p); } } catch (err) { return }
}
// copy Arc Files
fs.copySync(path.join(proDir, 'arc-N1'), '.')
// copy Source Extensions
unlinkIfExistsSync(path.join('src', 'error-logger-extensions'));
fs.copySync(path.join(proDir, 'src'), 'src');
// link Plugins
for (const plugin of fs.readdirSync(path.join(proDir, 'packages'))) {
const from = path.join(proDir, 'packages', plugin);
const to = path.join(path.resolve('internal_packages'), plugin);
unlinkIfExistsSync(to);
fs.symlinkSync(from, to, 'dir');
}
}
npm('install', {cwd: 'build'})
.then(() => npm('install', {cwd: 'apm', env: 'apm'}))
.then(() => npm('dedupe', {cwd: path.join('apm', 'node_modules', 'npm'), env: 'apm'}))
.then(() => npm('install', {cwd: '.', env: 'electron'}))
.then(() => npm('dedupe', {cwd: '.', env: 'electron'}))
.then(() => installPrivateResources())