mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
117 lines
3.9 KiB
JavaScript
Executable file
117 lines
3.9 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 submodule at ${privateDir}. Skipping...`)
|
|
return;
|
|
}
|
|
|
|
const unlinkIfExistsSync = (p) => {
|
|
try {
|
|
if (fs.lstatSync(p)) {
|
|
fs.removeSync(p);
|
|
}
|
|
} catch (err) {
|
|
return
|
|
}
|
|
}
|
|
|
|
// copy Arc Files
|
|
unlinkIfExistsSync('.arcconfig');
|
|
fs.symlinkSync(path.join('src', 'K2', '.arcconfig'), '.arcconfig', 'file');
|
|
unlinkIfExistsSync('.arclint');
|
|
fs.symlinkSync(path.join('src', 'K2', '.arclint'), '.arclint', 'file');
|
|
unlinkIfExistsSync('arclib');
|
|
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) => {
|
|
try {
|
|
const exec = require('child_process').exec;
|
|
const 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())
|
|
.catch((err) => {
|
|
console.log('script/bootstrap encountered an error')
|
|
console.log(err)
|
|
})
|