Mailspring/build/tasks/publish-task.js

178 lines
5.5 KiB
JavaScript
Raw Normal View History

build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */
const s3 = require('s3');
const request = require('request');
const Promise = require('bluebird');
const path = require('path');
const fs = require('fs-plus');
let s3Client = null;
let packageVersion = null;
let fullVersion = null;
module.exports = (grunt) => {
const {spawn} = require('./task-helpers')(grunt);
function populateVersion() {
return new Promise((resolve, reject) => {
const json = grunt.config.get('appJSON')
const cmd = 'git';
const args = ['rev-parse', '--short', 'HEAD'];
spawn({cmd, args}, (error, {stdout} = {}) => {
if (error) {
return reject();
}
const commitHash = stdout ? stdout.trim() : null;
packageVersion = json.version;
if (packageVersion.indexOf('-') > 0) {
fullVersion = packageVersion;
} else {
fullVersion = `${packageVersion}-${commitHash}`;
}
return resolve();
});
});
}
function postToSlack(msg) {
if (!process.env.NYLAS_INTERNAL_HOOK_URL) {
return Promise.resolve();
}
return new Promise((resolve, reject) =>
request.post({
url: process.env.NYLAS_INTERNAL_HOOK_URL,
json: {
username: "Edgehill Builds",
text: msg,
},
}
, (error) => {
return error ? reject(error) : resolve();
})
);
}
function put(localSource, destName, options = {}) {
grunt.log.writeln(`>> Uploading ${localSource} to S3…`);
const write = grunt.log.writeln;
let lastPc = 0;
const params = {
Key: destName,
ACL: "public-read",
Bucket: "edgehill",
};
Object.assign(params, options);
return new Promise((resolve, reject) => {
const uploader = s3Client.uploadFile({
localFile: localSource,
s3Params: params,
});
uploader.on("error", err => reject(err));
uploader.on("progress", () => {
const pc = Math.round((uploader.progressAmount / uploader.progressTotal) * 100.0);
if (pc !== lastPc) {
lastPc = pc;
write(`>> Uploading ${destName} ${pc}%`);
return;
}
});
uploader.on("end", data => resolve(data));
});
}
function uploadToS3(filepath, key) {
2016-11-19 03:58:09 +08:00
grunt.log.writeln(`>> Uploading ${filepath} to ${key}`);
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
return put(filepath, key).then((data) => {
const msg = `N1 release asset uploaded: <${data.Location}|${key}>`;
return postToSlack(msg).then(() => Promise.resolve(data));
});
}
grunt.registerTask("publish", "Publish Nylas build", function publish() {
const done = this.async();
populateVersion()
.then(() => {
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
// find files to publish
const {shouldPublishBuild} = require('./task-helpers')(grunt);
const outputDir = grunt.config.get('outputDir');
const uploads = [];
if (process.platform === 'darwin') {
uploads.push({
source: `${outputDir}/N1.zip`,
key: `${fullVersion}/${process.platform}/${process.arch}/N1.zip`,
});
} else if (process.platform === 'win32') {
uploads.push({
source: `${outputDir}/RELEASES`,
key: `${fullVersion}/${process.platform}/${process.arch}/RELEASES`,
});
uploads.push({
source: `${outputDir}/N1Setup.exe`,
key: `${fullVersion}/${process.platform}/${process.arch}/N1Setup.exe`,
});
uploads.push({
source: `${outputDir}/Nylas-${packageVersion}-full.nupkg`,
key: `${fullVersion}/${process.platform}/${process.arch}/nylas-${packageVersion}-full.nupkg`,
});
} else if (process.platform === 'linux') {
const files = fs.readdirSync(outputDir);
for (const file of files) {
if (path.extname(file) === '.deb') {
uploads.push({
2016-11-22 04:03:37 +08:00
source: `${outputDir}/${file}`,
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
key: `${fullVersion}/${process.platform}-deb/${process.arch}/N1.deb`,
options: {ContentType: "application/x-deb"},
});
}
if (path.extname(file) === '.rpm') {
uploads.push({
2016-11-22 04:03:37 +08:00
source: `${outputDir}/${file}`,
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
key: `${fullVersion}/${process.platform}-rpm/${process.arch}/N1.rpm`,
options: {ContentType: "application/x-rpm"},
});
}
}
} else {
grunt.fail.fatal(`Unsupported platform: '${process.platform}'`);
}
// configure environment
if (!shouldPublishBuild()) {
grunt.log.writeln(`>> Not publishing builds…`);
grunt.log.writeln(`>> Would have uploaded the following assets: ${JSON.stringify(uploads, null, 2)}`);
return Promise.resolve();
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
}
const awsKey = process.env.AWS_ACCESS_KEY_ID != null ? process.env.AWS_ACCESS_KEY_ID : "";
const awsSecret = process.env.AWS_SECRET_ACCESS_KEY != null ? process.env.AWS_SECRET_ACCESS_KEY : "";
if (awsKey.length === 0) {
grunt.fail.fatal("Please set the AWS_ACCESS_KEY_ID environment variable");
}
if (awsSecret.length === 0) {
grunt.fail.fatal("Please set the AWS_SECRET_ACCESS_KEY environment variable");
}
s3Client = s3.createClient({
s3Options: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
scretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
return Promise.all(uploads.map(({source, key, options}) =>
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
uploadToS3(source, key, options))
)
.then(done)
})
.catch((err) => {
grunt.fail.fatal(err)
build(*): electron-compile, electron-packager instead of custom tooling Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
2016-11-10 05:50:46 +08:00
});
});
}