@cloudbase/cals 0.3.33-alpha.2 → 0.3.35
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 +13 -4
- package/lib/parser/cals/index.d.ts.map +1 -1
- package/lib/parser/cals/index.js +70 -5
- package/lib/parser/cals/utils/block/index.d.ts.map +1 -1
- package/lib/parser/cals/utils/common.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/config.d.ts.map +1 -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/expression/index.d.ts.map +1 -1
- 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/common.d.ts.map +1 -1
- package/lib/types/platform/component.d.ts.map +1 -1
- 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.d.ts.map +1 -1
- package/lib/utils/build.js +3 -3
- package/lib/utils/constant.d.ts.map +1 -1
- package/lib/utils/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/lib/parser/cals/utils/code/index.d.ts +0 -35
- package/lib/parser/cals/utils/code/index.d.ts.map +0 -1
- package/lib/parser/cals/utils/code/index.js +0 -419
package/lib/utils/build.js
CHANGED
|
@@ -37,9 +37,9 @@ const compilerOptions = {
|
|
|
37
37
|
};
|
|
38
38
|
// optionally pass a base path
|
|
39
39
|
const basePath = '.';
|
|
40
|
-
const calsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'types/basic/app.ts')], compilerOptions, basePath);
|
|
41
|
-
const platformCalsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'types/platform/app.ts')], compilerOptions, basePath);
|
|
42
|
-
const lcdsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'types/lcds.ts')], compilerOptions, basePath);
|
|
40
|
+
const calsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'src/types/basic/app.ts')], compilerOptions, basePath);
|
|
41
|
+
const platformCalsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'src/types/platform/app.ts')], compilerOptions, basePath);
|
|
42
|
+
const lcdsProgram = TJS.getProgramFromFiles([(0, path_1.resolve)(process.cwd(), 'src/types/lcds.ts')], compilerOptions, basePath);
|
|
43
43
|
// ... or a generator that lets us incrementally get more schemas
|
|
44
44
|
const calsGenerator = TJS.buildGenerator(calsProgram, settings);
|
|
45
45
|
const platformCalsGenerator = TJS.buildGenerator(platformCalsProgram, settings);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../utils/constant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oBAAY,iBAAiB;IAC3B,UAAU,eAAe;CAC1B;AACD;;GAEG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,6BAA6B,QAAqD,CAAC"}
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/utils/constant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oBAAY,iBAAiB;IAC3B,UAAU,eAAe;CAC1B;AACD;;GAEG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,6BAA6B,QAAqD,CAAC"}
|
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,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cals",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.35",
|
|
4
4
|
"description": "Common application specifications",
|
|
5
5
|
"main": "lib/utils/index.js",
|
|
6
|
-
"typedocMain": "types/index.ts",
|
|
6
|
+
"typedocMain": "src/types/index.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
|
-
"build:schema": "node
|
|
12
|
+
"build:schema": "ts-node src/utils/build.ts",
|
|
13
13
|
"develop": "tsc --watch",
|
|
14
14
|
"docs": "typedoc --options typedoc.json types",
|
|
15
15
|
"test": "jest"
|
|
@@ -1,35 +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
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
15
|
-
*/
|
|
16
|
-
export declare function calsToCode(calsJSON: IPlatformApp, version?: 'v0' | 'v1'): ICodeItem[];
|
|
17
|
-
/**
|
|
18
|
-
* 中间状态的代码 转成 CALS
|
|
19
|
-
*
|
|
20
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
21
|
-
*/
|
|
22
|
-
export declare function codeToCals(codeList: ICodeItem[], version?: 'v0' | 'v1'): IPlatformApp;
|
|
23
|
-
/**
|
|
24
|
-
* 指定目录下的文件转代码
|
|
25
|
-
*/
|
|
26
|
-
export declare function fileToCode(dirPath: string, onlyPath?: boolean): Promise<ICodeItem[]>;
|
|
27
|
-
/**
|
|
28
|
-
* 指定代码内容是否存在冲突未解决
|
|
29
|
-
*/
|
|
30
|
-
export declare function checkForConflicts(code: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* 以 from 为准自动解决冲突
|
|
33
|
-
*/
|
|
34
|
-
export declare function autoResolveConflicts(code: string, from: 'theirs' | 'ours'): string;
|
|
35
|
-
//# 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;;;;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"}
|
|
@@ -1,419 +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
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
28
|
-
*/
|
|
29
|
-
function calsToCode(calsJSON, version = 'v1') {
|
|
30
|
-
// 边界处理
|
|
31
|
-
if (!calsJSON)
|
|
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";
|
|
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
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* 生成 app-config.json
|
|
71
|
-
*/
|
|
72
|
-
// 来自 Interface IPlatformApp
|
|
73
|
-
// dataSources, dataVariables 忽略,所以这里不包含
|
|
74
|
-
const appConfigFields = [
|
|
75
|
-
'author',
|
|
76
|
-
'dataset',
|
|
77
|
-
'dependencies',
|
|
78
|
-
'description',
|
|
79
|
-
'envId',
|
|
80
|
-
'extra',
|
|
81
|
-
'id',
|
|
82
|
-
'label',
|
|
83
|
-
'main',
|
|
84
|
-
'name',
|
|
85
|
-
'version',
|
|
86
|
-
];
|
|
87
|
-
const otherConfigFields = {
|
|
88
|
-
// 来自 Interface IPlatformAppExtra
|
|
89
|
-
extra: [
|
|
90
|
-
'appConfig',
|
|
91
|
-
'compHiddenConfig',
|
|
92
|
-
'domain',
|
|
93
|
-
'historyType',
|
|
94
|
-
'maxID',
|
|
95
|
-
'miniprogramPlugins',
|
|
96
|
-
'npmDependencies',
|
|
97
|
-
'plugins',
|
|
98
|
-
'presetColors',
|
|
99
|
-
'rootPath',
|
|
100
|
-
'themeVars',
|
|
101
|
-
'originHistoryId',
|
|
102
|
-
// 额外添加,非标准
|
|
103
|
-
'pages',
|
|
104
|
-
],
|
|
105
|
-
};
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
calsJSON.extra.pages = pagePaths;
|
|
108
|
-
genConfig(calsJSON, appConfigFields, 'app-config.json', otherConfigFields);
|
|
109
|
-
/**
|
|
110
|
-
* 生成全局代码
|
|
111
|
-
*/
|
|
112
|
-
genCode(calsJSON.resources);
|
|
113
|
-
/**
|
|
114
|
-
* 生成 package.json 文件
|
|
115
|
-
*/
|
|
116
|
-
addCodeItem('package.json', JSON.stringify({
|
|
117
|
-
name: calsJSON.name,
|
|
118
|
-
description: calsJSON.description,
|
|
119
|
-
version: calsJSON.version,
|
|
120
|
-
}, null, 2), '');
|
|
121
|
-
return codeList;
|
|
122
|
-
function addCodeItem(path, code, parentDir = 'src') {
|
|
123
|
-
codeList.push({
|
|
124
|
-
path: parentDir ? `${parentDir}/${path}` : path,
|
|
125
|
-
code,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function genConfig(itemJSON, configFields, configPath, otherConfigFields) {
|
|
129
|
-
const config = (0, lodash_1.pick)(itemJSON, configFields);
|
|
130
|
-
if (otherConfigFields) {
|
|
131
|
-
Object.keys(otherConfigFields).forEach((key) => {
|
|
132
|
-
config[key] = (0, lodash_1.pick)(config[key], otherConfigFields[key]);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
// state, computed 类型以及名称为 ____index____ 的都不生成代码
|
|
136
|
-
config._ignoreResources = itemJSON.resources.filter((item) => ['state', 'computed'].includes(item.codeType) || item.name === '____index____');
|
|
137
|
-
// 按 key 排序,这样确保每次生成都一样的顺序,减少冲突
|
|
138
|
-
const newConfig = {};
|
|
139
|
-
Object.keys(config)
|
|
140
|
-
.sort()
|
|
141
|
-
.forEach((key) => (newConfig[key] = config[key]));
|
|
142
|
-
addCodeItem(configPath, JSON.stringify(config, null, 2));
|
|
143
|
-
}
|
|
144
|
-
function genCode(resources, basePath = '') {
|
|
145
|
-
const codeResources = (resources || []).filter((item) => item.type === 'CODE' && item.name !== '____index____');
|
|
146
|
-
codeResources.forEach((codeItem) => {
|
|
147
|
-
let codePath = '';
|
|
148
|
-
let realBasePath = basePath ? `${basePath}/` : basePath;
|
|
149
|
-
switch (codeItem.codeType) {
|
|
150
|
-
case 'theme':
|
|
151
|
-
codePath = `${realBasePath}theme.less`;
|
|
152
|
-
break;
|
|
153
|
-
case 'style':
|
|
154
|
-
codePath = `${realBasePath}style.less`;
|
|
155
|
-
break;
|
|
156
|
-
case 'lifecycle':
|
|
157
|
-
codePath = `${realBasePath}lifecycle.js`;
|
|
158
|
-
break;
|
|
159
|
-
// 这两种类型的文件现在不生成文件,需要存放在 config 中
|
|
160
|
-
case 'state':
|
|
161
|
-
// codePath = `${realBasePath}state.js`;
|
|
162
|
-
break;
|
|
163
|
-
case 'computed':
|
|
164
|
-
// codePath = `${realBasePath}computed.js`;
|
|
165
|
-
break;
|
|
166
|
-
case 'normal-module':
|
|
167
|
-
codePath = `common/${codeItem.name}.js`;
|
|
168
|
-
break;
|
|
169
|
-
case 'handler-fn':
|
|
170
|
-
codePath = `${realBasePath}handler/${codeItem.name}.js`;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
if (codePath) {
|
|
174
|
-
addCodeItem(codePath, codeItem.code);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
exports.calsToCode = calsToCode;
|
|
180
|
-
/**
|
|
181
|
-
* 中间状态的代码 转成 CALS
|
|
182
|
-
*
|
|
183
|
-
* @params version: v0 - 没有 pages 目录; v1 - 有 pages 目录
|
|
184
|
-
*/
|
|
185
|
-
function codeToCals(codeList, version = 'v1') {
|
|
186
|
-
// 边界处理
|
|
187
|
-
if (!codeList || codeList.length === 0)
|
|
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";
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
const calsJSON = {
|
|
208
|
-
items: [],
|
|
209
|
-
resources: [],
|
|
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;
|
|
214
|
-
codeList.forEach((codeItem) => {
|
|
215
|
-
if (codeItem.path === 'src/app-config.json') {
|
|
216
|
-
/**
|
|
217
|
-
* app-config.json
|
|
218
|
-
*/
|
|
219
|
-
const config = appConfig;
|
|
220
|
-
Object.assign(calsJSON, (0, lodash_1.omit)(config, ['_ignoreResources', 'extra.pages']));
|
|
221
|
-
calsJSON.resources = (0, lodash_1.concat)(calsJSON.resources, config._ignoreResources);
|
|
222
|
-
}
|
|
223
|
-
else if (isPageFile(codeItem.path)) {
|
|
224
|
-
/**
|
|
225
|
-
* page
|
|
226
|
-
*/
|
|
227
|
-
const [, pageId] = codeItem.path.match(versionConfig.pageIdRegExp);
|
|
228
|
-
let pageItem = calsJSON.items.find((item) => item.id === pageId);
|
|
229
|
-
if (!pageItem) {
|
|
230
|
-
pageItem = {
|
|
231
|
-
id: pageId,
|
|
232
|
-
type: 'PAGE',
|
|
233
|
-
resources: [],
|
|
234
|
-
};
|
|
235
|
-
calsJSON.items.push(pageItem);
|
|
236
|
-
}
|
|
237
|
-
if (versionConfig.pageConfigRegExp.test(codeItem.path)) {
|
|
238
|
-
/**
|
|
239
|
-
* page-config.json
|
|
240
|
-
*/
|
|
241
|
-
const config = JSON.parse(codeItem.code);
|
|
242
|
-
const propsConfig = (0, lodash_1.omit)(config, ['_ignoreResources']);
|
|
243
|
-
Object.assign(pageItem, propsConfig);
|
|
244
|
-
pageItem.resources = (0, lodash_1.concat)(pageItem.resources, config._ignoreResources);
|
|
245
|
-
}
|
|
246
|
-
else if (versionConfig.pageJSONRegExp.test(codeItem.path)) {
|
|
247
|
-
/**
|
|
248
|
-
* page.json
|
|
249
|
-
*/
|
|
250
|
-
pageItem.items = JSON.parse(codeItem.code);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
/**
|
|
254
|
-
* page normal codes
|
|
255
|
-
*/
|
|
256
|
-
handleNormalCodes(codeItem, pageId, pageItem.resources);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
else if (codeItem.path.indexOf('src/') === 0) {
|
|
260
|
-
/**
|
|
261
|
-
* global normal codes
|
|
262
|
-
*/
|
|
263
|
-
handleNormalCodes(codeItem, '', calsJSON.resources);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
return calsJSON;
|
|
267
|
-
function handleNormalCodes(codeItem, pageId, resources) {
|
|
268
|
-
const relativePath = !pageId
|
|
269
|
-
? codeItem.path.replace('src/', '')
|
|
270
|
-
: codeItem.path.replace(`${versionConfig.pageDir}/${pageId}/`, '');
|
|
271
|
-
const _pageId = !pageId ? 'global' : pageId;
|
|
272
|
-
const commonVal = {
|
|
273
|
-
code: codeItem.code,
|
|
274
|
-
type: 'CODE',
|
|
275
|
-
system: true,
|
|
276
|
-
};
|
|
277
|
-
/**
|
|
278
|
-
* 只处理 path 为 src/theme.less, src/style.less, src/lifecycle.js, src/common/xxx.js, src/pages/xxx/handler/xxx.js
|
|
279
|
-
* 其它视为无效文件忽略
|
|
280
|
-
*/
|
|
281
|
-
switch (relativePath) {
|
|
282
|
-
case 'theme.less':
|
|
283
|
-
calsJSON.resources.push(Object.assign({ name: 'theme', path: `${_pageId}/theme`, codeType: 'theme' }, commonVal));
|
|
284
|
-
break;
|
|
285
|
-
case 'style.less':
|
|
286
|
-
resources.push(Object.assign({ name: 'style', path: `${_pageId}/style`, codeType: 'style' }, commonVal));
|
|
287
|
-
break;
|
|
288
|
-
case 'lifecycle.js':
|
|
289
|
-
resources.push(Object.assign({ name: 'lifecycle', path: `${_pageId}/lifecycle`, codeType: 'lifecycle' }, commonVal));
|
|
290
|
-
break;
|
|
291
|
-
default:
|
|
292
|
-
// page handler
|
|
293
|
-
const handlerMatches = relativePath.match(/^handler\/([^/]*?).js$/);
|
|
294
|
-
if (handlerMatches) {
|
|
295
|
-
const [, name] = handlerMatches;
|
|
296
|
-
resources.push(Object.assign(Object.assign({ name, path: `${_pageId}/handler/${name}`, codeType: 'handler-fn' }, commonVal), { system: false }));
|
|
297
|
-
}
|
|
298
|
-
// globa common
|
|
299
|
-
const commonMatches = relativePath.match(/^common\/([^/]*?).js$/);
|
|
300
|
-
if (commonMatches) {
|
|
301
|
-
const [, name] = commonMatches;
|
|
302
|
-
calsJSON.resources.push(Object.assign({ name, path: `${_pageId}/common/${name}`, codeType: 'normal-module' }, commonVal));
|
|
303
|
-
}
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
function isPageFile(filePath) {
|
|
308
|
-
return pagePaths.map((pagePath) => `src/${pagePath}`).some((pagePath) => filePath.indexOf(pagePath) === 0);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
exports.codeToCals = codeToCals;
|
|
312
|
-
/**
|
|
313
|
-
* 指定目录下的文件转代码
|
|
314
|
-
*/
|
|
315
|
-
function fileToCode(dirPath, onlyPath = false) {
|
|
316
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
const result = yield new Promise((resolve, reject) => {
|
|
318
|
-
// 只包含 js, json, less 文件,其它忽略(因为不属于 weda 的文件)
|
|
319
|
-
(0, glob_1.default)(path_1.default.resolve(dirPath, '**', '*.@(js|json|less)'), {}, function (err, files) {
|
|
320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
if (err)
|
|
322
|
-
reject(err);
|
|
323
|
-
else {
|
|
324
|
-
const codeList = yield Promise.all(files.map((filePath) => __awaiter(this, void 0, void 0, function* () {
|
|
325
|
-
const codePath = path_1.default.relative(dirPath, filePath);
|
|
326
|
-
const codeContent = onlyPath ? '' : yield fs_extra_1.default.readFile(filePath, 'utf8');
|
|
327
|
-
return {
|
|
328
|
-
path: codePath,
|
|
329
|
-
code: codeContent,
|
|
330
|
-
};
|
|
331
|
-
})));
|
|
332
|
-
resolve(codeList);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
return result;
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
exports.fileToCode = fileToCode;
|
|
341
|
-
/**
|
|
342
|
-
* 指定代码内容是否存在冲突未解决
|
|
343
|
-
*/
|
|
344
|
-
function checkForConflicts(code) {
|
|
345
|
-
return findAllConflicts(code, true).length > 0;
|
|
346
|
-
}
|
|
347
|
-
exports.checkForConflicts = checkForConflicts;
|
|
348
|
-
/**
|
|
349
|
-
* 以 from 为准自动解决冲突
|
|
350
|
-
*/
|
|
351
|
-
function autoResolveConflicts(code, from) {
|
|
352
|
-
const allConflicts = findAllConflicts(code);
|
|
353
|
-
const lines = code.split('\n');
|
|
354
|
-
const result = [];
|
|
355
|
-
const removeLines = [];
|
|
356
|
-
allConflicts.forEach((conflictItem) => {
|
|
357
|
-
if (from === 'theirs') {
|
|
358
|
-
// 删除上面的
|
|
359
|
-
removeLines.push([conflictItem.start, conflictItem.middle], conflictItem.end);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
// default is ours
|
|
363
|
-
// 删除下面的
|
|
364
|
-
removeLines.push(conflictItem.start, [conflictItem.middle, conflictItem.end]);
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
lines.forEach((line, idx) => {
|
|
368
|
-
const matched = removeLines.some((rmIdx) => {
|
|
369
|
-
if (Array.isArray(rmIdx)) {
|
|
370
|
-
return idx >= rmIdx[0] && idx <= rmIdx[1];
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
return idx === rmIdx;
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
if (!matched)
|
|
377
|
-
result.push(line);
|
|
378
|
-
});
|
|
379
|
-
return result.join('\n');
|
|
380
|
-
}
|
|
381
|
-
exports.autoResolveConflicts = autoResolveConflicts;
|
|
382
|
-
function findAllConflicts(code, onlyFindFirstOne = false) {
|
|
383
|
-
let allConflicts = [];
|
|
384
|
-
const lines = code.split('\n');
|
|
385
|
-
let oneConflict = { start: -1, middle: -1, end: -1 };
|
|
386
|
-
for (let i = 0, leng = lines.length; i < leng; i++) {
|
|
387
|
-
const line = lines[i];
|
|
388
|
-
if (/^<<<<<<<$/.test(line)) {
|
|
389
|
-
if (oneConflict.start === -1) {
|
|
390
|
-
// 起点
|
|
391
|
-
oneConflict.start = i;
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
// 非起点:一个完整的冲突还未结束,出现起点符号,下边的内容冲突全部无效
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
else if (/^=======$/.test(line)) {
|
|
399
|
-
if (oneConflict.start !== -1) {
|
|
400
|
-
// 有 <<<<<<< 起点符号
|
|
401
|
-
if (oneConflict.middle === -1) {
|
|
402
|
-
// 未有 ======= 中间符号
|
|
403
|
-
oneConflict.middle = i;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
else if (/^>>>>>>>$/.test(line)) {
|
|
408
|
-
if (oneConflict.start !== -1 && oneConflict.middle !== -1) {
|
|
409
|
-
oneConflict.end = i;
|
|
410
|
-
allConflicts.push(oneConflict);
|
|
411
|
-
// 重置
|
|
412
|
-
oneConflict = { start: -1, middle: -1, end: -1 };
|
|
413
|
-
if (onlyFindFirstOne)
|
|
414
|
-
break;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return allConflicts;
|
|
419
|
-
}
|