@tuya-sat/micro-script 1.1.4 → 2.0.0-rc.3
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/bin/cli.js +3 -3
- package/dist/config/paths.d.ts +1 -0
- package/dist/config/paths.js +1 -0
- package/dist/module/bundleServer.d.ts +1 -0
- package/dist/module/main/fakeSaas.d.ts +10 -0
- package/dist/module/main/fakeSaas.js +57 -0
- package/dist/module/main/fakeSaasInfo.d.ts +2 -0
- package/dist/module/main/fakeSaasInfo.js +85 -0
- package/dist/module/main/staticMain.d.ts +6 -0
- package/dist/module/main/staticMain.js +68 -0
- package/dist/module/mainServer.js +9 -122
- package/dist/module/proxy.d.ts +2 -0
- package/dist/module/proxy.js +15 -0
- package/dist/scripts/start.js +2 -7
- package/dist/scripts/startInMain.js +0 -8
- package/dist/utils/promiser.d.ts +1 -1
- package/dist/utils/promiser.js +2 -2
- package/dist/utils/validate.d.ts +5 -0
- package/dist/utils/validate.js +5 -0
- package/index.d.ts +3 -0
- package/package.json +14 -6
package/dist/bin/cli.js
CHANGED
|
@@ -4,11 +4,11 @@ const PORXY_SIGN = "--proxy";
|
|
|
4
4
|
const IS_MAIN = "--main";
|
|
5
5
|
const params = process.argv.slice(2);
|
|
6
6
|
const [action, ...rest] = params;
|
|
7
|
-
if (rest.includes(PORXY_SIGN)) {
|
|
8
|
-
process.env.MICRO_DEBUGGER = "true";
|
|
9
|
-
}
|
|
10
7
|
if (action === "start") {
|
|
11
8
|
process.env.NODE_ENV = "development";
|
|
9
|
+
if (rest.includes(PORXY_SIGN)) {
|
|
10
|
+
process.env.MICRO_PROXY = "true";
|
|
11
|
+
}
|
|
12
12
|
if (rest.includes(IS_MAIN)) {
|
|
13
13
|
process.env.START_IN_MAIN = "true";
|
|
14
14
|
require("../scripts/startInMain");
|
package/dist/config/paths.d.ts
CHANGED
package/dist/config/paths.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.default = {
|
|
|
14
14
|
publicDir: path_1.default.resolve(cwd, "public/"),
|
|
15
15
|
spaHtml: path_1.default.resolve(cwd, "public/index.html"),
|
|
16
16
|
manifest: path_1.default.resolve(cwd, "manifest.json"),
|
|
17
|
+
saasCache: path_1.default.resolve(cwd, ".saas-cache.json"),
|
|
17
18
|
vueTsEntryFile: path_1.default.resolve(cwd, "src/index.ts"),
|
|
18
19
|
vueJsEntryFile: path_1.default.resolve(cwd, "src/index.js"),
|
|
19
20
|
ReactTsEntryFile: path_1.default.resolve(cwd, "src/index.tsx"),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import webpack, { Compiler } from "webpack";
|
|
2
2
|
import { Configuration } from "webpack-dev-server";
|
|
3
|
+
export declare type CustomDevServer = (value: Configuration) => typeof value;
|
|
3
4
|
export declare function createServerCompiler(): webpack.Compiler;
|
|
4
5
|
export declare function runBundleServer({ port, compiler, internalDevConfig, }: {
|
|
5
6
|
port: number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DebuggerConfig } from "./staticMain";
|
|
2
|
+
interface anyObject {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
export default function getFakeSaas(config: DebuggerConfig): Promise<{
|
|
6
|
+
_SDF: anyObject;
|
|
7
|
+
_SDF_CONFIG: anyObject;
|
|
8
|
+
__MAIN_APP_PUBLIC_PATH: string;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const paths_1 = __importDefault(require("../../config/paths"));
|
|
19
|
+
function parse_SDF_CONFIG(html) {
|
|
20
|
+
var _a;
|
|
21
|
+
const REGEX = /(?<=window._SDF_CONFIG=).*?(?=;)/;
|
|
22
|
+
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
23
|
+
}
|
|
24
|
+
function parse_SDF(html) {
|
|
25
|
+
var _a;
|
|
26
|
+
const REGEX = /(?<=window._SDF=).*?(?=;)/;
|
|
27
|
+
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
28
|
+
}
|
|
29
|
+
function parse__MAIN_APP_PUBLIC_PATH(html) {
|
|
30
|
+
var _a;
|
|
31
|
+
const REGEX = /(?<=window.__MAIN_APP_PUBLIC_PATH=).*?(?=;)/;
|
|
32
|
+
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
33
|
+
}
|
|
34
|
+
function getFakeSaas(config) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!fs_extra_1.default.existsSync(paths_1.default.saasCache) && !config.target) {
|
|
37
|
+
console.log(chalk_1.default.red("不存在缓存文件,且没有配置target"));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
if (!fs_extra_1.default.existsSync(paths_1.default.saasCache)) {
|
|
41
|
+
const { data } = yield axios_1.default.get(config.target);
|
|
42
|
+
const _SDF_CONFIG = parse_SDF_CONFIG(data);
|
|
43
|
+
const _SDF = parse_SDF(data);
|
|
44
|
+
const __MAIN_APP_PUBLIC_PATH = parse__MAIN_APP_PUBLIC_PATH(data);
|
|
45
|
+
const saas = {
|
|
46
|
+
_SDF_CONFIG: JSON.parse(_SDF_CONFIG),
|
|
47
|
+
_SDF: JSON.parse(_SDF),
|
|
48
|
+
__MAIN_APP_PUBLIC_PATH: JSON.parse(__MAIN_APP_PUBLIC_PATH),
|
|
49
|
+
};
|
|
50
|
+
console.log(saas);
|
|
51
|
+
fs_extra_1.default.writeJSONSync(paths_1.default.saasCache, saas);
|
|
52
|
+
return saas;
|
|
53
|
+
}
|
|
54
|
+
return fs_extra_1.default.readJSONSync(paths_1.default.saasCache);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.default = getFakeSaas;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const paths_1 = __importDefault(require("../../config/paths"));
|
|
9
|
+
function mockSaasInfo(app, microPort) {
|
|
10
|
+
const oem_micro_app_id = (0, uuid_1.v4)();
|
|
11
|
+
const entry_id = (0, uuid_1.v4)();
|
|
12
|
+
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
13
|
+
const manifest = (0, micro_utils_1.parseManifest)();
|
|
14
|
+
app.get("/api/saas-info", (req, res) => {
|
|
15
|
+
const lang = parseCookie(req.headers["cookie"], "main-i18next");
|
|
16
|
+
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
|
|
17
|
+
const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang);
|
|
18
|
+
const permission = consturctPermissions();
|
|
19
|
+
res.send({
|
|
20
|
+
code: null,
|
|
21
|
+
errorMsg: null,
|
|
22
|
+
msg: null,
|
|
23
|
+
result: {
|
|
24
|
+
apps: [app],
|
|
25
|
+
entry_info: { entries: [entryInfo], entry_mode: "normal" },
|
|
26
|
+
permissions: { [oem_micro_app_id]: permission },
|
|
27
|
+
},
|
|
28
|
+
success: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return baseUrl;
|
|
32
|
+
}
|
|
33
|
+
exports.default = mockSaasInfo;
|
|
34
|
+
function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang) {
|
|
35
|
+
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest);
|
|
36
|
+
let stack = [fakeMenu];
|
|
37
|
+
while (stack.length) {
|
|
38
|
+
const menu = stack.shift();
|
|
39
|
+
menu.oem_micro_app_id = oem_micro_app_id;
|
|
40
|
+
menu.entry_id = entry_id;
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
menu.entry_name = pickText(menu.entry_name, lang);
|
|
43
|
+
//@ts-ignore
|
|
44
|
+
menu.micro_app_name = pickText(menu.micro_app_name, lang);
|
|
45
|
+
menu.path = `${baseUrl}${menu.path}`;
|
|
46
|
+
if (menu.sub_entry_list.length) {
|
|
47
|
+
stack.push(...menu.sub_entry_list);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return fakeMenu;
|
|
51
|
+
}
|
|
52
|
+
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
53
|
+
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
54
|
+
return {
|
|
55
|
+
active_rule: baseUrl,
|
|
56
|
+
dependencies: [""],
|
|
57
|
+
ext_info: null,
|
|
58
|
+
micro_app_code: `${packageInfo.name}`,
|
|
59
|
+
micro_app_name: `${pickText((0, micro_utils_1.nameProcesser2)("name"), lang)}-dev`,
|
|
60
|
+
micro_app_version: "0.0.0-x",
|
|
61
|
+
oem_micro_app_id,
|
|
62
|
+
resource: `http://localhost:${port}`,
|
|
63
|
+
schema: null,
|
|
64
|
+
universal_id: manifest.universalId,
|
|
65
|
+
isAuth: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function consturctPermissions() {
|
|
69
|
+
delete require.cache[paths_1.default.microConfig];
|
|
70
|
+
const { mockPermissions = [] } = require(paths_1.default.microConfig).debuggerConfig || {};
|
|
71
|
+
return mockPermissions;
|
|
72
|
+
}
|
|
73
|
+
function pickText(texts, lang) {
|
|
74
|
+
return lang === "en" ? texts[1] : texts[0];
|
|
75
|
+
}
|
|
76
|
+
function parseCookie(cookie, key) {
|
|
77
|
+
const cookies = (cookie || "").split(";");
|
|
78
|
+
for (let cookieItem of cookies) {
|
|
79
|
+
const [cookieKey, value] = cookieItem.split("=");
|
|
80
|
+
if (cookieKey.trim() === key) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 cheerio_1 = __importDefault(require("cheerio"));
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const fakeSaas_1 = __importDefault(require("./fakeSaas"));
|
|
18
|
+
const defaultBase = "https://static1.tuyacn.com/static/sdf-gw/v1.0.0.555/";
|
|
19
|
+
function staticMain(app, debuggerConfig) {
|
|
20
|
+
app.get([
|
|
21
|
+
"/",
|
|
22
|
+
"/apps/:appId",
|
|
23
|
+
"/login",
|
|
24
|
+
"/apps/:appId/*",
|
|
25
|
+
"/application",
|
|
26
|
+
"/application/*",
|
|
27
|
+
], (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const base = debuggerConfig.base || defaultBase;
|
|
29
|
+
const { data } = yield axios_1.default.get(new URL("index.html", debuggerConfig.base).href);
|
|
30
|
+
const $ = cheerio_1.default.load(data);
|
|
31
|
+
modifySrcAttr($, base);
|
|
32
|
+
insertLocalStorage($);
|
|
33
|
+
yield insertScript($, debuggerConfig);
|
|
34
|
+
res.send($.html());
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
exports.default = staticMain;
|
|
38
|
+
function insertLocalStorage($) {
|
|
39
|
+
//可能有坑
|
|
40
|
+
$("head").append($("<script>").text(`
|
|
41
|
+
window.localStorage.setItem('isLogin','Yes');
|
|
42
|
+
window.localStorage.setItem('_USERNAME','fake_user');
|
|
43
|
+
window.localStorage.setItem('_ROLE','普通');
|
|
44
|
+
`));
|
|
45
|
+
}
|
|
46
|
+
function insertScript($, debuggerConfig) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { _SDF_CONFIG, _SDF, __MAIN_APP_PUBLIC_PATH } = yield (0, fakeSaas_1.default)(debuggerConfig);
|
|
49
|
+
$("head").append($("<script>").text(`window._SDF_CONFIG=${JSON.stringify(_SDF_CONFIG)};window._SDF=${JSON.stringify(_SDF)};window.__MAIN_APP_PUBLIC_PATH=${JSON.stringify(__MAIN_APP_PUBLIC_PATH)};
|
|
50
|
+
`));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function modifySrcAttr($, base) {
|
|
54
|
+
const tags = ["img src", "link href", "script src"];
|
|
55
|
+
tags.forEach((p) => {
|
|
56
|
+
const [tagName, attr] = p.split(" ");
|
|
57
|
+
$(tagName).map(function () {
|
|
58
|
+
const origin = $(this).attr(attr);
|
|
59
|
+
if (/^(\/|http:|https:)/.test(origin))
|
|
60
|
+
return;
|
|
61
|
+
if (!origin) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const newUrl = new URL(origin, base).href;
|
|
65
|
+
$(this).attr(attr, newUrl);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -14,139 +14,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const express_1 = __importDefault(require("express"));
|
|
16
16
|
const ora_1 = __importDefault(require("ora"));
|
|
17
|
-
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
18
|
-
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
19
|
-
//@ts-ignore
|
|
20
|
-
const uuid_1 = require("uuid");
|
|
21
17
|
const promiser_1 = require("../utils/promiser");
|
|
22
18
|
const mock_1 = __importDefault(require("../module/mock"));
|
|
23
19
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const cookies = (cookie || "").split(";");
|
|
28
|
-
for (let cookieItem of cookies) {
|
|
29
|
-
const [cookieKey, value] = cookieItem.split("=");
|
|
30
|
-
if (cookieKey.trim() === key) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
20
|
+
const fakeSaasInfo_1 = __importDefault(require("./main/fakeSaasInfo"));
|
|
21
|
+
const staticMain_1 = __importDefault(require("./main/staticMain"));
|
|
22
|
+
const proxy_1 = __importDefault(require("../module/proxy"));
|
|
36
23
|
function runMain({ port, microPort, }) {
|
|
37
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const { debuggerConfig
|
|
25
|
+
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
39
26
|
const app = (0, express_1.default)();
|
|
40
|
-
|
|
27
|
+
(0, staticMain_1.default)(app, debuggerConfig);
|
|
28
|
+
(0, fakeSaasInfo_1.default)(app, microPort);
|
|
41
29
|
(0, mock_1.default)(app);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"/",
|
|
45
|
-
"/apps/:appId",
|
|
46
|
-
"/login",
|
|
47
|
-
"/apps/:appId/*",
|
|
48
|
-
"/application",
|
|
49
|
-
"/application/*",
|
|
50
|
-
//api
|
|
51
|
-
"/open-api/*",
|
|
52
|
-
"/custom-api/*",
|
|
53
|
-
"/api/*",
|
|
54
|
-
], (0, http_proxy_middleware_1.createProxyMiddleware)({
|
|
55
|
-
target,
|
|
56
|
-
changeOrigin: true,
|
|
57
|
-
selfHandleResponse: true,
|
|
58
|
-
onProxyReq(proxyReq, req) {
|
|
59
|
-
//强制覆盖host字段,优先级高于changeOrigin
|
|
60
|
-
const { host } = additionHeaders;
|
|
61
|
-
host && proxyReq.setHeader("host", host);
|
|
62
|
-
if (req.url === "/api/saas-info") {
|
|
63
|
-
//该死的,会有缓存
|
|
64
|
-
proxyReq.setHeader("if-none-match", "");
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
onProxyRes: (0, http_proxy_middleware_1.responseInterceptor)((responseBuffer, proxyRes, req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
if (req.url !== "/api/saas-info" || res.statusCode !== 200) {
|
|
69
|
-
return responseBuffer;
|
|
70
|
-
}
|
|
71
|
-
let response = responseBuffer;
|
|
72
|
-
try {
|
|
73
|
-
const lang = parseCookie(req.headers["cookie"], "main-i18next");
|
|
74
|
-
const data = JSON.parse(response.toString("utf8"));
|
|
75
|
-
response = JSON.stringify(processSaasInfo(data, lang, microPort));
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
console.log(`----json 解析错误----`, err);
|
|
79
|
-
}
|
|
80
|
-
return response;
|
|
81
|
-
})),
|
|
82
|
-
headers: additionHeaders,
|
|
83
|
-
}));
|
|
84
|
-
const { pp, resolve } = (0, promiser_1.promiser)();
|
|
30
|
+
(0, proxy_1.default)(app);
|
|
31
|
+
const { waiting, resolve } = (0, promiser_1.promiser)();
|
|
85
32
|
app.listen(port, () => {
|
|
86
33
|
(0, ora_1.default)(`main server in ${port} port`).succeed();
|
|
87
34
|
resolve();
|
|
88
35
|
});
|
|
89
|
-
yield
|
|
36
|
+
yield waiting;
|
|
90
37
|
});
|
|
91
38
|
}
|
|
92
39
|
exports.default = runMain;
|
|
93
|
-
function processSaasInfo(data, lang, port) {
|
|
94
|
-
if (data === null || data === void 0 ? void 0 : data.success) {
|
|
95
|
-
const { result: { entry_info, apps, permissions }, } = data;
|
|
96
|
-
const baseUrl = `/apps/${oem_micro_app_id}`;
|
|
97
|
-
const manifest = (0, micro_utils_1.parseManifest)();
|
|
98
|
-
const entry = consturctEntry(manifest, oem_micro_app_id, baseUrl, lang);
|
|
99
|
-
const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port);
|
|
100
|
-
if (entry_info.entry_mode === "group") {
|
|
101
|
-
entry_info.entries[0].sub_entry_list.unshift(entry);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
entry_info.entries.unshift(entry);
|
|
105
|
-
}
|
|
106
|
-
delete require.cache[paths_1.default.microConfig];
|
|
107
|
-
const { mockPermissions = [] } = require(paths_1.default.microConfig).debuggerConfig || {};
|
|
108
|
-
permissions[oem_micro_app_id] = mockPermissions;
|
|
109
|
-
apps.unshift(app);
|
|
110
|
-
}
|
|
111
|
-
return data;
|
|
112
|
-
}
|
|
113
|
-
function consturctEntry(manifest, oem_micro_app_id, baseUrl, lang) {
|
|
114
|
-
const fakeMenu = (0, micro_utils_1.getFakeMenu)(manifest);
|
|
115
|
-
let stack = [fakeMenu];
|
|
116
|
-
while (stack.length) {
|
|
117
|
-
const menu = stack.shift();
|
|
118
|
-
//@ts-ignore
|
|
119
|
-
menu.oem_micro_app_id = oem_micro_app_id;
|
|
120
|
-
//@ts-ignore
|
|
121
|
-
menu.entry_id = entry_id;
|
|
122
|
-
//@ts-ignore
|
|
123
|
-
menu.entry_name = pickText(menu.entry_name, lang);
|
|
124
|
-
//@ts-ignore
|
|
125
|
-
menu.micro_app_name = pickText(menu.micro_app_name, lang);
|
|
126
|
-
//@ts-ignore
|
|
127
|
-
menu.path = `${baseUrl}${menu.path}`;
|
|
128
|
-
if (menu.sub_entry_list.length) {
|
|
129
|
-
stack.push(...menu.sub_entry_list);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return fakeMenu;
|
|
133
|
-
}
|
|
134
|
-
function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
135
|
-
const packageInfo = (0, micro_utils_1.getPackage)();
|
|
136
|
-
return {
|
|
137
|
-
active_rule: baseUrl,
|
|
138
|
-
dependencies: [""],
|
|
139
|
-
ext_info: null,
|
|
140
|
-
micro_app_code: `${packageInfo.name}`,
|
|
141
|
-
micro_app_name: `${pickText((0, micro_utils_1.nameProcesser2)("name"), lang)}-dev`,
|
|
142
|
-
micro_app_version: "0.0.0-x",
|
|
143
|
-
oem_micro_app_id,
|
|
144
|
-
resource: `http://localhost:${port}`,
|
|
145
|
-
schema: null,
|
|
146
|
-
universal_id: manifest.universalId,
|
|
147
|
-
isAuth: true,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function pickText(texts, lang) {
|
|
151
|
-
return lang === "en" ? texts[1] : texts[0];
|
|
152
|
-
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
const paths_1 = __importDefault(require("../config/paths"));
|
|
7
|
+
function useProxy(app) {
|
|
8
|
+
const isProxy = process.env.MICRO_PROXY === "true";
|
|
9
|
+
if (isProxy) {
|
|
10
|
+
const createProxy = require("@tuya-sat/micro-dev-proxy").default;
|
|
11
|
+
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
12
|
+
createProxy(debuggerConfig)(app);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = useProxy;
|
package/dist/scripts/start.js
CHANGED
|
@@ -15,21 +15,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
16
16
|
const micro_dev_loader_1 = require("@tuya-sat/micro-dev-loader");
|
|
17
17
|
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
18
|
-
const paths_1 = __importDefault(require("../config/paths"));
|
|
19
18
|
const mock_1 = __importDefault(require("../module/mock"));
|
|
20
19
|
const bundleServer_1 = require("../module/bundleServer");
|
|
20
|
+
const proxy_1 = __importDefault(require("../module/proxy"));
|
|
21
21
|
const needLayout = !(0, micro_utils_1.isMobile)();
|
|
22
22
|
const internalDevConfig = {
|
|
23
23
|
open: true,
|
|
24
24
|
setupMiddlewares(middleware, { app }) {
|
|
25
25
|
needLayout && micro_dev_loader_1.LayoutMockPlugin.useLayoutStatic(app);
|
|
26
26
|
(0, mock_1.default)(app);
|
|
27
|
-
|
|
28
|
-
if (isProxy) {
|
|
29
|
-
const createProxy = require("@tuya-sat/micro-dev-proxy").default;
|
|
30
|
-
const { debuggerConfig } = require(paths_1.default.microConfig);
|
|
31
|
-
createProxy(debuggerConfig)(app);
|
|
32
|
-
}
|
|
27
|
+
(0, proxy_1.default)(app);
|
|
33
28
|
return middleware;
|
|
34
29
|
},
|
|
35
30
|
};
|
|
@@ -14,14 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
16
16
|
const open_1 = __importDefault(require("open"));
|
|
17
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
20
17
|
const mainServer_1 = __importDefault(require("../module/mainServer"));
|
|
21
|
-
const micro_utils_1 = require("@tuya-sat/micro-utils");
|
|
22
18
|
const bundleServer_1 = require("../module/bundleServer");
|
|
23
19
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
console.log(chalk_1.default.yellow(`Tip: 目前--main命令是个体验命令,请知悉`));
|
|
25
20
|
let defaultPort = 9000;
|
|
26
21
|
//检测端口占用情况
|
|
27
22
|
const bundledServerPort = yield portfinder_1.default.getPortPromise({
|
|
@@ -37,9 +32,6 @@ const bundleServer_1 = require("../module/bundleServer");
|
|
|
37
32
|
port: mainServerPort,
|
|
38
33
|
microPort: bundledServerPort,
|
|
39
34
|
});
|
|
40
|
-
const packagePath = path_1.default.resolve(__dirname, "../../package.json");
|
|
41
|
-
const { name, version } = fs_extra_1.default.readJSONSync(packagePath);
|
|
42
|
-
(0, micro_utils_1.isNewVersions)(name, version);
|
|
43
35
|
(0, open_1.default)(`http://localhost:${mainServerPort}`);
|
|
44
36
|
(0, bundleServer_1.runBundleServer)({
|
|
45
37
|
port: bundledServerPort,
|
package/dist/utils/promiser.d.ts
CHANGED
package/dist/utils/promiser.js
CHANGED
|
@@ -4,12 +4,12 @@ exports.promiser = void 0;
|
|
|
4
4
|
const promiser = () => {
|
|
5
5
|
let resolve;
|
|
6
6
|
let reject;
|
|
7
|
-
let
|
|
7
|
+
let waiting = new Promise((resolve$, reject$) => {
|
|
8
8
|
resolve = resolve$;
|
|
9
9
|
reject = reject$;
|
|
10
10
|
});
|
|
11
11
|
return {
|
|
12
|
-
|
|
12
|
+
waiting,
|
|
13
13
|
resolve,
|
|
14
14
|
reject,
|
|
15
15
|
};
|
package/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.3",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
7
12
|
"scripts": {
|
|
8
13
|
"dev": "rm -rf dist/ && tsc --watch",
|
|
9
14
|
"build": "rm -rf dist/ && tsc",
|
|
@@ -15,12 +20,13 @@
|
|
|
15
20
|
"@babel/preset-react": "^7.14.5",
|
|
16
21
|
"@babel/preset-typescript": "^7.15.0",
|
|
17
22
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
|
|
18
|
-
"@tuya-sat/micro-dev-loader": "
|
|
19
|
-
"@tuya-sat/micro-dev-proxy": "
|
|
20
|
-
"@tuya-sat/micro-utils": "
|
|
23
|
+
"@tuya-sat/micro-dev-loader": "2.0.0-rc.3",
|
|
24
|
+
"@tuya-sat/micro-dev-proxy": "2.0.0-rc.3",
|
|
25
|
+
"@tuya-sat/micro-utils": "2.0.0-rc.3",
|
|
21
26
|
"babel-loader": "^8.2.2",
|
|
22
27
|
"babel-plugin-import": "^1.13.3",
|
|
23
28
|
"chalk": "4.1.2",
|
|
29
|
+
"cheerio": "^1.0.0-rc.10",
|
|
24
30
|
"copy-webpack-plugin": "^9.0.1",
|
|
25
31
|
"css-loader": "^6.4.0",
|
|
26
32
|
"css-minimizer-webpack-plugin": "^3.2.0",
|
|
@@ -54,11 +60,12 @@
|
|
|
54
60
|
},
|
|
55
61
|
"devDependencies": {
|
|
56
62
|
"@types/express": "^4.17.13",
|
|
63
|
+
"@types/uuid": "^8.3.4",
|
|
57
64
|
"@types/webpack-dev-server": "^4.5.0",
|
|
58
65
|
"typescript": "^4.4.4"
|
|
59
66
|
},
|
|
60
67
|
"peerDependencies": {
|
|
61
|
-
"@tuya-sat/micro-dev-component": "^
|
|
68
|
+
"@tuya-sat/micro-dev-component": "^2.0.0-rc.3"
|
|
62
69
|
},
|
|
63
70
|
"keywords": [
|
|
64
71
|
"saturn-project",
|
|
@@ -68,5 +75,6 @@
|
|
|
68
75
|
"saas",
|
|
69
76
|
"cloud",
|
|
70
77
|
"tuya"
|
|
71
|
-
]
|
|
78
|
+
],
|
|
79
|
+
"stableVersion": "1.1.4"
|
|
72
80
|
}
|