mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
e5dfc7cadd
Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D1537
148 lines
4.9 KiB
JavaScript
Executable file
148 lines
4.9 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
var fs = require('fs');
|
|
var verifyRequirements = require('./utils/verify-requirements');
|
|
var safeExec = require('./utils/child-process-wrapper.js').safeExec;
|
|
var path = require('path');
|
|
|
|
// Executes an array of commands one by one.
|
|
function executeCommands(commands, done, index) {
|
|
index = (index == undefined ? 0 : index);
|
|
if (index < commands.length) {
|
|
var command = commands[index];
|
|
if (command.message)
|
|
console.log(command.message);
|
|
var options = null;
|
|
if (typeof command !== 'string') {
|
|
options = command.options;
|
|
command = command.command;
|
|
}
|
|
safeExec(command, options, executeCommands.bind(this, commands, done, index + 1));
|
|
}
|
|
else
|
|
done(null);
|
|
}
|
|
|
|
function printArgs(args) {
|
|
out = "";
|
|
for(key in args) {
|
|
out += "--"+key+"="+args[key]+" ";
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function bootstrap() {
|
|
var apmInstallPath = path.resolve(__dirname, '..', 'apm');
|
|
if (!fs.existsSync(apmInstallPath))
|
|
fs.mkdirSync(apmInstallPath);
|
|
if (!fs.existsSync(path.join(apmInstallPath, 'node_modules')))
|
|
fs.mkdirSync(path.join(apmInstallPath, 'node_modules'));
|
|
|
|
var apmPath = path.resolve(__dirname, '..', 'apm', 'node_modules', 'atom-package-manager', 'bin', 'apm')
|
|
var apmFlags = process.env.JANKY_SHA1 || process.argv.indexOf('--no-color') !== -1 ? ' --no-color' : '';
|
|
|
|
var npmPath = path.resolve(__dirname, '..', 'build', 'node_modules', '.bin', 'npm');
|
|
var initialNpmCommand = fs.existsSync(npmPath) ? npmPath : 'npm';
|
|
var npmFlags = ' --userconfig=' + path.resolve('.npmrc') + ' ';
|
|
|
|
var gruntPath = path.resolve(__dirname, '..', 'build', 'node_modules', '.bin', 'grunt');
|
|
|
|
var packagesToDedupe = ['fs-plus', 'humanize-plus', 'roaster', 'season', 'grim'];
|
|
|
|
var buildInstallCommand = initialNpmCommand + npmFlags + 'install';
|
|
var buildInstallOptions = {cwd: path.resolve(__dirname, '..', 'build')};
|
|
var apmInstallCommand = npmPath + npmFlags + 'install';
|
|
var apmInstallOptions = {cwd: apmInstallPath};
|
|
var moduleInstallCommand = apmPath + ' install' + apmFlags;
|
|
var dedupeApmCommand = apmPath + ' dedupe' + apmFlags;
|
|
var semverOptions = {cwd: path.resolve(__dirname, '..', 'apm', 'node_modules', 'atom-package-manager')};
|
|
|
|
if (process.argv.indexOf('--no-quiet') === -1) {
|
|
buildInstallCommand += ' --loglevel error';
|
|
apmInstallCommand += ' --loglevel error';
|
|
moduleInstallCommand += ' --loglevel error';
|
|
dedupeApmCommand += ' --quiet';
|
|
buildInstallOptions.ignoreStdout = true;
|
|
apmInstallOptions.ignoreStdout = true;
|
|
}
|
|
|
|
// apm ships with 32-bit node so make sure its native modules are compiled
|
|
// for a 32-bit target architecture
|
|
if (process.env.JANKY_SHA1 && process.platform === 'win32')
|
|
apmInstallCommand += ' --arch=ia32';
|
|
|
|
m1 = "\n---> Installing Nylas Mail build tools\n"
|
|
m1 += " This goes inside the `build` folder and runs `npm install`\n"
|
|
m1 += " It will use the system `npm` to bootstrap our own Nylas Mail npm.\n"
|
|
m1 += " Our build tools (like Grunt) need to be compiled against Node via `npm`.\n"
|
|
m1 += " Everything else needs to be compiled against Chromium with `apm`.\n\n"
|
|
m1 += " $ "+buildInstallCommand+" "+printArgs(buildInstallOptions)+"\n"
|
|
|
|
m2 = "\n\n---> Installing apm\n"
|
|
m2 += " This installs apm via Nylas Mail's `npm`\n"
|
|
m2 += " We use this local apm copy to install all Nylas Mail dependencies & packages\n\n"
|
|
m2 += " $ "+apmInstallCommand+" "+printArgs(apmInstallOptions)+"\n"
|
|
|
|
m3 = "\n\n---> Cleaning apm via `apm clean`\n"
|
|
|
|
m4 = "\n\n---> Installing Nylas Mail dependencies & packages via `apm install`\n\n"
|
|
m4 += " $ "+moduleInstallCommand+"\n"
|
|
|
|
m5 = "\n\n---> De-duping packages `apm clean`\n\n"
|
|
m5 += " $ apm "+packagesToDedupe.join(' ')+"\n"
|
|
|
|
m6 = "\n\n---> Request version `apm clean`\n\n"
|
|
m6 += " $ apm request semver "+printArgs(semverOptions)+"\n"
|
|
|
|
m7 = "\n\n---> Getting latest Electron\n\n"
|
|
var gruntCmd = ""
|
|
var downloadElectronCmd = gruntPath + " download-electron --gruntfile build/Gruntfile.coffee"
|
|
m7 += " $ "+downloadElectronCmd
|
|
|
|
var commands = [
|
|
{
|
|
command: buildInstallCommand,
|
|
message: m1,
|
|
options: buildInstallOptions
|
|
},
|
|
{
|
|
command: apmInstallCommand,
|
|
message: m2,
|
|
options: apmInstallOptions
|
|
},
|
|
{
|
|
command: apmPath + ' clean' + apmFlags,
|
|
message: m3
|
|
},
|
|
{
|
|
command: moduleInstallCommand,
|
|
message: m4
|
|
},
|
|
{
|
|
command: dedupeApmCommand + ' ' + packagesToDedupe.join(' '),
|
|
message: m5
|
|
},
|
|
{
|
|
command: dedupeApmCommand + ' request semver',
|
|
message: m6,
|
|
options: semverOptions
|
|
},
|
|
{
|
|
command: downloadElectronCmd,
|
|
message: m7
|
|
}
|
|
];
|
|
|
|
process.chdir(path.dirname(__dirname));
|
|
executeCommands(commands, process.exit);
|
|
}
|
|
|
|
verifyRequirements(function(error, successMessage) {
|
|
if (error) {
|
|
console.log(error);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(successMessage);
|
|
bootstrap();
|
|
});
|