mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 15:56:10 +08:00
3071856a8e
Summary: The prod build was failing because it couldn't find the .babelrc. I decided to put the babelrc in the main nylas-mail repo with the expectation that it'll need to be in the open source version too. To DRY up this for us building, we sylink the root one to the client-app babelrc Also since we now dereference symlinks we don't need to do the full copy of nylas-private-resources so we don't have two error reporters floating around Test Plan: npm run build-client Reviewers: juan, spang Reviewed By: juan, spang Differential Revision: https://phab.nylas.com/D3993
110 lines
3 KiB
JavaScript
110 lines
3 KiB
JavaScript
import fs from 'fs-plus'
|
|
import path from 'path'
|
|
import childProcess from 'child_process'
|
|
|
|
async function spawn(cmd, args, opts = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
const options = Object.assign({stdio: 'inherit'}, opts);
|
|
const proc = childProcess.spawn(cmd, args, options)
|
|
proc.on("error", reject)
|
|
proc.on("exit", resolve)
|
|
})
|
|
}
|
|
|
|
function unlinkIfExistsSync(p) {
|
|
try {
|
|
if (fs.lstatSync(p)) {
|
|
fs.removeSync(p);
|
|
}
|
|
} catch (err) {
|
|
return
|
|
}
|
|
}
|
|
|
|
function linkErrorLoggerExtensions(privateDir) {
|
|
const from = path.join(privateDir, 'src', 'error-logger-extensions')
|
|
const to = path.resolve(path.join('packages', 'client-app', 'src', 'error-logger-extensions'))
|
|
unlinkIfExistsSync(to);
|
|
fs.symlinkSync(from, to, 'dir');
|
|
}
|
|
|
|
async function installPrivateResources() {
|
|
console.log("\n---> Linking private plugins")
|
|
const privateDir = path.resolve(path.join('packages', 'client-private-plugins'))
|
|
if (!fs.existsSync(privateDir)) {
|
|
console.log("\n---> No client app to link. Moving on")
|
|
return;
|
|
}
|
|
|
|
linkErrorLoggerExtensions(privateDir)
|
|
|
|
// link private plugins
|
|
for (const plugin of fs.readdirSync(path.join(privateDir, 'packages'))) {
|
|
const from = path.resolve(path.join(privateDir, 'packages', plugin));
|
|
const to = path.resolve(path.join('packages', 'client-app', 'internal_packages', plugin));
|
|
unlinkIfExistsSync(to);
|
|
fs.symlinkSync(from, to, 'dir');
|
|
}
|
|
|
|
// link client-sync
|
|
const clientSyncDir = path.resolve(path.join('packages', 'client-sync'));
|
|
const destination = path.resolve(path.join('packages', 'client-app', 'internal_packages', 'client-sync'));
|
|
unlinkIfExistsSync(destination);
|
|
fs.symlinkSync(clientSyncDir, destination, 'dir');
|
|
}
|
|
|
|
async function lernaBootstrap() {
|
|
console.log("\n---> Installing packages");
|
|
await spawn("lerna", ["bootstrap"])
|
|
}
|
|
|
|
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.15',
|
|
NPM_CONFIG_ARCH: process.arch,
|
|
NPM_CONFIG_TARGET_ARCH: process.arch,
|
|
NPM_CONFIG_DISTURL: 'https://atom.io/download/electron',
|
|
NPM_CONFIG_RUNTIME: 'electron',
|
|
NPM_CONFIG_BUILD_FROM_SOURCE: true,
|
|
}),
|
|
};
|
|
|
|
async function npm(cmd, options) {
|
|
const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options);
|
|
await spawn("npm", [cmd], {
|
|
cwd: path.resolve(__dirname, '..', cwd),
|
|
env: npmEnvs[env],
|
|
})
|
|
}
|
|
|
|
async function electronRebuild() {
|
|
if (!fs.existsSync(path.join("packages", "client-app"))) {
|
|
console.log("\n---> No client app to rebuild. Moving on")
|
|
return;
|
|
}
|
|
await npm('install', {
|
|
cwd: path.join('packages', 'client-app', 'apm'),
|
|
env: 'apm',
|
|
})
|
|
await npm('rebuild', {
|
|
cwd: path.join('packages', 'client-app'),
|
|
env: 'electron',
|
|
})
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
await installPrivateResources()
|
|
await lernaBootstrap();
|
|
await electronRebuild();
|
|
} catch (err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
main()
|