@dcloudio/uni-uts-v1 3.0.0-alpha-3060720221018004
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/dist/code.d.ts +9 -0
- package/dist/code.js +272 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/kotlin.d.ts +4 -0
- package/dist/kotlin.js +228 -0
- package/dist/shared.d.ts +8 -0
- package/dist/shared.js +61 -0
- package/dist/swift.d.ts +2 -0
- package/dist/swift.js +65 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.js +125 -0
- package/package.json +32 -0
package/dist/code.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface GenProxyCodeOptions {
|
|
2
|
+
is_uni_modules: boolean;
|
|
3
|
+
name: string;
|
|
4
|
+
namespace: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function genProxyCode(module: string, options: GenProxyCodeOptions): Promise<string>;
|
|
7
|
+
export declare function resolveRootIndex(module: string, options: GenProxyCodeOptions): string | false;
|
|
8
|
+
export declare function resolvePlatformIndex(platform: 'app-android' | 'app-ios', module: string, options: GenProxyCodeOptions): string | false;
|
|
9
|
+
export {};
|
package/dist/code.js
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolvePlatformIndex = exports.resolveRootIndex = exports.genProxyCode = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const shared_1 = require("./shared");
|
|
11
|
+
async function genProxyCode(module, options) {
|
|
12
|
+
const { name, is_uni_modules } = options;
|
|
13
|
+
return `
|
|
14
|
+
import { initUtsProxyClass, initUtsProxyFunction, initUtsPackageName, initUtsIndexClassName, initUtsClassName } from '@dcloudio/uni-app'
|
|
15
|
+
const name = '${name}'
|
|
16
|
+
const is_uni_modules = ${is_uni_modules}
|
|
17
|
+
const pkg = initUtsPackageName(name, is_uni_modules)
|
|
18
|
+
const cls = initUtsIndexClassName(name, is_uni_modules)
|
|
19
|
+
${genModuleCode(await parseModuleDecls(module, options))}
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
exports.genProxyCode = genProxyCode;
|
|
23
|
+
function resolveRootIndex(module, options) {
|
|
24
|
+
const filename = path_1.default.resolve(module, options.is_uni_modules ? 'utssdk' : '', 'index.uts');
|
|
25
|
+
return fs_1.default.existsSync(filename) && filename;
|
|
26
|
+
}
|
|
27
|
+
exports.resolveRootIndex = resolveRootIndex;
|
|
28
|
+
function resolvePlatformIndex(platform, module, options) {
|
|
29
|
+
const filename = path_1.default.resolve(module, options.is_uni_modules ? 'utssdk' : '', platform, 'index.uts');
|
|
30
|
+
return fs_1.default.existsSync(filename) && filename;
|
|
31
|
+
}
|
|
32
|
+
exports.resolvePlatformIndex = resolvePlatformIndex;
|
|
33
|
+
function genModuleCode(decls) {
|
|
34
|
+
const codes = [];
|
|
35
|
+
decls.forEach((decl) => {
|
|
36
|
+
if (decl.type === 'Class') {
|
|
37
|
+
if (decl.isDefault) {
|
|
38
|
+
codes.push(`export default initUtsProxyClass(Object.assign({ package: pkg, class: initUtsClassName(name, '${decl.cls}', is_uni_modules) }, ${JSON.stringify(decl.options)} ))`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
codes.push(`export const ${decl.cls} = initUtsProxyClass(Object.assign({ package: pkg, class: initUtsClassName(name, '${decl.cls}', is_uni_modules) }, ${JSON.stringify(decl.options)} ))`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (decl.type === 'FunctionDeclaration') {
|
|
45
|
+
if (decl.isDefault) {
|
|
46
|
+
codes.push(`export default initUtsProxyFunction(${decl.async}, { main: true, package: pkg, class: cls, name: '${decl.method}', params: ${JSON.stringify(decl.params)}})`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
codes.push(`export const ${decl.method} = initUtsProxyFunction(${decl.async}, { main: true, package: pkg, class: cls, name: '${decl.method}', params: ${JSON.stringify(decl.params)}})`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (decl.type === 'VariableDeclaration') {
|
|
53
|
+
codes.push(`export ${decl.kind} ${decl.declarations
|
|
54
|
+
.map((d) => `${d.id.value} = ${genInitCode(d.init)}`)
|
|
55
|
+
.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return codes.join(`\n`);
|
|
59
|
+
}
|
|
60
|
+
async function parseModuleDecls(module, options) {
|
|
61
|
+
// 优先合并 ios + android,如果没有,查找根目录 index.uts
|
|
62
|
+
const iosDecls = await parseFile(resolvePlatformIndex('app-ios', module, options), options);
|
|
63
|
+
const androidDecls = await parseFile(resolvePlatformIndex('app-android', module, options), options);
|
|
64
|
+
// 优先使用 app-ios,因为 app-ios 平台函数类型需要正确的参数列表
|
|
65
|
+
const decls = mergeDecls(androidDecls, iosDecls);
|
|
66
|
+
// 如果没有平台特有,查找 root index.uts
|
|
67
|
+
if (!decls.length) {
|
|
68
|
+
return await parseFile(resolveRootIndex(module, options), options);
|
|
69
|
+
}
|
|
70
|
+
return decls;
|
|
71
|
+
}
|
|
72
|
+
function mergeDecls(from, to) {
|
|
73
|
+
from.forEach((item) => {
|
|
74
|
+
if (item.type === 'Class') {
|
|
75
|
+
if (!to.find((toItem) => toItem.type === 'Class' && toItem.cls === item.cls)) {
|
|
76
|
+
to.push(item);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (item.type === 'FunctionDeclaration') {
|
|
80
|
+
if (!to.find((toItem) => toItem.type === 'FunctionDeclaration' &&
|
|
81
|
+
toItem.method === item.method)) {
|
|
82
|
+
to.push(item);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (item.type === 'VariableDeclaration' &&
|
|
86
|
+
item.declarations.length === 1) {
|
|
87
|
+
if (!to.find((toItem) => {
|
|
88
|
+
if (toItem.type === 'VariableDeclaration' &&
|
|
89
|
+
toItem.declarations.length === 1) {
|
|
90
|
+
const toDecl = toItem.declarations[0].id;
|
|
91
|
+
const decl = item.declarations[0].id;
|
|
92
|
+
return (toDecl.type === 'Identifier' &&
|
|
93
|
+
decl.type === 'Identifier' &&
|
|
94
|
+
toDecl.value === decl.value);
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
})) {
|
|
98
|
+
to.push(item);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return to;
|
|
103
|
+
}
|
|
104
|
+
async function parseFile(filename, options) {
|
|
105
|
+
if (filename) {
|
|
106
|
+
return parseCode(fs_1.default.readFileSync(filename, 'utf8'), options.namespace);
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
async function parseCode(code, namespace) {
|
|
111
|
+
// 懒加载 uts 编译器
|
|
112
|
+
// eslint-disable-next-line no-restricted-globals
|
|
113
|
+
const { parse } = require('@dcloudio/uts');
|
|
114
|
+
const ast = await parse(code, { noColor: (0, shared_1.isInHBuilderX)() });
|
|
115
|
+
return parseAst(ast, (0, utils_1.createResolveTypeReferenceName)(namespace, ast));
|
|
116
|
+
}
|
|
117
|
+
function parseAst({ body }, resolveTypeReferenceName) {
|
|
118
|
+
const decls = [];
|
|
119
|
+
body.forEach((item) => {
|
|
120
|
+
if (item.type === 'ExportDeclaration') {
|
|
121
|
+
const decl = item.declaration;
|
|
122
|
+
switch (decl.type) {
|
|
123
|
+
case 'FunctionDeclaration':
|
|
124
|
+
decls.push(genFunctionDeclaration(decl, resolveTypeReferenceName, false));
|
|
125
|
+
break;
|
|
126
|
+
case 'ClassDeclaration':
|
|
127
|
+
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, false));
|
|
128
|
+
break;
|
|
129
|
+
case 'VariableDeclaration':
|
|
130
|
+
const varDecl = genVariableDeclaration(decl);
|
|
131
|
+
if (varDecl) {
|
|
132
|
+
decls.push(varDecl);
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (item.type === 'ExportDefaultDeclaration') {
|
|
138
|
+
const decl = item.decl;
|
|
139
|
+
if (decl.type === 'ClassExpression') {
|
|
140
|
+
if (decl.identifier) {
|
|
141
|
+
// export default class test{}
|
|
142
|
+
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, true));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (decl.type === 'FunctionExpression') {
|
|
146
|
+
if (decl.identifier) {
|
|
147
|
+
decls.push(genFunctionDeclaration(decl, resolveTypeReferenceName, true));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return decls;
|
|
153
|
+
}
|
|
154
|
+
function isReturnPromise(anno) {
|
|
155
|
+
if (!anno) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const { typeAnnotation } = anno;
|
|
159
|
+
return (typeAnnotation.type === 'TsTypeReference' &&
|
|
160
|
+
typeAnnotation.typeName.type === 'Identifier' &&
|
|
161
|
+
typeAnnotation.typeName.value === 'Promise');
|
|
162
|
+
}
|
|
163
|
+
function genProxyFunction(method, async, params, isDefault = false) {
|
|
164
|
+
return { type: 'FunctionDeclaration', method, async, params, isDefault };
|
|
165
|
+
}
|
|
166
|
+
function genProxyClass(cls, options, isDefault = false) {
|
|
167
|
+
return { type: 'Class', cls, options, isDefault };
|
|
168
|
+
}
|
|
169
|
+
function resolveIdentifierType(ident, resolveTypeReferenceName) {
|
|
170
|
+
if (ident.typeAnnotation) {
|
|
171
|
+
const { typeAnnotation } = ident.typeAnnotation;
|
|
172
|
+
if (typeAnnotation.type === 'TsKeywordType') {
|
|
173
|
+
return typeAnnotation.kind;
|
|
174
|
+
}
|
|
175
|
+
else if (typeAnnotation.type === 'TsFunctionType') {
|
|
176
|
+
return 'UTSCallback';
|
|
177
|
+
}
|
|
178
|
+
else if (typeAnnotation.type === 'TsTypeReference' &&
|
|
179
|
+
typeAnnotation.typeName.type === 'Identifier') {
|
|
180
|
+
return resolveTypeReferenceName(typeAnnotation.typeName.value);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
function resolveFunctionParams(params, resolveTypeReferenceName) {
|
|
186
|
+
const result = [];
|
|
187
|
+
params.forEach(({ pat }) => {
|
|
188
|
+
if (pat.type === 'Identifier') {
|
|
189
|
+
result.push({
|
|
190
|
+
name: pat.value,
|
|
191
|
+
type: resolveIdentifierType(pat, resolveTypeReferenceName),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
result.push({ name: '', type: '' });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
function genFunctionDeclaration(decl, resolveTypeReferenceName, isDefault = false) {
|
|
201
|
+
return genProxyFunction(decl.identifier.value, decl.async || isReturnPromise(decl.returnType), resolveFunctionParams(decl.params, resolveTypeReferenceName), isDefault);
|
|
202
|
+
}
|
|
203
|
+
function genClassDeclaration(decl, resolveTypeReferenceName, isDefault = false) {
|
|
204
|
+
const cls = decl.identifier.value;
|
|
205
|
+
const constructor = { params: [] };
|
|
206
|
+
const methods = {};
|
|
207
|
+
const staticMethods = {};
|
|
208
|
+
const props = [];
|
|
209
|
+
const staticProps = [];
|
|
210
|
+
decl.body.forEach((item) => {
|
|
211
|
+
if (item.type === 'Constructor') {
|
|
212
|
+
constructor.params = resolveFunctionParams(item.params, resolveTypeReferenceName);
|
|
213
|
+
}
|
|
214
|
+
else if (item.type === 'ClassMethod') {
|
|
215
|
+
if (item.key.type === 'Identifier') {
|
|
216
|
+
const name = item.key.value;
|
|
217
|
+
const value = {
|
|
218
|
+
async: item.function.async || isReturnPromise(item.function.returnType),
|
|
219
|
+
params: resolveFunctionParams(item.function.params, resolveTypeReferenceName),
|
|
220
|
+
};
|
|
221
|
+
if (item.isStatic) {
|
|
222
|
+
staticMethods[name] = value;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
methods[name] = value;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else if (item.type === 'ClassProperty') {
|
|
230
|
+
if (item.key.type === 'Identifier') {
|
|
231
|
+
if (item.isStatic) {
|
|
232
|
+
staticProps.push(item.key.value);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
props.push(item.key.value);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return genProxyClass(cls, { constructor, methods, staticMethods, props, staticProps }, isDefault);
|
|
241
|
+
}
|
|
242
|
+
function genInitCode(expr) {
|
|
243
|
+
switch (expr.type) {
|
|
244
|
+
case 'BooleanLiteral':
|
|
245
|
+
return expr.value + '';
|
|
246
|
+
case 'NumericLiteral':
|
|
247
|
+
return expr.value + '';
|
|
248
|
+
case 'StringLiteral':
|
|
249
|
+
return expr.value;
|
|
250
|
+
}
|
|
251
|
+
return '';
|
|
252
|
+
}
|
|
253
|
+
function genVariableDeclaration(decl) {
|
|
254
|
+
// 目前仅支持 const 的 boolean,number,string
|
|
255
|
+
const lits = ['BooleanLiteral', 'NumericLiteral', 'StringLiteral'];
|
|
256
|
+
if (decl.kind === 'const' &&
|
|
257
|
+
!decl.declarations.find((d) => {
|
|
258
|
+
if (d.id.type !== 'Identifier') {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
if (!d.init) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
const type = d.init.type;
|
|
265
|
+
if (!lits.includes(type)) {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
})) {
|
|
270
|
+
return decl;
|
|
271
|
+
}
|
|
272
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { runKotlinProd, runKotlinDev } from './kotlin';
|
|
2
|
+
import { runSwiftProd, runSwiftDev } from './swift';
|
|
3
|
+
export { genProxyCode, resolvePlatformIndex, resolveRootIndex } from './code';
|
|
4
|
+
export { resolvePackage } from './utils';
|
|
5
|
+
export declare function getCompiler(type: 'kotlin' | 'swift'): {
|
|
6
|
+
runProd: typeof runSwiftProd;
|
|
7
|
+
runDev: typeof runSwiftDev;
|
|
8
|
+
} | {
|
|
9
|
+
runProd: typeof runKotlinProd;
|
|
10
|
+
runDev: typeof runKotlinDev;
|
|
11
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompiler = exports.resolvePackage = exports.resolveRootIndex = exports.resolvePlatformIndex = exports.genProxyCode = void 0;
|
|
4
|
+
const kotlin_1 = require("./kotlin");
|
|
5
|
+
const swift_1 = require("./swift");
|
|
6
|
+
var code_1 = require("./code");
|
|
7
|
+
Object.defineProperty(exports, "genProxyCode", { enumerable: true, get: function () { return code_1.genProxyCode; } });
|
|
8
|
+
Object.defineProperty(exports, "resolvePlatformIndex", { enumerable: true, get: function () { return code_1.resolvePlatformIndex; } });
|
|
9
|
+
Object.defineProperty(exports, "resolveRootIndex", { enumerable: true, get: function () { return code_1.resolveRootIndex; } });
|
|
10
|
+
var utils_1 = require("./utils");
|
|
11
|
+
Object.defineProperty(exports, "resolvePackage", { enumerable: true, get: function () { return utils_1.resolvePackage; } });
|
|
12
|
+
function getCompiler(type) {
|
|
13
|
+
if (type === 'swift') {
|
|
14
|
+
return {
|
|
15
|
+
runProd: swift_1.runSwiftProd,
|
|
16
|
+
runDev: swift_1.runSwiftDev,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
runProd: kotlin_1.runKotlinProd,
|
|
21
|
+
runDev: kotlin_1.runKotlinDev,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.getCompiler = getCompiler;
|
package/dist/kotlin.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Module } from '../types/types';
|
|
2
|
+
export declare function createKotlinResolveTypeReferenceName(_namespace: string, _ast: Module): (name: string) => string;
|
|
3
|
+
export declare function runKotlinProd(filename: string): Promise<void>;
|
|
4
|
+
export declare function runKotlinDev(filename: string): Promise<string | undefined>;
|
package/dist/kotlin.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runKotlinDev = exports.runKotlinProd = exports.createKotlinResolveTypeReferenceName = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
11
|
+
const fast_glob_1 = require("fast-glob");
|
|
12
|
+
const shared_1 = require("@vue/shared");
|
|
13
|
+
const shared_2 = require("./shared");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
function createKotlinResolveTypeReferenceName(_namespace, _ast) {
|
|
16
|
+
return (name) => name;
|
|
17
|
+
}
|
|
18
|
+
exports.createKotlinResolveTypeReferenceName = createKotlinResolveTypeReferenceName;
|
|
19
|
+
function parseKotlinPackage(filename) {
|
|
20
|
+
const res = (0, utils_1.resolvePackage)(filename);
|
|
21
|
+
if (!res) {
|
|
22
|
+
return { package: '' };
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
package: 'uts.sdk.' + (res.is_uni_modules ? 'modules.' : '') + res.name,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function runKotlinProd(filename) {
|
|
29
|
+
// 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
|
|
30
|
+
if (filename.includes('app-ios')) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await compile(filename);
|
|
34
|
+
(0, utils_1.genUTSPlatformResource)(filename, {
|
|
35
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
36
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
37
|
+
platform: 'app-android',
|
|
38
|
+
extname: '.kt',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.runKotlinProd = runKotlinProd;
|
|
42
|
+
async function runKotlinDev(filename) {
|
|
43
|
+
// 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
|
|
44
|
+
if (filename.includes('app-ios')) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
await compile(filename);
|
|
48
|
+
const kotlinFile = (0, utils_1.resolveUTSPlatformFile)(filename, {
|
|
49
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
50
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
51
|
+
platform: 'app-android',
|
|
52
|
+
extname: '.kt',
|
|
53
|
+
});
|
|
54
|
+
// 开发模式下,需要生成 dex
|
|
55
|
+
if (fs_extra_1.default.existsSync(kotlinFile)) {
|
|
56
|
+
const compilerServer = getCompilerServer();
|
|
57
|
+
if (!compilerServer) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const { getDefaultJar, getKotlincHome, compile, checkDependencies } = compilerServer;
|
|
61
|
+
if (checkDependencies) {
|
|
62
|
+
await checkDeps(filename, checkDependencies);
|
|
63
|
+
}
|
|
64
|
+
// time = Date.now()
|
|
65
|
+
const jarFile = resolveJarPath(kotlinFile);
|
|
66
|
+
const options = {
|
|
67
|
+
kotlinc: resolveKotlincArgs(kotlinFile, getKotlincHome(), getDefaultJar().concat(resolveLibs(filename))),
|
|
68
|
+
d8: resolveD8Args(jarFile),
|
|
69
|
+
sourceRoot: process.env.UNI_INPUT_DIR,
|
|
70
|
+
sourceMapPath: resolveSourceMapFile(process.env.UNI_OUTPUT_DIR, kotlinFile),
|
|
71
|
+
};
|
|
72
|
+
const res = await compile(options, process.env.UNI_INPUT_DIR);
|
|
73
|
+
// console.log('dex compile time: ' + (Date.now() - time) + 'ms')
|
|
74
|
+
if (res) {
|
|
75
|
+
try {
|
|
76
|
+
fs_extra_1.default.unlinkSync(jarFile);
|
|
77
|
+
// 短期内先不删除,方便排查问题
|
|
78
|
+
// fs.unlinkSync(kotlinFile)
|
|
79
|
+
}
|
|
80
|
+
catch (e) { }
|
|
81
|
+
const dexFile = resolveDexFile(jarFile);
|
|
82
|
+
if (fs_extra_1.default.existsSync(dexFile)) {
|
|
83
|
+
return (0, shared_2.normalizePath)(path_1.default.relative(process.env.UNI_OUTPUT_DIR, dexFile));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.runKotlinDev = runKotlinDev;
|
|
89
|
+
function checkDeps(filename, checkDependencies) {
|
|
90
|
+
const configJsonFile = resolveConfigJsonFile(filename);
|
|
91
|
+
if (configJsonFile && hasDeps(configJsonFile)) {
|
|
92
|
+
return checkDependencies(configJsonFile).then(({ code, msg, data }) => {
|
|
93
|
+
if (code > 0) {
|
|
94
|
+
throw msg;
|
|
95
|
+
}
|
|
96
|
+
return data;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return Promise.resolve([]);
|
|
100
|
+
}
|
|
101
|
+
function hasDeps(configJsonFile) {
|
|
102
|
+
const deps = (0, shared_2.parseJson)(configJsonFile).dependencies || [];
|
|
103
|
+
if ((0, shared_1.isArray)(deps) && deps.length) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
function resolveConfigJsonFile(filename) {
|
|
109
|
+
const configJsonFile = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'config.json');
|
|
110
|
+
if (fs_extra_1.default.existsSync(configJsonFile)) {
|
|
111
|
+
return configJsonFile;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function resolveSourceMapFile(outputDir, kotlinFile) {
|
|
115
|
+
return (path_1.default.resolve((0, shared_2.resolveSourceMapPath)(), path_1.default.relative(outputDir, kotlinFile)) +
|
|
116
|
+
'.map');
|
|
117
|
+
}
|
|
118
|
+
async function compile(filename) {
|
|
119
|
+
if (!process.env.UNI_HBUILDERX_PLUGINS) {
|
|
120
|
+
return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found');
|
|
121
|
+
}
|
|
122
|
+
const { bundle, UtsTarget } = (0, utils_1.getUtsCompiler)();
|
|
123
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
124
|
+
const outputDir = process.env.UNI_OUTPUT_DIR;
|
|
125
|
+
// let time = Date.now()
|
|
126
|
+
await bundle(UtsTarget.KOTLIN, {
|
|
127
|
+
input: {
|
|
128
|
+
root: inputDir,
|
|
129
|
+
filename,
|
|
130
|
+
},
|
|
131
|
+
output: {
|
|
132
|
+
isPlugin: true,
|
|
133
|
+
outDir: outputDir,
|
|
134
|
+
package: parseKotlinPackage(filename).package,
|
|
135
|
+
sourceMap: (0, utils_1.resolveUTSSourceMapPath)(filename),
|
|
136
|
+
extname: 'kt',
|
|
137
|
+
imports: [
|
|
138
|
+
'kotlinx.coroutines.async',
|
|
139
|
+
'kotlinx.coroutines.CoroutineScope',
|
|
140
|
+
'kotlinx.coroutines.Deferred',
|
|
141
|
+
'kotlinx.coroutines.Dispatchers',
|
|
142
|
+
'io.dcloud.uts.*',
|
|
143
|
+
],
|
|
144
|
+
logFilename: true,
|
|
145
|
+
noColor: (0, shared_2.isInHBuilderX)(),
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
(0, utils_1.moveRootIndexSourceMap)(filename, {
|
|
149
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
150
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
151
|
+
platform: 'app-android',
|
|
152
|
+
extname: '.kt',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function resolveKotlincArgs(filename, kotlinc, jars) {
|
|
156
|
+
return [
|
|
157
|
+
filename,
|
|
158
|
+
'-cp',
|
|
159
|
+
resolveClassPath(jars),
|
|
160
|
+
'-d',
|
|
161
|
+
resolveJarPath(filename),
|
|
162
|
+
'-kotlin-home',
|
|
163
|
+
kotlinc,
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
function resolveD8Args(filename) {
|
|
167
|
+
return [
|
|
168
|
+
filename,
|
|
169
|
+
'--no-desugaring',
|
|
170
|
+
'--min-api',
|
|
171
|
+
'19',
|
|
172
|
+
'--output',
|
|
173
|
+
resolveDexPath(filename),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
function resolveLibs(filename) {
|
|
177
|
+
const libsPath = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'libs');
|
|
178
|
+
const libs = [];
|
|
179
|
+
if (fs_extra_1.default.existsSync(libsPath)) {
|
|
180
|
+
libs.push(...(0, fast_glob_1.sync)('*.jar', { cwd: libsPath, absolute: true }));
|
|
181
|
+
const zips = (0, fast_glob_1.sync)('*.aar', { cwd: libsPath });
|
|
182
|
+
zips.forEach((name) => {
|
|
183
|
+
const outputPath = resolveAndroidArchiveOutputPath(name);
|
|
184
|
+
if (!fs_extra_1.default.existsSync(outputPath)) {
|
|
185
|
+
// 解压
|
|
186
|
+
const zip = new adm_zip_1.default(path_1.default.resolve(libsPath, name));
|
|
187
|
+
zip.extractAllTo(outputPath, true);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
if (zips.length) {
|
|
191
|
+
libs.push(...(0, fast_glob_1.sync)('*/*.jar', {
|
|
192
|
+
cwd: resolveAndroidArchiveOutputPath(),
|
|
193
|
+
absolute: true,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return libs;
|
|
198
|
+
}
|
|
199
|
+
function resolveAndroidArchiveOutputPath(aar) {
|
|
200
|
+
return path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../.uts/aar', aar ? aar.replace('.aar', '') : '');
|
|
201
|
+
}
|
|
202
|
+
function resolveDexFile(jarFile) {
|
|
203
|
+
return (0, shared_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(jarFile), 'classes.dex'));
|
|
204
|
+
}
|
|
205
|
+
function resolveDexPath(filename) {
|
|
206
|
+
return path_1.default.dirname(filename);
|
|
207
|
+
}
|
|
208
|
+
function resolveJarPath(filename) {
|
|
209
|
+
return filename.replace(path_1.default.extname(filename), '.jar');
|
|
210
|
+
}
|
|
211
|
+
function resolveClassPath(jars) {
|
|
212
|
+
return jars.join(os_1.default.platform() === 'win32' ? ';' : ':');
|
|
213
|
+
}
|
|
214
|
+
function getCompilerServer() {
|
|
215
|
+
const compilerServerPath = path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-runextension/out/main.js');
|
|
216
|
+
if (fs_extra_1.default.existsSync(compilerServerPath)) {
|
|
217
|
+
// eslint-disable-next-line no-restricted-globals
|
|
218
|
+
return require(compilerServerPath);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
if ((0, shared_2.runByHBuilderX)()) {
|
|
222
|
+
(0, shared_2.installHBuilderXPlugin)('uniapp-runextension');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
console.error(compilerServerPath + ' is not found');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function parseJson(jsonStr: string): any;
|
|
2
|
+
export declare function once<T extends (...args: any[]) => any>(fn: T, ctx?: unknown): T;
|
|
3
|
+
export declare const runByHBuilderX: () => boolean;
|
|
4
|
+
export declare const isInHBuilderX: () => boolean;
|
|
5
|
+
export declare function resolveSourceMapPath(outputDir?: string, platform?: UniApp.PLATFORM): string;
|
|
6
|
+
export declare const isWindows: boolean;
|
|
7
|
+
export declare function normalizePath(id: string): string;
|
|
8
|
+
export declare function installHBuilderXPlugin(plugin: string): void;
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.installHBuilderXPlugin = exports.normalizePath = exports.isWindows = exports.resolveSourceMapPath = exports.isInHBuilderX = exports.runByHBuilderX = exports.once = exports.parseJson = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
10
|
+
function parseJson(jsonStr) {
|
|
11
|
+
return (0, jsonc_parser_1.parse)(jsonStr);
|
|
12
|
+
}
|
|
13
|
+
exports.parseJson = parseJson;
|
|
14
|
+
function once(fn, ctx = null) {
|
|
15
|
+
let res;
|
|
16
|
+
return ((...args) => {
|
|
17
|
+
if (fn) {
|
|
18
|
+
res = fn.apply(ctx, args);
|
|
19
|
+
fn = null;
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.once = once;
|
|
25
|
+
exports.runByHBuilderX = once(() => {
|
|
26
|
+
return !!process.env.UNI_HBUILDERX_PLUGINS && !!process.env.RUN_BY_HBUILDERX;
|
|
27
|
+
});
|
|
28
|
+
exports.isInHBuilderX = once(() => {
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line no-restricted-globals
|
|
31
|
+
const { name } = require(path_1.default.resolve(process.cwd(), '../about/package.json'));
|
|
32
|
+
if (name === 'about') {
|
|
33
|
+
process.env.UNI_HBUILDERX_PLUGINS = path_1.default.resolve(process.cwd(), '..');
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
// console.error(e)
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
});
|
|
42
|
+
function resolveSourceMapPath(outputDir, platform) {
|
|
43
|
+
return path_1.default.resolve(outputDir || process.env.UNI_OUTPUT_DIR, '../.sourcemap/' +
|
|
44
|
+
(platform || process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM));
|
|
45
|
+
}
|
|
46
|
+
exports.resolveSourceMapPath = resolveSourceMapPath;
|
|
47
|
+
exports.isWindows = os_1.default.platform() === 'win32';
|
|
48
|
+
function normalizePath(id) {
|
|
49
|
+
return exports.isWindows ? id.replace(/\\/g, '/') : id;
|
|
50
|
+
}
|
|
51
|
+
exports.normalizePath = normalizePath;
|
|
52
|
+
function supportAutoInstallPlugin() {
|
|
53
|
+
return !!process.env.HX_Version;
|
|
54
|
+
}
|
|
55
|
+
function installHBuilderXPlugin(plugin) {
|
|
56
|
+
if (!supportAutoInstallPlugin()) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return console.error(`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`);
|
|
60
|
+
}
|
|
61
|
+
exports.installHBuilderXPlugin = installHBuilderXPlugin;
|
package/dist/swift.d.ts
ADDED
package/dist/swift.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSwiftDev = exports.runSwiftProd = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const shared_2 = require("./shared");
|
|
7
|
+
function parseSwiftPackage(filename) {
|
|
8
|
+
const res = (0, utils_1.resolvePackage)(filename);
|
|
9
|
+
if (!res) {
|
|
10
|
+
return {
|
|
11
|
+
namespace: '',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const namespace = 'UTSSDK' + (res.is_uni_modules ? 'Modules' : '') + (0, shared_1.capitalize)(res.name);
|
|
15
|
+
return {
|
|
16
|
+
namespace,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function runSwiftProd(filename) {
|
|
20
|
+
// 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
|
|
21
|
+
if (filename.includes('app-android')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await compile(filename);
|
|
25
|
+
(0, utils_1.genUTSPlatformResource)(filename, {
|
|
26
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
27
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
28
|
+
platform: 'app-ios',
|
|
29
|
+
extname: '.swift',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.runSwiftProd = runSwiftProd;
|
|
33
|
+
async function runSwiftDev(_filename) { }
|
|
34
|
+
exports.runSwiftDev = runSwiftDev;
|
|
35
|
+
async function compile(filename) {
|
|
36
|
+
if (!process.env.UNI_HBUILDERX_PLUGINS) {
|
|
37
|
+
return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found');
|
|
38
|
+
}
|
|
39
|
+
const { bundle, UtsTarget } = (0, utils_1.getUtsCompiler)();
|
|
40
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
41
|
+
const outputDir = process.env.UNI_OUTPUT_DIR;
|
|
42
|
+
// let time = Date.now()
|
|
43
|
+
await bundle(UtsTarget.SWIFT, {
|
|
44
|
+
input: {
|
|
45
|
+
root: inputDir,
|
|
46
|
+
filename,
|
|
47
|
+
},
|
|
48
|
+
output: {
|
|
49
|
+
isPlugin: true,
|
|
50
|
+
outDir: outputDir,
|
|
51
|
+
package: parseSwiftPackage(filename).namespace,
|
|
52
|
+
sourceMap: (0, utils_1.resolveUTSSourceMapPath)(filename),
|
|
53
|
+
extname: 'swift',
|
|
54
|
+
imports: ['DCUTSPlugin'],
|
|
55
|
+
logFilename: true,
|
|
56
|
+
noColor: (0, shared_2.isInHBuilderX)(),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
(0, utils_1.moveRootIndexSourceMap)(filename, {
|
|
60
|
+
inputDir: process.env.UNI_INPUT_DIR,
|
|
61
|
+
outputDir: process.env.UNI_OUTPUT_DIR,
|
|
62
|
+
platform: 'app-ios',
|
|
63
|
+
extname: '.swift',
|
|
64
|
+
});
|
|
65
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { parse, bundle, UtsTarget } from '@dcloudio/uts';
|
|
2
|
+
import { Module } from '../types/types';
|
|
3
|
+
export declare function resolveUTSSourceMapPath(_filename: string): string;
|
|
4
|
+
export declare function getUtsCompiler(): {
|
|
5
|
+
parse: typeof parse;
|
|
6
|
+
bundle: typeof bundle;
|
|
7
|
+
UtsTarget: typeof UtsTarget;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolvePackage(filename: string): {
|
|
10
|
+
is_uni_modules: boolean;
|
|
11
|
+
name: string;
|
|
12
|
+
namespace: string;
|
|
13
|
+
} | undefined;
|
|
14
|
+
export interface UTSPlatformResourceOptions {
|
|
15
|
+
inputDir: string;
|
|
16
|
+
outputDir: string;
|
|
17
|
+
platform: typeof process.env.UNI_UTS_PLATFORM;
|
|
18
|
+
extname: '.kt' | '.swift';
|
|
19
|
+
}
|
|
20
|
+
export declare function genUTSPlatformResource(filename: string, options: UTSPlatformResourceOptions): void;
|
|
21
|
+
export declare function moveRootIndexSourceMap(filename: string, { inputDir, outputDir, platform, extname }: UTSPlatformResourceOptions): void;
|
|
22
|
+
export declare function isRootIndex(filename: string, platform: typeof process.env.UNI_UTS_PLATFORM): boolean;
|
|
23
|
+
export declare function resolveAndroidDir(filename: string): string;
|
|
24
|
+
export declare function resolveUTSPlatformFile(filename: string, { inputDir, outputDir, platform, extname }: UTSPlatformResourceOptions): string;
|
|
25
|
+
export declare function createResolveTypeReferenceName(namespace: string, ast: Module): (name: string) => string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createResolveTypeReferenceName = exports.resolveUTSPlatformFile = exports.resolveAndroidDir = exports.isRootIndex = exports.moveRootIndexSourceMap = exports.genUTSPlatformResource = exports.resolvePackage = exports.getUtsCompiler = exports.resolveUTSSourceMapPath = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const shared_1 = require("@vue/shared");
|
|
10
|
+
const shared_2 = require("./shared");
|
|
11
|
+
function resolveUTSSourceMapPath(_filename) {
|
|
12
|
+
return (0, shared_2.resolveSourceMapPath)();
|
|
13
|
+
}
|
|
14
|
+
exports.resolveUTSSourceMapPath = resolveUTSSourceMapPath;
|
|
15
|
+
function getUtsCompiler() {
|
|
16
|
+
// eslint-disable-next-line no-restricted-globals
|
|
17
|
+
return require('@dcloudio/uts');
|
|
18
|
+
}
|
|
19
|
+
exports.getUtsCompiler = getUtsCompiler;
|
|
20
|
+
function resolvePackage(filename) {
|
|
21
|
+
const parts = (0, shared_2.normalizePath)(filename).split('/');
|
|
22
|
+
const isUniModules = parts.includes('uni_modules');
|
|
23
|
+
const index = isUniModules
|
|
24
|
+
? parts.findIndex((part) => part === 'uni_modules')
|
|
25
|
+
: parts.findIndex((part) => part === 'utssdk');
|
|
26
|
+
if (index > -1) {
|
|
27
|
+
const name = (0, shared_1.camelize)(parts[index + 1]);
|
|
28
|
+
return {
|
|
29
|
+
is_uni_modules: isUniModules,
|
|
30
|
+
name,
|
|
31
|
+
namespace: 'UTSSDK' + (isUniModules ? 'Modules' : '') + (0, shared_1.capitalize)(name),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.resolvePackage = resolvePackage;
|
|
36
|
+
function genUTSPlatformResource(filename, options) {
|
|
37
|
+
const platformFile = resolveUTSPlatformFile(filename, options);
|
|
38
|
+
const { platform } = options;
|
|
39
|
+
const utsInputDir = resolveUTSPlatformDir(filename, platform);
|
|
40
|
+
const utsOutputDir = resolveUTSPlatformDir(platformFile, platform);
|
|
41
|
+
// 拷贝所有非uts文件及目录
|
|
42
|
+
if (fs_extra_1.default.existsSync(utsInputDir)) {
|
|
43
|
+
fs_extra_1.default.copySync(utsInputDir, utsOutputDir, {
|
|
44
|
+
filter(src) {
|
|
45
|
+
return path_1.default.extname(src) !== '.uts';
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// 生产模式下,需要将生成的平台文件转移到 src 下
|
|
50
|
+
const srcDir = path_1.default.resolve(utsOutputDir, 'src');
|
|
51
|
+
if (!fs_extra_1.default.existsSync(srcDir)) {
|
|
52
|
+
fs_extra_1.default.mkdirSync(srcDir);
|
|
53
|
+
}
|
|
54
|
+
if (fs_extra_1.default.existsSync(platformFile)) {
|
|
55
|
+
fs_extra_1.default.moveSync(platformFile, path_1.default.resolve(utsOutputDir, 'src/index' + options.extname), {
|
|
56
|
+
overwrite: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.genUTSPlatformResource = genUTSPlatformResource;
|
|
61
|
+
function moveRootIndexSourceMap(filename, { inputDir, outputDir, platform, extname }) {
|
|
62
|
+
if (isRootIndex(filename, platform)) {
|
|
63
|
+
const sourceMapFilename = path_1.default
|
|
64
|
+
.resolve(resolveUTSSourceMapPath(filename), path_1.default.relative(inputDir, filename))
|
|
65
|
+
.replace(path_1.default.extname(filename), extname + '.map');
|
|
66
|
+
if (fs_extra_1.default.existsSync(sourceMapFilename)) {
|
|
67
|
+
const newSourceMapFilename = path_1.default.resolve(path_1.default.dirname(sourceMapFilename), platform, path_1.default.basename(sourceMapFilename));
|
|
68
|
+
fs_extra_1.default.moveSync(sourceMapFilename, newSourceMapFilename, {
|
|
69
|
+
overwrite: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.moveRootIndexSourceMap = moveRootIndexSourceMap;
|
|
75
|
+
function isRootIndex(filename, platform) {
|
|
76
|
+
return path_1.default.basename(path_1.default.dirname(filename)) !== platform;
|
|
77
|
+
}
|
|
78
|
+
exports.isRootIndex = isRootIndex;
|
|
79
|
+
function resolveAndroidDir(filename) {
|
|
80
|
+
return resolveUTSPlatformDir(filename, 'app-android');
|
|
81
|
+
}
|
|
82
|
+
exports.resolveAndroidDir = resolveAndroidDir;
|
|
83
|
+
function resolveUTSPlatformDir(filename, platform) {
|
|
84
|
+
const maybePlatformDir = path_1.default.dirname(filename);
|
|
85
|
+
if (isRootIndex(filename, platform)) {
|
|
86
|
+
return path_1.default.join(maybePlatformDir, platform);
|
|
87
|
+
}
|
|
88
|
+
return maybePlatformDir;
|
|
89
|
+
}
|
|
90
|
+
function resolveUTSPlatformFile(filename, { inputDir, outputDir, platform, extname }) {
|
|
91
|
+
let platformFile = path_1.default
|
|
92
|
+
.resolve(outputDir, path_1.default.relative(inputDir, filename))
|
|
93
|
+
.replace(path_1.default.extname(filename), extname);
|
|
94
|
+
// 如果是根目录的 index.uts 编译出来的 index.kt,则移动到平台目录下
|
|
95
|
+
if (isRootIndex(filename, platform)) {
|
|
96
|
+
if (fs_extra_1.default.existsSync(platformFile)) {
|
|
97
|
+
const newPlatformFile = path_1.default.resolve(path_1.default.dirname(platformFile), platform + '/index' + extname);
|
|
98
|
+
fs_extra_1.default.moveSync(platformFile, newPlatformFile, {
|
|
99
|
+
overwrite: true,
|
|
100
|
+
});
|
|
101
|
+
platformFile = newPlatformFile;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return platformFile;
|
|
105
|
+
}
|
|
106
|
+
exports.resolveUTSPlatformFile = resolveUTSPlatformFile;
|
|
107
|
+
function resolveTypeAliasDeclNames(items) {
|
|
108
|
+
const names = [];
|
|
109
|
+
items.forEach((item) => {
|
|
110
|
+
if (item.type === 'TsTypeAliasDeclaration') {
|
|
111
|
+
names.push(item.id.value);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return names;
|
|
115
|
+
}
|
|
116
|
+
function createResolveTypeReferenceName(namespace, ast) {
|
|
117
|
+
const names = resolveTypeAliasDeclNames(ast.body);
|
|
118
|
+
return (name) => {
|
|
119
|
+
if (names.includes(name)) {
|
|
120
|
+
return namespace + (0, shared_1.capitalize)(name);
|
|
121
|
+
}
|
|
122
|
+
return name;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
exports.createResolveTypeReferenceName = createResolveTypeReferenceName;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/uni-uts-v1",
|
|
3
|
+
"version": "3.0.0-alpha-3060720221018004",
|
|
4
|
+
"description": "uni-uts-v1",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
13
|
+
"directory": "packages/uni-uts-v1"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@dcloudio/uts": "3.0.0-alpha-3060720221018004",
|
|
21
|
+
"@vue/shared": "3.2.41",
|
|
22
|
+
"adm-zip": "^0.5.9",
|
|
23
|
+
"execa": "^5.1.1",
|
|
24
|
+
"fast-glob": "^3.2.11",
|
|
25
|
+
"fs-extra": "^10.0.0",
|
|
26
|
+
"jsonc-parser": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/adm-zip": "^0.5.0",
|
|
30
|
+
"@types/fs-extra": "^9.0.13"
|
|
31
|
+
}
|
|
32
|
+
}
|