2019-04-15 00:55:37 -04:00
|
|
|
const {series, watch, src, dest, parallel} = require('gulp');
|
2019-03-10 12:15:39 -04:00
|
|
|
const pump = require('pump');
|
2020-03-31 11:03:17 -04:00
|
|
|
const path = require('path');
|
|
|
|
const releaseUtils = require('@tryghost/release-utils');
|
|
|
|
const inquirer = require('inquirer');
|
2017-05-15 16:03:47 -04:00
|
|
|
|
|
|
|
// gulp plugins and utils
|
2019-03-14 12:07:40 -04:00
|
|
|
const livereload = require('gulp-livereload');
|
|
|
|
const postcss = require('gulp-postcss');
|
|
|
|
const zip = require('gulp-zip');
|
2019-10-20 09:55:06 -04:00
|
|
|
const concat = require('gulp-concat');
|
2019-03-14 12:07:40 -04:00
|
|
|
const uglify = require('gulp-uglify');
|
|
|
|
const beeper = require('beeper');
|
2019-10-20 02:35:13 -04:00
|
|
|
const fs = require('fs');
|
2017-05-15 16:03:47 -04:00
|
|
|
|
|
|
|
// postcss plugins
|
2019-03-14 12:07:40 -04:00
|
|
|
const autoprefixer = require('autoprefixer');
|
2020-07-27 13:52:31 -04:00
|
|
|
const colorFunction = require('postcss-color-mod-function');
|
2019-03-14 12:07:40 -04:00
|
|
|
const cssnano = require('cssnano');
|
|
|
|
const easyimport = require('postcss-easy-import');
|
2017-05-15 16:03:47 -04:00
|
|
|
|
2020-03-31 11:03:17 -04:00
|
|
|
const REPO = 'TryGhost/Casper';
|
|
|
|
const REPO_READONLY = 'TryGhost/Casper';
|
|
|
|
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');
|
|
|
|
|
2019-03-10 12:15:39 -04:00
|
|
|
function serve(done) {
|
|
|
|
livereload.listen();
|
|
|
|
done();
|
|
|
|
}
|
2017-05-15 16:03:47 -04:00
|
|
|
|
2019-03-10 12:15:39 -04:00
|
|
|
const handleError = (done) => {
|
2019-01-22 06:00:10 -05:00
|
|
|
return function (err) {
|
|
|
|
if (err) {
|
|
|
|
beeper();
|
|
|
|
}
|
|
|
|
return done(err);
|
|
|
|
};
|
2019-03-10 12:15:39 -04:00
|
|
|
};
|
2018-10-12 01:41:06 -04:00
|
|
|
|
2019-04-15 00:55:37 -04:00
|
|
|
function hbs(done) {
|
|
|
|
pump([
|
2019-08-21 01:51:43 -04:00
|
|
|
src(['*.hbs', 'partials/**/*.hbs']),
|
2019-04-15 00:55:37 -04:00
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
|
|
|
}
|
|
|
|
|
2019-03-10 12:15:39 -04:00
|
|
|
function css(done) {
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
2019-03-10 12:15:39 -04:00
|
|
|
src('assets/css/*.css', {sourcemaps: true}),
|
2020-03-31 11:03:17 -04:00
|
|
|
postcss([
|
|
|
|
easyimport,
|
|
|
|
colorFunction(),
|
|
|
|
autoprefixer(),
|
|
|
|
cssnano()
|
|
|
|
]),
|
2019-03-10 12:15:39 -04:00
|
|
|
dest('assets/built/', {sourcemaps: '.'}),
|
2019-01-22 06:00:10 -05:00
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
2019-03-10 12:15:39 -04:00
|
|
|
}
|
2018-10-12 01:41:06 -04:00
|
|
|
|
2019-03-10 12:15:39 -04:00
|
|
|
function js(done) {
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
2019-10-20 09:55:06 -04:00
|
|
|
src([
|
|
|
|
// pull in lib files first so our own code can depend on it
|
|
|
|
'assets/js/lib/*.js',
|
|
|
|
'assets/js/*.js'
|
|
|
|
], {sourcemaps: true}),
|
|
|
|
concat('casper.js'),
|
2019-01-22 06:00:10 -05:00
|
|
|
uglify(),
|
2019-03-10 12:15:39 -04:00
|
|
|
dest('assets/built/', {sourcemaps: '.'}),
|
2019-01-22 06:00:10 -05:00
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
2019-03-10 12:15:39 -04:00
|
|
|
}
|
2017-05-15 16:03:47 -04:00
|
|
|
|
2019-03-10 12:15:39 -04:00
|
|
|
function zipper(done) {
|
2020-03-31 11:03:17 -04:00
|
|
|
const filename = require('./package.json').name + '.zip';
|
2017-09-18 12:37:00 -04:00
|
|
|
|
2019-01-22 06:00:10 -05:00
|
|
|
pump([
|
2019-03-10 12:15:39 -04:00
|
|
|
src([
|
2019-01-22 06:00:10 -05:00
|
|
|
'**',
|
|
|
|
'!node_modules', '!node_modules/**',
|
2020-06-17 14:07:34 -04:00
|
|
|
'!dist', '!dist/**',
|
|
|
|
'!yarn-error.log'
|
2019-01-22 06:00:10 -05:00
|
|
|
]),
|
|
|
|
zip(filename),
|
2020-03-31 11:03:17 -04:00
|
|
|
dest('dist/')
|
2019-01-22 06:00:10 -05:00
|
|
|
], handleError(done));
|
2019-03-10 12:15:39 -04:00
|
|
|
}
|
|
|
|
|
2019-04-15 00:55:37 -04:00
|
|
|
const cssWatcher = () => watch('assets/css/**', css);
|
2019-08-21 01:51:43 -04:00
|
|
|
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs'], hbs);
|
2019-04-15 00:55:37 -04:00
|
|
|
const watcher = parallel(cssWatcher, hbsWatcher);
|
2019-03-10 12:15:39 -04:00
|
|
|
const build = series(css, js);
|
2019-03-14 12:31:28 -04:00
|
|
|
|
2020-03-31 11:03:17 -04:00
|
|
|
exports.build = build;
|
|
|
|
exports.zip = series(build, zipper);
|
|
|
|
exports.default = series(build, serve, watcher);
|
|
|
|
|
2021-03-03 08:20:58 -05:00
|
|
|
exports.release = async () => {
|
2019-03-14 12:31:28 -04:00
|
|
|
// @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
|
2019-10-20 02:35:13 -04:00
|
|
|
// require(./package.json) can run into caching issues, this re-reads from file everytime on release
|
2021-03-03 08:20:58 -05:00
|
|
|
let packageJSON = JSON.parse(fs.readFileSync('./package.json'));
|
2019-10-20 02:35:13 -04:00
|
|
|
const newVersion = packageJSON.version;
|
2019-03-14 12:31:28 -04:00
|
|
|
|
|
|
|
if (!newVersion || newVersion === '') {
|
2020-03-31 11:03:17 -04:00
|
|
|
console.log(`Invalid version: ${newVersion}`);
|
2019-03-14 12:31:28 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:03:17 -04:00
|
|
|
console.log(`\nCreating release for ${newVersion}...`);
|
|
|
|
|
2021-03-03 08:20:58 -05:00
|
|
|
const githubToken = process.env.GST_TOKEN;
|
2019-03-14 12:31:28 -04:00
|
|
|
|
2021-03-03 19:29:56 -05:00
|
|
|
if (!githubToken) {
|
|
|
|
console.log('Please configure your environment with a GitHub token located in GST_TOKEN');
|
2019-03-14 12:31:28 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:20:58 -05:00
|
|
|
try {
|
|
|
|
const result = await inquirer.prompt([{
|
|
|
|
type: 'input',
|
|
|
|
name: 'compatibleWithGhost',
|
|
|
|
message: 'Which version of Ghost is it compatible with?',
|
2021-03-05 08:28:15 -05:00
|
|
|
default: '4.0.0'
|
2021-03-03 08:20:58 -05:00
|
|
|
}]);
|
|
|
|
|
|
|
|
const compatibleWithGhost = result.compatibleWithGhost;
|
|
|
|
|
|
|
|
const releasesResponse = await releaseUtils.releases.get({
|
|
|
|
userAgent: 'Casper',
|
|
|
|
uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!releasesResponse || !releasesResponse) {
|
2020-04-03 11:16:26 -04:00
|
|
|
console.log('No releases found. Skipping...');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-03 08:20:58 -05:00
|
|
|
let previousVersion = releasesResponse[0].tag_name || releasesResponse[0].name;
|
2020-04-03 11:16:26 -04:00
|
|
|
console.log(`Previous version: ${previousVersion}`);
|
2021-03-03 08:20:58 -05:00
|
|
|
|
2020-04-03 11:16:26 -04:00
|
|
|
const changelog = new releaseUtils.Changelog({
|
|
|
|
changelogPath: CHANGELOG_PATH,
|
|
|
|
folder: path.join(process.cwd(), '.')
|
2019-03-14 12:31:28 -04:00
|
|
|
});
|
2020-04-03 11:16:26 -04:00
|
|
|
|
|
|
|
changelog
|
|
|
|
.write({
|
|
|
|
githubRepoPath: `https://github.com/${REPO}`,
|
|
|
|
lastVersion: previousVersion
|
|
|
|
})
|
|
|
|
.sort()
|
|
|
|
.clean();
|
|
|
|
|
2021-03-03 08:20:58 -05:00
|
|
|
const newReleaseResponse = await releaseUtils.releases.create({
|
|
|
|
draft: true,
|
|
|
|
preRelease: false,
|
2021-03-10 16:11:23 -05:00
|
|
|
tagName: 'v' + newVersion,
|
2021-03-03 08:20:58 -05:00
|
|
|
releaseName: newVersion,
|
|
|
|
userAgent: 'Casper',
|
|
|
|
uri: `https://api.github.com/repos/${REPO}/releases`,
|
|
|
|
github: {
|
|
|
|
token: githubToken
|
|
|
|
},
|
|
|
|
content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
|
|
|
|
changelogPath: CHANGELOG_PATH
|
|
|
|
});
|
|
|
|
console.log(`\nRelease draft generated: ${newReleaseResponse.releaseUrl}\n`);
|
|
|
|
} catch (err) {
|
2020-04-03 11:16:26 -04:00
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2021-03-03 08:20:58 -05:00
|
|
|
}
|
2019-03-14 12:31:28 -04:00
|
|
|
};
|