transone-cli 0.2.0 → 0.3.1

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 CHANGED
@@ -1,35 +1,138 @@
1
1
  # transone-cli
2
2
 
3
- TransOne 多端编译器:Bun 原生 CLI,按 Target 将一份 TypeScript 源码静态转换为多端原生工程。
3
+ **English** · [简体中文](./README.zh-CN.md)
4
4
 
5
- ## 目标端抽象(Target)
5
+ Bun-native, multi-target compiler CLI for TransOne applications. It statically converts **one TypeScript source** into Web and multi-platform mini-program native projects at compile time, per target.
6
+
7
+ The CLI is the compiler half of the TransOne framework — the runtime model is in [`transone`](../transone), and the component library is in [`transone-ui`](../transone-ui).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ bun add -g transone-cli
13
+ # or npm i -g transone-cli
14
+ ```
15
+
16
+ Requires Bun >= 1.3.0.
17
+
18
+ ## Usage
6
19
 
7
20
  ```text
8
- web 直接渲染(HTML + 浏览器运行时,M1 已实现)
9
- mp-weixin WXML / WXSS / JS 静态转换(M2 规划中)
10
- mp-alipay AXML / ACSS 静态转换(M3 规划中)
11
- mp-bytedance ttml / ttss 静态转换(M3 规划中)
12
- app-* 远期占位(app-ios / app-android / app-harmony)
21
+ Usage:
22
+ transone create
23
+ transone dev [--host <host>] [--port <port>] [--base <path>] [--no-watch]
24
+ transone build [--target <target>] [--out-dir <path>] [--base <path>] [--library]
25
+
26
+ Targets: web, mp-weixin, mp-alipay, mp-bytedance, app-ios, app-android, app-harmony (default: web)
13
27
  ```
14
28
 
15
- 新增目标端:实现 `BuildTarget` 接口并注册到 `TargetRegistry`,无需改动构建入口。
29
+ ### `transone create`
30
+
31
+ Scaffolds a new TransOne project in the current directory (refuses to overwrite existing project files).
16
32
 
17
- ## 使用
33
+ ### `transone dev`
34
+
35
+ Starts the development server (Web target only) with optional watch mode (`--no-watch` to disable), custom `--host` / `--port`, and a `--base` path.
36
+
37
+ ### `transone build`
38
+
39
+ Builds the app for a target:
18
40
 
19
41
  ```bash
20
- transone build --target web # 产出 H5 站点
21
- transone build --target mp-weixin # 未实现时编译期报错并给出路线图阶段
22
- transone dev # 开发服务(仅 web)
23
- transone create # 脚手架
42
+ transone build --target web # H5 site / SPA
43
+ transone build --target mp-weixin # WeChat mini-program project (WXML/WXSS/JS)
44
+ transone build --target mp-alipay # Alipay mini-program project (AXML/ACSS)
45
+ transone build --target mp-bytedance # ByteDance mini-program project (TTML/TTSS)
24
46
  ```
25
47
 
48
+ - `--out-dir` overrides the output directory.
49
+ - `--base` sets the deployment base path (e.g. a GitHub Pages sub-path).
50
+ - `--library` builds in library mode (no page entry required).
51
+
52
+ Unimplemented targets fail fast at compile time with a clear error pointing to the corresponding roadmap stage.
53
+
54
+ ## Targets
55
+
56
+ | Target | Output | Mechanism | Status |
57
+ | --- | --- | --- | --- |
58
+ | `web` | H5 site / SPA | Direct rendering (HTML + browser runtime) | Implemented |
59
+ | `mp-weixin` | Native WeChat mini-program project | Compile-time static conversion (WXML / WXSS / JS) | Implemented |
60
+ | `mp-alipay` | Native Alipay mini-program project | Compile-time static conversion (AXML / ACSS) | Implemented |
61
+ | `mp-bytedance` | Native ByteDance mini-program project | Compile-time static conversion (TTML / TTSS) | Implemented |
62
+ | `app-ios` / `app-android` / `app-harmony` | Native app | TBD | Roadmap |
63
+
64
+ Mini-program builds emit a complete native project: `app.json` / `app.js` / app style file / project config, plus `pages/<route>/<name>.*` and `components/<tag>/<tag>.*`. Platform differences (template syntax, style language, event binding, lifecycle mapping) are handled by the `MpDialect` abstraction.
65
+
66
+ ## Configuration
67
+
68
+ Create a `transone.config.ts` in the project root and export the config with `defineConfig`:
69
+
70
+ ```ts
71
+ import { defineConfig } from 'transone-cli';
72
+
73
+ export default defineConfig({
74
+ entry: 'src/main.ts', // default
75
+ server: {
76
+ host: '127.0.0.1', // default
77
+ port: 52211, // default
78
+ proxy: {
79
+ '/api': { target: 'http://localhost:8080', changeOrigin: true },
80
+ },
81
+ },
82
+ build: {
83
+ outDir: 'dist/build/h5', // default
84
+ basePath: '',
85
+ directoryPages: false,
86
+ },
87
+ mp: {
88
+ appId: 'touristappid', // WeChat dev-tool test id by default
89
+ navigationBarTitleText: 'TransOne',
90
+ lengthUnit: 'px', // or 'rpx' (values converted at 1px = 2rpx)
91
+ // pages, window, tabBar, appExtra, pageExtra, globalData, publicDir ...
92
+ },
93
+ });
94
+ ```
95
+
96
+ The `mp` field accepts either a single `MiniProgramConfig` (applies to every mini-program target; recommended for WeChat-only apps) or a per-platform map like `{ 'mp-weixin': {...}, 'mp-alipay': {...} }` — only the config for the current target is used.
97
+
98
+ ## How the compiler works
99
+
100
+ 1. Loads the project config and resolves pages from the entry file.
101
+ 2. For Web: renders directly with the browser runtime (H5 site / SPA).
102
+ 3. For mini-program targets: statically analyzes the root component class of each page, then compiles the component tree into native files — WXML/JS (WeChat), AXML/ACSS (Alipay), TTML/TTSS (ByteDance) — including styles, template bindings, event methods, and data-state mapping. The generated code is a standalone native project with no TransOne runtime.
103
+ 4. Library components are resolved through the `"source"` field of each package's `package.json` (see `transone-ui`).
104
+
105
+ ## Extending a new target
106
+
107
+ Implement the `BuildTarget` interface and register it with `TargetRegistry` — no changes to the build entry point are needed:
108
+
109
+ ```ts
110
+ import type { BuildTarget, TargetType, ResolvedConfig, BuildOptions, BuildResult } from 'transone-cli';
111
+
112
+ export class MyTarget implements BuildTarget {
113
+ readonly type: TargetType = 'my-target';
114
+ readonly label = 'My target platform';
115
+ async build(config: ResolvedConfig, options: BuildOptions): Promise<BuildResult> {
116
+ // generate the native project for your platform
117
+ }
118
+ }
119
+ ```
120
+
121
+ ## Development
122
+
26
123
  ```bash
27
- bun test # 测试
28
- bun run build # 构建 dist(CLI bundle + .d.ts)
124
+ bun test # run tests
125
+ bun run build # build dist (CLI bundle + .d.ts)
126
+ bun run build:types
127
+ bun run lint
29
128
  ```
30
129
 
31
- ## 文档
130
+ ## Documentation
131
+
132
+ - Online docs (CLI site): <https://geektech-team.github.io/transone/cli/>
133
+ - Main docs site: <https://geektech-team.github.io/transone/>
134
+ - Repository: <https://github.com/geektech-team/transone>
135
+
136
+ ## License
32
137
 
33
- - 在线文档(CLI 子站):<https://geektech-team.github.io/transone/cli/>
34
- - 主文档站:<https://geektech-team.github.io/transone/>
35
- - 仓库:<https://github.com/geektech-team/transone>
138
+ MIT
@@ -0,0 +1,37 @@
1
+ # transone-cli
2
+
3
+ **简体中文** · [English](./README.md)
4
+
5
+ TransOne 多端编译器:Bun 原生 CLI,按 Target 将一份 TypeScript 源码静态转换为多端原生工程。
6
+
7
+ ## 目标端抽象(Target)
8
+
9
+ ```text
10
+ web 直接渲染(HTML + 浏览器运行时,M1 已实现)
11
+ mp-weixin WXML / WXSS / JS 静态转换(M2 规划中)
12
+ mp-alipay AXML / ACSS 静态转换(M3 规划中)
13
+ mp-bytedance ttml / ttss 静态转换(M3 规划中)
14
+ app-* 远期占位(app-ios / app-android / app-harmony)
15
+ ```
16
+
17
+ 新增目标端:实现 `BuildTarget` 接口并注册到 `TargetRegistry`,无需改动构建入口。
18
+
19
+ ## 使用
20
+
21
+ ```bash
22
+ transone build --target web # 产出 H5 站点
23
+ transone build --target mp-weixin # 未实现时编译期报错并给出路线图阶段
24
+ transone dev # 开发服务(仅 web)
25
+ transone create # 脚手架
26
+ ```
27
+
28
+ ```bash
29
+ bun test # 测试
30
+ bun run build # 构建 dist(CLI bundle + .d.ts)
31
+ ```
32
+
33
+ ## 文档
34
+
35
+ - 在线文档(CLI 子站):<https://geektech-team.github.io/transone/cli/>
36
+ - 主文档站:<https://geektech-team.github.io/transone/>
37
+ - 仓库:<https://github.com/geektech-team/transone>
@@ -1452,6 +1452,9 @@ function compileSlot(context, classSource, node, env) {
1452
1452
  return [indent(env.indent) + "<slot/>"];
1453
1453
  }
1454
1454
  const name = compileLiteralString(context, classSource, nameExpr, "slot \u540D\u79F0");
1455
+ if (name === "default") {
1456
+ return [indent(env.indent) + "<slot/>"];
1457
+ }
1455
1458
  return [indent(env.indent) + `<slot name="${name}"/>`];
1456
1459
  }
1457
1460
  function compileListener(context, classSource, eventName, handlerExpr, env) {
@@ -2119,6 +2122,7 @@ function collectModuleConsts3(context, classSource) {
2119
2122
  // src/mp/methods.ts
2120
2123
  var PAGE_LIFECYCLE = {
2121
2124
  beforeMount: "onLoad",
2125
+ onLoad: "onLoad",
2122
2126
  onMounted: "onReady",
2123
2127
  onUnmounted: "onUnload",
2124
2128
  onShow: "onShow",
@@ -2149,6 +2153,9 @@ function compileMethods(context, classSource, usedNames, kind, customEvents) {
2149
2153
  seed.add(hook);
2150
2154
  }
2151
2155
  }
2156
+ if (methods.has("onPropsChange")) {
2157
+ seed.add("onPropsChange");
2158
+ }
2152
2159
  const queue = [...seed];
2153
2160
  const visited = new Set;
2154
2161
  const entries = [];
@@ -2621,6 +2628,13 @@ function generateComponentJs(unit, dialect) {
2621
2628
  }
2622
2629
  parts.push(" },");
2623
2630
  }
2631
+ const hasPropsHook = unit.methods.some((entry) => entry.key === "onPropsChange");
2632
+ if (hasPropsHook) {
2633
+ const watched = Object.keys(unit.properties);
2634
+ parts.push(" observers: {");
2635
+ parts.push(` ${JSON.stringify(watched.join(", "))}: function () { if (typeof this.onPropsChange === 'function') this.onPropsChange(); },`);
2636
+ parts.push(" },");
2637
+ }
2624
2638
  parts.push("});");
2625
2639
  return parts.join(`
2626
2640
  `) + `
@@ -2791,5 +2805,5 @@ export {
2791
2805
  buildMiniProgram
2792
2806
  };
2793
2807
 
2794
- //# debugId=1B46276CC3CBABAA64756E2164756E21
2795
- //# sourceMappingURL=build-mp-kcnx989m.js.map
2808
+ //# debugId=EBDB309ADE017FFC64756E2164756E21
2809
+ //# sourceMappingURL=build-mp-k1dgvwwx.js.map