@cloudbase/cals 0.3.33-alpha.1 → 0.3.33-alpha.2
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.
|
@@ -10,12 +10,16 @@ export interface ICodeItem {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* CALS 转成 中间状态的代码
|
|
13
|
+
*
|
|
14
|
+
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
13
15
|
*/
|
|
14
|
-
export declare function calsToCode(calsJSON: IPlatformApp): ICodeItem[];
|
|
16
|
+
export declare function calsToCode(calsJSON: IPlatformApp, version?: 'v0' | 'v1'): ICodeItem[];
|
|
15
17
|
/**
|
|
16
18
|
* 中间状态的代码 转成 CALS
|
|
19
|
+
*
|
|
20
|
+
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
17
21
|
*/
|
|
18
|
-
export declare function codeToCals(codeList: ICodeItem[]): IPlatformApp;
|
|
22
|
+
export declare function codeToCals(codeList: ICodeItem[], version?: 'v0' | 'v1'): IPlatformApp;
|
|
19
23
|
/**
|
|
20
24
|
* 指定目录下的文件转代码
|
|
21
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../parser/cals/utils/code/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAiC,MAAM,mBAAmB,CAAC;AAMhF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../parser/cals/utils/code/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAiC,MAAM,mBAAmB,CAAC;AAMhF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,GAAE,IAAI,GAAG,IAAW,GAAG,SAAS,EAAE,CAiL3F;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,GAAE,IAAI,GAAG,IAAW,GAAG,YAAY,CA4J3F;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAqBjG;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CA6BlF"}
|
|
@@ -23,12 +23,49 @@ const path_1 = __importDefault(require("path"));
|
|
|
23
23
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
24
24
|
/**
|
|
25
25
|
* CALS 转成 中间状态的代码
|
|
26
|
+
*
|
|
27
|
+
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
26
28
|
*/
|
|
27
|
-
function calsToCode(calsJSON) {
|
|
29
|
+
function calsToCode(calsJSON, version = 'v1') {
|
|
28
30
|
// 边界处理
|
|
29
31
|
if (!calsJSON)
|
|
30
32
|
return [];
|
|
33
|
+
const versionMap = {
|
|
34
|
+
v0: {
|
|
35
|
+
pageDir: '',
|
|
36
|
+
},
|
|
37
|
+
v1: {
|
|
38
|
+
pageDir: 'pages',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const versionConfig = versionMap[version];
|
|
42
|
+
if (!versionConfig)
|
|
43
|
+
throw "version' value must be v0 or v1";
|
|
31
44
|
const codeList = [];
|
|
45
|
+
/**
|
|
46
|
+
* 生成 pages
|
|
47
|
+
*/
|
|
48
|
+
const pagePaths = [];
|
|
49
|
+
calsJSON.items.forEach((pageItem) => {
|
|
50
|
+
const pagePath = versionConfig.pageDir ? `${versionConfig.pageDir}/${pageItem.id}` : pageItem.id;
|
|
51
|
+
/**
|
|
52
|
+
* 生成 page-config.json
|
|
53
|
+
*/
|
|
54
|
+
// 来自 IPageComponent
|
|
55
|
+
// :class, :style, component, dataVariables, directives, id, listeners, module, type 忽略,所以这里不包含
|
|
56
|
+
const pageConfigFields = ['attributes', 'dataset', 'extra', 'label', 'name'];
|
|
57
|
+
genConfig(pageItem, pageConfigFields, `${pagePath}/page-config.json`);
|
|
58
|
+
/**
|
|
59
|
+
* 生成 page.json
|
|
60
|
+
*/
|
|
61
|
+
addCodeItem(`${pagePath}/page.json`, JSON.stringify(pageItem.items, null, 2));
|
|
62
|
+
/**
|
|
63
|
+
* 生成页面代码
|
|
64
|
+
*/
|
|
65
|
+
genCode(pageItem.resources, pagePath);
|
|
66
|
+
// 记录页面目录路径
|
|
67
|
+
pagePaths.push(pagePath);
|
|
68
|
+
});
|
|
32
69
|
/**
|
|
33
70
|
* 生成 app-config.json
|
|
34
71
|
*/
|
|
@@ -62,30 +99,13 @@ function calsToCode(calsJSON) {
|
|
|
62
99
|
'rootPath',
|
|
63
100
|
'themeVars',
|
|
64
101
|
'originHistoryId',
|
|
102
|
+
// 额外添加,非标准
|
|
103
|
+
'pages',
|
|
65
104
|
],
|
|
66
105
|
};
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
calsJSON.extra.pages = pagePaths;
|
|
67
108
|
genConfig(calsJSON, appConfigFields, 'app-config.json', otherConfigFields);
|
|
68
|
-
/**
|
|
69
|
-
* 生成 pages
|
|
70
|
-
*/
|
|
71
|
-
calsJSON.items.forEach((pageItem) => {
|
|
72
|
-
const pagePath = `pages/${pageItem.id}`;
|
|
73
|
-
/**
|
|
74
|
-
* 生成 page-config.json
|
|
75
|
-
*/
|
|
76
|
-
// 来自 IPageComponent
|
|
77
|
-
// :class, :style, component, dataVariables, directives, id, listeners, module, type 忽略,所以这里不包含
|
|
78
|
-
const pageConfigFields = ['attributes', 'dataset', 'extra', 'label', 'name'];
|
|
79
|
-
genConfig(pageItem, pageConfigFields, `${pagePath}/page-config.json`);
|
|
80
|
-
/**
|
|
81
|
-
* 生成 page.json
|
|
82
|
-
*/
|
|
83
|
-
addCodeItem(`${pagePath}/page.json`, JSON.stringify(pageItem.items, null, 2));
|
|
84
|
-
/**
|
|
85
|
-
* 生成页面代码
|
|
86
|
-
*/
|
|
87
|
-
genCode(pageItem.resources, pagePath);
|
|
88
|
-
});
|
|
89
109
|
/**
|
|
90
110
|
* 生成全局代码
|
|
91
111
|
*/
|
|
@@ -159,30 +179,52 @@ function calsToCode(calsJSON) {
|
|
|
159
179
|
exports.calsToCode = calsToCode;
|
|
160
180
|
/**
|
|
161
181
|
* 中间状态的代码 转成 CALS
|
|
182
|
+
*
|
|
183
|
+
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
162
184
|
*/
|
|
163
|
-
function codeToCals(codeList) {
|
|
185
|
+
function codeToCals(codeList, version = 'v1') {
|
|
164
186
|
// 边界处理
|
|
165
187
|
if (!codeList || codeList.length === 0)
|
|
166
188
|
return {};
|
|
189
|
+
const versionMap = {
|
|
190
|
+
v0: {
|
|
191
|
+
pageDir: 'src',
|
|
192
|
+
pageIdRegExp: /src\/(.*?)\/.*/,
|
|
193
|
+
pageConfigRegExp: /src\/.*?\/page-config.json$/,
|
|
194
|
+
pageJSONRegExp: /src\/.*?\/page.json/,
|
|
195
|
+
},
|
|
196
|
+
v1: {
|
|
197
|
+
pageDir: 'src/pages',
|
|
198
|
+
pageIdRegExp: /src\/pages\/(.*?)\/.*/,
|
|
199
|
+
pageConfigRegExp: /src\/pages\/.*?\/page-config.json$/,
|
|
200
|
+
pageJSONRegExp: /src\/pages\/.*?\/page.json/,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
const versionConfig = versionMap[version];
|
|
204
|
+
if (!versionConfig)
|
|
205
|
+
throw "version' value must be v0 or v1";
|
|
167
206
|
// @ts-ignore
|
|
168
207
|
const calsJSON = {
|
|
169
208
|
items: [],
|
|
170
209
|
resources: [],
|
|
171
210
|
};
|
|
211
|
+
const appConfigCodeItem = codeList.find((item) => item.path === 'src/app-config.json');
|
|
212
|
+
const appConfig = JSON.parse(appConfigCodeItem.code);
|
|
213
|
+
let pagePaths = appConfig.extra.pages;
|
|
172
214
|
codeList.forEach((codeItem) => {
|
|
173
215
|
if (codeItem.path === 'src/app-config.json') {
|
|
174
216
|
/**
|
|
175
217
|
* app-config.json
|
|
176
218
|
*/
|
|
177
|
-
const config =
|
|
178
|
-
Object.assign(calsJSON, (0, lodash_1.omit)(config, ['_ignoreResources']));
|
|
219
|
+
const config = appConfig;
|
|
220
|
+
Object.assign(calsJSON, (0, lodash_1.omit)(config, ['_ignoreResources', 'extra.pages']));
|
|
179
221
|
calsJSON.resources = (0, lodash_1.concat)(calsJSON.resources, config._ignoreResources);
|
|
180
222
|
}
|
|
181
|
-
else if (codeItem.path
|
|
223
|
+
else if (isPageFile(codeItem.path)) {
|
|
182
224
|
/**
|
|
183
225
|
* page
|
|
184
226
|
*/
|
|
185
|
-
const [, pageId] = codeItem.path.match(
|
|
227
|
+
const [, pageId] = codeItem.path.match(versionConfig.pageIdRegExp);
|
|
186
228
|
let pageItem = calsJSON.items.find((item) => item.id === pageId);
|
|
187
229
|
if (!pageItem) {
|
|
188
230
|
pageItem = {
|
|
@@ -192,7 +234,7 @@ function codeToCals(codeList) {
|
|
|
192
234
|
};
|
|
193
235
|
calsJSON.items.push(pageItem);
|
|
194
236
|
}
|
|
195
|
-
if (
|
|
237
|
+
if (versionConfig.pageConfigRegExp.test(codeItem.path)) {
|
|
196
238
|
/**
|
|
197
239
|
* page-config.json
|
|
198
240
|
*/
|
|
@@ -201,7 +243,7 @@ function codeToCals(codeList) {
|
|
|
201
243
|
Object.assign(pageItem, propsConfig);
|
|
202
244
|
pageItem.resources = (0, lodash_1.concat)(pageItem.resources, config._ignoreResources);
|
|
203
245
|
}
|
|
204
|
-
else if (
|
|
246
|
+
else if (versionConfig.pageJSONRegExp.test(codeItem.path)) {
|
|
205
247
|
/**
|
|
206
248
|
* page.json
|
|
207
249
|
*/
|
|
@@ -225,7 +267,7 @@ function codeToCals(codeList) {
|
|
|
225
267
|
function handleNormalCodes(codeItem, pageId, resources) {
|
|
226
268
|
const relativePath = !pageId
|
|
227
269
|
? codeItem.path.replace('src/', '')
|
|
228
|
-
: codeItem.path.replace(
|
|
270
|
+
: codeItem.path.replace(`${versionConfig.pageDir}/${pageId}/`, '');
|
|
229
271
|
const _pageId = !pageId ? 'global' : pageId;
|
|
230
272
|
const commonVal = {
|
|
231
273
|
code: codeItem.code,
|
|
@@ -262,6 +304,9 @@ function codeToCals(codeList) {
|
|
|
262
304
|
break;
|
|
263
305
|
}
|
|
264
306
|
}
|
|
307
|
+
function isPageFile(filePath) {
|
|
308
|
+
return pagePaths.map((pagePath) => `src/${pagePath}`).some((pagePath) => filePath.indexOf(pagePath) === 0);
|
|
309
|
+
}
|
|
265
310
|
}
|
|
266
311
|
exports.codeToCals = codeToCals;
|
|
267
312
|
/**
|