@cloudbase/cals 1.0.49 → 1.0.50
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/lib/parser/cals/utils/template.js +3 -3
- package/package.json +3 -3
- package/lib/parser/cals/utils/block/index.js +0 -151
- package/lib/parser/cals/utils/code/index.js +0 -393
- package/lib/parser/cals/utils/common.js +0 -268
- package/lib/parser/cals/utils/getUsedResources.d.ts +0 -10
- package/lib/parser/cals/utils/getUsedResources.d.ts.map +0 -1
- package/lib/parser/cals/utils/getUsedResources.js +0 -128
- package/lib/parser/cals/utils/runtime.js +0 -268
- package/lib/parser/cals/utils/style.js +0 -472
- package/lib/parser/cals/utils/version/common.js +0 -385
- package/lib/parser/cals/utils/version/config.d.ts +0 -16
- package/lib/parser/cals/utils/version/config.d.ts.map +0 -1
- package/lib/parser/cals/utils/version/config.js +0 -244
- package/lib/parser/cals/utils/version/index.js +0 -96
- package/lib/parser/cals/utils/version/parses.js +0 -581
- package/lib/parser/cals/utils/version/utils.d.ts +0 -14
- package/lib/parser/cals/utils/version/utils.d.ts.map +0 -1
- package/lib/parser/cals/utils/version/utils.js +0 -148
- package/lib/parser/expression/index.d.ts +0 -123
- package/lib/parser/expression/index.d.ts.map +0 -1
- package/lib/parser/expression/index.js +0 -301
- package/lib/parser/plugins/postcss-rpx2clac.d.ts +0 -18
- package/lib/parser/plugins/postcss-rpx2clac.d.ts.map +0 -1
- package/lib/parser/plugins/postcss-rpx2clac.js +0 -68
- package/lib/types/basic/app.d.ts +0 -73
- package/lib/types/basic/app.d.ts.map +0 -1
- package/lib/types/basic/app.js +0 -2
- package/lib/types/basic/common.d.ts +0 -93
- package/lib/types/basic/common.d.ts.map +0 -1
- package/lib/types/basic/common.js +0 -2
- package/lib/types/basic/component.d.ts +0 -211
- package/lib/types/basic/component.d.ts.map +0 -1
- package/lib/types/basic/component.js +0 -2
- package/lib/types/basic/datasource.d.ts +0 -50
- package/lib/types/basic/datasource.d.ts.map +0 -1
- package/lib/types/basic/datasource.js +0 -2
- package/lib/types/index.js +0 -42
- package/lib/types/lcds.js +0 -25
- package/lib/types/platform/app.js +0 -11
- package/lib/types/platform/common.d.ts +0 -181
- package/lib/types/platform/common.d.ts.map +0 -1
- package/lib/types/platform/common.js +0 -87
- package/lib/types/platform/component.d.ts +0 -139
- package/lib/types/platform/component.d.ts.map +0 -1
- package/lib/types/platform/component.js +0 -11
- package/lib/types/platform/datasource.d.ts +0 -467
- package/lib/types/platform/datasource.d.ts.map +0 -1
- package/lib/types/platform/datasource.js +0 -2
- package/lib/types/platform/eventFlow.d.ts +0 -20
- package/lib/types/platform/eventFlow.d.ts.map +0 -1
- package/lib/types/platform/eventFlow.js +0 -2
- package/lib/types/platform/query.d.ts +0 -67
- package/lib/types/platform/query.d.ts.map +0 -1
- package/lib/types/platform/query.js +0 -2
- package/lib/types/platform/theme.js +0 -2
- package/lib/types/platform/widget/form.d.ts +0 -5
- package/lib/types/platform/widget/form.d.ts.map +0 -1
- package/lib/types/platform/widget/form.js +0 -5
- package/lib/types/platform/widget/meta.d.ts +0 -60
- package/lib/types/platform/widget/meta.d.ts.map +0 -1
- package/lib/types/platform/widget/meta.js +0 -6
- package/lib/utils/CSSProperty.d.ts +0 -64
- package/lib/utils/CSSProperty.d.ts.map +0 -1
- package/lib/utils/CSSProperty.js +0 -89
- package/lib/utils/build.d.ts +0 -2
- package/lib/utils/build.d.ts.map +0 -1
- package/lib/utils/build.js +0 -75
- package/lib/utils/dts/auto-generated.d.ts +0 -2
- package/lib/utils/dts/auto-generated.d.ts.map +0 -1
- package/lib/utils/dts/auto-generated.js +0 -1796
- package/lib/utils/dts/build.d.ts +0 -2
- package/lib/utils/dts/build.d.ts.map +0 -1
- package/lib/utils/dts/build.js +0 -136
- package/lib/utils/dts/index.js +0 -1008
- package/lib/utils/index.js +0 -27
- package/lib/utils/version/common.d.ts +0 -3
- package/lib/utils/version/common.d.ts.map +0 -1
- package/lib/utils/version/common.js +0 -27
- package/lib/utils/version/featureChecker.js +0 -35
- package/lib/utils/version/migrations/version4.js +0 -199
- package/lib/utils/version-migrations/common.d.ts +0 -5
- package/lib/utils/version-migrations/common.d.ts.map +0 -1
- package/lib/utils/version-migrations/common.js +0 -29
- package/lib/utils/version-migrations/version4.d.ts +0 -3
- package/lib/utils/version-migrations/version4.d.ts.map +0 -1
- package/lib/utils/version-migrations/version4.js +0 -199
|
@@ -134,11 +134,11 @@ export default function({event, data}) {
|
|
|
134
134
|
// 普通模块-没有上下文,无法直接获取 state 信息
|
|
135
135
|
[types_1.ECodeType.NORMAL_MODULE]: `
|
|
136
136
|
/*
|
|
137
|
-
* 函数里面访问:通过 app.common.[name]
|
|
138
|
-
* 函数外面访问:通过 import(如在页面的 handler 引用的例子:import
|
|
137
|
+
* 函数里面访问:通过 app.common.[name] 访问这里定义的方法或值
|
|
138
|
+
* 函数外面访问:通过 import(如在页面的 handler 引用的例子:import sayHi from '../../common/[name]')
|
|
139
139
|
*/
|
|
140
140
|
|
|
141
|
-
export function sayHi() {
|
|
141
|
+
export default function sayHi() {
|
|
142
142
|
console.log('Hi LowCode')
|
|
143
143
|
}
|
|
144
144
|
`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cals",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.50",
|
|
4
4
|
"description": "Common application specifications",
|
|
5
5
|
"main": "lib/utils/index.js",
|
|
6
6
|
"source": "src/utils/index.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"postcss-less": "^6.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@tcwd/dev-tools": "
|
|
47
|
+
"@tcwd/dev-tools": "^1.0.1",
|
|
48
48
|
"@types/acorn": "^4.0.5",
|
|
49
49
|
"@types/jest": "^27.4.0",
|
|
50
50
|
"@types/lodash": "^4.14.168",
|
|
@@ -63,4 +63,4 @@
|
|
|
63
63
|
"typescript": "^4.7.4",
|
|
64
64
|
"typescript-json-schema": "^0.53.0"
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseComponentCals = void 0;
|
|
7
|
-
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
-
const set_1 = __importDefault(require("lodash/set"));
|
|
9
|
-
const expression_1 = require("../../../expression");
|
|
10
|
-
function parseComponentCals(ctx, cals) {
|
|
11
|
-
if (!ctx.datasetMap) {
|
|
12
|
-
ctx.datasetMap = {};
|
|
13
|
-
}
|
|
14
|
-
if (!ctx.dataSourceMap) {
|
|
15
|
-
ctx.dataSourceMap = {};
|
|
16
|
-
}
|
|
17
|
-
if (!ctx.componentMap) {
|
|
18
|
-
ctx.componentMap = {};
|
|
19
|
-
}
|
|
20
|
-
if (!ctx.lowcodeMap) {
|
|
21
|
-
ctx.lowcodeMap = {};
|
|
22
|
-
}
|
|
23
|
-
if (!ctx.componentLibMap) {
|
|
24
|
-
ctx.componentLibMap = {};
|
|
25
|
-
}
|
|
26
|
-
ctx.component = {
|
|
27
|
-
id: cals.id || '',
|
|
28
|
-
};
|
|
29
|
-
const { component, module, attributes = {}, items = [], listeners = [], directives = {}, [':class']: dynamicClassList, [':style']: dynamicStyle, } = cals;
|
|
30
|
-
if (module && component && !(0, get_1.default)(ctx.componentMap, `${module}.${component}`)) {
|
|
31
|
-
(0, set_1.default)(ctx.componentMap, `${module}.${component}`, true);
|
|
32
|
-
ctx.componentLibMap[module] = true;
|
|
33
|
-
}
|
|
34
|
-
// 优先处理 directives 因为其他绑定会用到for
|
|
35
|
-
parseDirectivesCals(ctx, directives);
|
|
36
|
-
pasrseDynamicMapCals(ctx, attributes);
|
|
37
|
-
for (let item of listeners) {
|
|
38
|
-
parseListenertCals(ctx, item);
|
|
39
|
-
}
|
|
40
|
-
if (dynamicClassList) {
|
|
41
|
-
parseValueCals(ctx, dynamicClassList);
|
|
42
|
-
}
|
|
43
|
-
if (dynamicStyle) {
|
|
44
|
-
parseValueCals(ctx, dynamicStyle);
|
|
45
|
-
}
|
|
46
|
-
for (let item of items) {
|
|
47
|
-
parseComponentCals(ctx, item);
|
|
48
|
-
}
|
|
49
|
-
return ctx;
|
|
50
|
-
}
|
|
51
|
-
exports.parseComponentCals = parseComponentCals;
|
|
52
|
-
function parseListenertCals(ctx, listener) {
|
|
53
|
-
let { type, handler } = listener;
|
|
54
|
-
switch (type) {
|
|
55
|
-
case expression_1.ActionType.Rematch: {
|
|
56
|
-
if (handler === null || handler === void 0 ? void 0 : handler.name) {
|
|
57
|
-
ctx.lowcodeMap[handler === null || handler === void 0 ? void 0 : handler.name] = true;
|
|
58
|
-
}
|
|
59
|
-
pasrseDynamicMapCals(ctx, handler === null || handler === void 0 ? void 0 : handler.params);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case expression_1.ActionType.DataSource: {
|
|
63
|
-
let params = handler === null || handler === void 0 ? void 0 : handler.params;
|
|
64
|
-
pasrseDynamicMapCals(params);
|
|
65
|
-
if (params === null || params === void 0 ? void 0 : params.dataSourceName) {
|
|
66
|
-
ctx.dataSourceMap[params === null || params === void 0 ? void 0 : params.dataSourceName] = true;
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case expression_1.ActionType.Material: {
|
|
71
|
-
if (handler === null || handler === void 0 ? void 0 : handler.module) {
|
|
72
|
-
ctx.componentLibMap[handler === null || handler === void 0 ? void 0 : handler.module] = true;
|
|
73
|
-
}
|
|
74
|
-
pasrseDynamicMapCals(ctx, handler === null || handler === void 0 ? void 0 : handler.params);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case expression_1.ActionType.Platform: {
|
|
78
|
-
pasrseDynamicMapCals(ctx, handler === null || handler === void 0 ? void 0 : handler.params);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function pasrseDynamicMapCals(ctx, map = {}) {
|
|
84
|
-
for (let key in map) {
|
|
85
|
-
if (/^:/.test(key) && typeof map[key] === 'string') {
|
|
86
|
-
parseValueCals(ctx, map[key]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function parseDirectivesCals(ctx, directives) {
|
|
91
|
-
var _a;
|
|
92
|
-
// 优先处理for,因为其他的可能会用到 foritem
|
|
93
|
-
let forValue = directives[':for'];
|
|
94
|
-
if (typeof forValue === 'string') {
|
|
95
|
-
parseValueCals(ctx, forValue);
|
|
96
|
-
if (!ctx.forContext) {
|
|
97
|
-
ctx.forContext = {};
|
|
98
|
-
}
|
|
99
|
-
if ((_a = ctx.component) === null || _a === void 0 ? void 0 : _a.id) {
|
|
100
|
-
ctx.forContext[ctx.component.id] = true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
let visibleValue = directives[':if'];
|
|
104
|
-
if (typeof visibleValue === 'string') {
|
|
105
|
-
parseValueCals(ctx, visibleValue);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function parseValueCals(ctx, value) {
|
|
109
|
-
var _a, _b;
|
|
110
|
-
try {
|
|
111
|
-
let parser = new expression_1.DynamicValueParser(value, { pageId: '$page' });
|
|
112
|
-
let res = parser.parse();
|
|
113
|
-
switch (res.type) {
|
|
114
|
-
case expression_1.PropBindType.params:
|
|
115
|
-
case expression_1.PropBindType.stateData: {
|
|
116
|
-
const TYPE_MAP = {
|
|
117
|
-
[expression_1.PropBindType.params]: 'params',
|
|
118
|
-
[expression_1.PropBindType.stateData]: 'state',
|
|
119
|
-
};
|
|
120
|
-
const type = TYPE_MAP[res.type];
|
|
121
|
-
const path = ((_a = res.value) === null || _a === void 0 ? void 0 : _a.split('.')) || [];
|
|
122
|
-
let key = path[0];
|
|
123
|
-
if (!ctx.datasetMap[key]) {
|
|
124
|
-
ctx.datasetMap[key] = {};
|
|
125
|
-
}
|
|
126
|
-
if (path.length === 1) {
|
|
127
|
-
ctx.datasetMap[key][type] = true;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
ctx.datasetMap[key][`${type}.${path[1].replace(/\[.*/, '')}`] = true;
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case expression_1.PropBindType.forItem: {
|
|
135
|
-
const [id] = ((_b = res.value) === null || _b === void 0 ? void 0 : _b.split('.')) || [];
|
|
136
|
-
if (!ctx.forContext[id]) {
|
|
137
|
-
throw {
|
|
138
|
-
code: 'INVALID_FOR_CONTEXT',
|
|
139
|
-
message: '缺少循环上下文,无法保存为区块',
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
if ((e === null || e === void 0 ? void 0 : e.code) === 'INVALID_FOR_CONTEXT') {
|
|
148
|
-
throw e;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* cals 与 code 互转
|
|
4
|
-
* 这里的 code 是中间状态的 code,即非最终生成的可运行的项目代码
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.findAllConflicts = exports.autoResolveConflicts = exports.checkForConflicts = exports.codeToCals = exports.calsToCode = void 0;
|
|
11
|
-
const types_1 = require("../../../../types");
|
|
12
|
-
const pick_1 = __importDefault(require("lodash/pick"));
|
|
13
|
-
const omit_1 = __importDefault(require("lodash/omit"));
|
|
14
|
-
const concat_1 = __importDefault(require("lodash/concat"));
|
|
15
|
-
/**
|
|
16
|
-
* CALS 转成 中间状态的代码
|
|
17
|
-
*
|
|
18
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
19
|
-
*/
|
|
20
|
-
function calsToCode(calsJSON, version = 'v1') {
|
|
21
|
-
// 边界处理
|
|
22
|
-
if (!calsJSON)
|
|
23
|
-
return [];
|
|
24
|
-
const versionMap = {
|
|
25
|
-
v0: {
|
|
26
|
-
pageDir: '',
|
|
27
|
-
},
|
|
28
|
-
v1: {
|
|
29
|
-
pageDir: 'pages',
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const versionConfig = versionMap[version];
|
|
33
|
-
if (!versionConfig)
|
|
34
|
-
throw "version' value must be v0 or v1";
|
|
35
|
-
const codeList = [];
|
|
36
|
-
/**
|
|
37
|
-
* 生成 pages
|
|
38
|
-
*/
|
|
39
|
-
const pagePaths = [];
|
|
40
|
-
calsJSON.items.forEach((pageItem) => {
|
|
41
|
-
const pagePath = versionConfig.pageDir ? `${versionConfig.pageDir}/${pageItem.id}` : pageItem.id;
|
|
42
|
-
/**
|
|
43
|
-
* 生成 page-config.json
|
|
44
|
-
*/
|
|
45
|
-
// 来自 IPageComponent
|
|
46
|
-
// :class, :style, component, dataVariables, directives, id, module, type 忽略,所以这里不包含
|
|
47
|
-
const pageConfigFields = ['attributes', 'dataset', 'extra', 'label', 'name', 'listeners'];
|
|
48
|
-
genConfig(pageItem, pageConfigFields, `${pagePath}/page-config.json`);
|
|
49
|
-
/**
|
|
50
|
-
* 生成 page.json
|
|
51
|
-
*/
|
|
52
|
-
addCodeItem(`${pagePath}/page.json`, JSON.stringify(pageItem.items, null, 2));
|
|
53
|
-
/**
|
|
54
|
-
* 生成页面代码
|
|
55
|
-
*/
|
|
56
|
-
genCode(pageItem.resources, pagePath);
|
|
57
|
-
// 记录页面目录路径
|
|
58
|
-
pagePaths.push(pagePath);
|
|
59
|
-
});
|
|
60
|
-
/**
|
|
61
|
-
* 生成 app-config.json
|
|
62
|
-
*/
|
|
63
|
-
// 来自 Interface IPlatformApp
|
|
64
|
-
// dataSources, dataVariables 忽略,所以这里不包含
|
|
65
|
-
const appConfigFields = [
|
|
66
|
-
'author',
|
|
67
|
-
'dataset',
|
|
68
|
-
'dependencies',
|
|
69
|
-
'description',
|
|
70
|
-
'envId',
|
|
71
|
-
'extra',
|
|
72
|
-
'id',
|
|
73
|
-
'label',
|
|
74
|
-
'main',
|
|
75
|
-
'name',
|
|
76
|
-
'version',
|
|
77
|
-
'schemaVersion',
|
|
78
|
-
'externalResources',
|
|
79
|
-
'theme',
|
|
80
|
-
];
|
|
81
|
-
const otherConfigFields = {
|
|
82
|
-
// 来自 Interface IPlatformAppExtra
|
|
83
|
-
extra: [
|
|
84
|
-
'appConfig',
|
|
85
|
-
'compHiddenConfig',
|
|
86
|
-
'domain',
|
|
87
|
-
'historyType',
|
|
88
|
-
'maxID',
|
|
89
|
-
'miniprogramPlugins',
|
|
90
|
-
'npmDependencies',
|
|
91
|
-
'plugins',
|
|
92
|
-
'presetColors',
|
|
93
|
-
'rootPath',
|
|
94
|
-
'themeVars',
|
|
95
|
-
'originHistoryId',
|
|
96
|
-
// 额外添加,非标准
|
|
97
|
-
'pages',
|
|
98
|
-
'processPages',
|
|
99
|
-
],
|
|
100
|
-
};
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
calsJSON.extra.pages = pagePaths;
|
|
103
|
-
genConfig(calsJSON, appConfigFields, 'app-config.json', otherConfigFields);
|
|
104
|
-
/**
|
|
105
|
-
* 生成全局代码
|
|
106
|
-
*/
|
|
107
|
-
genCode(calsJSON.resources);
|
|
108
|
-
/**
|
|
109
|
-
* 生成 package.json 文件
|
|
110
|
-
*/
|
|
111
|
-
addCodeItem('package.json', JSON.stringify({
|
|
112
|
-
name: calsJSON.name,
|
|
113
|
-
description: calsJSON.description,
|
|
114
|
-
version: calsJSON.version,
|
|
115
|
-
}, null, 2), '');
|
|
116
|
-
return codeList;
|
|
117
|
-
function addCodeItem(path, code, parentDir = 'src') {
|
|
118
|
-
codeList.push({
|
|
119
|
-
path: parentDir ? `${parentDir}/${path}` : path,
|
|
120
|
-
code,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function genConfig(itemJSON, configFields, configPath, otherConfigFields) {
|
|
124
|
-
var _a;
|
|
125
|
-
const config = (0, pick_1.default)(itemJSON, configFields);
|
|
126
|
-
if (otherConfigFields) {
|
|
127
|
-
Object.keys(otherConfigFields).forEach((key) => {
|
|
128
|
-
config[key] = (0, pick_1.default)(config[key], otherConfigFields[key]);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
// state, computed 类型以及名称为 ____index____ 的都不生成代码
|
|
132
|
-
config._ignoreResources =
|
|
133
|
-
((_a = itemJSON.resources) === null || _a === void 0 ? void 0 : _a.filter((item) => [types_1.ECodeType.STATE, types_1.ECodeType.COMPUTEDN].includes(item.codeType) ||
|
|
134
|
-
item.name === types_1.ECodeName.PLACEHOLDER)) || [];
|
|
135
|
-
// 按 key 排序,这样确保每次生成都一样的顺序,减少冲突
|
|
136
|
-
const newConfig = {};
|
|
137
|
-
Object.keys(config)
|
|
138
|
-
.sort()
|
|
139
|
-
.forEach((key) => (newConfig[key] = config[key]));
|
|
140
|
-
addCodeItem(configPath, JSON.stringify(config, null, 2));
|
|
141
|
-
}
|
|
142
|
-
function genCode(resources, basePath = '') {
|
|
143
|
-
const codeResources = (resources || []).filter((item) => item.type === types_1.EResourceType.CODE && item.name !== types_1.ECodeName.PLACEHOLDER);
|
|
144
|
-
codeResources.forEach((codeItem) => {
|
|
145
|
-
let codePath = '';
|
|
146
|
-
let realBasePath = basePath ? `${basePath}/` : basePath;
|
|
147
|
-
switch (codeItem.codeType) {
|
|
148
|
-
case types_1.ECodeType.THEME:
|
|
149
|
-
codePath = `${realBasePath}${types_1.ECodeName.THEME}.less`;
|
|
150
|
-
break;
|
|
151
|
-
case types_1.ECodeType.STYLE:
|
|
152
|
-
codePath = `${realBasePath}${types_1.ECodeName.STYLE}.less`;
|
|
153
|
-
break;
|
|
154
|
-
case types_1.ECodeType.LIFECYCLE:
|
|
155
|
-
codePath = `${realBasePath}${types_1.ECodeName.LIFECYCLE}.js`;
|
|
156
|
-
break;
|
|
157
|
-
// 这两种类型的文件现在不生成文件,需要存放在 config 中
|
|
158
|
-
case types_1.ECodeType.STATE:
|
|
159
|
-
// codePath = `${realBasePath}state.js`;
|
|
160
|
-
break;
|
|
161
|
-
case types_1.ECodeType.COMPUTEDN:
|
|
162
|
-
// codePath = `${realBasePath}computed.js`;
|
|
163
|
-
break;
|
|
164
|
-
case types_1.ECodeType.NORMAL_MODULE:
|
|
165
|
-
codePath = `${types_1.ECodeName.NORMAL_MODULE}/${codeItem.name}.js`;
|
|
166
|
-
break;
|
|
167
|
-
case types_1.ECodeType.HANDLER_FN:
|
|
168
|
-
codePath = `${realBasePath}${types_1.ECodeName.HANDLER_FN}/${codeItem.name}.js`;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
if (codePath) {
|
|
172
|
-
addCodeItem(codePath, codeItem.code);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.calsToCode = calsToCode;
|
|
178
|
-
/**
|
|
179
|
-
* 中间状态的代码 转成 CALS
|
|
180
|
-
*
|
|
181
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
182
|
-
*/
|
|
183
|
-
function codeToCals(codeList, version = 'v1') {
|
|
184
|
-
// 边界处理
|
|
185
|
-
if (!codeList || codeList.length === 0)
|
|
186
|
-
return {};
|
|
187
|
-
const versionMap = {
|
|
188
|
-
v0: {
|
|
189
|
-
pageDir: 'src',
|
|
190
|
-
pageIdRegExp: /src\/(.*?)\/.*/,
|
|
191
|
-
pageConfigRegExp: /src\/.*?\/page-config.json$/,
|
|
192
|
-
pageJSONRegExp: /src\/.*?\/page.json/,
|
|
193
|
-
},
|
|
194
|
-
v1: {
|
|
195
|
-
pageDir: 'src/pages',
|
|
196
|
-
pageIdRegExp: /src\/pages\/(.*?)\/.*/,
|
|
197
|
-
pageConfigRegExp: /src\/pages\/.*?\/page-config.json$/,
|
|
198
|
-
pageJSONRegExp: /src\/pages\/.*?\/page.json/,
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
const versionConfig = versionMap[version];
|
|
202
|
-
if (!versionConfig)
|
|
203
|
-
throw "version' value must be v0 or v1";
|
|
204
|
-
// @ts-ignore
|
|
205
|
-
const calsJSON = {
|
|
206
|
-
items: [],
|
|
207
|
-
resources: [],
|
|
208
|
-
};
|
|
209
|
-
const appConfigCodeItem = codeList.find((item) => item.path === 'src/app-config.json');
|
|
210
|
-
const appConfig = JSON.parse((appConfigCodeItem === null || appConfigCodeItem === void 0 ? void 0 : appConfigCodeItem.code) || '{}');
|
|
211
|
-
let pagePaths = appConfig.extra.pages;
|
|
212
|
-
codeList.forEach((codeItem) => {
|
|
213
|
-
if (codeItem.path === 'src/app-config.json') {
|
|
214
|
-
/**
|
|
215
|
-
* app-config.json
|
|
216
|
-
*/
|
|
217
|
-
const config = appConfig;
|
|
218
|
-
Object.assign(calsJSON, (0, omit_1.default)(config, ['_ignoreResources', 'extra.pages']));
|
|
219
|
-
calsJSON.resources = (0, concat_1.default)(calsJSON.resources, config._ignoreResources);
|
|
220
|
-
}
|
|
221
|
-
else if (isPageFile(codeItem.path)) {
|
|
222
|
-
/**
|
|
223
|
-
* page
|
|
224
|
-
*/
|
|
225
|
-
const [, pageId] = codeItem.path.match(versionConfig.pageIdRegExp) || [];
|
|
226
|
-
let pageItem = calsJSON.items.find((item) => item.id === pageId);
|
|
227
|
-
if (!pageItem) {
|
|
228
|
-
pageItem = {
|
|
229
|
-
id: pageId,
|
|
230
|
-
type: 'PAGE',
|
|
231
|
-
resources: [],
|
|
232
|
-
};
|
|
233
|
-
calsJSON.items.push(pageItem);
|
|
234
|
-
}
|
|
235
|
-
if (!pageItem.resources) {
|
|
236
|
-
pageItem.resources = [];
|
|
237
|
-
}
|
|
238
|
-
if (versionConfig.pageConfigRegExp.test(codeItem.path)) {
|
|
239
|
-
/**
|
|
240
|
-
* page-config.json
|
|
241
|
-
*/
|
|
242
|
-
const config = JSON.parse(codeItem.code);
|
|
243
|
-
const propsConfig = (0, omit_1.default)(config, ['_ignoreResources']);
|
|
244
|
-
Object.assign(pageItem, propsConfig);
|
|
245
|
-
pageItem.resources = (0, concat_1.default)(pageItem.resources, config._ignoreResources);
|
|
246
|
-
}
|
|
247
|
-
else if (versionConfig.pageJSONRegExp.test(codeItem.path)) {
|
|
248
|
-
/**
|
|
249
|
-
* page.json
|
|
250
|
-
*/
|
|
251
|
-
pageItem.items = JSON.parse(codeItem.code);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
/**
|
|
255
|
-
* page normal codes
|
|
256
|
-
*/
|
|
257
|
-
handleNormalCodes(codeItem, pageId, pageItem.resources);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
else if (codeItem.path.indexOf('src/') === 0) {
|
|
261
|
-
/**
|
|
262
|
-
* global normal codes
|
|
263
|
-
*/
|
|
264
|
-
handleNormalCodes(codeItem, '', calsJSON.resources || []);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
return calsJSON;
|
|
268
|
-
function handleNormalCodes(codeItem, pageId, resources) {
|
|
269
|
-
var _a, _b;
|
|
270
|
-
const relativePath = !pageId
|
|
271
|
-
? codeItem.path.replace('src/', '')
|
|
272
|
-
: codeItem.path.replace(`${versionConfig.pageDir}/${pageId}/`, '');
|
|
273
|
-
const _pageId = !pageId ? 'global' : pageId;
|
|
274
|
-
const commonVal = {
|
|
275
|
-
code: codeItem.code,
|
|
276
|
-
type: types_1.EResourceType.CODE,
|
|
277
|
-
system: true,
|
|
278
|
-
};
|
|
279
|
-
/**
|
|
280
|
-
* 只处理 path 为 src/theme.less, src/style.less, src/lifecycle.js, src/common/xxx.js, src/pages/xxx/handler/xxx.js
|
|
281
|
-
* 其它视为无效文件忽略
|
|
282
|
-
*/
|
|
283
|
-
switch (relativePath) {
|
|
284
|
-
case 'theme.less':
|
|
285
|
-
(_a = calsJSON.resources) === null || _a === void 0 ? void 0 : _a.push(Object.assign({ name: types_1.ECodeType.THEME, path: `${_pageId}/${types_1.ECodeType.THEME}`, codeType: types_1.ECodeType.THEME }, commonVal));
|
|
286
|
-
break;
|
|
287
|
-
case 'style.less':
|
|
288
|
-
resources.push(Object.assign({ name: types_1.ECodeType.STYLE, path: `${_pageId}/${types_1.ECodeType.STYLE}`, codeType: types_1.ECodeType.STYLE }, commonVal));
|
|
289
|
-
break;
|
|
290
|
-
case 'lifecycle.js':
|
|
291
|
-
resources.push(Object.assign({ name: types_1.ECodeType.LIFECYCLE, path: `${_pageId}/${types_1.ECodeType.LIFECYCLE}`, codeType: types_1.ECodeType.LIFECYCLE }, commonVal));
|
|
292
|
-
break;
|
|
293
|
-
default:
|
|
294
|
-
// page handler
|
|
295
|
-
const handlerMatches = relativePath.match(/^handler\/([^/]*?).js$/);
|
|
296
|
-
if (handlerMatches) {
|
|
297
|
-
const [, name] = handlerMatches;
|
|
298
|
-
resources.push(Object.assign(Object.assign({ name, path: `${_pageId}/handler/${name}`, codeType: types_1.ECodeType.HANDLER_FN }, commonVal), { system: false }));
|
|
299
|
-
}
|
|
300
|
-
// globa common
|
|
301
|
-
const commonMatches = relativePath.match(/^common\/([^/]*?).js$/);
|
|
302
|
-
if (commonMatches) {
|
|
303
|
-
const [, name] = commonMatches;
|
|
304
|
-
(_b = calsJSON.resources) === null || _b === void 0 ? void 0 : _b.push(Object.assign({ name, path: `${_pageId}/common/${name}`, codeType: types_1.ECodeType.NORMAL_MODULE }, commonVal));
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
function isPageFile(filePath) {
|
|
310
|
-
return pagePaths.map((pagePath) => `src/${pagePath}`).some((pagePath) => filePath.indexOf(pagePath) === 0);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
exports.codeToCals = codeToCals;
|
|
314
|
-
/**
|
|
315
|
-
* 指定代码内容是否存在冲突未解决
|
|
316
|
-
*/
|
|
317
|
-
function checkForConflicts(code) {
|
|
318
|
-
return findAllConflicts(code, true).length > 0;
|
|
319
|
-
}
|
|
320
|
-
exports.checkForConflicts = checkForConflicts;
|
|
321
|
-
/**
|
|
322
|
-
* 以 from 为准自动解决冲突
|
|
323
|
-
*/
|
|
324
|
-
function autoResolveConflicts(code, from) {
|
|
325
|
-
const allConflicts = findAllConflicts(code);
|
|
326
|
-
const lines = code.split('\n');
|
|
327
|
-
const result = [];
|
|
328
|
-
const removeLines = [];
|
|
329
|
-
allConflicts.forEach((conflictItem) => {
|
|
330
|
-
if (from === 'theirs') {
|
|
331
|
-
// 删除上面的
|
|
332
|
-
removeLines.push([conflictItem.start, conflictItem.middle], conflictItem.end);
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
// default is ours
|
|
336
|
-
// 删除下面的
|
|
337
|
-
removeLines.push(conflictItem.start, [conflictItem.middle, conflictItem.end]);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
lines.forEach((line, idx) => {
|
|
341
|
-
const matched = removeLines.some((rmIdx) => {
|
|
342
|
-
if (Array.isArray(rmIdx)) {
|
|
343
|
-
return idx >= rmIdx[0] && idx <= rmIdx[1];
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
return idx === rmIdx;
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
if (!matched)
|
|
350
|
-
result.push(line);
|
|
351
|
-
});
|
|
352
|
-
return result.join('\n');
|
|
353
|
-
}
|
|
354
|
-
exports.autoResolveConflicts = autoResolveConflicts;
|
|
355
|
-
function findAllConflicts(code, onlyFindFirstOne = false) {
|
|
356
|
-
let allConflicts = [];
|
|
357
|
-
const lines = code.split('\n');
|
|
358
|
-
let oneConflict = { start: -1, middle: -1, end: -1 };
|
|
359
|
-
for (let i = 0, leng = lines.length; i < leng; i++) {
|
|
360
|
-
const line = lines[i];
|
|
361
|
-
if (/^<<<<<<<.*/.test(line)) {
|
|
362
|
-
if (oneConflict.start === -1) {
|
|
363
|
-
// 起点
|
|
364
|
-
oneConflict.start = i;
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// 非起点:一个完整的冲突还未结束,出现起点符号,下边的内容冲突全部无效
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
else if (/^=======$/.test(line)) {
|
|
372
|
-
if (oneConflict.start !== -1) {
|
|
373
|
-
// 有 <<<<<<< 起点符号
|
|
374
|
-
if (oneConflict.middle === -1) {
|
|
375
|
-
// 未有 ======= 中间符号
|
|
376
|
-
oneConflict.middle = i;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
else if (/^>>>>>>>.*/.test(line)) {
|
|
381
|
-
if (oneConflict.start !== -1 && oneConflict.middle !== -1) {
|
|
382
|
-
oneConflict.end = i;
|
|
383
|
-
allConflicts.push(oneConflict);
|
|
384
|
-
// 重置
|
|
385
|
-
oneConflict = { start: -1, middle: -1, end: -1 };
|
|
386
|
-
if (onlyFindFirstOne)
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return allConflicts;
|
|
392
|
-
}
|
|
393
|
-
exports.findAllConflicts = findAllConflicts;
|