Mailspring/script/bootstrap

87 lines
3.2 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 privateDir = path.resolve(path.join('src', 'K2', 'packages', 'local-private'))
const canaryFileExists = fs.existsSync(path.join(privateDir, "README.md"))
if (!canaryFileExists) {
console.log(`Could not find pro submodule at ${privateDir}. Skipping...`)
return;
}
const unlinkIfExistsSync = (p) => {
try { if (fs.lstatSync(p)) { fs.removeSync(p); } } catch (err) { return }
}
// copy Arc Files
fs.copySync(path.join('src', 'K2', '.arcconfig'), '.')
fs.copySync(path.join('src', 'K2', '.arclint'), '.')
fs.copySync(path.join('src', 'K2', 'arclib'), '.')
// copy Source Extensions
unlinkIfExistsSync(path.join('src', 'error-logger-extensions'));
fs.copySync(path.join(privateDir, 'src'), 'src');
// link Plugins
for (const plugin of fs.readdirSync(path.join(privateDir, 'packages'))) {
const from = path.join(privateDir, 'packages', plugin);
const to = path.join(path.resolve('internal_packages'), plugin);
unlinkIfExistsSync(to);
fs.symlinkSync(from, to, 'dir');
}
// link local-sync
const localSyncDir = path.resolve(path.join('src', 'K2', 'packages', 'local-sync'))
const destination = path.join(path.resolve('internal_packages'), 'local-sync');
unlinkIfExistsSync(destination);
fs.symlinkSync(localSyncDir, destination, '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(() => npm('install', {cwd: path.join('src', 'K2'), env: 'electron'}))
.then(() => npm('dedupe', {cwd: path.join('src', 'K2'), env: 'electron'}))
.then(() => npm('rebuild', {cwd: path.join('src', 'K2', 'packages', 'cloud-core'), env: 'system'}))
.then(() => npm('rebuild', {cwd: path.join('src', 'K2', 'packages', 'cloud-api'), env: 'system'}))
.then(() => npm('rebuild', {cwd: path.join('src', 'K2', 'packages', 'cloud-workers'), env: 'system'}))
.then(() => installPrivateResources())