mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
9ca83c71e1
65
gulpfile.js
65
gulpfile.js
@ -1,11 +1,12 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
const watch = require('gulp-watch');
|
||||||
const babel = require('gulp-babel');
|
const babel = require('gulp-babel');
|
||||||
const ora = require('ora');
|
const ora = require('ora');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
let spinner = ora('请稍等...').start();
|
let spinner = null;
|
||||||
const DIST = 'server_dist/';
|
const DIST = 'server_dist/';
|
||||||
const SRC = 'server/**/*.js';
|
const SRC = 'server/**/*.js';
|
||||||
|
|
||||||
@ -30,21 +31,18 @@ function generateBabel(status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function excuteCmd(cmd, args, opts) {
|
function excuteCmd(cmd, args, opts) {
|
||||||
const command = spawn(cmd, args, opts);
|
const NAME = cmd === 'ykit' ? chalk.cyan('[ykit]') : chalk.blue('[dev-server]');
|
||||||
|
let command = spawn(cmd, args, opts);
|
||||||
|
|
||||||
command.stdout.on('data', data => {
|
command.stdout.on('data', data => {
|
||||||
output('log', `${cmd}: ${data.toString()}`, true);
|
output('log', `${NAME} ${data.toString()}`, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
command.stderr.on('data', data => {
|
command.stderr.on('data', data => {
|
||||||
output('log', `${cmd}: ${data.toString()}`, true);
|
output('log', `${NAME} ${data.toString()}`, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
command.on('close', code => {
|
return command;
|
||||||
if (code !== 0) {
|
|
||||||
output('log', `${cmd}: ${data.toString()}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function output(type, message, restart = false) {
|
function output(type, message, restart = false) {
|
||||||
@ -64,25 +62,29 @@ function output(type, message, restart = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitingSpinner() {
|
||||||
|
spinner = ora({
|
||||||
|
text: '等待文件变更...',
|
||||||
|
spinner: 'circleQuarters',
|
||||||
|
color: 'cyan'
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
gulp.task('removeDist', [], function () {
|
gulp.task('removeDist', [], function () {
|
||||||
return fs.removeSync(DIST)
|
return fs.removeSync(DIST)
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('initialBuild', ['removeDist'], () => {
|
gulp.task('initialBuild', ['removeDist'], () => {
|
||||||
spinner.text = '初始编译...';
|
spinner = ora('初始编译...').start();
|
||||||
|
|
||||||
return gulp.src(SRC)
|
return gulp.src(SRC)
|
||||||
.pipe(generateBabel())
|
.pipe(generateBabel())
|
||||||
.pipe(gulp.dest(DIST))
|
.pipe(gulp.dest(DIST))
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
output('success', '初始编译成功!');
|
output('success', '初始编译成功!');
|
||||||
spinner = ora({
|
waitingSpinner();
|
||||||
text: '等待文件变更...',
|
|
||||||
spinner: 'pong',
|
|
||||||
color: 'green'
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js', 'dev'], {
|
excuteCmd('node_modules/.bin/nodemon', ['-q', 'server_dist/app.js'], {
|
||||||
cwd: __dirname
|
cwd: __dirname
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,28 +96,41 @@ gulp.task('initialBuild', ['removeDist'], () => {
|
|||||||
|
|
||||||
gulp.task('default', ['initialBuild'], () => {
|
gulp.task('default', ['initialBuild'], () => {
|
||||||
gulp.watch(SRC, (event) => {
|
gulp.watch(SRC, (event) => {
|
||||||
|
let originFilePath = path.relative(path.join(__dirname, 'server'), event.path)
|
||||||
|
let distPath = path.resolve(DIST, path.join(originFilePath))
|
||||||
spinner.text = `正在编译 ${event.path}...`;
|
spinner.text = `正在编译 ${event.path}...`;
|
||||||
|
|
||||||
gulp.src(event.path).pipe(generateBabel())
|
gulp.src(event.path).pipe(generateBabel())
|
||||||
.pipe(gulp.dest(DIST)).on('end', () => {
|
.pipe(gulp.dest(path.parse(distPath).dir)).on('end', () => {
|
||||||
output('success', `成功编译 ${event.path}`);
|
output('success', `成功编译 ${originFilePath}`);
|
||||||
spinner = ora({
|
output('success', '正在重启服务器...');
|
||||||
text: 'waiting changes...',
|
waitingSpinner();
|
||||||
spinner: 'pong',
|
|
||||||
color: 'green'
|
|
||||||
});
|
|
||||||
spinner.start();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('buildNode', () => {
|
||||||
|
return gulp.src(SRC)
|
||||||
|
.pipe(generateBabel())
|
||||||
|
.pipe(gulp.dest(DIST));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('watchNode', ['buildNode'], () => {
|
||||||
|
return watch(SRC, {
|
||||||
|
verbose: true,
|
||||||
|
ignoreInitial: false
|
||||||
|
})
|
||||||
|
.pipe(generateBabel())
|
||||||
|
.pipe(gulp.dest(DIST));
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('build', () => {
|
gulp.task('build', () => {
|
||||||
let status = {
|
let status = {
|
||||||
count: 0
|
count: 0
|
||||||
};
|
};
|
||||||
let ykitOutput = '';
|
let ykitOutput = '';
|
||||||
|
|
||||||
spinner.text = '正在编译...';
|
spinner = ora('请稍等...').start();
|
||||||
|
|
||||||
gulp.src(SRC)
|
gulp.src(SRC)
|
||||||
.pipe(generateBabel(status))
|
.pipe(generateBabel(status))
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-server": "babel server -d server_dist",
|
"build-server": "babel server -d server_dist",
|
||||||
"dev-server": "nodemon server_dist/app.js",
|
"dev-server": "nodemon server_dist/app.js -L",
|
||||||
"install-server" : "node server_dist/install.js",
|
"install-server" : "node server_dist/install.js",
|
||||||
"dev": "gulp --silent",
|
"dev": "gulp --silent",
|
||||||
"build": "gulp build --silent"
|
"build": "gulp build --silent",
|
||||||
|
"only-watch": "gulp watchNode"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
Reference in New Issue
Block a user