forked from TryGhost/Casper
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
200 lines (172 loc) · 5.08 KB
/
gulpfile.mjs
File metadata and controls
200 lines (172 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// gulpfile.mjs
import gulpPkg from 'gulp';
const { series, watch, src, dest, parallel } = gulpPkg;
import pump from 'pump';
import path from 'path';
import * as releaseUtils from '@tryghost/release-utils';
import inquirer from 'inquirer';
import livereload from 'gulp-livereload';
import postcss from 'gulp-postcss';
import gulpZip from 'gulp-zip';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import beeper from 'beeper';
import * as fs from 'fs';
import autoprefixer from 'autoprefixer';
import colorFunction from 'postcss-color-mod-function';
import cssnano from 'cssnano';
import easyimport from 'postcss-easy-import';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass);
import webpackStream from 'webpack-stream';
import webpackConfig from './webpack.config.js';
const REPO = 'TryGhost/Casper';
const REPO_READONLY = 'TryGhost/Casper';
const CHANGELOG_PATH = path.join(process.cwd(), '.', 'changelog.md');
function serve(done) {
livereload.listen();
done();
}
const handleError = (done) => (err) => {
if (err) beeper();
return done(err);
};
function hbs(done) {
pump(
[ src(['*.hbs', 'partials/**/*.hbs']), livereload() ],
handleError(done)
);
}
function css(done) {
pump(
[
src('assets/css/*.css', { sourcemaps: true }),
postcss([easyimport, colorFunction(), autoprefixer(), cssnano()]),
dest('assets/built/', { sourcemaps: '.' }),
livereload(),
],
handleError(done)
);
}
function scss(done) {
pump(
[
src('assets/sass/*.scss', { sourcemaps: true }),
sass(),
dest('assets/built/', { sourcemaps: '.' }),
livereload(),
],
handleError(done)
);
}
function js(done) {
pump(
[
src(['assets/js/lib/*.js', 'assets/js/*.js'], { sourcemaps: true }),
concat('casper.js'),
uglify(),
dest('assets/built/', { sourcemaps: '.' }),
livereload(),
],
handleError(done)
);
}
function zipper(done) {
const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)));
const filename = pkg.name + '.zip';
pump(
[
src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**',
'!yarn-error.log',
'!yarn.lock',
'!gulpfile.js'
]),
gulpZip(filename),
dest('dist/'),
],
handleError(done)
);
}
function webpack(done) {
pump(
[
src('assets/built'),
webpackStream(webpackConfig),
dest('assets/built'),
livereload(),
],
handleError(done)
);
}
const scssWatcher = () => watch('assets/sass/**', scss);
const cssWatcher = () => watch('assets/css/**', css);
const jsWatcher = () => watch('assets/js/**', js);
const webpackWatcher = () => watch('src/**', webpack);
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs'], hbs);
const watcher = parallel(cssWatcher, hbsWatcher, scssWatcher, jsWatcher, webpackWatcher);
const build = series(css, js, scss, webpack);
export { build };
export const zip = series(build, zipper);
export default series(build, serve, watcher);
export async function release() {
const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)));
const newVersion = pkg.version;
if (!newVersion) {
console.log(`Invalid version: ${newVersion}`);
return;
}
console.log(`\nCreating release for ${newVersion}...`);
const githubToken = process.env.GST_TOKEN;
if (!githubToken) {
console.log('Please configure your environment with a GitHub token in GST_TOKEN');
return;
}
try {
const { compatibleWithGhost } = await inquirer.prompt([{
type: 'input',
name: 'compatibleWithGhost',
message: 'Which version of Ghost is it compatible with?',
default: '5.0.0'
}]);
const releasesResponse = await releaseUtils.releases.get({
userAgent: 'Casper',
uri: `https://api.github.com/repos/${REPO_READONLY}/releases`
});
if (!releasesResponse) {
console.log('No releases found. Skipping...');
return;
}
const previousVersion = releasesResponse[0].tag_name || releasesResponse[0].name;
console.log(`Previous version: ${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 newReleaseResponse = await releaseUtils.releases.create({
draft: true,
preRelease: false,
tagName: 'v' + newVersion,
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) {
console.error(err);
process.exit(1);
}
}