-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (81 loc) · 2.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var preprocess = require('./shark-preprocess');
var sharkWebpack = require('./shark-webpack');
var baseprocess = require('./shark-baseprocess');
var browersync = require('./shark-browersync');
var ftl2html = require('./shark-ftl2html');
var sharkAjax = require('./shark-ajax');
var sharkClean = require('./shark-clean');
var sharkCopy = require('./shark-copy');
var sharkJava = require('./shark-java');
var sharkZip = require('./shark-zip');
var open = require('./shark-open');
var sharkSprite = require('./shark-sprite');
var express = require('express');
var deploy = require('./shark-deploy');
var extend = require('extend');
var path = require('path');
var argv = require('yargs').argv;
var automation = {};
var defaultOpt = {
tmpDir: '.tmp',
build: 'build',
buildWebapp: 'app',
buildStatic: 'mimg'
};
/**
* 注册各个task
* conf
* baseConf: 对应的shark-deploy-conf.json的配置信息
* webpack: 对应的webpack的配置信息
* ... 各个插件的配置,允许修改task中使用的插件的默认配置
*/
automation.registerBuildTasks = function (conf) {
conf.baseConf = extend(false, defaultOpt, conf.baseConf);
preprocess(conf);
sharkWebpack.registerServerTask(conf);
sharkClean(conf);
baseprocess(conf);
sharkJava(conf);
sharkCopy(conf);
sharkZip(conf);
};
automation.registerSpriteTask = function (conf) {
sharkSprite(conf);
};
automation.registerDeployTasks = function (conf) {
deploy(conf);
};
automation.registerServerTasks = function (conf) {
conf.baseConf = extend(false, defaultOpt, conf.baseConf);
preprocess(conf, 'serve');
open(conf);
browersync(conf);
};
automation.registerServerRouter = function (conf) {
conf.baseConf = extend(false, defaultOpt, conf.baseConf);
var baseConf = conf.baseConf;
var prePath = path.join(baseConf.rootPath, baseConf.tmpDir, 'step1');
var webPath = path.join(baseConf.rootPath, baseConf.webapp);
var htmlPath = path.join(webPath, baseConf.htmlPath);
var router = express.Router();
router.use(sharkWebpack.serveStatic(conf));
router.use(express.static(prePath));
if (baseConf.contextPath) {
router.use(baseConf.contextPath, express.static(webPath));
}
router.use(express.static(htmlPath));
router.use(express.static(webPath));
router.use('/', function (req, res, next) {
ftl2html(req, res, next, baseConf);
});
if (argv.remote) {
router.use(sharkAjax.remoteRequest(baseConf));
} else {
if (baseConf.contextPath) {
router.use(baseConf.contextPath, sharkAjax.localRequset(baseConf));
}
router.use('/', sharkAjax.localRequset(baseConf));
}
return router;
};
module.exports = automation;