@cloudbase/cals 0.3.33-alpha.1 → 0.3.34
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/index.d.ts +1 -1
- package/lib/parser/cals/index.d.ts.map +1 -1
- package/lib/parser/cals/index.js +12 -2
- package/lib/parser/cals/utils/block/index.d.ts.map +1 -1
- package/lib/parser/cals/utils/runtime.d.ts.map +1 -1
- package/lib/parser/cals/utils/runtime.js +7 -2
- package/lib/parser/cals/utils/spinoff/index.d.ts.map +1 -1
- package/lib/parser/cals/utils/style.d.ts.map +1 -1
- package/lib/parser/cals/utils/transform/index.d.ts +4 -0
- package/lib/parser/cals/utils/transform/index.d.ts.map +1 -0
- package/lib/parser/cals/utils/transform/index.js +247 -0
- package/lib/parser/cals/utils/version/common.d.ts.map +1 -1
- package/lib/parser/cals/utils/version/common.js +6 -3
- package/lib/parser/cals/utils/version/config.d.ts.map +1 -1
- package/lib/parser/cals/utils/version/config.js +6 -1
- package/lib/parser/cals/utils/version/index.d.ts.map +1 -1
- package/lib/parser/cals/utils/version/parses.d.ts.map +1 -1
- package/lib/parser/cals/utils/version/utils.d.ts.map +1 -1
- package/lib/parser/cals/utils/version/utils.js +3 -1
- package/lib/parser/expression/index.d.ts.map +1 -1
- package/lib/parser/expression/index.js +4 -2
- package/lib/parser/index.d.ts +0 -1
- package/lib/parser/index.d.ts.map +1 -1
- package/lib/parser/index.js +1 -7
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/basic/app.d.ts.map +1 -1
- package/lib/types/basic/common.d.ts.map +1 -1
- package/lib/types/basic/component.d.ts +5 -0
- package/lib/types/basic/component.d.ts.map +1 -1
- package/lib/types/basic/datasource.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/lcds.d.ts.map +1 -1
- package/lib/types/platform/app.d.ts +0 -4
- package/lib/types/platform/app.d.ts.map +1 -1
- package/lib/types/platform/component.d.ts.map +1 -1
- package/lib/types/platform/datasource.d.ts +2 -2
- package/lib/types/platform/datasource.d.ts.map +1 -1
- package/lib/types/platform/widget/form.d.ts.map +1 -1
- package/lib/types/platform/widget/meta.d.ts.map +1 -1
- package/lib/utils/build.js +8 -8
- package/lib/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/parser/cals/utils/code/index.d.ts +0 -31
- package/lib/parser/cals/utils/code/index.d.ts.map +0 -1
- package/lib/parser/cals/utils/code/index.js +0 -374
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../types/platform/widget/form.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,UAAU,SAAS;IACjB;;OAEG;IACH,UAAU,EAAE;QACV;;;WAGG;QACH,UAAU,EAAE;YACV,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../types/platform/widget/form.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,UAAU,SAAS;IACjB;;OAEG;IACH,UAAU,EAAE;QACV;;;WAGG;QACH,UAAU,EAAE;YACV,EAAE,EAAE,MAAM,CAAA;YACV,OAAO,EAAE,MAAM,CAAA;SAChB,CAAA;QACD,kBAAkB;QAClB,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;QAcpB,+BAA+B;QAG/B,WAAW;QACX,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CAAA;QAElC,WAAW;QACX,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CAEF;AAED;;GAEG;AAQH;;GAEG;AACH,UAAU,UAAU;IAClB,WAAW;IACX,IAAI,EAAE,MAAM,CAAA;IAEZ,UAAU;IACV,KAAK,EAAE,GAAG,CAAA;IAEV,kDAAkD;IAElD;;;;;OAKG;IAGH,YAAY;IACZ,KAAK,EAAE,MAAM,CAAA;IAEb,UAAU,EAAE;QACV;;;YAGI;QACJ,IAAI,CAAC,EAAE,MAAM,CAAA;QAEb;;YAEI;QACJ,WAAW,CAAC,EAAE,MAAM,CAAA;QAEpB;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAA;QAElB;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IAED,aAAa;IACb,QAAQ,EAAE;QACR;;;YAGI;QACJ,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB;;WAEG;QACH,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ;;WAEG;QACH,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ;;;WAGG;QACH,OAAO,CAAC,EAAE,MAAM,CAAA;KAOjB,CAAA;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../../types/platform/widget/meta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IAGH,gBAAgB;IAChB,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../../types/platform/widget/meta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IAGH,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAA;IAEZ,YAAY;IACZ,KAAK,EAAE,MAAM,CAAA;IAEb,WAAW;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,gBAAgB;IAChB,aAAa,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAEzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,OAAO,EAAE,GAAG,CAAA;CACb"}
|
package/lib/utils/build.js
CHANGED
|
@@ -52,18 +52,18 @@ const lcdsAction = lcdsGenerator === null || lcdsGenerator === void 0 ? void 0 :
|
|
|
52
52
|
const resolveLcdsComponent = lodash_1.default.merge({}, lcdsComponent, {
|
|
53
53
|
properties: {
|
|
54
54
|
data: {
|
|
55
|
-
$schema:
|
|
56
|
-
$ref:
|
|
57
|
-
}
|
|
58
|
-
}
|
|
55
|
+
"$schema": "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/schema/schema#",
|
|
56
|
+
"$ref": "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/schema/schema#"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
59
|
});
|
|
60
60
|
const resolveLcdsAction = lodash_1.default.merge({}, lcdsAction, {
|
|
61
61
|
properties: {
|
|
62
62
|
data: {
|
|
63
|
-
$schema:
|
|
64
|
-
$ref:
|
|
65
|
-
}
|
|
66
|
-
}
|
|
63
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
64
|
+
"$ref": "http://json-schema.org/draft-07/schema#"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
67
|
});
|
|
68
68
|
(0, fs_1.writeFileSync)((0, path_1.resolve)(process.cwd(), 'schema/basic_application.json'), JSON.stringify(basicApp, null, 2));
|
|
69
69
|
(0, fs_1.writeFileSync)((0, path_1.resolve)(process.cwd(), 'schema/platform_application.json'), JSON.stringify(platformApp, null, 2));
|
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* clas 与 code 互转
|
|
3
|
-
* 这里的 code 是中间状态的 code,即非最终生成的可运行的项目代码
|
|
4
|
-
*/
|
|
5
|
-
import { IPlatformApp } from '../../../../types';
|
|
6
|
-
export interface ICodeItem {
|
|
7
|
-
path: string;
|
|
8
|
-
code: string;
|
|
9
|
-
conflict?: boolean;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* CALS 转成 中间状态的代码
|
|
13
|
-
*/
|
|
14
|
-
export declare function calsToCode(calsJSON: IPlatformApp): ICodeItem[];
|
|
15
|
-
/**
|
|
16
|
-
* 中间状态的代码 转成 CALS
|
|
17
|
-
*/
|
|
18
|
-
export declare function codeToCals(codeList: ICodeItem[]): IPlatformApp;
|
|
19
|
-
/**
|
|
20
|
-
* 指定目录下的文件转代码
|
|
21
|
-
*/
|
|
22
|
-
export declare function fileToCode(dirPath: string, onlyPath?: boolean): Promise<ICodeItem[]>;
|
|
23
|
-
/**
|
|
24
|
-
* 指定代码内容是否存在冲突未解决
|
|
25
|
-
*/
|
|
26
|
-
export declare function checkForConflicts(code: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* 以 from 为准自动解决冲突
|
|
29
|
-
*/
|
|
30
|
-
export declare function autoResolveConflicts(code: string, from: 'theirs' | 'ours'): string;
|
|
31
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAAE,CA8J9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,YAAY,CAmI9D;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"}
|
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* clas 与 code 互转
|
|
4
|
-
* 这里的 code 是中间状态的 code,即非最终生成的可运行的项目代码
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.autoResolveConflicts = exports.checkForConflicts = exports.fileToCode = exports.codeToCals = exports.calsToCode = void 0;
|
|
20
|
-
const lodash_1 = require("lodash");
|
|
21
|
-
const glob_1 = __importDefault(require("glob"));
|
|
22
|
-
const path_1 = __importDefault(require("path"));
|
|
23
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
24
|
-
/**
|
|
25
|
-
* CALS 转成 中间状态的代码
|
|
26
|
-
*/
|
|
27
|
-
function calsToCode(calsJSON) {
|
|
28
|
-
// 边界处理
|
|
29
|
-
if (!calsJSON)
|
|
30
|
-
return [];
|
|
31
|
-
const codeList = [];
|
|
32
|
-
/**
|
|
33
|
-
* 生成 app-config.json
|
|
34
|
-
*/
|
|
35
|
-
// 来自 Interface IPlatformApp
|
|
36
|
-
// dataSources, dataVariables 忽略,所以这里不包含
|
|
37
|
-
const appConfigFields = [
|
|
38
|
-
'author',
|
|
39
|
-
'dataset',
|
|
40
|
-
'dependencies',
|
|
41
|
-
'description',
|
|
42
|
-
'envId',
|
|
43
|
-
'extra',
|
|
44
|
-
'id',
|
|
45
|
-
'label',
|
|
46
|
-
'main',
|
|
47
|
-
'name',
|
|
48
|
-
'version',
|
|
49
|
-
];
|
|
50
|
-
const otherConfigFields = {
|
|
51
|
-
// 来自 Interface IPlatformAppExtra
|
|
52
|
-
extra: [
|
|
53
|
-
'appConfig',
|
|
54
|
-
'compHiddenConfig',
|
|
55
|
-
'domain',
|
|
56
|
-
'historyType',
|
|
57
|
-
'maxID',
|
|
58
|
-
'miniprogramPlugins',
|
|
59
|
-
'npmDependencies',
|
|
60
|
-
'plugins',
|
|
61
|
-
'presetColors',
|
|
62
|
-
'rootPath',
|
|
63
|
-
'themeVars',
|
|
64
|
-
'originHistoryId',
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
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
|
-
/**
|
|
90
|
-
* 生成全局代码
|
|
91
|
-
*/
|
|
92
|
-
genCode(calsJSON.resources);
|
|
93
|
-
/**
|
|
94
|
-
* 生成 package.json 文件
|
|
95
|
-
*/
|
|
96
|
-
addCodeItem('package.json', JSON.stringify({
|
|
97
|
-
name: calsJSON.name,
|
|
98
|
-
description: calsJSON.description,
|
|
99
|
-
version: calsJSON.version,
|
|
100
|
-
}, null, 2), '');
|
|
101
|
-
return codeList;
|
|
102
|
-
function addCodeItem(path, code, parentDir = 'src') {
|
|
103
|
-
codeList.push({
|
|
104
|
-
path: parentDir ? `${parentDir}/${path}` : path,
|
|
105
|
-
code,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function genConfig(itemJSON, configFields, configPath, otherConfigFields) {
|
|
109
|
-
const config = (0, lodash_1.pick)(itemJSON, configFields);
|
|
110
|
-
if (otherConfigFields) {
|
|
111
|
-
Object.keys(otherConfigFields).forEach((key) => {
|
|
112
|
-
config[key] = (0, lodash_1.pick)(config[key], otherConfigFields[key]);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
// state, computed 类型以及名称为 ____index____ 的都不生成代码
|
|
116
|
-
config._ignoreResources = itemJSON.resources.filter((item) => ['state', 'computed'].includes(item.codeType) || item.name === '____index____');
|
|
117
|
-
// 按 key 排序,这样确保每次生成都一样的顺序,减少冲突
|
|
118
|
-
const newConfig = {};
|
|
119
|
-
Object.keys(config)
|
|
120
|
-
.sort()
|
|
121
|
-
.forEach((key) => (newConfig[key] = config[key]));
|
|
122
|
-
addCodeItem(configPath, JSON.stringify(config, null, 2));
|
|
123
|
-
}
|
|
124
|
-
function genCode(resources, basePath = '') {
|
|
125
|
-
const codeResources = (resources || []).filter((item) => item.type === 'CODE' && item.name !== '____index____');
|
|
126
|
-
codeResources.forEach((codeItem) => {
|
|
127
|
-
let codePath = '';
|
|
128
|
-
let realBasePath = basePath ? `${basePath}/` : basePath;
|
|
129
|
-
switch (codeItem.codeType) {
|
|
130
|
-
case 'theme':
|
|
131
|
-
codePath = `${realBasePath}theme.less`;
|
|
132
|
-
break;
|
|
133
|
-
case 'style':
|
|
134
|
-
codePath = `${realBasePath}style.less`;
|
|
135
|
-
break;
|
|
136
|
-
case 'lifecycle':
|
|
137
|
-
codePath = `${realBasePath}lifecycle.js`;
|
|
138
|
-
break;
|
|
139
|
-
// 这两种类型的文件现在不生成文件,需要存放在 config 中
|
|
140
|
-
case 'state':
|
|
141
|
-
// codePath = `${realBasePath}state.js`;
|
|
142
|
-
break;
|
|
143
|
-
case 'computed':
|
|
144
|
-
// codePath = `${realBasePath}computed.js`;
|
|
145
|
-
break;
|
|
146
|
-
case 'normal-module':
|
|
147
|
-
codePath = `common/${codeItem.name}.js`;
|
|
148
|
-
break;
|
|
149
|
-
case 'handler-fn':
|
|
150
|
-
codePath = `${realBasePath}handler/${codeItem.name}.js`;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
if (codePath) {
|
|
154
|
-
addCodeItem(codePath, codeItem.code);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
exports.calsToCode = calsToCode;
|
|
160
|
-
/**
|
|
161
|
-
* 中间状态的代码 转成 CALS
|
|
162
|
-
*/
|
|
163
|
-
function codeToCals(codeList) {
|
|
164
|
-
// 边界处理
|
|
165
|
-
if (!codeList || codeList.length === 0)
|
|
166
|
-
return {};
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
const calsJSON = {
|
|
169
|
-
items: [],
|
|
170
|
-
resources: [],
|
|
171
|
-
};
|
|
172
|
-
codeList.forEach((codeItem) => {
|
|
173
|
-
if (codeItem.path === 'src/app-config.json') {
|
|
174
|
-
/**
|
|
175
|
-
* app-config.json
|
|
176
|
-
*/
|
|
177
|
-
const config = JSON.parse(codeItem.code);
|
|
178
|
-
Object.assign(calsJSON, (0, lodash_1.omit)(config, ['_ignoreResources']));
|
|
179
|
-
calsJSON.resources = (0, lodash_1.concat)(calsJSON.resources, config._ignoreResources);
|
|
180
|
-
}
|
|
181
|
-
else if (codeItem.path.indexOf('src/pages/') === 0) {
|
|
182
|
-
/**
|
|
183
|
-
* page
|
|
184
|
-
*/
|
|
185
|
-
const [, pageId] = codeItem.path.match(/src\/pages\/(.*?)\/.*/);
|
|
186
|
-
let pageItem = calsJSON.items.find((item) => item.id === pageId);
|
|
187
|
-
if (!pageItem) {
|
|
188
|
-
pageItem = {
|
|
189
|
-
id: pageId,
|
|
190
|
-
type: 'PAGE',
|
|
191
|
-
resources: [],
|
|
192
|
-
};
|
|
193
|
-
calsJSON.items.push(pageItem);
|
|
194
|
-
}
|
|
195
|
-
if (/src\/pages\/.*?\/page-config.json/.test(codeItem.path)) {
|
|
196
|
-
/**
|
|
197
|
-
* page-config.json
|
|
198
|
-
*/
|
|
199
|
-
const config = JSON.parse(codeItem.code);
|
|
200
|
-
const propsConfig = (0, lodash_1.omit)(config, ['_ignoreResources']);
|
|
201
|
-
Object.assign(pageItem, propsConfig);
|
|
202
|
-
pageItem.resources = (0, lodash_1.concat)(pageItem.resources, config._ignoreResources);
|
|
203
|
-
}
|
|
204
|
-
else if (/src\/pages\/.*?\/page.json/.test(codeItem.path)) {
|
|
205
|
-
/**
|
|
206
|
-
* page.json
|
|
207
|
-
*/
|
|
208
|
-
pageItem.items = JSON.parse(codeItem.code);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
/**
|
|
212
|
-
* page normal codes
|
|
213
|
-
*/
|
|
214
|
-
handleNormalCodes(codeItem, pageId, pageItem.resources);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else if (codeItem.path.indexOf('src/') === 0) {
|
|
218
|
-
/**
|
|
219
|
-
* global normal codes
|
|
220
|
-
*/
|
|
221
|
-
handleNormalCodes(codeItem, '', calsJSON.resources);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
return calsJSON;
|
|
225
|
-
function handleNormalCodes(codeItem, pageId, resources) {
|
|
226
|
-
const relativePath = !pageId
|
|
227
|
-
? codeItem.path.replace('src/', '')
|
|
228
|
-
: codeItem.path.replace(`src/pages/${pageId}/`, '');
|
|
229
|
-
const _pageId = !pageId ? 'global' : pageId;
|
|
230
|
-
const commonVal = {
|
|
231
|
-
code: codeItem.code,
|
|
232
|
-
type: 'CODE',
|
|
233
|
-
system: true,
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* 只处理 path 为 src/theme.less, src/style.less, src/lifecycle.js, src/common/xxx.js, src/pages/xxx/handler/xxx.js
|
|
237
|
-
* 其它视为无效文件忽略
|
|
238
|
-
*/
|
|
239
|
-
switch (relativePath) {
|
|
240
|
-
case 'theme.less':
|
|
241
|
-
calsJSON.resources.push(Object.assign({ name: 'theme', path: `${_pageId}/theme`, codeType: 'theme' }, commonVal));
|
|
242
|
-
break;
|
|
243
|
-
case 'style.less':
|
|
244
|
-
resources.push(Object.assign({ name: 'style', path: `${_pageId}/style`, codeType: 'style' }, commonVal));
|
|
245
|
-
break;
|
|
246
|
-
case 'lifecycle.js':
|
|
247
|
-
resources.push(Object.assign({ name: 'lifecycle', path: `${_pageId}/lifecycle`, codeType: 'lifecycle' }, commonVal));
|
|
248
|
-
break;
|
|
249
|
-
default:
|
|
250
|
-
// page handler
|
|
251
|
-
const handlerMatches = relativePath.match(/^handler\/([^/]*?).js$/);
|
|
252
|
-
if (handlerMatches) {
|
|
253
|
-
const [, name] = handlerMatches;
|
|
254
|
-
resources.push(Object.assign(Object.assign({ name, path: `${_pageId}/handler/${name}`, codeType: 'handler-fn' }, commonVal), { system: false }));
|
|
255
|
-
}
|
|
256
|
-
// globa common
|
|
257
|
-
const commonMatches = relativePath.match(/^common\/([^/]*?).js$/);
|
|
258
|
-
if (commonMatches) {
|
|
259
|
-
const [, name] = commonMatches;
|
|
260
|
-
calsJSON.resources.push(Object.assign({ name, path: `${_pageId}/common/${name}`, codeType: 'normal-module' }, commonVal));
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
exports.codeToCals = codeToCals;
|
|
267
|
-
/**
|
|
268
|
-
* 指定目录下的文件转代码
|
|
269
|
-
*/
|
|
270
|
-
function fileToCode(dirPath, onlyPath = false) {
|
|
271
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
const result = yield new Promise((resolve, reject) => {
|
|
273
|
-
// 只包含 js, json, less 文件,其它忽略(因为不属于 weda 的文件)
|
|
274
|
-
(0, glob_1.default)(path_1.default.resolve(dirPath, '**', '*.@(js|json|less)'), {}, function (err, files) {
|
|
275
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
if (err)
|
|
277
|
-
reject(err);
|
|
278
|
-
else {
|
|
279
|
-
const codeList = yield Promise.all(files.map((filePath) => __awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
const codePath = path_1.default.relative(dirPath, filePath);
|
|
281
|
-
const codeContent = onlyPath ? '' : yield fs_extra_1.default.readFile(filePath, 'utf8');
|
|
282
|
-
return {
|
|
283
|
-
path: codePath,
|
|
284
|
-
code: codeContent,
|
|
285
|
-
};
|
|
286
|
-
})));
|
|
287
|
-
resolve(codeList);
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
return result;
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
exports.fileToCode = fileToCode;
|
|
296
|
-
/**
|
|
297
|
-
* 指定代码内容是否存在冲突未解决
|
|
298
|
-
*/
|
|
299
|
-
function checkForConflicts(code) {
|
|
300
|
-
return findAllConflicts(code, true).length > 0;
|
|
301
|
-
}
|
|
302
|
-
exports.checkForConflicts = checkForConflicts;
|
|
303
|
-
/**
|
|
304
|
-
* 以 from 为准自动解决冲突
|
|
305
|
-
*/
|
|
306
|
-
function autoResolveConflicts(code, from) {
|
|
307
|
-
const allConflicts = findAllConflicts(code);
|
|
308
|
-
const lines = code.split('\n');
|
|
309
|
-
const result = [];
|
|
310
|
-
const removeLines = [];
|
|
311
|
-
allConflicts.forEach((conflictItem) => {
|
|
312
|
-
if (from === 'theirs') {
|
|
313
|
-
// 删除上面的
|
|
314
|
-
removeLines.push([conflictItem.start, conflictItem.middle], conflictItem.end);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
// default is ours
|
|
318
|
-
// 删除下面的
|
|
319
|
-
removeLines.push(conflictItem.start, [conflictItem.middle, conflictItem.end]);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
lines.forEach((line, idx) => {
|
|
323
|
-
const matched = removeLines.some((rmIdx) => {
|
|
324
|
-
if (Array.isArray(rmIdx)) {
|
|
325
|
-
return idx >= rmIdx[0] && idx <= rmIdx[1];
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
return idx === rmIdx;
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
if (!matched)
|
|
332
|
-
result.push(line);
|
|
333
|
-
});
|
|
334
|
-
return result.join('\n');
|
|
335
|
-
}
|
|
336
|
-
exports.autoResolveConflicts = autoResolveConflicts;
|
|
337
|
-
function findAllConflicts(code, onlyFindFirstOne = false) {
|
|
338
|
-
let allConflicts = [];
|
|
339
|
-
const lines = code.split('\n');
|
|
340
|
-
let oneConflict = { start: -1, middle: -1, end: -1 };
|
|
341
|
-
for (let i = 0, leng = lines.length; i < leng; i++) {
|
|
342
|
-
const line = lines[i];
|
|
343
|
-
if (/^<<<<<<<$/.test(line)) {
|
|
344
|
-
if (oneConflict.start === -1) {
|
|
345
|
-
// 起点
|
|
346
|
-
oneConflict.start = i;
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
// 非起点:一个完整的冲突还未结束,出现起点符号,下边的内容冲突全部无效
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else if (/^=======$/.test(line)) {
|
|
354
|
-
if (oneConflict.start !== -1) {
|
|
355
|
-
// 有 <<<<<<< 起点符号
|
|
356
|
-
if (oneConflict.middle === -1) {
|
|
357
|
-
// 未有 ======= 中间符号
|
|
358
|
-
oneConflict.middle = i;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
else if (/^>>>>>>>$/.test(line)) {
|
|
363
|
-
if (oneConflict.start !== -1 && oneConflict.middle !== -1) {
|
|
364
|
-
oneConflict.end = i;
|
|
365
|
-
allConflicts.push(oneConflict);
|
|
366
|
-
// 重置
|
|
367
|
-
oneConflict = { start: -1, middle: -1, end: -1 };
|
|
368
|
-
if (onlyFindFirstOne)
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return allConflicts;
|
|
374
|
-
}
|