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