2017-12-13 17:33:03 +00:00
|
|
|
import * as Promise from 'bluebird';
|
|
|
|
import * as path from 'path';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as fs from 'fs-extra';
|
2017-12-18 13:49:45 +00:00
|
|
|
import * as mkdirp from 'mkdirp';
|
2017-12-13 17:33:03 +00:00
|
|
|
import * as publishRelease from 'publish-release';
|
|
|
|
import * as archiver from 'archiver';
|
2018-01-04 14:07:55 +00:00
|
|
|
import * as packageJSON from '../package.json';
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2017-12-14 11:29:54 +00:00
|
|
|
const publishReleaseAsync = Promise.promisify(publishRelease);
|
2017-12-18 13:49:45 +00:00
|
|
|
const mkdirpAsync = Promise.promisify<string | null, string>(mkdirp);
|
2017-12-13 17:33:03 +00:00
|
|
|
|
|
|
|
const { GITHUB_TOKEN } = process.env;
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
|
2018-01-04 14:07:55 +00:00
|
|
|
const version = 'v' + packageJSON.version;
|
2017-12-18 13:49:45 +00:00
|
|
|
const outputFile = path.join(ROOT, 'build-zip', `resin-cli-${version}-${os.platform()}-${os.arch()}.zip`);
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2017-12-18 13:49:45 +00:00
|
|
|
mkdirpAsync(path.dirname(outputFile)).then(() => new Promise((resolve, reject) => {
|
2017-12-13 17:33:03 +00:00
|
|
|
console.log('Zipping build...');
|
|
|
|
|
|
|
|
let archive = archiver('zip', {
|
2018-01-04 14:07:55 +00:00
|
|
|
zlib: { level: 7 },
|
2017-12-13 17:33:03 +00:00
|
|
|
});
|
|
|
|
archive.directory(path.join(ROOT, 'build-bin'), 'resin-cli');
|
|
|
|
|
|
|
|
let outputStream = fs.createWriteStream(outputFile);
|
|
|
|
|
|
|
|
outputStream.on('close', resolve);
|
|
|
|
outputStream.on('error', reject);
|
|
|
|
|
|
|
|
archive.on('error', reject);
|
|
|
|
archive.on('warning', console.warn);
|
|
|
|
|
|
|
|
archive.pipe(outputStream);
|
|
|
|
archive.finalize();
|
2017-12-18 13:49:45 +00:00
|
|
|
})).then(() => {
|
2017-12-13 17:33:03 +00:00
|
|
|
console.log('Build zipped');
|
|
|
|
console.log('Publishing build...');
|
|
|
|
|
|
|
|
return publishReleaseAsync({
|
2017-12-18 13:49:45 +00:00
|
|
|
token: <string> GITHUB_TOKEN,
|
2017-12-13 17:33:03 +00:00
|
|
|
owner: 'resin-io',
|
|
|
|
repo: 'resin-cli',
|
|
|
|
tag: version,
|
|
|
|
name: `Resin-CLI ${version}`,
|
|
|
|
reuseRelease: true,
|
2018-01-04 14:07:55 +00:00
|
|
|
assets: [outputFile],
|
2017-12-13 17:33:03 +00:00
|
|
|
});
|
|
|
|
}).then((release) => {
|
|
|
|
console.log(`Release ${version} successful: ${release.html_url}`);
|
|
|
|
}).catch((err) => {
|
|
|
|
console.error('Release failed');
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|