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;
|
2018-01-09 15:05:24 +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
|
|
|
|
2018-01-09 15:05:24 +00:00
|
|
|
mkdirpAsync(path.dirname(outputFile))
|
|
|
|
.then(
|
|
|
|
() =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
console.log('Zipping build...');
|
2017-12-13 17:33:03 +00:00
|
|
|
|
2018-01-09 15:05:24 +00:00
|
|
|
let archive = archiver('zip', {
|
|
|
|
zlib: { level: 7 },
|
|
|
|
});
|
|
|
|
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();
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
console.log('Build zipped');
|
|
|
|
console.log('Publishing build...');
|
|
|
|
|
|
|
|
return publishReleaseAsync({
|
|
|
|
token: <string>GITHUB_TOKEN,
|
|
|
|
owner: 'resin-io',
|
|
|
|
repo: 'resin-cli',
|
|
|
|
tag: version,
|
|
|
|
name: `Resin-CLI ${version}`,
|
|
|
|
reuseRelease: true,
|
|
|
|
assets: [outputFile],
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(release => {
|
|
|
|
console.log(`Release ${version} successful: ${release.html_url}`);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error('Release failed');
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2017-12-13 17:33:03 +00:00
|
|
|
});
|