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');
|
|
|
|
const colorFunction = require('postcss-color-function');
|
|
|
|
const cssnano = require('cssnano');
|
|
|
|
const customProperties = require('postcss-custom-properties');
|
|
|
|
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 USER_AGENT = '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,
|
|
|
|
customProperties({preserve: false}),
|
|
|
|
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/**',
|
|
|
|
'!dist', '!dist/**'
|
|
|
|
]),
|
|
|
|
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
|
|
|
|
|
|
|
const previousRelease = () => {
|
|
|
|
return releaseUtils
|
|
|
|
.releases
|
|
|
|
.get({
|
|
|
|
userAgent: USER_AGENT,
|
2020-03-31 15:03:17 +00:00
|
|
|
uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
|
2019-03-14 16:31:28 +00:00
|
|
|
})
|
2020-03-31 15:03:17 +00:00
|
|
|
.then(response => {
|
2019-03-14 16:31:28 +00:00
|
|
|
if (!response || !response.length) {
|
2020-03-31 15:03:17 +00:00
|
|
|
console.log('No releases found. Skipping...');
|
2019-03-14 16:31:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-03-31 15:03:17 +00:00
|
|
|
|
2019-10-20 06:35:13 +00:00
|
|
|
let prevVersion = response[0].tag_name || response[0].name;
|
|
|
|
console.log(`Previous version ${prevVersion}`);
|
|
|
|
return prevVersion;
|
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
|
|
|
|
|
|
|
if (!config || !config.github || !config.github.username || !config.github.token) {
|
|
|
|
console.log('Please copy config.example.json and configure Github token.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-31 15:03:17 +00:00
|
|
|
inquirer.prompt([{
|
|
|
|
type: 'input',
|
|
|
|
name: 'compatibleWithGhost',
|
|
|
|
message: 'Which version of Ghost is it compatible with?',
|
|
|
|
default: '3.0.0'
|
|
|
|
}]).then(result => {
|
|
|
|
let compatibleWithGhost = result.compatibleWithGhost;
|
|
|
|
|
|
|
|
previousRelease().then(previousVersion => {
|
|
|
|
const changelog = new releaseUtils.Changelog({
|
|
|
|
changelogPath: CHANGELOG_PATH,
|
|
|
|
folder: path.join(process.cwd(), '.')
|
|
|
|
});
|
|
|
|
|
|
|
|
changelog
|
|
|
|
.write({
|
|
|
|
githubRepoPath: `https://github.com/${REPO}`,
|
|
|
|
lastVersion: previousVersion
|
|
|
|
})
|
|
|
|
.sort()
|
|
|
|
.clean();
|
2019-03-14 16:31:28 +00:00
|
|
|
|
2020-03-31 15:03:17 +00:00
|
|
|
releaseUtils
|
2019-03-14 16:31:28 +00:00
|
|
|
.releases
|
|
|
|
.create({
|
|
|
|
draft: true,
|
|
|
|
preRelease: false,
|
|
|
|
tagName: newVersion,
|
|
|
|
releaseName: newVersion,
|
|
|
|
userAgent: USER_AGENT,
|
|
|
|
uri: `https://api.github.com/repos/${REPO}/releases`,
|
|
|
|
github: {
|
|
|
|
username: config.github.username,
|
|
|
|
token: config.github.token
|
|
|
|
},
|
2020-03-31 15:03:17 +00:00
|
|
|
content: [`**Compatible with Ghost ≥ ${compatibleWithGhost}**\n\n`],
|
2019-03-14 16:31:28 +00:00
|
|
|
changelogPath: CHANGELOG_PATH
|
|
|
|
})
|
2020-03-31 15:03:17 +00:00
|
|
|
.then(response => {
|
2019-03-14 16:31:28 +00:00
|
|
|
console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
|
|
|
|
});
|
|
|
|
});
|
2020-03-31 15:03:17 +00:00
|
|
|
});
|
2019-03-14 16:31:28 +00:00
|
|
|
};
|