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');
|
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');
|
|
|
|
const uglify = require('gulp-uglify');
|
|
|
|
const beeper = require('beeper');
|
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
|
|
|
|
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([
|
|
|
|
src(['*.hbs', 'partials/**/*.hbs', '!node_modules/**/*.hbs']),
|
|
|
|
livereload()
|
|
|
|
], handleError(done));
|
|
|
|
}
|
|
|
|
|
2019-03-10 16:15:39 +00:00
|
|
|
function css(done) {
|
2019-03-14 16:07:40 +00:00
|
|
|
const processors = [
|
2017-05-15 20:03:47 +00:00
|
|
|
easyimport,
|
2019-03-12 18:14:48 +00:00
|
|
|
customProperties({preserve: false}),
|
2017-05-15 20:03:47 +00:00
|
|
|
colorFunction(),
|
|
|
|
autoprefixer({browsers: ['last 2 versions']}),
|
|
|
|
cssnano()
|
|
|
|
];
|
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('assets/css/*.css', {sourcemaps: true}),
|
2019-01-22 11:00:10 +00:00
|
|
|
postcss(processors),
|
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-03-10 16:15:39 +00:00
|
|
|
src('assets/js/*.js', {sourcemaps: true}),
|
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) {
|
2019-03-14 16:07:40 +00:00
|
|
|
const targetDir = 'dist/';
|
|
|
|
const themeName = require('./package.json').name;
|
|
|
|
const filename = themeName + '.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),
|
2019-03-10 16:15:39 +00:00
|
|
|
dest(targetDir)
|
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);
|
|
|
|
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs', '!node_modules/**/*.hbs'], hbs);
|
|
|
|
const watcher = parallel(cssWatcher, hbsWatcher);
|
2019-03-10 16:15:39 +00:00
|
|
|
const build = series(css, js);
|
|
|
|
const dev = series(build, serve, watcher);
|
2017-09-18 16:37:00 +00:00
|
|
|
|
2019-03-10 16:15:39 +00:00
|
|
|
exports.build = build;
|
|
|
|
exports.zip = series(build, zipper);
|
|
|
|
exports.default = dev;
|
2019-03-14 16:31:28 +00:00
|
|
|
|
|
|
|
// release imports
|
|
|
|
const path = require('path');
|
|
|
|
const releaseUtils = require('@tryghost/release-utils');
|
|
|
|
|
|
|
|
let config;
|
|
|
|
try {
|
|
|
|
config = require('./config');
|
|
|
|
} catch (err) {
|
|
|
|
config = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const REPO = 'TryGhost/Casper';
|
|
|
|
const USER_AGENT = 'Casper';
|
|
|
|
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');
|
|
|
|
|
|
|
|
const changelog = ({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();
|
|
|
|
};
|
|
|
|
|
|
|
|
const previousRelease = () => {
|
|
|
|
return releaseUtils
|
|
|
|
.releases
|
|
|
|
.get({
|
|
|
|
userAgent: USER_AGENT,
|
|
|
|
uri: `https://api.github.com/repos/${REPO}/releases`
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
if (!response || !response.length) {
|
|
|
|
console.log('No releases found. Skipping');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Previous version ${response[0].name}`);
|
|
|
|
return response[0].name;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* `yarn ship` will trigger `postship` task.
|
|
|
|
*
|
|
|
|
* [optional] For full automation
|
|
|
|
*
|
|
|
|
* `GHOST=2.10.1,2.10.0 yarn ship`
|
|
|
|
* First value: Ships with Ghost
|
|
|
|
* Second value: Compatible with Ghost/GScan
|
|
|
|
*
|
|
|
|
* You can manually run in case the task has thrown an error.
|
|
|
|
*
|
|
|
|
* `npm_package_version=0.5.0 gulp release`
|
|
|
|
*/
|
|
|
|
const release = () => {
|
|
|
|
// @NOTE: https://yarnpkg.com/lang/en/docs/cli/version/
|
|
|
|
const newVersion = process.env.npm_package_version;
|
|
|
|
let shipsWithGhost = '{version}';
|
|
|
|
let compatibleWithGhost = '2.10.0';
|
|
|
|
const ghostEnvValues = process.env.GHOST || null;
|
|
|
|
|
|
|
|
if (ghostEnvValues) {
|
|
|
|
shipsWithGhost = ghostEnvValues.split(',')[0];
|
|
|
|
compatibleWithGhost = ghostEnvValues.split(',')[1];
|
|
|
|
|
|
|
|
if (!compatibleWithGhost) {
|
|
|
|
compatibleWithGhost = '2.10.0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newVersion || newVersion === '') {
|
|
|
|
console.log('Invalid version.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`\nDraft release for ${newVersion}.`);
|
|
|
|
|
|
|
|
if (!config || !config.github || !config.github.username || !config.github.token) {
|
|
|
|
console.log('Please copy config.example.json and configure Github token.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return previousRelease()
|
2019-04-15 04:55:37 +00:00
|
|
|
.then((previousVersion) => {
|
2019-03-14 16:31:28 +00:00
|
|
|
changelog({previousVersion});
|
|
|
|
|
|
|
|
return releaseUtils
|
|
|
|
.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
|
|
|
|
},
|
|
|
|
content: [`**Ships with Ghost ${shipsWithGhost} Compatible with Ghost >= ${compatibleWithGhost}**\n\n`],
|
|
|
|
changelogPath: CHANGELOG_PATH
|
|
|
|
})
|
2019-04-15 04:55:37 +00:00
|
|
|
.then((response) => {
|
2019-03-14 16:31:28 +00:00
|
|
|
console.log(`\nRelease draft generated: ${response.releaseUrl}\n`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.release = release;
|