Showing
7 changed files
with
81 additions
and
1 deletions
@@ -16,6 +16,7 @@ import Socket from 'socket.io'; | @@ -16,6 +16,7 @@ import Socket from 'socket.io'; | ||
16 | 16 | ||
17 | import config from './config/config'; | 17 | import config from './config/config'; |
18 | import webApp from './apps/web'; | 18 | import webApp from './apps/web'; |
19 | +import api from './apps/api'; | ||
19 | import ws from './lib/ws'; | 20 | import ws from './lib/ws'; |
20 | import errorHandle from './middleware/error-handle'; | 21 | import errorHandle from './middleware/error-handle'; |
21 | 22 | ||
@@ -41,6 +42,7 @@ app.use(convert(body({ | @@ -41,6 +42,7 @@ app.use(convert(body({ | ||
41 | }))); | 42 | }))); |
42 | app.use(mount('/', webApp)); | 43 | app.use(mount('/', webApp)); |
43 | 44 | ||
45 | +app.use(mount('/', api)); | ||
44 | // app.on('error', function(err, ctx) { | 46 | // app.on('error', function(err, ctx) { |
45 | // console.log(err); | 47 | // console.log(err); |
46 | // switch (ctx.accepts('json', 'html', 'text')) { | 48 | // switch (ctx.accepts('json', 'html', 'text')) { |
apps/api/actions/source-map.js
0 → 100644
1 | +import config from '../../../config/config'; | ||
2 | +import fs from 'fs'; | ||
3 | +import path from 'path'; | ||
4 | +import Router from 'koa-router'; | ||
5 | + | ||
6 | +let r = new Router(); | ||
7 | + | ||
8 | + | ||
9 | +r.get('/load', (ctx, next) => { | ||
10 | + const reqPath = ctx.request.query.path; | ||
11 | + const filePath = path.join(config.sourceMapDir, reqPath); | ||
12 | + | ||
13 | + if (fs.existsSync(filePath)) { | ||
14 | + const rs = fs.createReadStream(filePath, { | ||
15 | + encoding: 'utf-8' | ||
16 | + }); | ||
17 | + | ||
18 | + const fileName = path.basename(filePath) | ||
19 | + | ||
20 | + ctx.set('Content-Type', 'application/javascript; charset=utf-8'); | ||
21 | + ctx.response.body = rs; | ||
22 | + return; | ||
23 | + } | ||
24 | + return next(); | ||
25 | +}); | ||
26 | + | ||
27 | +export default r; |
apps/api/index.js
0 → 100644
apps/api/routers.js
0 → 100644
@@ -52,6 +52,8 @@ class Build { | @@ -52,6 +52,8 @@ class Build { | ||
52 | self.version = pkg.version; | 52 | self.version = pkg.version; |
53 | self.pkgName = pkg.name; | 53 | self.pkgName = pkg.name; |
54 | 54 | ||
55 | + sh.rm('-rf', path.join(self.codePath, 'public/dist/')); | ||
56 | + | ||
55 | return self._installdep(); | 57 | return self._installdep(); |
56 | }).then(() => { | 58 | }).then(() => { |
57 | return self._buildScript(); | 59 | return self._buildScript(); |
@@ -75,6 +77,10 @@ class Build { | @@ -75,6 +77,10 @@ class Build { | ||
75 | get buildPath() { | 77 | get buildPath() { |
76 | return path.join(config.buildDir, this.project.name, this.buildTime, this.pkgName); | 78 | return path.join(config.buildDir, this.project.name, this.buildTime, this.pkgName); |
77 | } | 79 | } |
80 | + | ||
81 | + get sourceMapPath() { | ||
82 | + return path.join(config.sourceMapDir, this.project.name); | ||
83 | + } | ||
78 | 84 | ||
79 | get rootPath() { | 85 | get rootPath() { |
80 | return path.join(config.buildDir, this.project.name, this.buildTime); | 86 | return path.join(config.buildDir, this.project.name, this.buildTime); |
@@ -91,6 +97,10 @@ class Build { | @@ -91,6 +97,10 @@ class Build { | ||
91 | if (!sh.test('-e', config.codeDir)) { | 97 | if (!sh.test('-e', config.codeDir)) { |
92 | sh.mkdir('-p', config.codeDir); | 98 | sh.mkdir('-p', config.codeDir); |
93 | } | 99 | } |
100 | + | ||
101 | + if (!sh.test('-e', config.sourceMapDir)) { | ||
102 | + sh.mkdir('-p', config.sourceMapDir); | ||
103 | + } | ||
94 | 104 | ||
95 | if (!sh.test('-e', this.rootPath)) { | 105 | if (!sh.test('-e', this.rootPath)) { |
96 | sh.mkdir('-p', this.rootPath); | 106 | sh.mkdir('-p', this.rootPath); |
@@ -216,11 +226,23 @@ class Build { | @@ -216,11 +226,23 @@ class Build { | ||
216 | this._log('>>>>>>>>> clone to deploy folder >>>>>>>>>>'); | 226 | this._log('>>>>>>>>> clone to deploy folder >>>>>>>>>>'); |
217 | return new Promise((resolve, reject) => { | 227 | return new Promise((resolve, reject) => { |
218 | let projectRoot = `public/dist/${self.pkgName}/`; | 228 | let projectRoot = `public/dist/${self.pkgName}/`; |
229 | + let copyPath = path.join(self.codePath, projectRoot); | ||
219 | 230 | ||
220 | self._state('clone to deploy'); | 231 | self._state('clone to deploy'); |
221 | 232 | ||
233 | + sh.cd(copyPath); | ||
234 | + | ||
235 | + sh.find('.').filter(file => file.match(/\.map$/)).forEach(file => { | ||
236 | + const destFile = path.join(this.sourceMapPath, file); | ||
237 | + const firdir = path.dirname(destFile); | ||
238 | + if (!sh.test('-e', firdir)) { | ||
239 | + sh.mkdir('-p', firdir); | ||
240 | + } | ||
241 | + sh.mv(path.join(copyPath, file), destFile) | ||
242 | + }); | ||
243 | + | ||
222 | // assets folder & version folder | 244 | // assets folder & version folder |
223 | - var child = sh.cp('-r', path.join(self.codePath, projectRoot), self.buildPath); | 245 | + var child = sh.cp('-r', copyPath, self.buildPath); |
224 | 246 | ||
225 | if (child.code === 0) { | 247 | if (child.code === 0) { |
226 | console.log('cope to deploy success'); | 248 | console.log('cope to deploy success'); |
@@ -8,6 +8,7 @@ const defaults = { | @@ -8,6 +8,7 @@ const defaults = { | ||
8 | port: 6006, | 8 | port: 6006, |
9 | codeDir: path.normalize(__dirname + '/../code/'), // 代码位置 | 9 | codeDir: path.normalize(__dirname + '/../code/'), // 代码位置 |
10 | buildDir: path.normalize(__dirname + '/../packages/'), // 静态资源包位置 | 10 | buildDir: path.normalize(__dirname + '/../packages/'), // 静态资源包位置 |
11 | + sourceMapDir: path.normalize(__dirname + '/../sourcemap/'), // sourcemap位置 | ||
11 | dbDir: path.normalize(__dirname + '/../db'), | 12 | dbDir: path.normalize(__dirname + '/../db'), |
12 | ci: path.normalize(__dirname + '/../apps/ci') | 13 | ci: path.normalize(__dirname + '/../apps/ci') |
13 | }; | 14 | }; |
-
Please register or login to post a comment