@dd-code/uni-tools 1.0.6 → 1.0.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.
- package/dist/cli.js +94 -1
- package/dist/index.js +1296 -1
- package/dist/index.mjs.js +1294 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var shared = require('@dd-code/shared');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
require('fs');
|
|
7
|
+
require('crypto');
|
|
8
|
+
var child_process = require('child_process');
|
|
9
|
+
|
|
10
|
+
/******************************************************************************
|
|
11
|
+
Copyright (c) Microsoft Corporation.
|
|
12
|
+
|
|
13
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
+
purpose with or without fee is hereby granted.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
+
***************************************************************************** */
|
|
24
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var loadViteConfig = function (mode) {
|
|
33
|
+
var loadEnv = require("vite").loadEnv;
|
|
34
|
+
var ROOT = process.cwd();
|
|
35
|
+
return loadEnv(mode, ROOT, "MFE_");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// CDN 文件保存路径
|
|
39
|
+
path.join(process.cwd(), "node_modules/@dd-code/uni-files");
|
|
40
|
+
path.join(process.cwd(), "node_modules/@dd-code/current-files");
|
|
41
|
+
var ROOT_APP_CODE = "main"; //"__MFE_APP_ROOT__";
|
|
42
|
+
var formatCliCommandConfig = function (mode) {
|
|
43
|
+
var viteEnv = loadViteConfig(mode || "dev");
|
|
44
|
+
var isRoot = viteEnv.MFE_UNI_IS_ROOT;
|
|
45
|
+
// MFE_CDN_HOST
|
|
46
|
+
return {
|
|
47
|
+
isRoot: isRoot,
|
|
48
|
+
appCode: isRoot ? ROOT_APP_CODE : viteEnv.MFE_APP_CODE,
|
|
49
|
+
code: viteEnv.MFE_UNI_CODE,
|
|
50
|
+
mode: mode,
|
|
51
|
+
cdn: viteEnv.MFE_CDN_HOST,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var E_WS_TYPE;
|
|
55
|
+
(function (E_WS_TYPE) {
|
|
56
|
+
E_WS_TYPE["INIT"] = "init_files";
|
|
57
|
+
E_WS_TYPE["CHANGE"] = "change_files";
|
|
58
|
+
})(E_WS_TYPE || (E_WS_TYPE = {}));
|
|
59
|
+
|
|
60
|
+
var excuteUniCommand = function (command, _a) {
|
|
61
|
+
var isRoot = _a.isRoot, appCode = _a.appCode;
|
|
62
|
+
var cmd = "uni ".concat(command, " ").concat(!isRoot ? "--subpackage=".concat(appCode) : "");
|
|
63
|
+
child_process.execSync(cmd, {
|
|
64
|
+
stdio: "inherit",
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var addUniOptions = function (program) {
|
|
69
|
+
return program
|
|
70
|
+
.option("-p <platform>", "平台", "h5")
|
|
71
|
+
.option("--mode <mode>", "模式", "development");
|
|
72
|
+
};
|
|
73
|
+
var dev = shared.program
|
|
74
|
+
.name("uni-tools")
|
|
75
|
+
.command("serve")
|
|
76
|
+
.description("uni 工具方法");
|
|
77
|
+
var build = shared.program.command("build").description("构建 uni 项目");
|
|
78
|
+
addUniOptions(dev).action(function (_a) {
|
|
79
|
+
var mode = _a.mode, platform = _a.p;
|
|
80
|
+
var _b = formatCliCommandConfig(mode), isRoot = _b.isRoot, appCode = _b.appCode;
|
|
81
|
+
switch (platform) {
|
|
82
|
+
case "h5":
|
|
83
|
+
break;
|
|
84
|
+
case "mp-weixin":
|
|
85
|
+
excuteUniCommand("uni -p ".concat(platform, " --mode ").concat(mode), {
|
|
86
|
+
isRoot: isRoot,
|
|
87
|
+
appCode: appCode,
|
|
88
|
+
});
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
// debugger;
|
|
92
|
+
// console.log(JSON.stringify({ mode, platform, mfeJson }), "-111-------------");
|
|
93
|
+
});
|
|
94
|
+
addUniOptions(build).action(function (opt) { });
|
|
95
|
+
shared.program.parseAsync(process.argv);
|