@aiot-toolkit/aiotpack 2.0.6-beta.8 → 2.0.6-beta.9
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
2
|
import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
3
4
|
/**
|
|
4
5
|
* JsLoader
|
|
5
6
|
*/
|
|
6
7
|
declare class JsLoader implements ILoader {
|
|
7
8
|
context: IFileLaneContext;
|
|
8
9
|
compilerOption: IJavascriptCompileOption;
|
|
10
|
+
compilation: FileLaneCompilation;
|
|
9
11
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
10
12
|
}
|
|
11
13
|
export default JsLoader;
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _parser = require("@aiot-toolkit/parser");
|
|
8
8
|
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
9
|
+
var _UxLoaderUtils = _interopRequireDefault(require("../../utils/ux/UxLoaderUtils"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
11
|
/**
|
|
10
12
|
* JsLoader
|
|
11
13
|
*/
|
|
@@ -27,11 +29,18 @@ class JsLoader {
|
|
|
27
29
|
projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
|
|
28
30
|
onLog
|
|
29
31
|
};
|
|
32
|
+
const scriptTree = await new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
|
|
33
|
+
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
+
}, []);
|
|
35
|
+
const isService = _UxLoaderUtils.default.isServiceFile(item.path, {
|
|
36
|
+
compilation: this.compilation,
|
|
37
|
+
compilerOption: this.compilerOption,
|
|
38
|
+
context: this.context
|
|
39
|
+
});
|
|
40
|
+
const content = isService ? _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n') : scriptTree.targetTree.getFullText();
|
|
30
41
|
result.push({
|
|
31
42
|
path: item.path,
|
|
32
|
-
content
|
|
33
|
-
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
-
}, [])).targetTree.getFullText()
|
|
43
|
+
content
|
|
35
44
|
});
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -65,5 +65,11 @@ declare class UxLoaderUtils {
|
|
|
65
65
|
*/
|
|
66
66
|
static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
|
|
67
67
|
static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
|
|
68
|
+
static createServiceWrapper(appScriptTree: SourceFile): string[];
|
|
69
|
+
static isServiceFile(filePath: string, option: {
|
|
70
|
+
compilation: FileLaneCompilation;
|
|
71
|
+
context: IFileLaneContext;
|
|
72
|
+
compilerOption: IJavascriptCompileOption;
|
|
73
|
+
}): boolean;
|
|
68
74
|
}
|
|
69
75
|
export default UxLoaderUtils;
|
|
@@ -144,11 +144,13 @@ class UxLoaderUtils {
|
|
|
144
144
|
`;
|
|
145
145
|
}
|
|
146
146
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
147
|
-
const services = compilation['services'];
|
|
148
147
|
const scriptCode = appScriptTree.getText();
|
|
149
148
|
const hasScript = Boolean(scriptCode) && scriptCode !== '""';
|
|
150
|
-
const
|
|
151
|
-
|
|
149
|
+
const isService = UxLoaderUtils.isServiceFile(filePath, {
|
|
150
|
+
compilation,
|
|
151
|
+
context,
|
|
152
|
+
compilerOption
|
|
153
|
+
});
|
|
152
154
|
|
|
153
155
|
// script代码放在第三个位置不能变化,影响更新source map
|
|
154
156
|
const createAppWrapper = () => {
|
|
@@ -157,13 +159,10 @@ class UxLoaderUtils {
|
|
|
157
159
|
const createComponentWrapper = () => {
|
|
158
160
|
return [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}` : '', `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`, `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`, hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.template = $app_template$;`, `$app_exports$.default.style = $app_style$;`, `}`];
|
|
159
161
|
};
|
|
160
|
-
const createServiceWrapper = () => {
|
|
161
|
-
return ['', '', `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`, `$app_script$({}, $app_exports$, $app_require$);`, `module.exports = $app_exports$.default;`];
|
|
162
|
-
};
|
|
163
162
|
if (isAppUx) {
|
|
164
163
|
return createAppWrapper();
|
|
165
164
|
} else if (isService) {
|
|
166
|
-
return createServiceWrapper();
|
|
165
|
+
return UxLoaderUtils.createServiceWrapper(appScriptTree);
|
|
167
166
|
} else {
|
|
168
167
|
return createComponentWrapper();
|
|
169
168
|
}
|
|
@@ -392,5 +391,13 @@ class UxLoaderUtils {
|
|
|
392
391
|
static getReturnType(isPageUx) {
|
|
393
392
|
return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
|
|
394
393
|
}
|
|
394
|
+
static createServiceWrapper(appScriptTree) {
|
|
395
|
+
return ['', '', `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`, `$app_script$({}, $app_exports$, $app_require$);`, `module.exports = $app_exports$.default;`];
|
|
396
|
+
}
|
|
397
|
+
static isServiceFile(filePath, option) {
|
|
398
|
+
const services = option.compilation['services'];
|
|
399
|
+
const relativeFilePath = _path.default.relative(_path.default.join(option.context.projectPath, option.compilerOption.sourceRoot), filePath).replace(/\\/g, _path.default.posix.sep);
|
|
400
|
+
return services?.some(service => relativeFilePath.startsWith(service.path));
|
|
401
|
+
}
|
|
395
402
|
}
|
|
396
403
|
var _default = exports.default = UxLoaderUtils;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.6-beta.
|
|
3
|
+
"version": "2.0.6-beta.9",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.0.6-beta.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.6-beta.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.6-beta.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.6-beta.9",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.6-beta.9",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.6-beta.9",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.3.9",
|
|
27
27
|
"aiot-parse5": "^1.0.2",
|
|
28
28
|
"babel-loader": "^9.1.3",
|
|
29
|
-
"file-lane": "2.0.6-beta.
|
|
29
|
+
"file-lane": "2.0.6-beta.9",
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
31
|
"fs-extra": "^11.2.0",
|
|
32
32
|
"jsrsasign": "^11.1.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@types/jsrsasign": "^10.5.12",
|
|
43
43
|
"@types/webpack-sources": "^3.2.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "18718f09f1ee7f1d7361022c5fb7858c87cee2bd"
|
|
46
46
|
}
|