@tuya-sat/micro-dev-loader 0.0.1-beta.3 → 0.0.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.
package/dist/transform.js CHANGED
@@ -1,117 +1,117 @@
1
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 core_1 = require("@babel/core");
7
- const template_1 = __importDefault(require("@babel/template"));
8
- const generator_1 = __importDefault(require("@babel/generator"));
9
- const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
10
- const VUE_TYPES = ["VUE_TS", "VUE_JS"];
11
- const REACT_TYPES = ["REACT_TS", "REACT_JS"];
12
- class CodeMaker {
13
- constructor({ sourceCode, microFramework }) {
14
- this.ast = this.parse(sourceCode);
15
- this.microFramework = microFramework;
16
- }
17
- parse(code) {
18
- return (0, core_1.parse)(code, {
19
- plugins: [
20
- [
21
- plugin_syntax_typescript_1.default,
22
- {
23
- isTSX: true,
24
- allExtensions: true,
25
- },
26
- ],
27
- ],
28
- });
29
- }
30
- changeAst(props) {
31
- const temp = this.getTemp(props);
32
- (0, core_1.traverse)(this.ast, {
33
- ExportNamedDeclaration(path) {
34
- let isTarget = false;
35
- try {
36
- isTarget =
37
- path.node.declaration.kind === "let" &&
38
- path.node.declaration.declarations[0].id.name ===
39
- "hasPermission";
40
- }
41
- catch (_a) { }
42
- if (!isTarget) {
43
- return;
44
- }
45
- let tempNode = template_1.default.ast(temp);
46
- path.insertAfter(tempNode);
47
- },
48
- });
49
- }
50
- gtAst() {
51
- const { code } = (0, generator_1.default)(this.ast);
52
- return code;
53
- }
54
- vueReRenderTemp() {
55
- return `
56
- const reRender = () => {
57
- app.unmount()
58
- render({})
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = void 0;
6
+ var _core = require("@babel/core");
7
+ var _template = _interopRequireDefault(require("@babel/template"));
8
+ var _generator = _interopRequireDefault(require("@babel/generator"));
9
+ var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
10
+ function _classCallCheck(instance, Constructor) {
11
+ if (!(instance instanceof Constructor)) {
12
+ throw new TypeError("Cannot call a class as a function");
59
13
  }
60
- `;
61
- }
62
- reactReRenderTemp() {
63
- return `
64
- const reRender = () => {
65
- ReactDOM.unmountComponentAtNode(document.querySelector('#root'))
66
- render({})
14
+ }
15
+ function _defineProperties(target, props) {
16
+ for(var i = 0; i < props.length; i++){
17
+ var descriptor = props[i];
18
+ descriptor.enumerable = descriptor.enumerable || false;
19
+ descriptor.configurable = true;
20
+ if ("value" in descriptor) descriptor.writable = true;
21
+ Object.defineProperty(target, descriptor.key, descriptor);
67
22
  }
68
- `;
23
+ }
24
+ function _createClass(Constructor, protoProps, staticProps) {
25
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
26
+ if (staticProps) _defineProperties(Constructor, staticProps);
27
+ return Constructor;
28
+ }
29
+ function _interopRequireDefault(obj) {
30
+ return obj && obj.__esModule ? obj : {
31
+ default: obj
32
+ };
33
+ }
34
+ var VUE_TYPES = [
35
+ "VUE_TS",
36
+ "VUE_JS"
37
+ ];
38
+ var REACT_TYPES = [
39
+ "REACT_TS",
40
+ "REACT_JS"
41
+ ];
42
+ var CodeMaker = /*#__PURE__*/ function() {
43
+ "use strict";
44
+ function CodeMaker(param) {
45
+ var sourceCode = param.sourceCode, microFramework = param.microFramework;
46
+ _classCallCheck(this, CodeMaker);
47
+ this.ast = this.parse(sourceCode);
48
+ this.microFramework = microFramework;
69
49
  }
70
- getTemp(props) {
71
- const { privileges, authedCode } = props;
72
- const temp = `
73
- {
74
- window._allCodesStatusMap = new Map()
75
- window._authedCodeInfoProxy = {}
76
- hasPermission = (code) => {
77
- return window._allCodesStatusMap.get(code)
78
- };
79
- const changeAuthedMap = (authedCode) => {
80
- const privileges = ${JSON.stringify(privileges)}
81
- const allCodesStatus = privileges?.map(
82
- ({ name, code }) => [
83
- code,
84
- authedCode.includes(code),
85
- ]
86
- );
87
- window._allCodesStatusMap = new Map(allCodesStatus)
88
- }
89
-
90
- ${REACT_TYPES.includes(this.microFramework)
91
- ? this.reactReRenderTemp()
92
- : this.vueReRenderTemp()}
93
- const authedCodeInfo = {
94
- authedCode:${JSON.stringify(authedCode)}
95
- }
96
-
97
- changeAuthedMap(authedCodeInfo.authedCode)
98
- window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{
99
- get(target,prop){
100
- return target[prop]
101
- },
102
- set(target,prop,value){
103
- if(prop === 'authedCode') {
104
- changeAuthedMap(value)
105
- reRender()
50
+ _createClass(CodeMaker, [
51
+ {
52
+ key: "parse",
53
+ value: function parse(code) {
54
+ return (0, _core).parse(code, {
55
+ plugins: [
56
+ [
57
+ _pluginSyntaxTypescript.default,
58
+ {
59
+ isTSX: true,
60
+ allExtensions: true
61
+ },
62
+ ],
63
+ ]
64
+ });
106
65
  }
107
- target[prop] = value
108
- return true
109
- }
110
- })
111
-
112
- }
113
- `;
114
- return temp;
115
- }
116
- }
66
+ },
67
+ {
68
+ key: "changeAst",
69
+ value: function changeAst(props) {
70
+ var temp = this.getTemp(props);
71
+ (0, _core).traverse(this.ast, {
72
+ ExportNamedDeclaration: function ExportNamedDeclaration(path) {
73
+ var isTarget = false;
74
+ try {
75
+ isTarget = path.node.declaration.kind === "let" && path.node.declaration.declarations[0].id.name === "hasPermission";
76
+ } catch (e) {
77
+ }
78
+ if (!isTarget) {
79
+ return;
80
+ }
81
+ var tempNode = _template.default.ast(temp);
82
+ path.insertAfter(tempNode);
83
+ }
84
+ });
85
+ }
86
+ },
87
+ {
88
+ key: "gtAst",
89
+ value: function gtAst() {
90
+ var code = (0, _generator).default(this.ast).code;
91
+ return code;
92
+ }
93
+ },
94
+ {
95
+ key: "vueReRenderTemp",
96
+ value: function vueReRenderTemp() {
97
+ return "\n const reRender = () => {\n app.unmount()\n render({})\n }\n ";
98
+ }
99
+ },
100
+ {
101
+ key: "reactReRenderTemp",
102
+ value: function reactReRenderTemp() {
103
+ return "\n const reRender = () => {\n ReactDOM.unmountComponentAtNode(document.querySelector('#root'))\n render({})\n }\n ";
104
+ }
105
+ },
106
+ {
107
+ key: "getTemp",
108
+ value: function getTemp(props) {
109
+ var privileges = props.privileges, authedCode = props.authedCode;
110
+ var temp = "\n {\n window._allCodesStatusMap = new Map()\n window._authedCodeInfoProxy = {}\n hasPermission = (code) => {\n return window._allCodesStatusMap.get(code)\n };\n const changeAuthedMap = (authedCode) => {\n const privileges = ".concat(JSON.stringify(privileges), "\n const allCodesStatus = privileges?.map(\n ({ name, code }) => [\n code,\n authedCode.includes(code),\n ]\n );\n window._allCodesStatusMap = new Map(allCodesStatus)\n }\n \n ").concat(REACT_TYPES.includes(this.microFramework) ? this.reactReRenderTemp() : this.vueReRenderTemp(), "\n const authedCodeInfo = {\n authedCode:").concat(JSON.stringify(authedCode), "\n }\n \n changeAuthedMap(authedCodeInfo.authedCode)\n window._authedCodeInfoProxy = new Proxy(authedCodeInfo,{\n get(target,prop){\n return target[prop]\n },\n set(target,prop,value){\n if(prop === 'authedCode') {\n changeAuthedMap(value)\n reRender()\n }\n target[prop] = value\n return true\n }\n })\n\n }\n ");
111
+ return temp;
112
+ }
113
+ }
114
+ ]);
115
+ return CodeMaker;
116
+ }();
117
117
  exports.default = CodeMaker;
@@ -1,14 +1,18 @@
1
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 fs_extra_1 = __importDefault(require("fs-extra"));
7
- const path_1 = __importDefault(require("path"));
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = parseManifest;
6
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
7
+ var _path = _interopRequireDefault(require("path"));
8
+ function _interopRequireDefault(obj) {
9
+ return obj && obj.__esModule ? obj : {
10
+ default: obj
11
+ };
12
+ }
8
13
  function parseManifest() {
9
- const MANIFEST_FILE = "manifest.json";
10
- const cwd = process.cwd();
11
- const manifest = fs_extra_1.default.readJSONSync(path_1.default.resolve(cwd, MANIFEST_FILE), "utf-8");
14
+ var MANIFEST_FILE = "manifest.json";
15
+ var cwd = process.cwd();
16
+ var manifest = _fsExtra.default.readJSONSync(_path.default.resolve(cwd, MANIFEST_FILE), "utf-8");
12
17
  return manifest;
13
18
  }
14
- exports.default = parseManifest;
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-loader",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
- "dev": "tsc --watch",
8
- "build": "rm -rf dist/ && tsc && yarn copyOtherFiles",
9
- "copyOtherFiles": "cp -R src/plugins/layoutMock/layout-static dist/plugins/layoutMock/layout-static",
7
+ "dev": "swc src -D -w -d dist",
8
+ "build": "swc src -D -d dist",
10
9
  "prepublish": "yarn build",
11
10
  "test": "jest --verbose ./__tests__"
12
11
  },
@@ -21,9 +20,20 @@
21
20
  "loader-utils": "^2.0.0"
22
21
  },
23
22
  "devDependencies": {
23
+ "@swc/cli": "^0.1.52",
24
+ "@swc/core": "^1.2.117",
24
25
  "@types/jest": "^26.0.24",
25
26
  "jest": "^27.0.6",
26
27
  "ts-jest": "^27.0.4",
27
28
  "typescript": "^4.4.4"
28
- }
29
+ },
30
+ "keywords": [
31
+ "saturn-project",
32
+ "micro-frontend",
33
+ "no-code",
34
+ "IoT",
35
+ "saas",
36
+ "cloud",
37
+ "tuya"
38
+ ]
29
39
  }
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import LayoutMockPlugin from "./plugins/layoutMock";
2
- declare const addjsLoader: (sourceCode: string) => string;
3
- export default addjsLoader;
4
- export { LayoutMockPlugin };
@@ -1,2 +0,0 @@
1
- declare const manifestDom = "\n(function ExternalRender() {\n const div = document.createElement('div');\n const { insertDom } = require(\"@tuya-sat/micro-dev-component\");\n insertDom(div)\n document.body.appendChild(div);\n})();\n";
2
- export default manifestDom;
@@ -1,4 +0,0 @@
1
- export default class LayoutMockPlugin {
2
- static useLayoutStatic(app: any): void;
3
- apply(compiler: any): void;
4
- }