-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (79 loc) · 2.25 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
93
94
95
/**
* @file 入口模块
* @author sparklewhy@gmail.com
*/
'use strict';
var path = require('path');
/**
* 创建文件
*
* @param {string} filePath 相对于项目根目录的文件路径
* @param {string=} content 文件内容
* @param {Object=} options 附加文件选项
* @return {File}
*/
function createFile(filePath, content, options) {
var file = fis.file.wrap(path.join(fis.project.getProjectPath(), filePath));
if (arguments.length === 2) {
if (content && !fis.util.isString(content)) {
options = content;
content = null;
}
}
content != null && file.setContent(content);
options && Object.keys(options).forEach(function (k) {
file[k] = options[k];
});
return file;
}
function addFile(ret, file) {
var subPath = file.subpath;
ret.src[subPath] = file;
var id = file.getId();
ret.ids[id] = file;
file.map = ret.map.res[id] = {
uri: file.getUrl(),
type: file.rExt.replace(/^\./, '')
};
ret.pkg[subPath] = file;
}
function prepack(ret, conf, settings, opt) {
var assign = fis.util.assign;
var opts = assign({}, exports.DEFAULT_OPTIONS, settings);
opts.babelHelperFileOption = assign(
{},
exports.DEFAULT_OPTIONS.babelHelperFileOption,
settings.babelHelperFileOption || {}
);
var src = ret.src;
var babelHelpers = [];
Object.keys(src).forEach(function (item) {
var helpers = src[item].extras.babelHelpers;
(helpers || []).forEach(function (item) {
if (babelHelpers.indexOf(item) === -1) {
babelHelpers.push(item);
}
});
});
var code = exports.babel.buildExternalHelpers(
babelHelpers, opts.babelHelperCodeStyle
);
var babelHelperFile = createFile(
opts.babelHelperFileName, code,
opts.babelHelperFileOption
);
addFile(ret, babelHelperFile);
fis.compile.process(babelHelperFile);
}
module.exports = exports = prepack;
exports.babel = null;
exports.DEFAULT_OPTIONS = {
babelHelperFileName: 'src/babelHelpers.js',
babelHelperCodeStyle: 'umd',
babelHelperFileOption: {
useHash: false,
relative: true,
disableBabel: true,
disableWrap: true
}
};