@cloudbase/cals 0.4.11 → 0.5.0
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/style.d.ts.map +1 -1
- package/lib/parser/cals/utils/style.js +121 -15
- package/lib/utils/dts/auto-generated.d.ts +2 -0
- package/lib/utils/dts/auto-generated.d.ts.map +1 -0
- package/lib/utils/dts/auto-generated.js +289 -0
- package/lib/utils/dts/build.d.ts +2 -0
- package/lib/utils/dts/build.d.ts.map +1 -0
- package/lib/utils/dts/build.js +103 -0
- package/lib/utils/dts/index.d.ts +62 -0
- package/lib/utils/dts/index.d.ts.map +1 -0
- package/lib/utils/dts/index.js +302 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/package.json +8 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../../src/parser/cals/utils/style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../../src/parser/cals/utils/style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMrC,wBAAgB,2BAA2B,CAAC,SAAS,GAAE,GAA2B,GAAG,GAAG,CAUvF;AA+ID,wBAAgB,gCAAgC,CAC9C,WAAW,GAAE,GAAQ,EACrB,OAAO,GAAE;IACP,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACoD,GACrE,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,CAgU7B;AASD,wBAAgB,wBAAwB,CACtC,KAAK,GAAE,UAAU,CAAC,MAAM,GAAG,MAAM,CAAM,EACvC,OAAO;;CAAwB,GAC9B,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,CAE7B"}
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.processCSSProperties2Rem = exports.processCommonStyle2CSSProperties = exports.removeInvalidStyleFormValue = void 0;
|
|
15
15
|
const common_1 = require("./common");
|
|
16
16
|
const lodash_1 = require("lodash");
|
|
17
|
-
const
|
|
17
|
+
const utils_1 = require("../../../utils");
|
|
18
18
|
const DISTANCE_KEY_LIST = ['top', 'right', 'bottom', 'left'];
|
|
19
19
|
function removeInvalidStyleFormValue(styleForm = {}) {
|
|
20
20
|
return Object.keys(styleForm).reduce((result, key) => {
|
|
@@ -40,7 +40,13 @@ function setStyleValue(object, key, value) {
|
|
|
40
40
|
if ((0, common_1.isEmptyObj)(value)) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
if (key.startsWith('--')) {
|
|
44
|
+
// css 自定义属性
|
|
45
|
+
object[key] = value;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
object[(0, common_1.camelcase)(key)] = value;
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
function _handleStyleNumValue(styleVal, addPXUnit) {
|
|
46
52
|
if (addPXUnit) {
|
|
@@ -81,7 +87,7 @@ function setDistanceStyle(style, distance, attr, addPXUnit) {
|
|
|
81
87
|
function translateStyleByHandler(style = {}, handler, options = { looseError: false }) {
|
|
82
88
|
return Object.keys(style).reduce((result, key) => {
|
|
83
89
|
const value = style[key];
|
|
84
|
-
if (
|
|
90
|
+
if (utils_1.isUnitlessNumber[key]) {
|
|
85
91
|
setStyleValue(result, key, value);
|
|
86
92
|
}
|
|
87
93
|
else if (value !== undefined && value !== null) {
|
|
@@ -147,7 +153,7 @@ function toRPX(cssLen) {
|
|
|
147
153
|
function processCommonStyle2CSSProperties(commonStyle = {}, options = { toRem: true, ignoreSelf: false, addPXUnit: false, toRpx: false }) {
|
|
148
154
|
const { size,
|
|
149
155
|
// transform,
|
|
150
|
-
text, border, background, margin, padding, zIndex, position, display, flexConfig, custom, self, } = commonStyle;
|
|
156
|
+
text, border, background, margin, padding, zIndex, position, display, flexConfig, custom, self, boxShadow, } = commonStyle;
|
|
151
157
|
const style = {};
|
|
152
158
|
if (size) {
|
|
153
159
|
setStyleValue(style, 'width', _handleStyleNumValue(size.width, !!options.addPXUnit));
|
|
@@ -200,7 +206,8 @@ function processCommonStyle2CSSProperties(commonStyle = {}, options = { toRem: t
|
|
|
200
206
|
}
|
|
201
207
|
if (border) {
|
|
202
208
|
const { type, color, width, radius, radiusInfo } = border;
|
|
203
|
-
|
|
209
|
+
// width
|
|
210
|
+
if (typeof width === 'string') {
|
|
204
211
|
if (type && type !== 'none') {
|
|
205
212
|
setStyleValue(style, 'border', `${_handleStyleNumValue(width, !!options.addPXUnit)} ${type} ${color || ''}`);
|
|
206
213
|
}
|
|
@@ -210,31 +217,60 @@ function processCommonStyle2CSSProperties(commonStyle = {}, options = { toRem: t
|
|
|
210
217
|
setStyleValue(style, 'borderColor', color);
|
|
211
218
|
}
|
|
212
219
|
}
|
|
220
|
+
else if (Object.prototype.toString.call(width) === '[object Object]' && Object.keys(width).length !== 0) {
|
|
221
|
+
// https://developer.mozilla.org/zh-CN/docs/Web/CSS/border
|
|
222
|
+
// 虽然border-width,、border-style和 border-color 简写属性接受最多 4 个参数来为不同的边设置宽度、风格和颜色,但 boder 属性只接受三个参数,分别是宽度、风格和颜色,所以这样会使得四条边的边框相同。
|
|
223
|
+
const { top = '0', right = '0', bottom = '0', left = '0' } = width;
|
|
224
|
+
setStyleValue(style, 'borderWidth', `${_handleStyleNumValue(top, !!options.addPXUnit) || '0'} ${_handleStyleNumValue(right, !!options.addPXUnit) || '0'} ${_handleStyleNumValue(bottom, !!options.addPXUnit) || '0'} ${_handleStyleNumValue(left, !!options.addPXUnit) || '0'}`);
|
|
225
|
+
if (type) {
|
|
226
|
+
setStyleValue(style, 'borderStyle', type);
|
|
227
|
+
}
|
|
228
|
+
if (color) {
|
|
229
|
+
setStyleValue(style, 'borderColor', color);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// border radius
|
|
213
233
|
if (radius !== undefined) {
|
|
214
234
|
setStyleValue(style, 'borderRadius', _handleStyleNumValue(radius, !!options.addPXUnit));
|
|
215
235
|
}
|
|
216
236
|
if (radiusInfo && !(0, common_1.isEmptyObj)(radiusInfo)) {
|
|
237
|
+
let { topLeft, topRight, bottomRight, bottomLeft } = radiusInfo;
|
|
217
238
|
if (Object.keys(radiusInfo).length === 4) {
|
|
239
|
+
// 包含不为空的属性,将部分为空属性处理成 0
|
|
240
|
+
if (Object.values(radiusInfo).some((corner) => !!corner)) {
|
|
241
|
+
if (!topLeft) {
|
|
242
|
+
topLeft = '0';
|
|
243
|
+
}
|
|
244
|
+
if (!topRight) {
|
|
245
|
+
topRight = '0';
|
|
246
|
+
}
|
|
247
|
+
if (!bottomRight) {
|
|
248
|
+
bottomRight = '0';
|
|
249
|
+
}
|
|
250
|
+
if (!bottomLeft) {
|
|
251
|
+
bottomLeft = '0';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
218
254
|
if ((0, lodash_1.uniq)((0, lodash_1.map)(radiusInfo, (val) => val)).length === 1) {
|
|
219
255
|
// 4个值全相等的情况
|
|
220
|
-
setStyleValue(style, 'borderRadius', _handleStyleNumValue(
|
|
256
|
+
setStyleValue(style, 'borderRadius', _handleStyleNumValue(topLeft, !!options.addPXUnit));
|
|
221
257
|
}
|
|
222
|
-
else if (
|
|
258
|
+
else if (topLeft === bottomRight && topRight === bottomLeft) {
|
|
223
259
|
// 俩俩相等的情况
|
|
224
|
-
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(
|
|
260
|
+
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(topLeft, !!options.addPXUnit)} ${_handleStyleNumValue(topRight, !!options.addPXUnit)}`);
|
|
225
261
|
}
|
|
226
|
-
else if (
|
|
227
|
-
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(
|
|
262
|
+
else if (topRight === bottomLeft) {
|
|
263
|
+
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(topLeft, !!options.addPXUnit)} ${_handleStyleNumValue(topRight, !!options.addPXUnit)} ${_handleStyleNumValue(bottomRight, !!options.addPXUnit)}`);
|
|
228
264
|
}
|
|
229
265
|
else {
|
|
230
|
-
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(
|
|
266
|
+
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(topLeft, !!options.addPXUnit)} ${_handleStyleNumValue(topRight, !!options.addPXUnit)} ${_handleStyleNumValue(bottomRight, !!options.addPXUnit)} ${_handleStyleNumValue(bottomLeft, !!options.addPXUnit)}`);
|
|
231
267
|
}
|
|
232
268
|
}
|
|
233
269
|
else {
|
|
234
|
-
setStyleValue(style, 'borderTopLeftRadius', _handleStyleNumValue(
|
|
235
|
-
setStyleValue(style, 'borderTopRightRadius', _handleStyleNumValue(
|
|
236
|
-
setStyleValue(style, 'borderBottomRightRadius', _handleStyleNumValue(
|
|
237
|
-
setStyleValue(style, 'borderBottomLeftRadius', _handleStyleNumValue(
|
|
270
|
+
setStyleValue(style, 'borderTopLeftRadius', _handleStyleNumValue(topLeft, !!options.addPXUnit));
|
|
271
|
+
setStyleValue(style, 'borderTopRightRadius', _handleStyleNumValue(topRight, !!options.addPXUnit));
|
|
272
|
+
setStyleValue(style, 'borderBottomRightRadius', _handleStyleNumValue(bottomRight, !!options.addPXUnit));
|
|
273
|
+
setStyleValue(style, 'borderBottomLeftRadius', _handleStyleNumValue(bottomLeft, !!options.addPXUnit));
|
|
238
274
|
}
|
|
239
275
|
}
|
|
240
276
|
if (type === 'none') {
|
|
@@ -292,6 +328,76 @@ function processCommonStyle2CSSProperties(commonStyle = {}, options = { toRem: t
|
|
|
292
328
|
setStyleValue(style, 'bottom', _handleStyleNumValue(position.bottom, !!options.addPXUnit));
|
|
293
329
|
}
|
|
294
330
|
}
|
|
331
|
+
if (boxShadow) {
|
|
332
|
+
let processedBoxShadow = boxShadow;
|
|
333
|
+
if (Object.prototype.toString.call(boxShadow) === '[object Object]') {
|
|
334
|
+
processedBoxShadow = [boxShadow];
|
|
335
|
+
}
|
|
336
|
+
let boxShadowStyleString = '';
|
|
337
|
+
if (Array.isArray(processedBoxShadow)) {
|
|
338
|
+
processedBoxShadow.forEach((boxShadowItem, index) => {
|
|
339
|
+
let currentBoxShadowStyleString = '';
|
|
340
|
+
const { keyWord, offsetX, offsetY, blurRadius, spreadRadius, color, global, inset } = boxShadowItem;
|
|
341
|
+
// Keyword values
|
|
342
|
+
if (keyWord === 'none') {
|
|
343
|
+
currentBoxShadowStyleString = 'none';
|
|
344
|
+
}
|
|
345
|
+
else if (!!global) {
|
|
346
|
+
currentBoxShadowStyleString = global;
|
|
347
|
+
}
|
|
348
|
+
else if (!!offsetX || !!offsetY) {
|
|
349
|
+
// inset
|
|
350
|
+
if (!!inset) {
|
|
351
|
+
currentBoxShadowStyleString = 'inset ';
|
|
352
|
+
}
|
|
353
|
+
// offsetX
|
|
354
|
+
if (!!offsetX) {
|
|
355
|
+
currentBoxShadowStyleString += _handleStyleNumValue(offsetX, !!options.addPXUnit);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
currentBoxShadowStyleString += '0';
|
|
359
|
+
}
|
|
360
|
+
// offsetY
|
|
361
|
+
if (!!offsetY) {
|
|
362
|
+
currentBoxShadowStyleString += ' ' + _handleStyleNumValue(offsetY, !!options.addPXUnit);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
currentBoxShadowStyleString += ' 0';
|
|
366
|
+
}
|
|
367
|
+
// blur-radius 当 spread-radius 存在时,即使不存在 blur-radius,blur-radius 也要为 0
|
|
368
|
+
if (!!blurRadius || !!spreadRadius) {
|
|
369
|
+
if (!!blurRadius) {
|
|
370
|
+
currentBoxShadowStyleString += ' ' + _handleStyleNumValue(blurRadius, !!options.addPXUnit);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
currentBoxShadowStyleString += ' 0';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// spread-radius
|
|
377
|
+
if (!!spreadRadius) {
|
|
378
|
+
currentBoxShadowStyleString += ' ' + _handleStyleNumValue(spreadRadius, !!options.addPXUnit);
|
|
379
|
+
}
|
|
380
|
+
// color
|
|
381
|
+
if (!!color) {
|
|
382
|
+
currentBoxShadowStyleString += ' ' + color;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (!!currentBoxShadowStyleString) {
|
|
386
|
+
let splitLabel;
|
|
387
|
+
if (!!boxShadowStyleString) {
|
|
388
|
+
splitLabel = ' , ';
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
splitLabel = '';
|
|
392
|
+
}
|
|
393
|
+
boxShadowStyleString += splitLabel + currentBoxShadowStyleString;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (!!boxShadowStyleString) {
|
|
398
|
+
setStyleValue(style, 'boxShadow', boxShadowStyleString);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
295
401
|
if (custom && custom.length > 0) {
|
|
296
402
|
custom.map((item) => {
|
|
297
403
|
setStyleValue(style, item.key, item.value);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const wedaDTS = "declare namespace $app {\n namespace dataset {\n\n const state: {\n // Global State Inner Begin\n // Global State \u5168\u5C40\u53D8\u91CF - Don't touch me\n // Global State Inner End\n }\n\n }\n\n namespace utils {\n function ABS(num: number): number;\n function Min(...args: number[]): number;\n function Max(...args: number[]): number;\n function Average(...args: number[]): number;\n function Floor(num: number): number;\n function Ceiling(num: number): number;\n function Round(num: number): number;\n function Sum(...args: number[]): number;\n function Rand(num: number): number;\n\n function If(condition: boolean, val1: any, val2: any): any;\n function IsEmpty(text: string | string[]): boolean;\n function NotNull(val: any): boolean;\n function And(...args: boolean[]): boolean;\n function Or(...args: boolean[]): boolean;\n\n function Len(text: string): number;\n function Contains(text1: string, text2: string): boolean;\n function Split(text1: string, text2: string): string[];\n function Trim(text: string): string;\n function Upper(text: string): string;\n function Lower(text: string): string;\n function Concat(...text: string[]): string;\n\n function Now(): number;\n function Timestamp(arg: number | string | Date): number;\n function Second(arg: number | string | Date): number;\n function Minute(arg: number | string | Date): number;\n function Hour(arg: number | string | Date): number;\n function Day(arg: number | string | Date): number;\n function DayOfWeek(arg: number | string | Date): number;\n function Month(arg: number | string | Date): number;\n function Year(arg: number | string | Date): number;\n function GetDate(year: number, month: number, day: number): number;\n function DateTimeValue(arg: string, val: string): number;\n function Age(arg: number | string | Date, val: number | string | Date): number;\n function AgeOfNow(arg: number | string | Date): number;\n function DateAdd(arg: number | string | Date, day: number): number;\n function MonthAdd(arg: number | string | Date, month: number): number;\n function YearAdd(arg: number | string | Date, year: number): number;\n function DateDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function HourDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function MinuteDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function SecondDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function MonthDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function YearDiff(startDay: number | string | Date, endDay: number | string | Date): number;\n function DateText(createdTime: number | string | Date, text: string): string;\n function IsToday(date: number | string | Date): boolean;\n\n }\n\n namespace common {\n // Global Common Inner Begin\n // Global Common \u5168\u5C40\u65B9\u6CD5 - Don't touch me\n // Global Common Inner End\n }\n\n namespace auth {\n const currentUser: {\n userId?: string\n phone?: string\n type?: number\n relatedRoles?: {\n id?: string\n envId?: string\n name?: string\n roleIdentity?: string\n }[]\n openId?: string\n name?: string\n nickName?: string\n email?: string\n mainOrg?: {\n id?: string\n name?: string\n }\n orgs?: {\n id?: string\n name?: string\n }[]\n}\n\n }\n\n \n\ninterface navigatorOptions {\n packageName: string;\n pageId: string;\n data?: Record<string, any>;\n params?: Record<string, any>;\n events?: Record<string, (data: any) => void>;\n success(res: any);\n fail(res: any);\n complete(res: any);\n}\n\ninterface navigateBackOptions {\n delta: number;\n}\n\n// \u8BBE\u7F6E\u72B6\u6001\nfunction setState(userSetState: Record<string, any>): void\n\n// \u7279\u5236\u8DEF\u7531\nfunction navigateTo(options: navigatorOptions)\nfunction redirectTo(options: navigatorOptions)\nfunction reLaunch(options: navigatorOptions)\nfunction navigateBack(options: navigateBackOptions)\n\n// \u663E\u793A\u63D0\u793A\nfunction showToast(options);\n\n// \u663E\u793A\u6A21\u6001\u63D0\u793A\nfunction showModal(options);\n\n// \u663E\u793A loading \u63D0\u793A\nfunction showLoading(options);\n\n// \u9690\u85CF loading \u63D0\u793A\nfunction hideLoading(options);\n\n// \u9690\u85CF\u63D0\u793A\nfunction hideToast(options);\n\n// sacnCode\nfunction scanCode(options: {\n onlyFromCamera?: boolean;\n enableDefaultBehavior?: boolean;\n scanType?: ('barCode' | 'qrCode')[];\n success?: (res: { result: string; scanType: string }) => void;\n fail?: (err: Error) => void;\n complete?: () => void;\n}): Promise<ScanCodeResult> | ScanCodeResult;\n\n\n}\n\ndeclare const app = $app\n\n// Global For Begin\ndeclare const $for: {\n // Global For Inner Begin\n // For \u5FAA\u73AF\u53D8\u91CF - Don't touch me\n // Global For Inner End\n}\ndeclare const forItems = $for\n// Global For End\n\n// $page Begin\ndeclare namespace $page {\n namespace dataset {\n\n const state: {\n // Page State Inner Begin\n // Page State \u9875\u9762\u53D8\u91CF - Don't touch me\n // Page State Inner End\n }\n\n const params: {\n // Page Param Inner Begin\n // Page Param \u9875\u9762\u53C2\u6570 - Don't touch me\n // Page Param Inner End\n }\n\n }\n\n namespace handler {\n // Page Handler Inner Begin\n // Page Handler \u9875\u9762\u65B9\u6CD5 - Don't touch me\n // Page Handler Inner End\n }\n\n \n\n// \u8BBE\u7F6E\u72B6\u6001\nfunction setState(userSetState: Record<string, any>): void\n\n\n}\n// $page End\n\n// $comp Begin\ndeclare namespace $comp {\n\n namespace props {\n\n const data: {\n // Comp Prop Data Inner Begin\n // Comp Prop Data \u7EC4\u4EF6\u5C5E\u6027 - Don't touch me\n // Comp Prop Data Inner End\n }\n\n namespace events {\n // Comp Prop Events Inner Begin\n // Comp Prop Events \u7EC4\u4EF6\u4E8B\u4EF6 - Don't touch me\n // Comp Prop Events Inner End\n }\n\n }\n\n namespace dataset {\n\n const state: {\n // Comp State Inner Begin\n // Comp State \u7EC4\u4EF6\u53D8\u91CF - Don't touch me\n // Comp State Inner End\n }\n\n }\n\n namespace handler {\n // Comp Handler Inner Begin\n // Comp Handler \u7EC4\u4EF6\u65B9\u6CD5 - Don't touch me\n // Comp Handler Inner End\n }\n\n}\n// $comp End\n\n// Global Formula Begin\n\ndeclare function ABS(num: number): number;\ndeclare function Min(...args: number[]): number;\ndeclare function Max(...args: number[]): number;\ndeclare function Average(...args: number[]): number;\ndeclare function Floor(num: number): number;\ndeclare function Ceiling(num: number): number;\ndeclare function Round(num: number): number;\ndeclare function Sum(...args: number[]): number;\ndeclare function Rand(num: number): number;\n\ndeclare function If(condition: boolean, val1: any, val2: any): any;\ndeclare function IsEmpty(text: string | string[]): boolean;\ndeclare function NotNull(val: any): boolean;\ndeclare function And(...args: boolean[]): boolean;\ndeclare function Or(...args: boolean[]): boolean;\n\ndeclare function Len(text: string): number;\ndeclare function Contains(text1: string, text2: string): boolean;\ndeclare function Split(text1: string, text2: string): string[];\ndeclare function Trim(text: string): string;\ndeclare function Upper(text: string): string;\ndeclare function Lower(text: string): string;\ndeclare function Concat(...text: string[]): string;\n\ndeclare function Now(): number;\ndeclare function Timestamp(arg: number | string | Date): number;\ndeclare function Second(arg: number | string | Date): number;\ndeclare function Minute(arg: number | string | Date): number;\ndeclare function Hour(arg: number | string | Date): number;\ndeclare function Day(arg: number | string | Date): number;\ndeclare function DayOfWeek(arg: number | string | Date): number;\ndeclare function Month(arg: number | string | Date): number;\ndeclare function Year(arg: number | string | Date): number;\ndeclare function GetDate(year: number, month: number, day: number): number;\ndeclare function DateTimeValue(arg: string, val: string): number;\ndeclare function Age(arg: number | string | Date, val: number | string | Date): number;\ndeclare function AgeOfNow(arg: number | string | Date): number;\ndeclare function DateAdd(arg: number | string | Date, day: number): number;\ndeclare function MonthAdd(arg: number | string | Date, month: number): number;\ndeclare function YearAdd(arg: number | string | Date, year: number): number;\ndeclare function DateDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function HourDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function MinuteDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function SecondDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function MonthDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function YearDiff(startDay: number | string | Date, endDay: number | string | Date): number;\ndeclare function DateText(createdTime: number | string | Date, text: string): string;\ndeclare function IsToday(date: number | string | Date): boolean;\n\n\n// Global Formula End\n";
|
|
2
|
+
//# sourceMappingURL=auto-generated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-generated.d.ts","sourceRoot":"","sources":["../../../src/utils/dts/auto-generated.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,wrSA6RnB,CAAA"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wedaDTS = void 0;
|
|
4
|
+
exports.wedaDTS = `declare namespace $app {
|
|
5
|
+
namespace dataset {
|
|
6
|
+
|
|
7
|
+
const state: {
|
|
8
|
+
// Global State Inner Begin
|
|
9
|
+
// Global State 全局变量 - Don't touch me
|
|
10
|
+
// Global State Inner End
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
namespace utils {
|
|
16
|
+
function ABS(num: number): number;
|
|
17
|
+
function Min(...args: number[]): number;
|
|
18
|
+
function Max(...args: number[]): number;
|
|
19
|
+
function Average(...args: number[]): number;
|
|
20
|
+
function Floor(num: number): number;
|
|
21
|
+
function Ceiling(num: number): number;
|
|
22
|
+
function Round(num: number): number;
|
|
23
|
+
function Sum(...args: number[]): number;
|
|
24
|
+
function Rand(num: number): number;
|
|
25
|
+
|
|
26
|
+
function If(condition: boolean, val1: any, val2: any): any;
|
|
27
|
+
function IsEmpty(text: string | string[]): boolean;
|
|
28
|
+
function NotNull(val: any): boolean;
|
|
29
|
+
function And(...args: boolean[]): boolean;
|
|
30
|
+
function Or(...args: boolean[]): boolean;
|
|
31
|
+
|
|
32
|
+
function Len(text: string): number;
|
|
33
|
+
function Contains(text1: string, text2: string): boolean;
|
|
34
|
+
function Split(text1: string, text2: string): string[];
|
|
35
|
+
function Trim(text: string): string;
|
|
36
|
+
function Upper(text: string): string;
|
|
37
|
+
function Lower(text: string): string;
|
|
38
|
+
function Concat(...text: string[]): string;
|
|
39
|
+
|
|
40
|
+
function Now(): number;
|
|
41
|
+
function Timestamp(arg: number | string | Date): number;
|
|
42
|
+
function Second(arg: number | string | Date): number;
|
|
43
|
+
function Minute(arg: number | string | Date): number;
|
|
44
|
+
function Hour(arg: number | string | Date): number;
|
|
45
|
+
function Day(arg: number | string | Date): number;
|
|
46
|
+
function DayOfWeek(arg: number | string | Date): number;
|
|
47
|
+
function Month(arg: number | string | Date): number;
|
|
48
|
+
function Year(arg: number | string | Date): number;
|
|
49
|
+
function GetDate(year: number, month: number, day: number): number;
|
|
50
|
+
function DateTimeValue(arg: string, val: string): number;
|
|
51
|
+
function Age(arg: number | string | Date, val: number | string | Date): number;
|
|
52
|
+
function AgeOfNow(arg: number | string | Date): number;
|
|
53
|
+
function DateAdd(arg: number | string | Date, day: number): number;
|
|
54
|
+
function MonthAdd(arg: number | string | Date, month: number): number;
|
|
55
|
+
function YearAdd(arg: number | string | Date, year: number): number;
|
|
56
|
+
function DateDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
57
|
+
function HourDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
58
|
+
function MinuteDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
59
|
+
function SecondDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
60
|
+
function MonthDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
61
|
+
function YearDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
62
|
+
function DateText(createdTime: number | string | Date, text: string): string;
|
|
63
|
+
function IsToday(date: number | string | Date): boolean;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
namespace common {
|
|
68
|
+
// Global Common Inner Begin
|
|
69
|
+
// Global Common 全局方法 - Don't touch me
|
|
70
|
+
// Global Common Inner End
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
namespace auth {
|
|
74
|
+
const currentUser: {
|
|
75
|
+
userId?: string
|
|
76
|
+
phone?: string
|
|
77
|
+
type?: number
|
|
78
|
+
relatedRoles?: {
|
|
79
|
+
id?: string
|
|
80
|
+
envId?: string
|
|
81
|
+
name?: string
|
|
82
|
+
roleIdentity?: string
|
|
83
|
+
}[]
|
|
84
|
+
openId?: string
|
|
85
|
+
name?: string
|
|
86
|
+
nickName?: string
|
|
87
|
+
email?: string
|
|
88
|
+
mainOrg?: {
|
|
89
|
+
id?: string
|
|
90
|
+
name?: string
|
|
91
|
+
}
|
|
92
|
+
orgs?: {
|
|
93
|
+
id?: string
|
|
94
|
+
name?: string
|
|
95
|
+
}[]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
interface navigatorOptions {
|
|
103
|
+
packageName: string;
|
|
104
|
+
pageId: string;
|
|
105
|
+
data?: Record<string, any>;
|
|
106
|
+
params?: Record<string, any>;
|
|
107
|
+
events?: Record<string, (data: any) => void>;
|
|
108
|
+
success(res: any);
|
|
109
|
+
fail(res: any);
|
|
110
|
+
complete(res: any);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface navigateBackOptions {
|
|
114
|
+
delta: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 设置状态
|
|
118
|
+
function setState(userSetState: Record<string, any>): void
|
|
119
|
+
|
|
120
|
+
// 特制路由
|
|
121
|
+
function navigateTo(options: navigatorOptions)
|
|
122
|
+
function redirectTo(options: navigatorOptions)
|
|
123
|
+
function reLaunch(options: navigatorOptions)
|
|
124
|
+
function navigateBack(options: navigateBackOptions)
|
|
125
|
+
|
|
126
|
+
// 显示提示
|
|
127
|
+
function showToast(options);
|
|
128
|
+
|
|
129
|
+
// 显示模态提示
|
|
130
|
+
function showModal(options);
|
|
131
|
+
|
|
132
|
+
// 显示 loading 提示
|
|
133
|
+
function showLoading(options);
|
|
134
|
+
|
|
135
|
+
// 隐藏 loading 提示
|
|
136
|
+
function hideLoading(options);
|
|
137
|
+
|
|
138
|
+
// 隐藏提示
|
|
139
|
+
function hideToast(options);
|
|
140
|
+
|
|
141
|
+
// sacnCode
|
|
142
|
+
function scanCode(options: {
|
|
143
|
+
onlyFromCamera?: boolean;
|
|
144
|
+
enableDefaultBehavior?: boolean;
|
|
145
|
+
scanType?: ('barCode' | 'qrCode')[];
|
|
146
|
+
success?: (res: { result: string; scanType: string }) => void;
|
|
147
|
+
fail?: (err: Error) => void;
|
|
148
|
+
complete?: () => void;
|
|
149
|
+
}): Promise<ScanCodeResult> | ScanCodeResult;
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare const app = $app
|
|
155
|
+
|
|
156
|
+
// Global For Begin
|
|
157
|
+
declare const $for: {
|
|
158
|
+
// Global For Inner Begin
|
|
159
|
+
// For 循环变量 - Don't touch me
|
|
160
|
+
// Global For Inner End
|
|
161
|
+
}
|
|
162
|
+
declare const forItems = $for
|
|
163
|
+
// Global For End
|
|
164
|
+
|
|
165
|
+
// $page Begin
|
|
166
|
+
declare namespace $page {
|
|
167
|
+
namespace dataset {
|
|
168
|
+
|
|
169
|
+
const state: {
|
|
170
|
+
// Page State Inner Begin
|
|
171
|
+
// Page State 页面变量 - Don't touch me
|
|
172
|
+
// Page State Inner End
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const params: {
|
|
176
|
+
// Page Param Inner Begin
|
|
177
|
+
// Page Param 页面参数 - Don't touch me
|
|
178
|
+
// Page Param Inner End
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
namespace handler {
|
|
184
|
+
// Page Handler Inner Begin
|
|
185
|
+
// Page Handler 页面方法 - Don't touch me
|
|
186
|
+
// Page Handler Inner End
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
// 设置状态
|
|
192
|
+
function setState(userSetState: Record<string, any>): void
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
// $page End
|
|
197
|
+
|
|
198
|
+
// $comp Begin
|
|
199
|
+
declare namespace $comp {
|
|
200
|
+
|
|
201
|
+
namespace props {
|
|
202
|
+
|
|
203
|
+
const data: {
|
|
204
|
+
// Comp Prop Data Inner Begin
|
|
205
|
+
// Comp Prop Data 组件属性 - Don't touch me
|
|
206
|
+
// Comp Prop Data Inner End
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
namespace events {
|
|
210
|
+
// Comp Prop Events Inner Begin
|
|
211
|
+
// Comp Prop Events 组件事件 - Don't touch me
|
|
212
|
+
// Comp Prop Events Inner End
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
namespace dataset {
|
|
218
|
+
|
|
219
|
+
const state: {
|
|
220
|
+
// Comp State Inner Begin
|
|
221
|
+
// Comp State 组件变量 - Don't touch me
|
|
222
|
+
// Comp State Inner End
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
namespace handler {
|
|
228
|
+
// Comp Handler Inner Begin
|
|
229
|
+
// Comp Handler 组件方法 - Don't touch me
|
|
230
|
+
// Comp Handler Inner End
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
// $comp End
|
|
235
|
+
|
|
236
|
+
// Global Formula Begin
|
|
237
|
+
|
|
238
|
+
declare function ABS(num: number): number;
|
|
239
|
+
declare function Min(...args: number[]): number;
|
|
240
|
+
declare function Max(...args: number[]): number;
|
|
241
|
+
declare function Average(...args: number[]): number;
|
|
242
|
+
declare function Floor(num: number): number;
|
|
243
|
+
declare function Ceiling(num: number): number;
|
|
244
|
+
declare function Round(num: number): number;
|
|
245
|
+
declare function Sum(...args: number[]): number;
|
|
246
|
+
declare function Rand(num: number): number;
|
|
247
|
+
|
|
248
|
+
declare function If(condition: boolean, val1: any, val2: any): any;
|
|
249
|
+
declare function IsEmpty(text: string | string[]): boolean;
|
|
250
|
+
declare function NotNull(val: any): boolean;
|
|
251
|
+
declare function And(...args: boolean[]): boolean;
|
|
252
|
+
declare function Or(...args: boolean[]): boolean;
|
|
253
|
+
|
|
254
|
+
declare function Len(text: string): number;
|
|
255
|
+
declare function Contains(text1: string, text2: string): boolean;
|
|
256
|
+
declare function Split(text1: string, text2: string): string[];
|
|
257
|
+
declare function Trim(text: string): string;
|
|
258
|
+
declare function Upper(text: string): string;
|
|
259
|
+
declare function Lower(text: string): string;
|
|
260
|
+
declare function Concat(...text: string[]): string;
|
|
261
|
+
|
|
262
|
+
declare function Now(): number;
|
|
263
|
+
declare function Timestamp(arg: number | string | Date): number;
|
|
264
|
+
declare function Second(arg: number | string | Date): number;
|
|
265
|
+
declare function Minute(arg: number | string | Date): number;
|
|
266
|
+
declare function Hour(arg: number | string | Date): number;
|
|
267
|
+
declare function Day(arg: number | string | Date): number;
|
|
268
|
+
declare function DayOfWeek(arg: number | string | Date): number;
|
|
269
|
+
declare function Month(arg: number | string | Date): number;
|
|
270
|
+
declare function Year(arg: number | string | Date): number;
|
|
271
|
+
declare function GetDate(year: number, month: number, day: number): number;
|
|
272
|
+
declare function DateTimeValue(arg: string, val: string): number;
|
|
273
|
+
declare function Age(arg: number | string | Date, val: number | string | Date): number;
|
|
274
|
+
declare function AgeOfNow(arg: number | string | Date): number;
|
|
275
|
+
declare function DateAdd(arg: number | string | Date, day: number): number;
|
|
276
|
+
declare function MonthAdd(arg: number | string | Date, month: number): number;
|
|
277
|
+
declare function YearAdd(arg: number | string | Date, year: number): number;
|
|
278
|
+
declare function DateDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
279
|
+
declare function HourDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
280
|
+
declare function MinuteDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
281
|
+
declare function SecondDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
282
|
+
declare function MonthDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
283
|
+
declare function YearDiff(startDay: number | string | Date, endDay: number | string | Date): number;
|
|
284
|
+
declare function DateText(createdTime: number | string | Date, text: string): string;
|
|
285
|
+
declare function IsToday(date: number | string | Date): boolean;
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
// Global Formula End
|
|
289
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/utils/dts/build.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const child_process_1 = __importDefault(require("child_process"));
|
|
18
|
+
const os_1 = __importDefault(require("os"));
|
|
19
|
+
const node_watch_1 = __importDefault(require("node-watch"));
|
|
20
|
+
/**
|
|
21
|
+
* 生成函数公式的 dts
|
|
22
|
+
* 已包含的函数公式:packages/weda-client/src/common/<calculation|logic|text|time>
|
|
23
|
+
*/
|
|
24
|
+
function buildFormulaDTS() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
// 确保在 packages/cals 目录执行该脚本
|
|
27
|
+
const baseDirPath = path_1.default.resolve('..', 'weda-client', 'src', 'common');
|
|
28
|
+
const formulaDirs = ['calculation', 'logic', 'text', 'time'];
|
|
29
|
+
const dtsList = yield Promise.all(formulaDirs.map(fDir => {
|
|
30
|
+
return genDTS(fDir);
|
|
31
|
+
}));
|
|
32
|
+
return dtsList.join('\n');
|
|
33
|
+
function genDTS(fDir) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const randomId = Math.random()
|
|
36
|
+
.toString(36)
|
|
37
|
+
.substring(2, 6);
|
|
38
|
+
const tempDtsPath = path_1.default.resolve(os_1.default.tmpdir(), `weda-temp-${randomId}.d.ts`);
|
|
39
|
+
yield new Promise((resolve) => {
|
|
40
|
+
child_process_1.default.exec(`tsc ${path_1.default.resolve(baseDirPath, fDir, 'index.ts')} --declaration --emitDeclarationOnly --allowSyntheticDefaultImports true --out ${tempDtsPath}`, () => {
|
|
41
|
+
resolve('done');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const dts = yield fs_extra_1.default.readFile(tempDtsPath, 'utf8');
|
|
45
|
+
yield fs_extra_1.default.remove(tempDtsPath);
|
|
46
|
+
// 去掉最外层的模块声明
|
|
47
|
+
return dts.replace(/^declare module.*$/m, '').replace(/\}$/m, '').replace(/^\s+/mg, '');
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function genWeDaAPPDTS() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
console.log('genWeDaAPPDTS processing...');
|
|
55
|
+
/**
|
|
56
|
+
* 获取所有的 DTS
|
|
57
|
+
*/
|
|
58
|
+
const wedaFrameworkDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-framework.d.ts'), 'utf8'); // 低码框架
|
|
59
|
+
const wedaAPIDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-api.d.ts'), 'utf8'); // 低码 API
|
|
60
|
+
const wedaAuthDTS = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, 'framework', 'weda-auth.d.ts'), 'utf8'); // Auth 信息
|
|
61
|
+
const formulaDTS = yield buildFormulaDTS(); // 函数公式
|
|
62
|
+
/**
|
|
63
|
+
* 聚合 DTS
|
|
64
|
+
*/
|
|
65
|
+
const wedaDTS = groupDTSs({ wedaFrameworkDTS, wedaAPIDTS, wedaAuthDTS, formulaDTS });
|
|
66
|
+
/**
|
|
67
|
+
* 将聚合结果保存在 auto-generated.ts
|
|
68
|
+
*/
|
|
69
|
+
yield fs_extra_1.default.writeFile(path_1.default.resolve(__dirname, 'auto-generated.ts'), `export const wedaDTS = \`${wedaDTS}\``, 'utf8');
|
|
70
|
+
console.log('genWeDaAPPDTS done!');
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 聚合所有的 DTS(不包括动态生成的)
|
|
75
|
+
*/
|
|
76
|
+
function groupDTSs({ wedaFrameworkDTS = '', wedaAPIDTS = '', wedaAuthDTS = '', formulaDTS = '' }) {
|
|
77
|
+
let resultDts = wedaFrameworkDTS;
|
|
78
|
+
// 函数公式:$app.utils.xxx
|
|
79
|
+
resultDts = resultDts.replace("// Formula 函数公式 - Don't touch me", formulaDTS.replace(/export/g, ''));
|
|
80
|
+
// 函数公式:全局变量提示
|
|
81
|
+
resultDts = resultDts.replace("// Global Formula 全局函数公式- Don't touch me", formulaDTS.replace(/export/g, 'declare'));
|
|
82
|
+
// 增加 API
|
|
83
|
+
const appAPIDTS = wedaAPIDTS.replace(/[\s\S]*\/\/ ============ App API Begin ============ \/\/([\s\S]*?)\/\/ ============ App API End ============ \/\/[\s\S]*/, '$1');
|
|
84
|
+
resultDts = resultDts.replace("// App API - Don't touch me", appAPIDTS);
|
|
85
|
+
const pageAPIDTS = wedaAPIDTS.replace(/[\s\S]*\/\/ ============ Page API Begin ============ \/\/([\s\S]*?)\/\/ ============ Page API End ============ \/\/[\s\S]*/, '$1');
|
|
86
|
+
resultDts = resultDts.replace("// Page API - Don't touch me", pageAPIDTS);
|
|
87
|
+
// 增加 Auth 信息
|
|
88
|
+
resultDts = resultDts.replace("// Auth 认证 - Don't touch me", wedaAuthDTS);
|
|
89
|
+
return resultDts;
|
|
90
|
+
}
|
|
91
|
+
function main() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
yield genWeDaAPPDTS();
|
|
94
|
+
const [, , watchArgv] = process.argv;
|
|
95
|
+
if (watchArgv === '--watch') {
|
|
96
|
+
console.log('Start watching mode');
|
|
97
|
+
(0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-framework.d.ts'), genWeDaAPPDTS);
|
|
98
|
+
(0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-api.d.ts'), genWeDaAPPDTS);
|
|
99
|
+
(0, node_watch_1.default)(path_1.default.resolve(__dirname, 'framework', 'weda-auth.d.ts'), genWeDaAPPDTS);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
main();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { IJsonSchemaObject } from '../../types';
|
|
2
|
+
export interface IDTSCodeItem {
|
|
3
|
+
name: string;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IOptions {
|
|
7
|
+
isCompMode?: boolean;
|
|
8
|
+
needGlobalFormula?: boolean;
|
|
9
|
+
needGlobalFor?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare enum IInputDataType {
|
|
12
|
+
globalState = "globalState",
|
|
13
|
+
pageState = "pageState",
|
|
14
|
+
compState = "compState",
|
|
15
|
+
pageParams = "pageParams",
|
|
16
|
+
forState = "forState",
|
|
17
|
+
globalCommonCodes = "globalCommonCodes",
|
|
18
|
+
pageHandlerCodes = "pageHandlerCodes",
|
|
19
|
+
compHandlerCodes = "compHandlerCodes",
|
|
20
|
+
compPropData = "compPropData",
|
|
21
|
+
compPropEvents = "compPropEvents"
|
|
22
|
+
}
|
|
23
|
+
export interface IInputData {
|
|
24
|
+
[IInputDataType.globalState]?: IJsonSchemaObject;
|
|
25
|
+
[IInputDataType.pageState]?: IJsonSchemaObject;
|
|
26
|
+
[IInputDataType.compState]?: IJsonSchemaObject;
|
|
27
|
+
[IInputDataType.pageParams]?: IJsonSchemaObject;
|
|
28
|
+
[IInputDataType.forState]?: IJsonSchemaObject;
|
|
29
|
+
[IInputDataType.globalCommonCodes]?: IDTSCodeItem[];
|
|
30
|
+
[IInputDataType.pageHandlerCodes]?: IDTSCodeItem[];
|
|
31
|
+
[IInputDataType.compHandlerCodes]?: IDTSCodeItem[];
|
|
32
|
+
[IInputDataType.compPropData]?: IJsonSchemaObject;
|
|
33
|
+
[IInputDataType.compPropEvents]?: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 通过该类可以共享同个dts。
|
|
37
|
+
* 场景:在 weda 中,低代码的变更会通知更改 dts,而低码编辑器和表达式编辑器对 dts 的需求是不一样的,这样不同的 dts 共享的是同一份全的 dts。如果直接调用 generateWeDaAppDTS 会导致 dts 重复地解析
|
|
38
|
+
*/
|
|
39
|
+
export declare class WeDaDTS {
|
|
40
|
+
private static _dts;
|
|
41
|
+
/**
|
|
42
|
+
* 全部更新
|
|
43
|
+
*/
|
|
44
|
+
static updateDTS(inputData?: IInputData, options?: Pick<IOptions, "isCompMode">): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* 部分更新 - 只更新一种类型
|
|
47
|
+
*/
|
|
48
|
+
static updateDTSPartial(inputData: IJsonSchemaObject | IDTSCodeItem[] | string[], itemType: IInputDataType, options?: {
|
|
49
|
+
setEmptyIfError: boolean;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
static getDTS(options?: Omit<IOptions, "isCompMode">): string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 生成 WeDa 应用的低码代码提示的 dts 类型声明内容
|
|
55
|
+
*/
|
|
56
|
+
export declare function generateWeDaAppDTS(inputData?: IInputData, options?: IOptions): Promise<string>;
|
|
57
|
+
export declare const workerCode = "\nimportScripts('https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_url/devtools/typescriptServices.min.js');\n\nts.transpileOptionValueCompilerOptions.forEach(item => {\n if (['emitDeclarationOnly', 'declaration'].includes(item.name)) {\n item.transpileOptionValue = true\n }\n})\naddEventListener('message', (message) => {\n const {action, data: {id, code}} = message.data\n switch(action) {\n case 'dts':\n const dts = ts.transpile(code, {})\n postMessage({action: 'dts_back', data: {id, dts}})\n break\n default:\n break\n }\n})\n";
|
|
58
|
+
/**
|
|
59
|
+
* 通过 js/ts 代码生成 dts
|
|
60
|
+
*/
|
|
61
|
+
export declare function transpileToDTS(code: string): Promise<string>;
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/dts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAK/C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,QAAQ;IAEvB,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAE3B,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,oBAAY,cAAc;IACxB,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,iBAAiB,sBAAsB;IACvC,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,YAAY,iBAAiB;IAC7B,cAAc,mBAAmB;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,EAAE,iBAAiB,CAAA;IAChD,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,iBAAiB,CAAA;IAC9C,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,iBAAiB,CAAA;IAC9C,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,EAAE,iBAAiB,CAAA;IAC/C,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,iBAAiB,CAAA;IAC7C,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAA;IACnD,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAA;IAClD,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAA;IAClD,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,EAAE,iBAAiB,CAAA;IACjD,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3C;AA4BD;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAa;IAEhC;;OAEG;WACU,SAAS,CAAC,SAAS,GAAE,UAAe,EAAE,OAAO,GAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAyB;IAIhH;;OAEG;WACU,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,GAAG,YAAY,EAAE,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE;QAAE,eAAe,EAAE,OAAO,CAAA;KAA+B;IAYpL,MAAM,CAAC,MAAM,CAAC,OAAO,GAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAsD;CAUzG;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,SAAS,GAAE,UAAe,EAAE,OAAO,GAAE,QAAgF,GAAG,OAAO,CAAC,MAAM,CAAC,CAoC/K;AAyED,eAAO,MAAM,UAAU,onBAmBtB,CAAA;AA6CD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO5D"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
|
|
36
|
+
const jstt = __importStar(require("json-schema-to-typescript-for-browser/dist/bundle.js"));
|
|
37
|
+
const auto_generated_1 = require("./auto-generated");
|
|
38
|
+
const compile = jstt.compile;
|
|
39
|
+
var IInputDataType;
|
|
40
|
+
(function (IInputDataType) {
|
|
41
|
+
IInputDataType["globalState"] = "globalState";
|
|
42
|
+
IInputDataType["pageState"] = "pageState";
|
|
43
|
+
IInputDataType["compState"] = "compState";
|
|
44
|
+
IInputDataType["pageParams"] = "pageParams";
|
|
45
|
+
IInputDataType["forState"] = "forState";
|
|
46
|
+
IInputDataType["globalCommonCodes"] = "globalCommonCodes";
|
|
47
|
+
IInputDataType["pageHandlerCodes"] = "pageHandlerCodes";
|
|
48
|
+
IInputDataType["compHandlerCodes"] = "compHandlerCodes";
|
|
49
|
+
IInputDataType["compPropData"] = "compPropData";
|
|
50
|
+
IInputDataType["compPropEvents"] = "compPropEvents";
|
|
51
|
+
})(IInputDataType = exports.IInputDataType || (exports.IInputDataType = {}));
|
|
52
|
+
const DtsPlaceholder = {
|
|
53
|
+
[IInputDataType.globalState]: "// Global State 全局变量 - Don't touch me",
|
|
54
|
+
[IInputDataType.pageState]: "// Page State 页面变量 - Don't touch me",
|
|
55
|
+
[IInputDataType.compState]: "// Comp State 组件变量 - Don't touch me",
|
|
56
|
+
[IInputDataType.pageParams]: "// Page Param 页面参数 - Don't touch me",
|
|
57
|
+
[IInputDataType.forState]: "// For 循环变量 - Don't touch me",
|
|
58
|
+
[IInputDataType.globalCommonCodes]: "// Global Common 全局方法 - Don't touch me",
|
|
59
|
+
[IInputDataType.pageHandlerCodes]: "// Page Handler 页面方法 - Don't touch me",
|
|
60
|
+
[IInputDataType.compHandlerCodes]: "// Comp Handler 组件方法 - Don't touch me",
|
|
61
|
+
[IInputDataType.compPropData]: "// Comp Prop Data 组件属性 - Don't touch me",
|
|
62
|
+
[IInputDataType.compPropEvents]: "// Comp Prop Events 组件事件 - Don't touch me",
|
|
63
|
+
};
|
|
64
|
+
const DtsInnerSign = {
|
|
65
|
+
[IInputDataType.globalState]: "Global State Inner",
|
|
66
|
+
[IInputDataType.pageState]: "Page State Inner",
|
|
67
|
+
[IInputDataType.compState]: "Comp State Inner",
|
|
68
|
+
[IInputDataType.pageParams]: "Page Param Inner",
|
|
69
|
+
[IInputDataType.forState]: "Global For Inner",
|
|
70
|
+
[IInputDataType.globalCommonCodes]: "Global Common Inner",
|
|
71
|
+
[IInputDataType.pageHandlerCodes]: "Page Handler Inner",
|
|
72
|
+
[IInputDataType.compHandlerCodes]: "Comp Handler Inner",
|
|
73
|
+
[IInputDataType.compPropData]: "Comp Prop Data Inner",
|
|
74
|
+
[IInputDataType.compPropEvents]: "Comp Prop Events Inner",
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* 通过该类可以共享同个dts。
|
|
78
|
+
* 场景:在 weda 中,低代码的变更会通知更改 dts,而低码编辑器和表达式编辑器对 dts 的需求是不一样的,这样不同的 dts 共享的是同一份全的 dts。如果直接调用 generateWeDaAppDTS 会导致 dts 重复地解析
|
|
79
|
+
*/
|
|
80
|
+
class WeDaDTS {
|
|
81
|
+
/**
|
|
82
|
+
* 全部更新
|
|
83
|
+
*/
|
|
84
|
+
static updateDTS(inputData = {}, options = { isCompMode: false }) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
WeDaDTS._dts = yield generateWeDaAppDTS(inputData, Object.assign(Object.assign({}, options), { needGlobalFormula: true, needGlobalFor: true }));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 部分更新 - 只更新一种类型
|
|
91
|
+
*/
|
|
92
|
+
static updateDTSPartial(inputData, itemType, options = { setEmptyIfError: false }) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
let dts = '';
|
|
95
|
+
try {
|
|
96
|
+
dts = yield _generateOneItemDTS(inputData, itemType);
|
|
97
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
if (options.setEmptyIfError) {
|
|
101
|
+
WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
static getDTS(options = { needGlobalFormula: false, needGlobalFor: false }) {
|
|
107
|
+
let resultDts = WeDaDTS._dts;
|
|
108
|
+
if (!options.needGlobalFormula) {
|
|
109
|
+
resultDts = resultDts.replace(/^\/\/ Global Formula Begin[\s\S]*^\/\/ Global Formula End$/m, '');
|
|
110
|
+
}
|
|
111
|
+
if (!options.needGlobalFor) {
|
|
112
|
+
resultDts = resultDts.replace(/^\/\/ Global For Begin[\s\S]*^\/\/ Global For End$/m, '');
|
|
113
|
+
}
|
|
114
|
+
return resultDts;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.WeDaDTS = WeDaDTS;
|
|
118
|
+
WeDaDTS._dts = '';
|
|
119
|
+
/**
|
|
120
|
+
* 生成 WeDa 应用的低码代码提示的 dts 类型声明内容
|
|
121
|
+
*/
|
|
122
|
+
function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needGlobalFormula: false, needGlobalFor: false }) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
let resultDts = auto_generated_1.wedaDTS;
|
|
125
|
+
yield Promise.all(Object.keys(inputData).map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const placeholder = DtsPlaceholder[key];
|
|
127
|
+
if (placeholder) {
|
|
128
|
+
// 防止某项错误导致全部都错误
|
|
129
|
+
try {
|
|
130
|
+
const dts = yield _generateOneItemDTS(inputData[key], key);
|
|
131
|
+
resultDts = resultDts.replace(placeholder, dts + placeholder);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
console.error(e);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})));
|
|
138
|
+
// 根据是否组件模式删除一些类型定义
|
|
139
|
+
if (options === null || options === void 0 ? void 0 : options.isCompMode) {
|
|
140
|
+
resultDts = resultDts.replace(/^\/\/ \$page Begin[\s\S]*^\/\/ \$page End$/m, '');
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
resultDts = resultDts.replace(/^\/\/ \$comp Begin[\s\S]*^\/\/ \$comp End$/m, '');
|
|
144
|
+
}
|
|
145
|
+
// 根据是否需要全局提示函数公式删除一些类型定义
|
|
146
|
+
if (!(options === null || options === void 0 ? void 0 : options.needGlobalFormula)) {
|
|
147
|
+
resultDts = resultDts.replace(/^\/\/ Global Formula Begin[\s\S]*^\/\/ Global Formula End$/m, '');
|
|
148
|
+
}
|
|
149
|
+
// 根据是否需要全局 $for 来删除一些类型定义
|
|
150
|
+
if (!(options === null || options === void 0 ? void 0 : options.needGlobalFor)) {
|
|
151
|
+
resultDts = resultDts.replace(/^\/\/ Global For Begin[\s\S]*^\/\/ Global For End$/m, '');
|
|
152
|
+
}
|
|
153
|
+
// console.log(resultDts)
|
|
154
|
+
return resultDts;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
exports.generateWeDaAppDTS = generateWeDaAppDTS;
|
|
158
|
+
/**
|
|
159
|
+
* 生成指定类型的 DTS
|
|
160
|
+
*/
|
|
161
|
+
function _generateOneItemDTS(inputData, itemType) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const hanlderMap = {
|
|
164
|
+
[IInputDataType.globalCommonCodes]: function (inputData) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
const dts = yield transpileToDTS(item.code);
|
|
168
|
+
return `namespace ${item.name} { ${dts} }`;
|
|
169
|
+
})));
|
|
170
|
+
return dts.join('\n');
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
[IInputDataType.pageHandlerCodes]: function (inputData) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const IParams = `{
|
|
176
|
+
data?: {
|
|
177
|
+
target?: {
|
|
178
|
+
[key: string]: any
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
event?: {
|
|
182
|
+
target?: EventTarget
|
|
183
|
+
currentTarget?: EventTarget
|
|
184
|
+
detail?: {
|
|
185
|
+
detail?: {
|
|
186
|
+
[key: string]: any
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
forItems?: {
|
|
191
|
+
[key: string]: any
|
|
192
|
+
}
|
|
193
|
+
}`;
|
|
194
|
+
const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const dts = yield transpileToDTS(item.code);
|
|
196
|
+
// 将 export default function() 替换成类似 export function onClick
|
|
197
|
+
return dts.replace(/default function\s*\([\s\S]*?\)/, `function ${item.name} (params: ${IParams})`);
|
|
198
|
+
})));
|
|
199
|
+
return dts.join('\n');
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
[IInputDataType.compHandlerCodes]: function (inputData) {
|
|
203
|
+
return this.pageHandlerCodes(inputData);
|
|
204
|
+
},
|
|
205
|
+
[IInputDataType.compPropEvents]: function (inputData) {
|
|
206
|
+
const IData = `any`;
|
|
207
|
+
return inputData.map(eventName => {
|
|
208
|
+
return `function ${eventName}(data?: ${IData}): void`;
|
|
209
|
+
}).join('\n');
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
function _compile(jsonschema) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
let dts = yield compile(jsonschema, 'IWeDa', { additionalProperties: false, bannerComment: '', format: false });
|
|
215
|
+
dts = dts.replace(/^export interface.*$/m, '');
|
|
216
|
+
dts = dts.substring(0, dts.length - 2);
|
|
217
|
+
return dts;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
let dts = '';
|
|
221
|
+
if (!inputData)
|
|
222
|
+
return dts;
|
|
223
|
+
const handler = hanlderMap[itemType];
|
|
224
|
+
// 优先判断是否有独立的处理逻辑
|
|
225
|
+
if (handler) {
|
|
226
|
+
dts = yield handler.call(hanlderMap, inputData);
|
|
227
|
+
}
|
|
228
|
+
dts = dts || (yield _compile(inputData));
|
|
229
|
+
return dts;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// 仅仅为了与 unittest 共享,外部请不要使用
|
|
233
|
+
exports.workerCode = `
|
|
234
|
+
importScripts('https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_url/devtools/typescriptServices.min.js');
|
|
235
|
+
|
|
236
|
+
ts.transpileOptionValueCompilerOptions.forEach(item => {
|
|
237
|
+
if (['emitDeclarationOnly', 'declaration'].includes(item.name)) {
|
|
238
|
+
item.transpileOptionValue = true
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
addEventListener('message', (message) => {
|
|
242
|
+
const {action, data: {id, code}} = message.data
|
|
243
|
+
switch(action) {
|
|
244
|
+
case 'dts':
|
|
245
|
+
const dts = ts.transpile(code, {})
|
|
246
|
+
postMessage({action: 'dts_back', data: {id, dts}})
|
|
247
|
+
break
|
|
248
|
+
default:
|
|
249
|
+
break
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
`;
|
|
253
|
+
function TypescriptWorker() {
|
|
254
|
+
let typescriptWorker = null;
|
|
255
|
+
let sendMessageCallbackFn = {};
|
|
256
|
+
return function getInstance() {
|
|
257
|
+
if (!typescriptWorker) {
|
|
258
|
+
const workerURL = URL.createObjectURL(new Blob([exports.workerCode]));
|
|
259
|
+
typescriptWorker = new Worker(workerURL);
|
|
260
|
+
typescriptWorker.onmessage = function (event) {
|
|
261
|
+
const { action } = event.data;
|
|
262
|
+
if (action === 'dts_back') {
|
|
263
|
+
const { data: { id, dts } } = event.data;
|
|
264
|
+
sendMessageCallbackFn[id] && sendMessageCallbackFn[id](dts);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function sendMessage(msgData, callbackFn) {
|
|
269
|
+
const id = Math.random()
|
|
270
|
+
.toString(36)
|
|
271
|
+
.substring(2, 5);
|
|
272
|
+
msgData.data.id = id;
|
|
273
|
+
sendMessageCallbackFn[id] = callbackFn;
|
|
274
|
+
typescriptWorker.postMessage(msgData);
|
|
275
|
+
}
|
|
276
|
+
return { sendMessage };
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 使用:
|
|
281
|
+
* const typescriptWorker = getTypescriptWorker();
|
|
282
|
+
* typescriptWorker.sendMessage({ action: 'dts', data: { code } }, dts => {
|
|
283
|
+
*
|
|
284
|
+
* })
|
|
285
|
+
* // 以下暂未实现
|
|
286
|
+
* typescriptWorker.sendMessage({ action: 'ts', data: { code } }, ts => {
|
|
287
|
+
*
|
|
288
|
+
* })
|
|
289
|
+
*/
|
|
290
|
+
const getTypescriptWorker = TypescriptWorker();
|
|
291
|
+
/**
|
|
292
|
+
* 通过 js/ts 代码生成 dts
|
|
293
|
+
*/
|
|
294
|
+
function transpileToDTS(code) {
|
|
295
|
+
return new Promise(resolve => {
|
|
296
|
+
const typescriptWorker = getTypescriptWorker();
|
|
297
|
+
typescriptWorker.sendMessage({ action: 'dts', data: { code } }, (dts) => {
|
|
298
|
+
resolve(dts);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
exports.transpileToDTS = transpileToDTS;
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,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;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/utils/index.js
CHANGED
|
@@ -18,5 +18,6 @@ exports.isUnitlessNumber = void 0;
|
|
|
18
18
|
__exportStar(require("../parser"), exports);
|
|
19
19
|
__exportStar(require("../types/index"), exports);
|
|
20
20
|
__exportStar(require("./constant"), exports);
|
|
21
|
+
__exportStar(require("./dts/index"), exports);
|
|
21
22
|
var CSSProperty_1 = require("./CSSProperty");
|
|
22
23
|
Object.defineProperty(exports, "isUnitlessNumber", { enumerable: true, get: function () { return CSSProperty_1.isUnitlessNumber; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Common application specifications",
|
|
5
5
|
"main": "lib/utils/index.js",
|
|
6
6
|
"source": "src/utils/index.ts",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"build:schema": "ts-node src/utils/build.ts",
|
|
14
|
+
"build:dts": "ts-node src/utils/dts/build.ts",
|
|
15
|
+
"build:dts:watch": "ts-node src/utils/dts/build.ts --watch",
|
|
14
16
|
"develop": "tsc --watch",
|
|
15
17
|
"docs": "typedoc --options typedoc.json types",
|
|
16
18
|
"test": "jest",
|
|
@@ -25,6 +27,7 @@
|
|
|
25
27
|
"license": "MIT",
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"acorn": "^8.0.4",
|
|
30
|
+
"json-schema-to-typescript-for-browser": "^11.0.3",
|
|
28
31
|
"lodash": "^4.17.20"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
@@ -33,9 +36,13 @@
|
|
|
33
36
|
"@types/lodash": "^4.14.168",
|
|
34
37
|
"@types/node": "^14.14.6",
|
|
35
38
|
"@types/react": "^18.0.17",
|
|
39
|
+
"@types/web": "^0.0.78",
|
|
36
40
|
"ajv": "^8.8.2",
|
|
37
41
|
"csstype": "^3.0.11",
|
|
38
42
|
"jest": "^27.1.0",
|
|
43
|
+
"jest-fetch-mock": "^3.0.3",
|
|
44
|
+
"jsdom-worker": "^0.3.0",
|
|
45
|
+
"node-watch": "^0.7.3",
|
|
39
46
|
"ts-jest": "^27.0.5",
|
|
40
47
|
"ts-node": "^10.4.0",
|
|
41
48
|
"typescript": "^4.7.4",
|