Skip to content

Commit 85b53cc

Browse files
committed
Added bump and tag scripts
1 parent 6bbe22a commit 85b53cc

File tree

6 files changed

+346
-228
lines changed

6 files changed

+346
-228
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
build/*.js
22
config/*.js
33
src/libs/*.js
4-
./index.js

build/gulpfile.js

-20
This file was deleted.

gulpfile.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const path = require('path');
2+
const gulp = require('gulp');
3+
const concat = require('gulp-concat');
4+
const spawn = require('child_process').spawn;
5+
const util = require('gulp-util');
6+
const version = require('./package').version;
7+
8+
const prismScripts = [
9+
'prismjs/components/prism-core',
10+
'prismjs/components/prism-markup',
11+
'prismjs/components/prism-clike',
12+
'prismjs/components/prism-c',
13+
'prismjs/components/prism-javascript',
14+
'prismjs/components/prism-css',
15+
'prismjs/components/prism-ruby',
16+
].map(require.resolve);
17+
prismScripts.push(
18+
path.join(path.dirname(require.resolve('prismjs/components/prism-core')), 'prism-!(*.min).js'));
19+
20+
function exec(commands, cb) {
21+
if (commands.length === 0) {
22+
cb();
23+
return;
24+
}
25+
let file;
26+
let args;
27+
const command = commands.shift();
28+
const options = {
29+
cwd: process.cwd(),
30+
};
31+
// Credit: https://github.com/nodejs/node/blob/master/lib/child_process.js
32+
if (process.platform === 'win32') {
33+
file = process.env.comspec || 'cmd.exe';
34+
args = ['/s', '/c', `"${command}"`];
35+
options.windowsVerbatimArguments = true;
36+
} else {
37+
file = '/bin/sh';
38+
args = ['-c', command];
39+
}
40+
const proc = spawn(file, args, options);
41+
proc.stdout.pipe(process.stdout);
42+
proc.stderr.pipe(process.stderr);
43+
proc.on('error', (error) => {
44+
util.log(util.colors.red(error));
45+
cb(error);
46+
});
47+
proc.on('exit', (code) => {
48+
if (code) {
49+
cb(code);
50+
} else {
51+
exec(commands, cb);
52+
}
53+
});
54+
}
55+
56+
gulp.task('build-prism', () => gulp.src(prismScripts)
57+
.pipe(concat('prism.js'))
58+
.pipe(gulp.dest(path.dirname(require.resolve('prismjs')))));
59+
60+
gulp.task('tag', (cb) => {
61+
const tag = `v${version}`;
62+
util.log(`Tagging as: ${util.colors.cyan(tag)}`);
63+
exec([
64+
'git add package.json',
65+
'git commit -m "Prepare release"; true', // Ignore "no changes added to commit" error
66+
`git tag -a ${tag} -m "Version ${version}"`,
67+
'git push origin master --tags',
68+
'npm publish',
69+
], cb);
70+
});

index.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
process.env.NODE_ENV = 'production';
22

3-
var cluster = require('cluster');
4-
var http = require('http');
5-
var https = require('https');
6-
var path = require('path');
7-
var express = require('express');
8-
var app = express();
3+
const http = require('http');
4+
const https = require('https');
5+
const path = require('path');
6+
const express = require('express');
7+
const fs = require('fs');
8+
9+
const app = express();
910

1011
require('./server')(app, process.env.SERVE_V4);
1112

12-
var port = parseInt(process.env.PORT || 8080, 10);
13-
if(port === 443) {
14-
var fs = require('fs');
15-
var credentials = {
16-
key: fs.readFileSync(path.join(__dirname, 'ssl.key'), 'utf8'),
17-
cert: fs.readFileSync(path.join(__dirname, 'ssl.crt'), 'utf8'),
18-
ca: fs.readFileSync(path.join(__dirname, 'ssl.ca'), 'utf8').split('\n\n')
19-
};
20-
var httpsServer = https.createServer(credentials, app);
21-
httpsServer.listen(port, null, function() {
22-
console.log('HTTPS server started: https://localhost');
23-
});
24-
port = 80;
13+
let port = parseInt(process.env.PORT || 8080, 10);
14+
if (port === 443) {
15+
const credentials = {
16+
key: fs.readFileSync(path.join(__dirname, 'ssl.key'), 'utf8'),
17+
cert: fs.readFileSync(path.join(__dirname, 'ssl.crt'), 'utf8'),
18+
ca: fs.readFileSync(path.join(__dirname, 'ssl.ca'), 'utf8').split('\n\n'),
19+
};
20+
const httpsServer = https.createServer(credentials, app);
21+
httpsServer.listen(port, null, () => {
22+
console.log('HTTPS server started: https://localhost');
23+
});
24+
port = 80;
2525
}
26-
var httpServer = http.createServer(app);
27-
httpServer.listen(port, null, function() {
28-
console.log('HTTP server started: http://localhost:' + port);
26+
const httpServer = http.createServer(app);
27+
httpServer.listen(port, null, () => {
28+
console.log(`HTTP server started: http://localhost:${port}`);
2929
});

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
},
1010
"main": "index.js",
1111
"scripts": {
12-
"postinstall": "gulp --cwd build build-prism",
12+
"postinstall": "gulp build-prism",
1313
"start": "node build/dev-server.js",
1414
"build": "node build/build.js",
15-
"lint": "eslint --ext .js,.vue src"
15+
"lint": "eslint --ext .js,.vue src",
16+
"patch": "yarn run lint && npm-bump patch",
17+
"minor": "yarn run lint && npm-bump minor",
18+
"major": "yarn run lint && npm-bump major",
19+
"tag": "gulp tag"
1620
},
1721
"dependencies": {
1822
"bezier-easing": "^1.1.0",
@@ -69,11 +73,14 @@
6973
"file-loader": "^0.11.1",
7074
"friendly-errors-webpack-plugin": "^1.1.3",
7175
"gulp": "^3.9.1",
76+
"gulp-bump": "^2.7.0",
7277
"gulp-concat": "^2.6.1",
78+
"gulp-util": "^3.0.8",
7379
"html-webpack-plugin": "^2.28.0",
7480
"http-proxy-middleware": "^0.17.3",
7581
"ignore-loader": "^0.1.2",
7682
"node-sass": "^4.5.3",
83+
"npm-bump": "^0.0.23",
7784
"offline-plugin": "^4.8.4",
7885
"opn": "^4.0.2",
7986
"optimize-css-assets-webpack-plugin": "^1.3.0",

0 commit comments

Comments
 (0)