pixifact-cli 0.17.0 → 0.18.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 CHANGED
@@ -122,6 +122,10 @@ pixifact dev --mode douyin
122
122
 
123
123
  Web mode 只需要 `pixifact`,不安装小游戏平台包也能构建。`dev` 默认 mode 为 `development`,`build` 和 `validate` 默认为 `production`;显式 `--mode` 原样交给 Vite。默认产物目录为 `dist/<platform>/`,需要修改时使用 Vite `build.outDir`。
124
124
 
125
+ `pixifact dev` 的 Web 开发服务默认监听所有网络接口,启动 JSON 的 `urls.local` 和 `urls.network` 分别提供本机与局域网游戏地址;同一局域网的手机或电脑可直接打开 `urls.network` 中的 URL。项目在 `vite.config.ts` 显式设置的 `server.host` 会优先使用,例如 `server: { host: '127.0.0.1' }` 只监听本机。
126
+
127
+ `pixifact dev` 同时自动启用 Bun Inspector,默认监听 `0.0.0.0`,端口由系统分配;项目的 `dev` 脚本直接调用 `pixifact dev` 即可。远程调试时,将 Bun 输出的 WebSocket 或浏览器调试链接中的 `0.0.0.0` 替换为开发电脑的局域网 IP,保留端口和路径。若启动 Bun 时已指定 `--inspect`、`--inspect-brk` 或 `--inspect-wait`(包括自定义地址),CLI 使用已有调试参数。
128
+
125
129
  CLI 使用 Vite 完成 env、TypeScript、tree-shaking、watch、静态资源和产物生命周期;Pixifact 插件负责 Scene 编译、当前平台虚拟模块、Pixi manifest、资源分包、原生配置和包体检查。业务代码只使用 PixiJS `Assets`,不需要手动加载分包。
126
130
 
127
131
  完整配置见 [微信小游戏构建](https://github.com/hxg2050/pixifact/blob/main/docs/zh/wechat-minigame.md) 和 [抖音小游戏构建](https://github.com/hxg2050/pixifact/blob/main/docs/zh/douyin-minigame.md),可运行三端示例见 [wechat-minigame-demo](https://github.com/hxg2050/pixifact/tree/main/sample-projects/wechat-minigame-demo)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixifact-cli",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Pixifact Scene 自动化 CLI。",
5
5
  "packageManager": "bun@1.3.13",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "start": "bun src/pixifact-cli.ts"
33
33
  },
34
34
  "dependencies": {
35
- "pixifact": "^0.17.0",
35
+ "pixifact": "^0.18.0",
36
36
  "playwright": "1.58.2",
37
37
  "vite": "^8.0.10"
38
38
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import { pathToFileURL } from 'node:url';
4
+ import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import { createPixifactAutomation } from './automation';
6
6
  import { hintForCommandError } from 'pixifact';
7
7
  import { CompileSceneError, compileScenes } from 'pixifact/compiler-node';
@@ -50,6 +50,7 @@ interface ParsedArgs {
50
50
  }
51
51
 
52
52
  const runtimeScreenshotDefaultOutput = '.pixifact/runtime/frame.png';
53
+ const isCliEntrypoint = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
53
54
 
54
55
  function parseArgs(argv: string[]): ParsedArgs {
55
56
  const positionals: string[] = [];
@@ -440,6 +441,7 @@ async function executeFileCommand(
440
441
  mode,
441
442
  watching: true,
442
443
  report: session.initialReport,
444
+ urls: session.urls,
443
445
  };
444
446
  } catch (error) {
445
447
  if (error instanceof PixifactTargetError) {
@@ -611,6 +613,30 @@ export async function executePixifactCli(argv: string[], options: CliOptions = {
611
613
  };
612
614
  }
613
615
 
616
+ if (isCliEntrypoint
617
+ && parsed.positionals.length === 1
618
+ && parsed.positionals[0] === 'dev'
619
+ && !process.execArgv.some((arg) => /^--inspect(?:-brk|-wait)?(?:=|$)/.test(arg))) {
620
+ assertAllowedFlags(parsed.flags, ['mode', 'project-root'], 'dev');
621
+ const child = Bun.spawn([
622
+ process.execPath,
623
+ ...process.execArgv,
624
+ '--inspect=0.0.0.0:0',
625
+ fileURLToPath(import.meta.url),
626
+ ...argv,
627
+ ], { stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' });
628
+ const interrupt = () => child.kill('SIGINT');
629
+ const terminate = () => child.kill('SIGTERM');
630
+ process.on('SIGINT', interrupt);
631
+ process.on('SIGTERM', terminate);
632
+ try {
633
+ return { exitCode: await child.exited, stdout: '', stderr: '' };
634
+ } finally {
635
+ process.off('SIGINT', interrupt);
636
+ process.off('SIGTERM', terminate);
637
+ }
638
+ }
639
+
614
640
  const automation = options.automation ?? createPixifactAutomation();
615
641
  const result = await executeFileCommand(
616
642
  parsed.positionals,
@@ -650,7 +676,7 @@ export async function executePixifactCli(argv: string[], options: CliOptions = {
650
676
  }
651
677
  }
652
678
 
653
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
679
+ if (isCliEntrypoint) {
654
680
  const result = await executePixifactCli(process.argv.slice(2), {
655
681
  onDevEvent: (event) => process.stdout.write(jsonLine(event)),
656
682
  });
package/src/viteTarget.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  build,
5
5
  createServer,
6
6
  resolveConfig,
7
+ type ResolvedServerUrls,
7
8
  type Rollup,
8
9
  } from 'vite';
9
10
  import {
@@ -42,6 +43,7 @@ export interface PixifactDevSession {
42
43
  close(): Promise<void>;
43
44
  initialReport: PixifactBuildReport;
44
45
  platform: PixifactPlatform;
46
+ urls?: ResolvedServerUrls | null;
45
47
  }
46
48
 
47
49
  export class PixifactTargetError extends Error {
@@ -123,12 +125,17 @@ export async function devPixifactTarget(
123
125
  root: validation.projectRoot,
124
126
  mode,
125
127
  logLevel: 'silent',
128
+ plugins: [{
129
+ name: 'pixifact-dev-host',
130
+ config: (config) => ({ server: { host: config.server?.host ?? true } }),
131
+ }],
126
132
  });
127
133
  await server.listen();
128
134
  return {
129
135
  close: () => server.close(),
130
136
  initialReport: emptyReport('web', validation.resolved.build.outDir),
131
137
  platform: 'web',
138
+ urls: server.resolvedUrls,
132
139
  };
133
140
  }
134
141
  let resolveInitial: (report: PixifactBuildReport) => void;