@aiot-toolkit/parser 2.0.5-widget-provider-beta.1 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/lib/utils/ParserUtil.js +15 -15
- package/lib/ux/config/ExtensionConfig.js +2 -2
- package/lib/ux/config/FeatureConfig.js +19 -19
- package/lib/ux/config/vela/StyleAttributeConfig.js +134 -88
- package/lib/ux/enum/StyleSelectorType.js +6 -6
- package/lib/ux/enum/TemplateNodeType.js +2 -2
- package/lib/ux/enum/android/StyleSelectorName.js +2 -2
- package/lib/ux/interface/IUxAst.d.ts +2 -0
- package/lib/ux/parser/ScriptParser.js +2 -2
- package/lib/ux/parser/StyleParser.js +79 -72
- package/lib/ux/parser/TemplateValueParser.js +49 -49
- package/lib/ux/parser/UxParser.js +18 -12
- package/lib/ux/translate/android/StyleToTypescript.js +51 -51
- package/lib/ux/translate/android/TemplateToTypescript.js +51 -51
- package/lib/ux/translate/android/UxToTypescript.js +14 -14
- package/lib/ux/translate/android/attributeTranslate/ForTranslate.js +17 -17
- package/lib/ux/translate/android/attributeTranslate/IfTranslate.js +9 -9
- package/lib/ux/translate/vela/ScriptToTypescript.js +10 -10
- package/lib/ux/translate/vela/StyleToTypescript.js +10 -10
- package/lib/ux/translate/vela/TemplateToTypescript.js +74 -74
- package/lib/ux/translate/vela/TranslateCache.js +2 -2
- package/lib/ux/translate/vela/UxToTypescript.js +6 -6
- package/lib/ux/translate/vela/VelaContext.js +2 -2
- package/lib/ux/translate/vela/plugins/e2e.js +63 -62
- package/lib/ux/translate/vela/plugins/startPage.js +1 -1
- package/lib/ux/translate/vela/protobuf/BinaryPlugin.js +172 -172
- package/lib/ux/translate/vela/protobuf/protobuf.js +235 -235
- package/lib/ux/translate/vela/protobuf/protobufControl.js +159 -159
- package/lib/ux/translate/vela/protobuf/vdom_pb.js +2374 -2374
- package/lib/ux/translate/vela/runtime/velaTestLibrary.js +104 -104
- package/lib/ux/translate/vela/utils/AttributeConfig.js +15 -15
- package/lib/ux/translate/vela/utils/ExtendedBoxStyle.js +38 -38
- package/lib/ux/translate/vela/utils/SourceMapUtil.js +30 -30
- package/lib/ux/translate/vela/utils/TemplateUtil.js +180 -180
- package/lib/ux/translate/vela/wrap/CbTranslate.js +8 -8
- package/lib/ux/translate/vela/wrap/CfTranslate.js +14 -14
- package/lib/ux/translate/vela/wrap/CiTranslate.js +11 -11
- package/lib/ux/utils/BabelUtil.js +35 -35
- package/lib/ux/utils/ElementConfigUtil.js +24 -24
- package/lib/ux/utils/StyleMapUtil.js +15 -15
- package/lib/ux/utils/StyleUtil.d.ts +1 -1
- package/lib/ux/utils/StyleUtil.js +192 -248
- package/lib/ux/utils/UxUtil.js +32 -32
- package/lib/ux/validate/ElementValidate.js +2 -2
- package/lib/ux/validate/UxFileValidate.js +2 -2
- package/package.json +4 -4
|
@@ -12,11 +12,11 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
/**
|
|
16
|
-
* 用于添加应用自动化测试代码
|
|
17
|
-
* 分为两种情况
|
|
18
|
-
* 1. app文件
|
|
19
|
-
* 2. page 文件
|
|
15
|
+
/**
|
|
16
|
+
* 用于添加应用自动化测试代码
|
|
17
|
+
* 分为两种情况
|
|
18
|
+
* 1. app文件
|
|
19
|
+
* 2. page 文件
|
|
20
20
|
*/
|
|
21
21
|
function e2e() {
|
|
22
22
|
return {
|
|
@@ -40,12 +40,12 @@ function e2e() {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* 添加 app 的测试代码
|
|
45
|
-
*
|
|
46
|
-
* 引入测试框架文件
|
|
47
|
-
* @param path
|
|
48
|
-
* @param opts
|
|
43
|
+
/**
|
|
44
|
+
* 添加 app 的测试代码
|
|
45
|
+
*
|
|
46
|
+
* 引入测试框架文件
|
|
47
|
+
* @param path
|
|
48
|
+
* @param opts
|
|
49
49
|
*/
|
|
50
50
|
function addAppTestCode(path) {
|
|
51
51
|
const runtimePath = _path.default.join(__dirname, '../runtime/velaTestLibrary.js');
|
|
@@ -55,40 +55,40 @@ function addAppTestCode(path) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* 添加页面的测试代码
|
|
60
|
-
* 1. 如果测试文件存在,则
|
|
61
|
-
* a. import 测试文件
|
|
62
|
-
* b. 设置测试函数: 如果 onTestStart 方法已存在,则在其内部添加测试代码;否则,添加 onTestStart方法
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* 2. 如果启用自动路由,且当前页面是首页
|
|
66
|
-
* a. 从routerList 中过滤出有测试文件的路由
|
|
67
|
-
* b. 在末尾添加 $generateAutoRunTest
|
|
68
|
-
* c. 在onShow 方法中调用 $generateAutoRunTest
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @description 示例
|
|
72
|
-
*
|
|
73
|
-
* 源码 `src/home/myHome.ux`
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* export default {}
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* 产物
|
|
80
|
-
* ```
|
|
81
|
-
* import fnTestCase from 'test/home/myHome.js'
|
|
82
|
-
*
|
|
83
|
-
* export default {
|
|
84
|
-
* onTestStart: (){
|
|
85
|
-
* // code
|
|
86
|
-
* }
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*
|
|
90
|
-
* @param path
|
|
91
|
-
* @param opts
|
|
58
|
+
/**
|
|
59
|
+
* 添加页面的测试代码
|
|
60
|
+
* 1. 如果测试文件存在,则
|
|
61
|
+
* a. import 测试文件
|
|
62
|
+
* b. 设置测试函数: 如果 onTestStart 方法已存在,则在其内部添加测试代码;否则,添加 onTestStart方法
|
|
63
|
+
*
|
|
64
|
+
*
|
|
65
|
+
* 2. 如果启用自动路由,且当前页面是首页
|
|
66
|
+
* a. 从routerList 中过滤出有测试文件的路由
|
|
67
|
+
* b. 在末尾添加 $generateAutoRunTest
|
|
68
|
+
* c. 在onShow 方法中调用 $generateAutoRunTest
|
|
69
|
+
*
|
|
70
|
+
*
|
|
71
|
+
* @description 示例
|
|
72
|
+
*
|
|
73
|
+
* 源码 `src/home/myHome.ux`
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* export default {}
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* 产物
|
|
80
|
+
* ```
|
|
81
|
+
* import fnTestCase from 'test/home/myHome.js'
|
|
82
|
+
*
|
|
83
|
+
* export default {
|
|
84
|
+
* onTestStart: (){
|
|
85
|
+
* // code
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @param path
|
|
91
|
+
* @param opts
|
|
92
92
|
*/
|
|
93
93
|
function addPageTestCode(path, opts) {
|
|
94
94
|
const e2eConfig = getE2eConfig(opts);
|
|
@@ -96,7 +96,8 @@ function addPageTestCode(path, opts) {
|
|
|
96
96
|
// 1
|
|
97
97
|
if (_fsExtra.default.existsSync(testFilePath)) {
|
|
98
98
|
// 1.a
|
|
99
|
-
const
|
|
99
|
+
const relativePath = _path.default.relative(_path.default.dirname(opts.options.filePath), testFilePath);
|
|
100
|
+
const vmImport = t.importDeclaration([t.importDefaultSpecifier(t.identifier('fnTestCase'))], t.stringLiteral(relativePath));
|
|
100
101
|
if (path.parent.type === 'Program') {
|
|
101
102
|
path.parent.body.unshift(vmImport);
|
|
102
103
|
}
|
|
@@ -132,13 +133,13 @@ function addPageTestCode(path, opts) {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
/**
|
|
136
|
-
* 插入函数
|
|
137
|
-
*
|
|
138
|
-
* 如果已存在,把函数体插入到指定函数末尾;不存在,则添加
|
|
139
|
-
*
|
|
140
|
-
* @param name 函数名
|
|
141
|
-
* @param body 函数体
|
|
136
|
+
/**
|
|
137
|
+
* 插入函数
|
|
138
|
+
*
|
|
139
|
+
* 如果已存在,把函数体插入到指定函数末尾;不存在,则添加
|
|
140
|
+
*
|
|
141
|
+
* @param name 函数名
|
|
142
|
+
* @param body 函数体
|
|
142
143
|
*/
|
|
143
144
|
function insertFun(name, body, properties) {
|
|
144
145
|
const fun = properties.find(p => p.type === 'ObjectMethod' && p.key.name === name);
|
|
@@ -223,12 +224,12 @@ function getE2eConfig(opts) {
|
|
|
223
224
|
return result;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
/**
|
|
227
|
-
* 获取源文件对应的测试文件地址
|
|
228
|
-
* @param sourceFile 源文件
|
|
229
|
-
* @param opts
|
|
230
|
-
* @param e2eConfig
|
|
231
|
-
* @returns
|
|
227
|
+
/**
|
|
228
|
+
* 获取源文件对应的测试文件地址
|
|
229
|
+
* @param sourceFile 源文件
|
|
230
|
+
* @param opts
|
|
231
|
+
* @param e2eConfig
|
|
232
|
+
* @returns
|
|
232
233
|
*/
|
|
233
234
|
function getTestFilePath(sourceFile, opts, e2eConfig) {
|
|
234
235
|
const {
|
|
@@ -242,9 +243,9 @@ function getTestFilePath(sourceFile, opts, e2eConfig) {
|
|
|
242
243
|
return _path.default.join(e2eConfig.testDir, parsed.dir, `${parsed.name}.js`);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
/**
|
|
246
|
-
* 获取测试函数的函数体
|
|
247
|
-
* @returns
|
|
246
|
+
/**
|
|
247
|
+
* 获取测试函数的函数体
|
|
248
|
+
* @returns
|
|
248
249
|
*/
|
|
249
250
|
function generateTestFn() {
|
|
250
251
|
const fn = `function(){
|
|
@@ -23,7 +23,7 @@ function startPage() {
|
|
|
23
23
|
_BabelUtil.default.insertImportToProgram('router', '@system.router', path.parent);
|
|
24
24
|
_BabelUtil.default.insertOrUpdateFunctionToObject('onShow', _BabelUtil.default.generateFunctionBody(`
|
|
25
25
|
setTimeout(() => {
|
|
26
|
-
router.
|
|
26
|
+
router.replace({
|
|
27
27
|
uri: "${url.pathname}",
|
|
28
28
|
params: ${JSON.stringify(url.query)},
|
|
29
29
|
});
|
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
const Path = require('path')
|
|
2
|
-
const { createBin } = require('./protobufControl')
|
|
3
|
-
|
|
4
|
-
const contentType = {
|
|
5
|
-
style: 'style',
|
|
6
|
-
template: 'template',
|
|
7
|
-
tagName: 'tagName'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const ext = '.bin'
|
|
11
|
-
|
|
12
|
-
class BinaryPlugin {
|
|
13
|
-
/**
|
|
14
|
-
* 所有要创建二进制文件的数据
|
|
15
|
-
*
|
|
16
|
-
* @type {{[binFileName:string]:{
|
|
17
|
-
* sourceFileName:string,
|
|
18
|
-
* tagName?:string,
|
|
19
|
-
* style?:string
|
|
20
|
-
* template?:string
|
|
21
|
-
* }[]}}
|
|
22
|
-
*/
|
|
23
|
-
static binaryData = {}
|
|
24
|
-
|
|
25
|
-
static config = {}
|
|
26
|
-
|
|
27
|
-
static createBinFiles() {
|
|
28
|
-
const keys = Object.keys(BinaryPlugin.binaryData)
|
|
29
|
-
if (keys.length > 0) {
|
|
30
|
-
keys.forEach((binPath) => {
|
|
31
|
-
// 写入文件
|
|
32
|
-
// 1. 获取style template内容
|
|
33
|
-
// 2. 获取bin文件名= build目录 + 文件名相对src的路径
|
|
34
|
-
// 3. 创建buffer数据
|
|
35
|
-
// 4. 写入文件
|
|
36
|
-
const data = BinaryPlugin.binaryData[binPath]
|
|
37
|
-
const styleList = []
|
|
38
|
-
const templateList = []
|
|
39
|
-
const tagList = []
|
|
40
|
-
|
|
41
|
-
data.forEach((item) => {
|
|
42
|
-
tagList.push(item.tagName || '')
|
|
43
|
-
styleList.push(item.style || '[]')
|
|
44
|
-
templateList.push(item.template || '')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const ext = Path.extname(binPath)
|
|
48
|
-
|
|
49
|
-
// 如果不是hml文件,生成style.bin
|
|
50
|
-
if (ext !== '.hml') {
|
|
51
|
-
const cssBinPath = BinaryPlugin.getBinPath(binPath, 'style')
|
|
52
|
-
createBin(
|
|
53
|
-
cssBinPath,
|
|
54
|
-
new Array(tagList.length).fill(''),
|
|
55
|
-
styleList,
|
|
56
|
-
new Array(templateList.length).fill('')
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 如果不是css类型的文件,生成template.bin
|
|
61
|
-
if (!['.css', '.less', '.scss', '.sass'].includes(ext)) {
|
|
62
|
-
const templateBinPath = BinaryPlugin.getBinPath(binPath, 'template')
|
|
63
|
-
createBin(templateBinPath, tagList, new Array(styleList.length).fill('[]'), templateList)
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static reset() {
|
|
70
|
-
BinaryPlugin.binaryData = {}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @private
|
|
76
|
-
* @param {string} binPath
|
|
77
|
-
* @param {'style'|'template'} type
|
|
78
|
-
*/
|
|
79
|
-
static getBinPath(binPath, type) {
|
|
80
|
-
const srcPath = Path.join(this.config.projectPath, this.config.source)
|
|
81
|
-
const relativePath = Path.relative(srcPath, binPath)
|
|
82
|
-
const parse = Path.parse(relativePath)
|
|
83
|
-
|
|
84
|
-
const result = Path.join(
|
|
85
|
-
this.config.outputProjectPath,
|
|
86
|
-
this.config.output,
|
|
87
|
-
Path.dirname(relativePath),
|
|
88
|
-
`${parse.name}.${type}${ext}`
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
return result
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* @private
|
|
97
|
-
* @param {string} binFileName 要生成的bin文件路径
|
|
98
|
-
* @param {string} sourceFileName 源码文件路径
|
|
99
|
-
* @param {string} type 添加内容的类型, 参考contentType
|
|
100
|
-
* @param {string} content
|
|
101
|
-
*
|
|
102
|
-
* @returns {{index:number, name:string}}
|
|
103
|
-
*/
|
|
104
|
-
static addContent(binFileName, sourceFileName, type, content, pagePath = '') {
|
|
105
|
-
const binaryData = BinaryPlugin.binaryData
|
|
106
|
-
// 1. 如果没有对应的bin数据,则创建
|
|
107
|
-
|
|
108
|
-
if (!binaryData[binFileName]) {
|
|
109
|
-
binaryData[binFileName] = []
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const array = binaryData[binFileName]
|
|
113
|
-
let item
|
|
114
|
-
// 2. 通过sourceFileName寻找是否已存在对应的数据,如果存在,记录位置并直接使用;不存在,则新建
|
|
115
|
-
const index = array.findIndex((item) => item.sourceFileName === sourceFileName)
|
|
116
|
-
if (index >= 0) {
|
|
117
|
-
item = array[index]
|
|
118
|
-
item[type] = content
|
|
119
|
-
} else {
|
|
120
|
-
item = {
|
|
121
|
-
sourceFileName,
|
|
122
|
-
[type]: content
|
|
123
|
-
}
|
|
124
|
-
array.push(item)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const binPath = BinaryPlugin.getBinPath(binFileName, type)
|
|
128
|
-
let relativePath = Path.relative(
|
|
129
|
-
Path.resolve(this.config.outputProjectPath, this.config.output),
|
|
130
|
-
binPath
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
relativePath = relativePath.replace(/\\/g, '/')
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
index: index >= 0 ? index : array.length - 1,
|
|
137
|
-
name: relativePath
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
static addTagName(binFileName, sourceFileName, content, pagePath = '') {
|
|
142
|
-
return BinaryPlugin.addContent(
|
|
143
|
-
binFileName,
|
|
144
|
-
sourceFileName,
|
|
145
|
-
contentType.tagName,
|
|
146
|
-
content,
|
|
147
|
-
pagePath
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
static addTemplate(binFileName, sourceFileName, content, pagePath = '') {
|
|
152
|
-
return BinaryPlugin.addContent(
|
|
153
|
-
binFileName,
|
|
154
|
-
sourceFileName,
|
|
155
|
-
contentType.template,
|
|
156
|
-
content,
|
|
157
|
-
pagePath
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
static addStyle(binFileName, sourceFileName, content, pagePath = '') {
|
|
162
|
-
return BinaryPlugin.addContent(
|
|
163
|
-
binFileName,
|
|
164
|
-
sourceFileName,
|
|
165
|
-
contentType.style,
|
|
166
|
-
content,
|
|
167
|
-
pagePath
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
module.exports = BinaryPlugin
|
|
1
|
+
const Path = require('path')
|
|
2
|
+
const { createBin } = require('./protobufControl')
|
|
3
|
+
|
|
4
|
+
const contentType = {
|
|
5
|
+
style: 'style',
|
|
6
|
+
template: 'template',
|
|
7
|
+
tagName: 'tagName'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ext = '.bin'
|
|
11
|
+
|
|
12
|
+
class BinaryPlugin {
|
|
13
|
+
/**
|
|
14
|
+
* 所有要创建二进制文件的数据
|
|
15
|
+
*
|
|
16
|
+
* @type {{[binFileName:string]:{
|
|
17
|
+
* sourceFileName:string,
|
|
18
|
+
* tagName?:string,
|
|
19
|
+
* style?:string
|
|
20
|
+
* template?:string
|
|
21
|
+
* }[]}}
|
|
22
|
+
*/
|
|
23
|
+
static binaryData = {}
|
|
24
|
+
|
|
25
|
+
static config = {}
|
|
26
|
+
|
|
27
|
+
static createBinFiles() {
|
|
28
|
+
const keys = Object.keys(BinaryPlugin.binaryData)
|
|
29
|
+
if (keys.length > 0) {
|
|
30
|
+
keys.forEach((binPath) => {
|
|
31
|
+
// 写入文件
|
|
32
|
+
// 1. 获取style template内容
|
|
33
|
+
// 2. 获取bin文件名= build目录 + 文件名相对src的路径
|
|
34
|
+
// 3. 创建buffer数据
|
|
35
|
+
// 4. 写入文件
|
|
36
|
+
const data = BinaryPlugin.binaryData[binPath]
|
|
37
|
+
const styleList = []
|
|
38
|
+
const templateList = []
|
|
39
|
+
const tagList = []
|
|
40
|
+
|
|
41
|
+
data.forEach((item) => {
|
|
42
|
+
tagList.push(item.tagName || '')
|
|
43
|
+
styleList.push(item.style || '[]')
|
|
44
|
+
templateList.push(item.template || '')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const ext = Path.extname(binPath)
|
|
48
|
+
|
|
49
|
+
// 如果不是hml文件,生成style.bin
|
|
50
|
+
if (ext !== '.hml') {
|
|
51
|
+
const cssBinPath = BinaryPlugin.getBinPath(binPath, 'style')
|
|
52
|
+
createBin(
|
|
53
|
+
cssBinPath,
|
|
54
|
+
new Array(tagList.length).fill(''),
|
|
55
|
+
styleList,
|
|
56
|
+
new Array(templateList.length).fill('')
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 如果不是css类型的文件,生成template.bin
|
|
61
|
+
if (!['.css', '.less', '.scss', '.sass'].includes(ext)) {
|
|
62
|
+
const templateBinPath = BinaryPlugin.getBinPath(binPath, 'template')
|
|
63
|
+
createBin(templateBinPath, tagList, new Array(styleList.length).fill('[]'), templateList)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static reset() {
|
|
70
|
+
BinaryPlugin.binaryData = {}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
* @param {string} binPath
|
|
77
|
+
* @param {'style'|'template'} type
|
|
78
|
+
*/
|
|
79
|
+
static getBinPath(binPath, type) {
|
|
80
|
+
const srcPath = Path.join(this.config.projectPath, this.config.source)
|
|
81
|
+
const relativePath = Path.relative(srcPath, binPath)
|
|
82
|
+
const parse = Path.parse(relativePath)
|
|
83
|
+
|
|
84
|
+
const result = Path.join(
|
|
85
|
+
this.config.outputProjectPath,
|
|
86
|
+
this.config.output,
|
|
87
|
+
Path.dirname(relativePath),
|
|
88
|
+
`${parse.name}.${type}${ext}`
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return result
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
* @param {string} binFileName 要生成的bin文件路径
|
|
98
|
+
* @param {string} sourceFileName 源码文件路径
|
|
99
|
+
* @param {string} type 添加内容的类型, 参考contentType
|
|
100
|
+
* @param {string} content
|
|
101
|
+
*
|
|
102
|
+
* @returns {{index:number, name:string}}
|
|
103
|
+
*/
|
|
104
|
+
static addContent(binFileName, sourceFileName, type, content, pagePath = '') {
|
|
105
|
+
const binaryData = BinaryPlugin.binaryData
|
|
106
|
+
// 1. 如果没有对应的bin数据,则创建
|
|
107
|
+
|
|
108
|
+
if (!binaryData[binFileName]) {
|
|
109
|
+
binaryData[binFileName] = []
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const array = binaryData[binFileName]
|
|
113
|
+
let item
|
|
114
|
+
// 2. 通过sourceFileName寻找是否已存在对应的数据,如果存在,记录位置并直接使用;不存在,则新建
|
|
115
|
+
const index = array.findIndex((item) => item.sourceFileName === sourceFileName)
|
|
116
|
+
if (index >= 0) {
|
|
117
|
+
item = array[index]
|
|
118
|
+
item[type] = content
|
|
119
|
+
} else {
|
|
120
|
+
item = {
|
|
121
|
+
sourceFileName,
|
|
122
|
+
[type]: content
|
|
123
|
+
}
|
|
124
|
+
array.push(item)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const binPath = BinaryPlugin.getBinPath(binFileName, type)
|
|
128
|
+
let relativePath = Path.relative(
|
|
129
|
+
Path.resolve(this.config.outputProjectPath, this.config.output),
|
|
130
|
+
binPath
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
relativePath = relativePath.replace(/\\/g, '/')
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
index: index >= 0 ? index : array.length - 1,
|
|
137
|
+
name: relativePath
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static addTagName(binFileName, sourceFileName, content, pagePath = '') {
|
|
142
|
+
return BinaryPlugin.addContent(
|
|
143
|
+
binFileName,
|
|
144
|
+
sourceFileName,
|
|
145
|
+
contentType.tagName,
|
|
146
|
+
content,
|
|
147
|
+
pagePath
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static addTemplate(binFileName, sourceFileName, content, pagePath = '') {
|
|
152
|
+
return BinaryPlugin.addContent(
|
|
153
|
+
binFileName,
|
|
154
|
+
sourceFileName,
|
|
155
|
+
contentType.template,
|
|
156
|
+
content,
|
|
157
|
+
pagePath
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static addStyle(binFileName, sourceFileName, content, pagePath = '') {
|
|
162
|
+
return BinaryPlugin.addContent(
|
|
163
|
+
binFileName,
|
|
164
|
+
sourceFileName,
|
|
165
|
+
contentType.style,
|
|
166
|
+
content,
|
|
167
|
+
pagePath
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = BinaryPlugin
|