Authored by 陈峰

单独保存sourcemap并提供接口访问

... ... @@ -5,6 +5,7 @@ node_modules/
db/**
packages/
sourcemap/
.idea/
... ...
... ... @@ -16,6 +16,7 @@ import Socket from 'socket.io';
import config from './config/config';
import webApp from './apps/web';
import api from './apps/api';
import ws from './lib/ws';
import errorHandle from './middleware/error-handle';
... ... @@ -41,6 +42,7 @@ app.use(convert(body({
})));
app.use(mount('/', webApp));
app.use(mount('/', api));
// app.on('error', function(err, ctx) {
// console.log(err);
// switch (ctx.accepts('json', 'html', 'text')) {
... ...
import config from '../../../config/config';
import fs from 'fs';
import path from 'path';
import Router from 'koa-router';
let r = new Router();
r.get('/load', (ctx, next) => {
const reqPath = ctx.request.query.path;
const filePath = path.join(config.sourceMapDir, reqPath);
if (fs.existsSync(filePath)) {
const rs = fs.createReadStream(filePath, {
encoding: 'utf-8'
});
const fileName = path.basename(filePath)
ctx.set('Content-Type', 'application/javascript; charset=utf-8');
ctx.response.body = rs;
return;
}
return next();
});
export default r;
\ No newline at end of file
... ...
/**
* web ui 模块
*
* @author: jiang
*/
import path from 'path';
import Koa from 'koa';
import routers from './routers'
const app = new Koa();
routers(app);
export default app;
\ No newline at end of file
... ...
import Router from 'koa-router';
import sourceMap from './actions/source-map';
const r = new Router();
export default function (app) {
r.use('/sourcemap', sourceMap.routes(), sourceMap.allowedMethods());
app.use(r.routes(), r.allowedMethods());
}
\ No newline at end of file
... ...
... ... @@ -52,6 +52,8 @@ class Build {
self.version = pkg.version;
self.pkgName = pkg.name;
sh.rm('-rf', path.join(self.codePath, 'public/dist/'));
return self._installdep();
}).then(() => {
return self._buildScript();
... ... @@ -75,6 +77,10 @@ class Build {
get buildPath() {
return path.join(config.buildDir, this.project.name, this.buildTime, this.pkgName);
}
get sourceMapPath() {
return path.join(config.sourceMapDir, this.project.name);
}
get rootPath() {
return path.join(config.buildDir, this.project.name, this.buildTime);
... ... @@ -91,6 +97,10 @@ class Build {
if (!sh.test('-e', config.codeDir)) {
sh.mkdir('-p', config.codeDir);
}
if (!sh.test('-e', config.sourceMapDir)) {
sh.mkdir('-p', config.sourceMapDir);
}
if (!sh.test('-e', this.rootPath)) {
sh.mkdir('-p', this.rootPath);
... ... @@ -216,11 +226,23 @@ class Build {
this._log('>>>>>>>>> clone to deploy folder >>>>>>>>>>');
return new Promise((resolve, reject) => {
let projectRoot = `public/dist/${self.pkgName}/`;
let copyPath = path.join(self.codePath, projectRoot);
self._state('clone to deploy');
sh.cd(copyPath);
sh.find('.').filter(file => file.match(/\.map$/)).forEach(file => {
const destFile = path.join(this.sourceMapPath, file);
const firdir = path.dirname(destFile);
if (!sh.test('-e', firdir)) {
sh.mkdir('-p', firdir);
}
sh.mv(path.join(copyPath, file), destFile)
});
// assets folder & version folder
var child = sh.cp('-r', path.join(self.codePath, projectRoot), self.buildPath);
var child = sh.cp('-r', copyPath, self.buildPath);
if (child.code === 0) {
console.log('cope to deploy success');
... ...
... ... @@ -8,6 +8,7 @@ const defaults = {
port: 6006,
codeDir: path.normalize(__dirname + '/../code/'), // 代码位置
buildDir: path.normalize(__dirname + '/../packages/'), // 静态资源包位置
sourceMapDir: path.normalize(__dirname + '/../sourcemap/'), // sourcemap位置
dbDir: path.normalize(__dirname + '/../db'),
ci: path.normalize(__dirname + '/../apps/ci')
};
... ...