@tuya-sat/micro-utils 1.0.7

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/README.md ADDED
@@ -0,0 +1,37 @@
1
+ <div id="top"></div>
2
+ <br />
3
+ <div align="center">
4
+ <a href="https://github.com/othneildrew/Best-README-Template">
5
+ <img src="https://images.tuyacn.com/rms-static/da7f7ac0-3e0c-11ec-89bb-d7b7de210e4b-1636098546797.png" alt="Logo" width="80" height="80">
6
+ </a>
7
+
8
+ <h3 align="center">Saturn - micro-utils</h3>
9
+
10
+ <p align="center">
11
+ 工具包
12
+ <br/>
13
+ <a href="https://github.com/tuya-sat/discuss">土星项目</a>
14
+ ·
15
+ <a href="https://github.com/tuya-sat/discuss/issues">报告问题</a>
16
+ ·
17
+ <a href="https://github.com/tuya-sat/discuss/issues">提交需求</a>
18
+ </p>
19
+ </div>
20
+
21
+ ## 介绍
22
+
23
+ 该包主要被@tuya-sat 相关的 npm 包引用
24
+
25
+ ## 资源工具
26
+
27
+ - [@tuya-sat/components](https://www.npmjs.com/package/@tuya-sat/components)
28
+ - [@tuya-sat/sdf-cli](https://www.npmjs.com/package/@tuya-sat/sdf-cli)
29
+ - [@tuya-sat/create-micro-app](https://www.npmjs.com/package/@tuya-sat/create-micro-app)
30
+
31
+ ## License
32
+
33
+ MIT
34
+
35
+ ## 联系我们
36
+
37
+ 欢迎在 [https://github.com/tuya-sat/discuss/issues](https://github.com/tuya-sat/discuss/issues) 向我们提交反馈
@@ -0,0 +1,10 @@
1
+ import { Manifest } from "./parseManifest";
2
+ interface FakeMenu {
3
+ micro_app_name: string[];
4
+ entry_name: string[];
5
+ path: string;
6
+ icon?: string;
7
+ sub_entry_list: FakeMenu[];
8
+ }
9
+ export declare function getFakeMenu(manifest: Manifest): FakeMenu;
10
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFakeMenu = void 0;
4
+ const getLang_1 = require("./getLang");
5
+ function getFakeMenu(manifest) {
6
+ const { name: appName, entries = [] } = manifest;
7
+ const appNameLang = (0, getLang_1.nameProcesser2)(appName);
8
+ const fakeMenuDefault = {
9
+ micro_app_name: appNameLang,
10
+ sub_entry_list: [],
11
+ };
12
+ let fakeMenu;
13
+ switch (entries.length) {
14
+ case 0:
15
+ fakeMenu = Object.assign({ entry_name: appNameLang, path: "" }, fakeMenuDefault);
16
+ break;
17
+ case 1:
18
+ const { name, path } = entries[0];
19
+ fakeMenu = Object.assign({ entry_name: (0, getLang_1.nameProcesser2)(name), path }, fakeMenuDefault);
20
+ break;
21
+ default:
22
+ fakeMenu = Object.assign(Object.assign({ entry_name: appNameLang, path: "" }, fakeMenuDefault), { sub_entry_list: entries.map(({ name, path }) => (Object.assign({ entry_name: (0, getLang_1.nameProcesser2)(name), path }, fakeMenuDefault))) });
23
+ break;
24
+ }
25
+ fakeMenu.icon = manifest.defaultMenuIcon.url;
26
+ return fakeMenu;
27
+ }
28
+ exports.getFakeMenu = getFakeMenu;
@@ -0,0 +1 @@
1
+ export declare const nameProcesser2: (name: string) => any[];
@@ -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
+ exports.nameProcesser2 = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const zhLang = fs_extra_1.default.readJSONSync(path_1.default.resolve(process.cwd(), "_locales/zh-CN.json"));
10
+ const enLang = fs_extra_1.default.readJSONSync(path_1.default.resolve(process.cwd(), "_locales/en.json"));
11
+ const nameProcesser2 = (name) => {
12
+ const [_, key] = name.split(".");
13
+ return [zhLang[key] || name, enLang[key] || name];
14
+ };
15
+ exports.nameProcesser2 = nameProcesser2;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare function getPackage(): any;
3
+ export declare function getPackageVersions(packageName: string): Buffer;
4
+ export declare function isNewVersions(packageName: string, currentVersion: string): void;
@@ -0,0 +1,26 @@
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.isNewVersions = exports.getPackageVersions = exports.getPackage = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const semver_1 = require("semver");
10
+ const child_process_1 = require("child_process");
11
+ function getPackage() {
12
+ return fs_extra_1.default.readJSONSync(path_1.default.resolve(process.cwd(), "package.json"));
13
+ }
14
+ exports.getPackage = getPackage;
15
+ function getPackageVersions(packageName) {
16
+ return (0, child_process_1.execSync)(`npm show ${packageName} version`);
17
+ }
18
+ exports.getPackageVersions = getPackageVersions;
19
+ function isNewVersions(packageName, currentVersion) {
20
+ const remoteVersion = getPackageVersions(packageName);
21
+ if ((0, semver_1.gt)(remoteVersion.toString("utf-8"), currentVersion)) {
22
+ console.error("start --main, 这是一个体验性的功能,需要升级到最新的版本");
23
+ process.exit(1);
24
+ }
25
+ }
26
+ exports.isNewVersions = isNewVersions;
@@ -0,0 +1,4 @@
1
+ export * from "./getLang";
2
+ export * from "./getFakeMenu";
3
+ export * from "./parseManifest";
4
+ export * from "./getPackage";
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./getLang"), exports);
14
+ __exportStar(require("./getFakeMenu"), exports);
15
+ __exportStar(require("./parseManifest"), exports);
16
+ __exportStar(require("./getPackage"), exports);
@@ -0,0 +1,24 @@
1
+ export interface Privilege {
2
+ name: string;
3
+ code: string;
4
+ }
5
+ export interface Manifest {
6
+ name: string;
7
+ defaultMenuIcon: {
8
+ type: "URL";
9
+ url?: string;
10
+ name?: string;
11
+ };
12
+ entries: {
13
+ type: string;
14
+ code: string;
15
+ appIcon?: Object;
16
+ name: string;
17
+ path: string;
18
+ ratio?: number;
19
+ }[];
20
+ supportedPlatform: ["MOBILE" | "DESKTOP"];
21
+ privileges: Privilege[];
22
+ }
23
+ export declare function parseManifest(): Manifest;
24
+ export declare function isMobile(): boolean;
@@ -0,0 +1,20 @@
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.isMobile = exports.parseManifest = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function parseManifest() {
10
+ const MANIFEST_FILE = "manifest.json";
11
+ const cwd = process.cwd();
12
+ const manifest = fs_extra_1.default.readJSONSync(path_1.default.resolve(cwd, MANIFEST_FILE), "utf-8");
13
+ return manifest;
14
+ }
15
+ exports.parseManifest = parseManifest;
16
+ function isMobile() {
17
+ var _a;
18
+ return ((_a = parseManifest().supportedPlatform) === null || _a === void 0 ? void 0 : _a[0]) === "MOBILE";
19
+ }
20
+ exports.isMobile = isMobile;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@tuya-sat/micro-utils",
3
+ "version": "1.0.7",
4
+ "type": "commonjs",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "dev": "rm -rf dist/ && tsc --watch",
9
+ "build": "rm -rf dist/ && tsc",
10
+ "prepublish": "yarn build",
11
+ "test": "jest --verbose ./__tests__"
12
+ },
13
+ "keywords": [
14
+ "saturn-project",
15
+ "micro-frontend",
16
+ "no-code",
17
+ "IoT",
18
+ "saas",
19
+ "cloud",
20
+ "tuya"
21
+ ],
22
+ "devDependencies": {
23
+ "@types/semver": "^7.3.9",
24
+ "fs-extra": "^10.0.0",
25
+ "jest": "^27.5.1",
26
+ "ts-jest": "^27.1.3",
27
+ "typescript": "^4.5.4"
28
+ },
29
+ "dependencies": {
30
+ "semver": "^7.3.5"
31
+ }
32
+ }