@macle-community/simulator-web 0.0.0-stage → 1.0.0
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 +125 -2
- package/bin/macle-web-simulator.js +108 -0
- package/package.json +37 -4
- package/runtime/framework/service/service.js +1 -0
- package/runtime/framework/view/view.js +1 -0
- package/runtime/remoteDebug/adapter.js +1 -0
- package/runtime/remoteDebug/service.html +16 -0
- package/runtime/remoteDebug/sub-packages.js +1 -0
- package/runtime/simulator/config/config.json +40 -0
- package/runtime/simulator/css/common.css +945 -0
- package/runtime/simulator/index.html +95 -0
- package/runtime/simulator/mockApi.json +1 -0
- package/runtime/simulator/native/native.js +1 -0
- package/runtime/simulator/public/default-user-avatar@128w.jpg +0 -0
- package/runtime/simulator/service/app.js +1 -0
- package/runtime/simulator/service/service.html +14 -0
- package/runtime/simulator/service/sync-api.js +1 -0
- package/runtime/simulator/version.json +1 -0
- package/runtime/simulator/view/webview.js +1 -0
- package/src/compiler.js +117 -0
- package/src/mock-backend.js +225 -0
- package/src/project-parser.js +87 -0
- package/src/server.js +334 -0
- package/src/watcher.js +76 -0
- package/web/index.html +234 -0
- package/web/qrcode.js +1145 -0
- package/web/simulator.css +526 -0
- package/web/simulator.js +510 -0
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @macle-community/simulator-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Standalone, lightweight, zero-Electron web simulator and developer workbench for Macle MiniPrograms (Taro React/Vue & Native MAML).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@macle-community/simulator-web)
|
|
6
|
+
[](https://www.huawei.com)
|
|
7
|
+
[](https://www.huawei.com)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[-orange.svg)]()
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- **Zero Electron Dependencies**: Runs on standard Node.js (v16+) with zero heavy binary dependencies. Compatible with Linux, macOS, Windows, Docker, and remote cloud development environments.
|
|
16
|
+
- **Official Dual-Thread Engine (v26.6.0-LG0001 / v100.4.2)**: Includes official service and view runtime engines, patched with webpack chunk loading proxy traps and null-safe DOM reconciliation.
|
|
17
|
+
- **Embedded Web Workbench**:
|
|
18
|
+
- **Realistic Device Frames**: Huawei Mate 60 Pro, Huawei Pura 70 Ultra, iPhone 15 Pro, iPhone 14 Pro Max, iPhone 13, iPhone 8 / SE, and iPad Pro 11".
|
|
19
|
+
- **Device Controls**: Portrait / Landscape orientation rotation, zoom scaling (50%, 75%, 100%, 125%, Fit-to-screen).
|
|
20
|
+
- **Touch Gesture Simulation**: Mouse-to-touch emulation with animated ripple cursor.
|
|
21
|
+
- **Page Selector**: Direct navigation to any page declared in `app.json`.
|
|
22
|
+
- **Integrated DevTools Drawer**:
|
|
23
|
+
- **Console**: Captures logs from both the logic thread (`service.js`) and render thread (`view.js`), with level filtering and interactive JavaScript REPL.
|
|
24
|
+
- **Storage**: Real-time inspection, editing, and deletion of `ma.getStorage` and `localStorage` keys.
|
|
25
|
+
- **Network**: Monitor and inspect `ma.request` calls, latency, payloads, and HTTP statuses.
|
|
26
|
+
- **App Info**: Project metadata, registered routes, window settings, and compiler versions.
|
|
27
|
+
- **Live Reload & Watcher**: Automatic file watching and hot-reloading via Server-Sent Events (SSE).
|
|
28
|
+
- **Mobile Device Preview via QR Code**: Auto-detects local LAN IP and generates a mobile-ready QR code for instant testing on physical phones/tablets.
|
|
29
|
+
- **Universal Compilation**: Compiles native MAML miniapps via `@macle/compiler` or serves pre-compiled Taro output bundles.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start
|
|
34
|
+
|
|
35
|
+
### 1. Installation via NPM
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Global CLI installation
|
|
39
|
+
npm install -g @macle-community/simulator-web
|
|
40
|
+
|
|
41
|
+
# Or run directly via npx
|
|
42
|
+
npx @macle-community/simulator-web -s ./dist
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Run from Source / Repository
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Clone the repository
|
|
49
|
+
git clone https://github.com/natiDotnet/macle-simulator-web.git
|
|
50
|
+
cd macle-simulator-web
|
|
51
|
+
|
|
52
|
+
# Run the web simulator
|
|
53
|
+
node bin/macle-web-simulator.js -s ../sample-project/dist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. CLI Options
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
macle-simulator-web [options]
|
|
60
|
+
|
|
61
|
+
Options:
|
|
62
|
+
-s, --source <path> Path to compiled (dist) or source Macle project [default: auto-detected]
|
|
63
|
+
-p, --port <port> Port to run the simulator server [default: 30001]
|
|
64
|
+
-H, --host <host> Host interface to bind [default: 0.0.0.0]
|
|
65
|
+
-w, --watch Watch files and auto-recompile / live-reload on changes
|
|
66
|
+
-o, --open Automatically open simulator in default browser
|
|
67
|
+
-v, --version Show version information
|
|
68
|
+
-h, --help Show help message
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. NPM Scripts
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Run with sample project
|
|
75
|
+
npm run sample
|
|
76
|
+
|
|
77
|
+
# Run with opendoc native miniapp
|
|
78
|
+
npm run opendoc
|
|
79
|
+
|
|
80
|
+
# Watch mode
|
|
81
|
+
npm run dev
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📁 Project Structure
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
macle-web-simulator/
|
|
90
|
+
├── bin/
|
|
91
|
+
│ └── macle-web-simulator.js # CLI executable
|
|
92
|
+
├── src/
|
|
93
|
+
│ ├── server.js # Pure Node.js HTTP server & static router
|
|
94
|
+
│ ├── compiler.js # @macle/compiler runner
|
|
95
|
+
│ ├── mock-backend.js # /mcss/simulate/* native Macle backend APIs
|
|
96
|
+
│ ├── project-parser.js # app.json & project.config.json parser
|
|
97
|
+
│ └── watcher.js # Live reload file watcher & SSE emitter
|
|
98
|
+
├── runtime/ # Bundled 26.6.0-LG0001 / v100.4.2 runtime
|
|
99
|
+
│ ├── framework/ # service.js & view.js
|
|
100
|
+
│ └── simulator/ # native.js, service.html, webview.js, common.css
|
|
101
|
+
├── web/ # Web simulator shell & DevTools
|
|
102
|
+
│ ├── index.html # Workbench UI
|
|
103
|
+
│ ├── simulator.css # Sleek device frames & dark DevTools theme
|
|
104
|
+
│ ├── simulator.js # Device dimensions, devtools, and router logic
|
|
105
|
+
│ └── qrcode.js # Client-side QR generator
|
|
106
|
+
├── package.json
|
|
107
|
+
└── README.md
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 🛠️ Native APIs Supported in Web Simulation
|
|
113
|
+
|
|
114
|
+
- `ma.request`: Outbound HTTP request proxying through the backend server.
|
|
115
|
+
- `ma.getStorage` / `ma.setStorage` / `ma.removeStorage` / `ma.clearStorage`.
|
|
116
|
+
- `ma.navigateTo` / `ma.redirectTo` / `ma.navigateBack` / `ma.switchTab`.
|
|
117
|
+
- `ma.setNavigationBarTitle` / `ma.setNavigationBarColor`.
|
|
118
|
+
- `ma.showToast` / `ma.showModal` / `ma.showLoading` / `ma.hideLoading`.
|
|
119
|
+
- `ma.getSystemInfo` / `ma.getSystemInfoSync` (responsive to device viewport changes).
|
|
120
|
+
- `ma.saveFile` / `ma.removeSavedFile` / `ma.getFileInfo` / `ma.getSavedFileList`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 📄 License
|
|
125
|
+
|
|
126
|
+
MIT © [Macle Team & natiDotnet](https://github.com/natiDotnet)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Macle MiniProgram Standalone Web Simulator CLI
|
|
4
|
+
* Pure Node.js - Zero Electron Dependencies
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const { exec } = require('child_process');
|
|
10
|
+
const { MacleWebSimulatorServer } = require('../src/server');
|
|
11
|
+
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
|
|
14
|
+
function printHelp() {
|
|
15
|
+
console.log(`
|
|
16
|
+
Macle MiniProgram Standalone Web Simulator
|
|
17
|
+
Version: 1.0.0 (Engine: 26.6.0-LG0001 / Runtime: v100.4.2)
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
macle-web-simulator [options]
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
-s, --source <path> Path to compiled or source Macle project (e.g. sample-project/dist)
|
|
24
|
+
-p, --port <port> Port to run the simulator server (default: 30001)
|
|
25
|
+
-H, --host <host> Host to bind server (default: 0.0.0.0)
|
|
26
|
+
-w, --watch Watch files and auto-recompile / live-reload on changes
|
|
27
|
+
-o, --open Automatically open simulator in default browser
|
|
28
|
+
-v, --version Show version information
|
|
29
|
+
-h, --help Show this help message
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
npx macle-web-simulator -s ./sample-project/dist
|
|
33
|
+
macle-web-simulator -s ./opendoc/miniapp --watch --open
|
|
34
|
+
macle-web-simulator -p 30005
|
|
35
|
+
`);
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
40
|
+
printHelp();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (args.includes('-v') || args.includes('--version')) {
|
|
44
|
+
console.log('macle-web-simulator v1.0.0');
|
|
45
|
+
console.log('Macle Engine: 26.6.0-LG0001');
|
|
46
|
+
console.log('Framework Runtime: v100.4.2');
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getArgValue(shortFlag, longFlag, defaultValue) {
|
|
51
|
+
const shortIdx = args.indexOf(shortFlag);
|
|
52
|
+
if (shortIdx !== -1 && args[shortIdx + 1]) return args[shortIdx + 1];
|
|
53
|
+
const longIdx = args.indexOf(longFlag);
|
|
54
|
+
if (longIdx !== -1 && args[longIdx + 1]) return args[longIdx + 1];
|
|
55
|
+
return defaultValue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const source = getArgValue('-s', '--source', null);
|
|
59
|
+
const portStr = getArgValue('-p', '--port', '30001');
|
|
60
|
+
const host = getArgValue('-H', '--host', '0.0.0.0');
|
|
61
|
+
const watch = args.includes('-w') || args.includes('--watch');
|
|
62
|
+
const shouldOpen = args.includes('-o') || args.includes('--open');
|
|
63
|
+
|
|
64
|
+
const port = parseInt(portStr, 10) || 30001;
|
|
65
|
+
|
|
66
|
+
async function run() {
|
|
67
|
+
try {
|
|
68
|
+
const simulator = new MacleWebSimulatorServer({
|
|
69
|
+
source,
|
|
70
|
+
port,
|
|
71
|
+
host,
|
|
72
|
+
watch
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await simulator.init();
|
|
76
|
+
const { localUrl } = await simulator.start();
|
|
77
|
+
|
|
78
|
+
if (shouldOpen) {
|
|
79
|
+
openBrowser(localUrl);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
process.on('SIGINT', () => {
|
|
83
|
+
console.log('\n[Simulator] Stopping web simulator server...');
|
|
84
|
+
simulator.close();
|
|
85
|
+
process.exit(0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
process.on('SIGTERM', () => {
|
|
89
|
+
simulator.close();
|
|
90
|
+
process.exit(0);
|
|
91
|
+
});
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error('[Simulator] Fatal error starting web simulator:', err);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function openBrowser(url) {
|
|
99
|
+
const start = process.platform === 'darwin' ? 'open' :
|
|
100
|
+
process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
101
|
+
exec(`${start} ${url}`, (err) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
console.warn('[Simulator] Could not auto-open browser:', err.message);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macle-community/simulator-web",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Standalone, zero-electron Web Simulator for Macle MiniPrograms (Taro & Native MAML)",
|
|
5
|
+
"main": "src/server.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"macle-simulator-web": "bin/macle-web-simulator.js",
|
|
8
|
+
"macle-web-simulator": "bin/macle-web-simulator.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "node bin/macle-web-simulator.js",
|
|
15
|
+
"dev": "node bin/macle-web-simulator.js --watch",
|
|
16
|
+
"sample": "node bin/macle-web-simulator.js -s ../sample-project/dist",
|
|
17
|
+
"opendoc": "node bin/macle-web-simulator.js -s ../opendoc/miniapp",
|
|
18
|
+
"test": "node bin/macle-web-simulator.js --help"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"macle",
|
|
22
|
+
"miniprogram",
|
|
23
|
+
"simulator",
|
|
24
|
+
"web-simulator",
|
|
25
|
+
"devtools",
|
|
26
|
+
"taro",
|
|
27
|
+
"maml",
|
|
28
|
+
"huawei"
|
|
29
|
+
],
|
|
30
|
+
"author": "t.tsegaye <t.tsegaye@appdiv.com>",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/natiDotnet/macle-simulator-web.git"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=16.0.0"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
}
|