代码拉取完成,页面将自动刷新
同步操作将从 daokes/map-demo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
const gulp = require('gulp');
const sequence = require('gulp-sequence');
const shell = require('gulp-shell');
gulp.task('clean', () => {
const del = require('del');
return del('./dist/');
});
gulp.task('compile-ts', shell.task('node --max-old-space-size=4000 "./node_modules/typescript/bin/tsc"'));
gulp.task('dev', shell.task('npm run dev'));
gulp.task('service-watch', shell.task('tsc -w -p ./tsconfig-service.json'));
gulp.task('watch-ts', shell.task('tsc -w -m umd'));
gulp.task('build-html', () => {
const through = require('through2');
const rename = require('gulp-rename');
const path = require('path');
const minifyHtml = require("gulp-minify-html");
return gulp.src('./src/**/server/body.ts')
.pipe(rename((file) => {
const page_no = file.dirname.match(/(.*)(\/server)/)[1];
file.basename = page_no;
file.extname = '.html';
file.dirname = '../pages';
}))
.pipe(through.obj((chunk, enc, callback) => {
const page_no = path.basename(chunk.path, '.html');
const head = Buffer.from(`<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<link rel="stylesheet" type="text/css" href="../css/iconfont.css">
<link href="https://cdn.jsdelivr.net/npm/feidao-css/feidao.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="../css/daokes.css">
<script src="../../node_modules/@dojo/loader/loader.js"></script>
<script type="text/javascript">
(() => {
const baseUrl = '../../node_modules/';
require.config({
baseUrl: baseUrl,
packages: [{
name: 'daoke',
location: '../dist'
},{
name: '@feidao/core',
location: '@feidao/core/umd'
},{
name: '@feidao/web',
location: '@feidao/web/umd'
},{
name: '@feidao/widgets',
location: '@feidao/widgets/umd'
},{
name: '@feidao/animation',
location: '@feidao/animation/umd',
main: 'index'
},{
name: 'node-html-parser',
location: 'node-html-parser/dist/umd',
main: 'index'
},{
name: 'javascript-state-machine',
location: './javascript-state-machine',
main: 'state-machine'
},{
name: 'dask',
location: 'dask/umd',
main: 'index'
},{
name: 'mqtt',
location: './mqtt/dist',
main: 'mqtt'
},{
name: 'dot',
location: 'dot',
main: 'doT'
},{
name: 'nools-ts',
location: 'nools-ts/umd'
},{
name: 'lodash-ts',
location: 'lodash-ts/umd'
},{
name: 'he',
location: './he',
main: 'he.js'
},{
name: 'quill',
location: '../node_modules/quill/dist',
main: 'quill.min'
},{
name: 'i18next',
location: './i18next/dist/umd',
main: 'i18next'
},{
name: 'ol',
location: './openlayers/dist',
main: 'ol-debug'
}]
});
})();
</script>
</head>
<body>`, 'utf8');
const tail = Buffer.from(`
<script type="text/javascript">
(() => {
require(['daoke/${page_no}/server/p'],function(main){
const url = window.location.href;
main.default(url).then((res) => {
document.body.innerHTML = res;
require(['daoke/${page_no}/client/p']);
});
});
})();
</script>
</body></html>`, 'utf8');
// const body = chunk.contents.toString('utf8');
chunk.contents = Buffer.concat([head, /*Buffer.from(body.substring(body.indexOf('`') + 1, body.lastIndexOf('`'))), */tail]);
// this.push(chunk);
// callback();
callback(null, chunk);
}))
.pipe(minifyHtml()) //压缩
.pipe(gulp.dest('./dist/pages/'));
});
gulp.task('browser-sync', () => {
const browserSync = require('browser-sync').create();
browserSync.init({
files: ['./dist/'],
server: {
baseDir: './dist/pages/',
directory: true
},
online: false,
serveStatic: ['./'],
port: 8000
});
});
gulp.task('default', ['watch-ts', 'build-html', 'browser-sync', 'dev', 'service-watch']);
gulp.task('build-servicies', shell.task('tsc -p ./tsconfig-service.json'));
gulp.task('release-clean', () => {
const del = require('del');
return del(['./dist/release', './release/']);
});
gulp.task('release-copy-files', () => {
// todo
return gulp.src('./src/**/*')
.pipe(gulp.dest('./release/'));
});
gulp.task('release-compile-ts', shell.task('tsc -p ./tsconfig-release.json'));
gulp.task('release-client', (cb) => {
const dest = './dist/release/server/js/';
const pack_file_path = `./dist/release/*/client/p.js`;
const path = require('path');
const webpack = require('webpack');
const through = require('through');
const ws = require('webpack-stream');
return gulp.src([pack_file_path])
.pipe(((opts) => {
return through(function (file) {
file.named = file.path.match(/.*release\/(.*)\/client\/p\.js/)[1];
this.queue(file);
});
})())
.pipe(ws({
mode: 'production',
// mode: 'development',
optimization: {
splitChunks: {
name: 'feidao',
chunks: 'all'
}
},
externals: [
// "nools" // this is a bad js file
],
output: {
globalObject: 'window',
publicPath: dest
},
module: {
rules: [{
test: /\.js$/,
// exclude: /(node_modules|bower_components)/,
exclude: /core-js|babel/,
use: {
loader: 'babel-loader'
}
}]
}
}, webpack))
.pipe(gulp.dest(dest));
});
gulp.task('release-service', (cb) => {
const dest = './dist/release/service/';
const pack_file_path = `./dist/release/*/server/p.js`;
const path = require('path');
const webpack = require('webpack');
const through = require('through');
const ws = require('webpack-stream');
return gulp.src([pack_file_path])
.pipe(((opts) => {
return through(function (file) {
file.named = path.basename(path.dirname(file.path));
this.queue(file);
});
})())
.pipe(ws({
mode: 'production',
module: {
rules: [{
test: /\.js$/,
// exclude: /(node_modules|bower_components)/,
exclude: /core-js|babel/,
use: {
loader: 'babel-loader'
}
}]
}
}, webpack))
.pipe(gulp.dest(dest))
});
function prefix(str, len, separator = '0') {
return (Array(len).join(separator) + str).slice(-len);
}
function get_file_name() {
const path = require('path');
const proj_name = path.basename(process.cwd());
const dt = new Date();
return `${proj_name}-${prefix(dt.getFullYear(), 4)}${prefix(dt.getMonth() + 1, 2)}${prefix(dt.getDate(), 2)}${prefix(dt.getHours(), 2)}${prefix(dt.getMinutes(), 2)}`;
}
gulp.task('zip-server', function () {
const zip = require('gulp-zip');
return gulp.src(['./dist/release/server/js/**/*', './dist/server/css/**/*', './dist/server/images/**/*'])
.pipe(zip(`${get_file_name()}-server.zip`))
.pipe(gulp.dest('./'));
});
gulp.task('zip-service', function () {
const zip = require('gulp-zip');
return gulp.src('./dist/release/service/**/*')
.pipe(zip(`${get_file_name()}-service.zip`))
.pipe(gulp.dest('./'));
});
gulp.task('zip', ['zip-server', 'zip-service']);
gulp.task('release', sequence('release-clean', 'release-copy-files', 'release-compile-ts', ['release-client', 'release-service'], 'build-servicies', 'zip'));
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。