Mailspring/script/bootstrap
Evan Morikawa 41c893cc17 Move old edgehill src/pro into K2/packages/nylas-private
Summary:
feat(bootstrap): automatically init submodule if able

fix(bootstrap): symlink arc instead of copy

Test Plan: test

Reviewers: juan

Differential Revision: https://phab.nylas.com/D3494
2016-12-12 10:38:43 -05:00

104 lines
3.6 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.symlinkSync(path.join('src', 'K2', '.arcconfig'), '.arcconfig', 'file');
fs.symlinkSync(path.join('src', 'K2', '.arclint'), '.arclint', 'file');
fs.symlinkSync(path.join('src', 'K2', 'arclib'), 'arclib', 'dir');
// 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');
}
function verifySubmodule() {
return new Promise((resolve, reject) => {
try {
var exec = require('child_process').exec;
var cmd = 'git submodule update --init --recursive';
exec(cmd, (error, stdout) => {
console.log(stdout);
if (error) console.error(error);
resolve()
})
} catch (err) {
console.error(err)
resolve()
}
})
}
verifySubmodule()
.then(() => 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())