@aiot-toolkit/aiotpack 2.1.0-prender.3 → 2.1.0-prender.4
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.
|
@@ -214,7 +214,7 @@ function elementToJson(el, styleSheet, importMap, scopeVars, pageDir) {
|
|
|
214
214
|
if (name === 'is' && tagName === 'component') {
|
|
215
215
|
continue; // is attribute handled at runtime
|
|
216
216
|
} else if (name === 'class') {
|
|
217
|
-
className = value.trim();
|
|
217
|
+
className = value.replace(/\s+/g, ' ').trim();
|
|
218
218
|
} else if (name.startsWith('@') || name.startsWith('on') && name.length > 2) {
|
|
219
219
|
const rawEvtName = name.startsWith('@') ? name.slice(1) : name.replace(/^on/, '');
|
|
220
220
|
const evtName = rawEvtName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
@@ -11,6 +11,23 @@ var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"
|
|
|
11
11
|
var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
|
|
12
12
|
var _UxLoaderUtils = _interopRequireDefault(require("../../utils/ux/UxLoaderUtils"));
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function loadUserViteConfig(projectPath, mode) {
|
|
15
|
+
const configPath = _path.default.join(projectPath, 'quickapp.config.js');
|
|
16
|
+
if (!_fsExtra.default.existsSync(configPath)) return {};
|
|
17
|
+
delete require.cache[require.resolve(configPath)];
|
|
18
|
+
const userConfig = require(configPath);
|
|
19
|
+
if (userConfig?.postHook && !userConfig?.vite) {
|
|
20
|
+
console.warn(`[aiot-toolkit] quickapp.config.js uses legacy webpack-style \`postHook\` API; ` + `the toolkit now reads a vite-native \`vite\` section instead. ` + `Migrate to: module.exports = { vite: { define: { ... }, plugins: [ ... ] } }`);
|
|
21
|
+
}
|
|
22
|
+
const viteSection = userConfig?.vite;
|
|
23
|
+
if (!viteSection) return {};
|
|
24
|
+
if (typeof viteSection === 'function') {
|
|
25
|
+
return viteSection({
|
|
26
|
+
mode
|
|
27
|
+
}) ?? {};
|
|
28
|
+
}
|
|
29
|
+
return viteSection;
|
|
30
|
+
}
|
|
14
31
|
function extractAppStyleLiteral(code) {
|
|
15
32
|
const m = code.match(/var\s+\$app_style\$\s*=\s*\[/);
|
|
16
33
|
if (!m) return null;
|
|
@@ -56,6 +73,15 @@ class ViteCompiler {
|
|
|
56
73
|
const manifestPath = _UxFileUtils.default.getManifestFilePath(originalProjectPath, sourceRoot);
|
|
57
74
|
const manifest = _fsExtra.default.readJSONSync(manifestPath);
|
|
58
75
|
const entries = _UxCompileUtil.default.resolveEntries(manifest, srcPath, originalProjectPath);
|
|
76
|
+
let userVite = {};
|
|
77
|
+
try {
|
|
78
|
+
userVite = loadUserViteConfig(originalProjectPath, param.mode === 'production' ? 'production' : 'development');
|
|
79
|
+
} catch (e) {
|
|
80
|
+
this.onLog?.([{
|
|
81
|
+
level: 1,
|
|
82
|
+
message: [`Failed to load quickapp.config.js: ${e.message}`]
|
|
83
|
+
}]);
|
|
84
|
+
}
|
|
59
85
|
for (const [entryName, entryValue] of Object.entries(entries)) {
|
|
60
86
|
const entryPath = entryValue.split('?')[0];
|
|
61
87
|
const resolvedEntry = _path.default.resolve(originalProjectPath, entryPath);
|
|
@@ -73,8 +99,10 @@ class ViteCompiler {
|
|
|
73
99
|
const result = await build({
|
|
74
100
|
root: originalProjectPath,
|
|
75
101
|
logLevel: 'silent',
|
|
102
|
+
define: userVite.define ?? {},
|
|
76
103
|
resolve: {
|
|
77
|
-
extensions: ['.js', '.ts', '.ux', '.json']
|
|
104
|
+
extensions: ['.js', '.ts', '.ux', '.json'],
|
|
105
|
+
...(userVite.resolve ?? {})
|
|
78
106
|
},
|
|
79
107
|
build: {
|
|
80
108
|
write: false,
|
|
@@ -285,7 +313,7 @@ class ViteCompiler {
|
|
|
285
313
|
}, isApp, param, compilation);
|
|
286
314
|
return files[0]?.content || '';
|
|
287
315
|
}
|
|
288
|
-
}]
|
|
316
|
+
}, ...(userVite.plugins ?? [])]
|
|
289
317
|
});
|
|
290
318
|
// Extract the output code
|
|
291
319
|
if (result && !Array.isArray(result)) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Jsc
|
|
3
|
-
*/
|
|
4
1
|
declare class Jsc {
|
|
5
2
|
readonly projectPath: string;
|
|
6
3
|
readonly buildPath: string;
|
|
7
4
|
constructor(projectPath: string, buildPath: string);
|
|
8
5
|
jsc(deleteJs?: boolean): Promise<boolean>;
|
|
6
|
+
private logBeforeInvoke;
|
|
7
|
+
private logAfterInvoke;
|
|
8
|
+
private static listFiles;
|
|
9
9
|
}
|
|
10
10
|
export default Jsc;
|
|
@@ -4,10 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var fs = _interopRequireWildcard(require("fs"));
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
7
9
|
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
12
|
class Jsc {
|
|
12
13
|
constructor(projectPath, buildPath) {
|
|
13
14
|
this.projectPath = projectPath;
|
|
@@ -20,21 +21,93 @@ class Jsc {
|
|
|
20
21
|
buildPath
|
|
21
22
|
} = this;
|
|
22
23
|
return _sharedUtils.CommonUtil.requireNodeModule(projectPath, `@aiot-toolkit/jsc`).then(async module => {
|
|
24
|
+
this.logBeforeInvoke();
|
|
25
|
+
const start = Date.now();
|
|
23
26
|
const msg = await module.default(buildPath);
|
|
27
|
+
const elapsed = Date.now() - start;
|
|
24
28
|
if (msg) {
|
|
25
29
|
_sharedUtils.ColorConsole.success({
|
|
26
30
|
word: 'jsc command'
|
|
27
31
|
}, msg);
|
|
28
32
|
}
|
|
33
|
+
this.logAfterInvoke(elapsed);
|
|
29
34
|
}).then(() => {
|
|
30
35
|
if (deleteJs) {
|
|
31
36
|
return _sharedUtils.FileUtil.del(`${buildPath}/**/*.js`);
|
|
32
37
|
}
|
|
33
38
|
return true;
|
|
34
39
|
}).catch(error => {
|
|
35
|
-
|
|
40
|
+
const fields = [];
|
|
41
|
+
if (error.code !== undefined) fields.push(`code=${error.code}`);
|
|
42
|
+
if (error.status !== undefined) fields.push(`status=${error.status}`);
|
|
43
|
+
if (error.signal) fields.push(`signal=${error.signal}`);
|
|
44
|
+
if (error.killed !== undefined) fields.push(`killed=${error.killed}`);
|
|
45
|
+
if (error.cmd) fields.push(`cmd=${error.cmd}`);
|
|
46
|
+
const stderr = error.stderr ? Buffer.from(error.stderr).toString() : '';
|
|
47
|
+
const stdout = error.stdout ? Buffer.from(error.stdout).toString() : '';
|
|
48
|
+
const parts = [fields.length ? `[jsc] error fields: ${fields.join(' ')}` : '', stderr ? `[jsc] stderr:\n${stderr}` : '', stdout ? `[jsc] stdout:\n${stdout}` : ''];
|
|
49
|
+
const detail = parts.filter(Boolean).join('\n').trim();
|
|
50
|
+
_sharedUtils.ColorConsole.throw(detail ? `${error.message}\n${detail}` : error.message);
|
|
36
51
|
return Promise.reject(error);
|
|
37
52
|
});
|
|
38
53
|
}
|
|
54
|
+
logBeforeInvoke() {
|
|
55
|
+
const {
|
|
56
|
+
projectPath,
|
|
57
|
+
buildPath
|
|
58
|
+
} = this;
|
|
59
|
+
const jscName = '@aiot-toolkit/jsc';
|
|
60
|
+
try {
|
|
61
|
+
const pkgJsonPath = require.resolve(`${jscName}/package.json`, {
|
|
62
|
+
paths: [projectPath]
|
|
63
|
+
});
|
|
64
|
+
const pkg = require(pkgJsonPath);
|
|
65
|
+
_sharedUtils.ColorConsole.info(`[jsc] using ${jscName}@${pkg.version} resolved at ${pkgJsonPath}`);
|
|
66
|
+
} catch {
|
|
67
|
+
_sharedUtils.ColorConsole.info(`[jsc] cannot resolve ${jscName}/package.json from ${projectPath}`);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const files = Jsc.listFiles(buildPath, '.js');
|
|
71
|
+
const total = files.reduce((n, f) => n + f.size, 0);
|
|
72
|
+
_sharedUtils.ColorConsole.info(`[jsc] buildPath=${buildPath} files=${files.length} totalBytes=${total}`);
|
|
73
|
+
if (files.length) {
|
|
74
|
+
const sample = files.slice(0, 12).map(f => `${f.rel}:${f.size}`).join(', ');
|
|
75
|
+
const more = files.length > 12 ? ` ...and ${files.length - 12} more` : '';
|
|
76
|
+
_sharedUtils.ColorConsole.info(`[jsc] inputs: ${sample}${more}`);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
_sharedUtils.ColorConsole.info(`[jsc] failed to enumerate inputs in ${buildPath}: ${e?.message ?? e}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
logAfterInvoke(elapsedMs) {
|
|
83
|
+
const {
|
|
84
|
+
buildPath
|
|
85
|
+
} = this;
|
|
86
|
+
try {
|
|
87
|
+
const jscFiles = Jsc.listFiles(buildPath, '.jsc');
|
|
88
|
+
const total = jscFiles.reduce((n, f) => n + f.size, 0);
|
|
89
|
+
_sharedUtils.ColorConsole.info(`[jsc] produced ${jscFiles.length} .jsc files (${total} bytes) in ${elapsedMs}ms`);
|
|
90
|
+
} catch {
|
|
91
|
+
/* ignore */
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static listFiles(dir, ext) {
|
|
95
|
+
const out = [];
|
|
96
|
+
if (!fs.existsSync(dir)) return out;
|
|
97
|
+
const walk = d => {
|
|
98
|
+
for (const name of fs.readdirSync(d)) {
|
|
99
|
+
const abs = path.join(d, name);
|
|
100
|
+
const stat = fs.statSync(abs);
|
|
101
|
+
if (stat.isDirectory()) walk(abs);else if (name.endsWith(ext)) {
|
|
102
|
+
out.push({
|
|
103
|
+
rel: path.relative(dir, abs),
|
|
104
|
+
size: stat.size
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
walk(dir);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
39
112
|
}
|
|
40
113
|
var _default = exports.default = Jsc;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.1.0-prender.
|
|
3
|
+
"version": "2.1.0-prender.4",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.1.0-prender.
|
|
23
|
-
"@aiot-toolkit/parser": "2.1.0-prender.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.1.0-prender.
|
|
22
|
+
"@aiot-toolkit/generator": "2.1.0-prender.4",
|
|
23
|
+
"@aiot-toolkit/parser": "2.1.0-prender.4",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.1.0-prender.4",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.3.9",
|
|
27
27
|
"acorn": "^8.16.0",
|
|
28
28
|
"aiot-parse5": "^1.0.2",
|
|
29
29
|
"astring": "^1.9.0",
|
|
30
30
|
"babel-loader": "^9.1.3",
|
|
31
|
-
"file-lane": "2.1.0-prender.
|
|
31
|
+
"file-lane": "2.1.0-prender.4",
|
|
32
32
|
"file-loader": "^6.2.0",
|
|
33
33
|
"fs-extra": "^11.2.0",
|
|
34
34
|
"jsrsasign": "^11.1.0",
|