@next2d/builder 0.1.8 → 0.1.11

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.
Files changed (67) hide show
  1. package/dist/cli.d.ts +59 -0
  2. package/dist/cli.js +141 -0
  3. package/dist/constants.d.ts +53 -0
  4. package/dist/constants.js +64 -0
  5. package/dist/context.d.ts +29 -0
  6. package/dist/context.js +19 -0
  7. package/dist/electron.d.ts +10 -0
  8. package/dist/electron.js +142 -0
  9. package/dist/index.js +18 -790
  10. package/dist/native.d.ts +27 -0
  11. package/dist/native.js +123 -0
  12. package/dist/utils.d.ts +27 -0
  13. package/dist/utils.js +40 -0
  14. package/dist/web.d.ts +18 -0
  15. package/dist/web.js +70 -0
  16. package/dist/xbox.d.ts +62 -0
  17. package/dist/xbox.js +426 -0
  18. package/package.json +11 -9
  19. package/templates/xbox/CMakeLists.txt +47 -11
  20. package/templates/xbox/README.md +18 -0
  21. package/templates/xbox/js/bootstrap.js +120 -0
  22. package/templates/xbox/src/AssetLoader.cpp +115 -12
  23. package/templates/xbox/src/AssetLoader.h +4 -0
  24. package/templates/xbox/src/EmbeddedAssets.cpp +149 -0
  25. package/templates/xbox/src/EmbeddedAssets.h +60 -0
  26. package/templates/xbox/src/EventLoop.cpp +0 -15
  27. package/templates/xbox/src/bindings/Audio.cpp +118 -22
  28. package/templates/xbox/src/bindings/Canvas.cpp +32 -2
  29. package/templates/xbox/src/bindings/Canvas2D.cpp +495 -39
  30. package/templates/xbox/src/bindings/Console.cpp +6 -1
  31. package/templates/xbox/src/bindings/DomShims.cpp +18 -2
  32. package/templates/xbox/src/bindings/EventTarget.cpp +9 -0
  33. package/templates/xbox/src/bindings/Image.cpp +83 -57
  34. package/templates/xbox/src/bindings/Polyfills.cpp +671 -236
  35. package/templates/xbox/src/bindings/RasterCore.h +105 -1
  36. package/templates/xbox/src/bindings/Video.cpp +57 -3
  37. package/templates/xbox/src/bindings/webgpu/WebGPU.cpp +29 -3
  38. package/templates/xbox/src/bindings/webgpu/WebGPUCommon.h +4 -1
  39. package/templates/xbox/src/bindings/webgpu/WebGPUEnums.h +32 -0
  40. package/templates/xbox/src/gpu/DawnContext.cpp +167 -16
  41. package/templates/xbox/src/main.cpp +385 -16
  42. package/templates/xbox/src/platform/AudioDecoder.cpp +121 -0
  43. package/templates/xbox/src/platform/AudioDecoder.h +18 -0
  44. package/templates/xbox/src/platform/AudioEngine.cpp +28 -3
  45. package/templates/xbox/src/platform/DecodeQueue.cpp +136 -0
  46. package/templates/xbox/src/platform/DecodeQueue.h +27 -0
  47. package/templates/xbox/src/platform/ImageDecoder.cpp +44 -0
  48. package/templates/xbox/src/platform/ImageDecoder.h +18 -0
  49. package/templates/xbox/src/platform/StbTextRasterizer.cpp +324 -0
  50. package/templates/xbox/src/platform/StbTextRasterizer.h +37 -0
  51. package/templates/xbox/src/platform/TextRasterizer.cpp +32 -0
  52. package/templates/xbox/src/platform/WicDecoder.cpp +19 -0
  53. package/templates/xbox/src/v8/CodeCache.h +223 -0
  54. package/templates/xbox/src/v8/V8Runtime.cpp +34 -33
  55. package/templates/xbox/src/v8/V8Util.h +54 -4
  56. package/templates/xbox/src/worker/WorkerRuntime.cpp +165 -65
  57. package/templates/xbox/src/worker/WorkerRuntime.h +23 -3
  58. package/templates/xbox/tests/check_local.sh +5 -1
  59. package/templates/xbox/tests/gamecore_api_probe.cpp +172 -0
  60. package/templates/xbox/tests/raster_test.cpp +50 -0
  61. package/templates/xbox/tests/windows_platform_test.cpp +75 -3
  62. package/templates/xbox/third_party/LICENSES.md +14 -0
  63. package/templates/xbox/third_party/dr_mp3.h +5412 -0
  64. package/templates/xbox/third_party/dr_wav.h +9131 -0
  65. package/templates/xbox/third_party/stb_image.h +7988 -0
  66. package/templates/xbox/third_party/stb_truetype.h +5079 -0
  67. package/templates/xbox/third_party/stb_vorbis.c +5584 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @description iOS用アプリの書き出し関数
3
+ * Export function for iOS apps
4
+ *
5
+ * @return {Promise}
6
+ * @method
7
+ * @public
8
+ */
9
+ export declare const runNative: () => Promise<void>;
10
+ /**
11
+ * @description iOS/Androidアプリのオープン関数
12
+ * Open function for iOS/Android apps
13
+ *
14
+ * @return {Promise}
15
+ * @method
16
+ * @public
17
+ */
18
+ export declare const openNative: () => Promise<void>;
19
+ /**
20
+ * @description iOS/Androidアプリのビルド関数
21
+ * Build function for iOS/Android apps
22
+ *
23
+ * @return {Promise}
24
+ * @method
25
+ * @public
26
+ */
27
+ export declare const buildNative: () => Promise<void>;
package/dist/native.js ADDED
@@ -0,0 +1,123 @@
1
+ // iOS / Android (Capacitor) ビルド。
2
+ import pc from "picocolors";
3
+ import fs from "fs";
4
+ import { ctx } from "./context.js";
5
+ import { $spawn } from "./utils.js";
6
+ import { CAPACITOR_CONFIG_NAME } from "./constants.js";
7
+ /**
8
+ * @description iOS/Androidのプロジェクトを生成
9
+ * Generate iOS/Android project
10
+ *
11
+ * @return {Promise}
12
+ * @method
13
+ * @private
14
+ */
15
+ const generateNativeProject = () => {
16
+ return new Promise((resolve, reject) => {
17
+ if (fs.existsSync(`${process.cwd()}/${ctx.platform}`)) {
18
+ return resolve();
19
+ }
20
+ const stream = $spawn("npx", [
21
+ "cap",
22
+ "add",
23
+ ctx.platform
24
+ ], { "stdio": "inherit" });
25
+ stream.on("close", (code) => {
26
+ if (code !== 0) {
27
+ reject(`Failed generated ${ctx.platform} project.`);
28
+ }
29
+ console.log(pc.green(`Successfully generated ${ctx.platform} project.`));
30
+ console.log();
31
+ resolve();
32
+ });
33
+ });
34
+ };
35
+ /**
36
+ * @description Capacitor の webDir を現在のビルド出力へ書き換える
37
+ * Point the Capacitor webDir at the current build output
38
+ *
39
+ * @return {void}
40
+ * @method
41
+ * @private
42
+ */
43
+ const applyCapacitorWebDir = () => {
44
+ const config = JSON.parse(fs.readFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, { "encoding": "utf8" }));
45
+ config.webDir = `${ctx.outDir}/${ctx.platformDir}/${ctx.environment}/`;
46
+ fs.writeFileSync(`${process.cwd()}/${CAPACITOR_CONFIG_NAME}`, JSON.stringify(config, null, 2));
47
+ };
48
+ /**
49
+ * @description iOS用アプリの書き出し関数
50
+ * Export function for iOS apps
51
+ *
52
+ * @return {Promise}
53
+ * @method
54
+ * @public
55
+ */
56
+ export const runNative = async () => {
57
+ await generateNativeProject();
58
+ // Capacitorの書き出しに必要な設定を生成
59
+ applyCapacitorWebDir();
60
+ $spawn("npx", [
61
+ "cap",
62
+ "run",
63
+ ctx.platform
64
+ ], { "stdio": "inherit" });
65
+ };
66
+ /**
67
+ * @description iOS/Androidアプリのオープン関数
68
+ * Open function for iOS/Android apps
69
+ *
70
+ * @return {Promise}
71
+ * @method
72
+ * @public
73
+ */
74
+ export const openNative = async () => {
75
+ await generateNativeProject();
76
+ // Capacitorの書き出しに必要な設定を生成
77
+ applyCapacitorWebDir();
78
+ const stream = $spawn("npx", [
79
+ "cap",
80
+ "sync",
81
+ ctx.platform
82
+ ], { "stdio": "inherit" });
83
+ stream.on("close", (code) => {
84
+ if (code !== 0) {
85
+ console.log(pc.red(`Failed to sync ${ctx.platform} project.`));
86
+ return;
87
+ }
88
+ $spawn("npx", [
89
+ "cap",
90
+ "open",
91
+ ctx.platform
92
+ ], { "stdio": "inherit" });
93
+ });
94
+ };
95
+ /**
96
+ * @description iOS/Androidアプリのビルド関数
97
+ * Build function for iOS/Android apps
98
+ *
99
+ * @return {Promise}
100
+ * @method
101
+ * @public
102
+ */
103
+ export const buildNative = async () => {
104
+ await generateNativeProject();
105
+ // Capacitorの書き出しに必要な設定を生成
106
+ applyCapacitorWebDir();
107
+ const stream = $spawn("npx", [
108
+ "cap",
109
+ "sync",
110
+ ctx.platform
111
+ ], { "stdio": "inherit" });
112
+ stream.on("close", (code) => {
113
+ if (code !== 0) {
114
+ console.log(pc.red(`Failed to sync ${ctx.platform} project.`));
115
+ return;
116
+ }
117
+ $spawn("npx", [
118
+ "cap",
119
+ "build",
120
+ ctx.platform
121
+ ], { "stdio": "inherit" });
122
+ });
123
+ };
@@ -0,0 +1,27 @@
1
+ import cp from "child_process";
2
+ /**
3
+ * @description builder パッケージに同梱したテンプレートの絶対パスを取得
4
+ * Get the absolute path of a template shipped with the builder package
5
+ *
6
+ * @param {string} name
7
+ * @return {string}
8
+ * @method
9
+ * @public
10
+ */
11
+ export declare const getTemplateDir: (name: string) => string;
12
+ /**
13
+ * @description npx / npm を子プロセスとして起動する (クロスプラットフォーム)。
14
+ * Windows では npx/npm が .cmd (バッチファイル) のため、shell 経由で
15
+ * ないと起動できない (spawn ENOENT / Node の CVE-2024-27980 対応により
16
+ * .cmd の直接 spawn も不可)。スペースを含む引数は二重引用符で保護する。
17
+ * Spawn npx/npm cross-platform. On Windows they are .cmd batch files,
18
+ * which require a shell to spawn.
19
+ *
20
+ * @param {string} command
21
+ * @param {array} args
22
+ * @param {object} options
23
+ * @return {object}
24
+ * @method
25
+ * @public
26
+ */
27
+ export declare const $spawn: (command: string, args: string[], options?: object) => cp.ChildProcess;
package/dist/utils.js ADDED
@@ -0,0 +1,40 @@
1
+ // 汎用ユーティリティ (テンプレート解決 / 子プロセス起動)。
2
+ import path from "path";
3
+ import cp from "child_process";
4
+ import { fileURLToPath } from "url";
5
+ /**
6
+ * @description builder パッケージに同梱したテンプレートの絶対パスを取得
7
+ * Get the absolute path of a template shipped with the builder package
8
+ *
9
+ * @param {string} name
10
+ * @return {string}
11
+ * @method
12
+ * @public
13
+ */
14
+ export const getTemplateDir = (name) => {
15
+ // dist/*.js から見た templates/ (パッケージルート直下)
16
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
17
+ return path.resolve(currentDir, "..", "templates", name);
18
+ };
19
+ /**
20
+ * @description npx / npm を子プロセスとして起動する (クロスプラットフォーム)。
21
+ * Windows では npx/npm が .cmd (バッチファイル) のため、shell 経由で
22
+ * ないと起動できない (spawn ENOENT / Node の CVE-2024-27980 対応により
23
+ * .cmd の直接 spawn も不可)。スペースを含む引数は二重引用符で保護する。
24
+ * Spawn npx/npm cross-platform. On Windows they are .cmd batch files,
25
+ * which require a shell to spawn.
26
+ *
27
+ * @param {string} command
28
+ * @param {array} args
29
+ * @param {object} options
30
+ * @return {object}
31
+ * @method
32
+ * @public
33
+ */
34
+ export const $spawn = (command, args, options = {}) => {
35
+ if (process.platform === "win32" && (command === "npx" || command === "npm")) {
36
+ const quoted = args.map((a) => /\s/.test(a) ? `"${a}"` : a);
37
+ return cp.spawn(command, quoted, { ...options, "shell": true });
38
+ }
39
+ return cp.spawn(command, args, options);
40
+ };
package/dist/web.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description package.json / vite.config を読み取り、ビルドディレクトリ等を ctx へ設定
3
+ * Load vite config and populate build directories into ctx
4
+ *
5
+ * @return {Promise}
6
+ * @method
7
+ * @public
8
+ */
9
+ export declare const loadConfig: () => Promise<void>;
10
+ /**
11
+ * @description Web用アプリの書き出し関数
12
+ * Export function for web applications
13
+ *
14
+ * @return {Promise}
15
+ * @method
16
+ * @public
17
+ */
18
+ export declare const buildWeb: () => Promise<void>;
package/dist/web.js ADDED
@@ -0,0 +1,70 @@
1
+ // Web ビルド: vite 設定の読み込みと HTML/JavaScript の書き出し。
2
+ import pc from "picocolors";
3
+ import fs from "fs";
4
+ import { loadConfigFromFile } from "vite";
5
+ import { ctx } from "./context.js";
6
+ import { $spawn } from "./utils.js";
7
+ /**
8
+ * @description package.json / vite.config を読み取り、ビルドディレクトリ等を ctx へ設定
9
+ * Load vite config and populate build directories into ctx
10
+ *
11
+ * @return {Promise}
12
+ * @method
13
+ * @public
14
+ */
15
+ export const loadConfig = async () => {
16
+ const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`, { "encoding": "utf8" }));
17
+ if (packageJson.type !== "module") {
18
+ packageJson.type = "module";
19
+ // overwride
20
+ fs.writeFileSync(`${process.cwd()}/package.json`, JSON.stringify(packageJson, null, 2));
21
+ }
22
+ const ext = fs.existsSync(`${process.cwd()}/vite.config.ts`) ? "ts" : "js";
23
+ const config = await loadConfigFromFile({
24
+ "command": "build",
25
+ "mode": "build"
26
+ }, `${process.cwd()}/vite.config.${ext}`);
27
+ // update config
28
+ ctx.configObject = config;
29
+ ctx.outDir = ctx.configObject.config?.build?.outDir || "dist";
30
+ ctx.buildDir = `${process.cwd()}/${ctx.outDir}/${ctx.platformDir}/${ctx.environment}`;
31
+ if (!fs.existsSync(`${ctx.buildDir}`)) {
32
+ fs.mkdirSync(`${ctx.buildDir}`, { "recursive": true });
33
+ console.log(pc.green(`Create build directory: ${ctx.buildDir}`));
34
+ console.log();
35
+ }
36
+ };
37
+ /**
38
+ * @description Web用アプリの書き出し関数
39
+ * Export function for web applications
40
+ *
41
+ * @return {Promise}
42
+ * @method
43
+ * @public
44
+ */
45
+ export const buildWeb = () => {
46
+ return new Promise((resolve, reject) => {
47
+ const stream = $spawn("npx", [
48
+ "@next2d/vite-plugin-next2d-auto-loader"
49
+ ], { "stdio": "inherit" });
50
+ stream.on("close", (code) => {
51
+ if (code !== 0) {
52
+ reject("vite plugin command failed.");
53
+ }
54
+ const stream = $spawn("npx", [
55
+ "vite",
56
+ "--outDir",
57
+ ctx.buildDir,
58
+ "build"
59
+ ], { "stdio": "inherit" });
60
+ stream.on("close", (code) => {
61
+ if (code !== 0) {
62
+ reject("Export of `HTML` and `JavaScript` failed.");
63
+ }
64
+ console.log();
65
+ console.log(pc.green("`HTML` and `JavaScript` files are written out."));
66
+ resolve();
67
+ });
68
+ });
69
+ });
70
+ };
package/dist/xbox.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @description ディレクトリを再帰的に走査し、各ファイルの
3
+ * [posix 相対キー, 絶対パス] を集める。
4
+ * Walk a directory recursively, collecting [posixRelKey, absPath] pairs.
5
+ *
6
+ * @param {string} rootDir 走査ルート
7
+ * @param {string} [prefix] キーへ付与する接頭辞 (例 "" / "assets/")
8
+ * @return {Array<[string, string]>}
9
+ * @method
10
+ * @public
11
+ */
12
+ export declare const walkFiles: (rootDir: string, prefix?: string) => [string, string][];
13
+ /**
14
+ * @description (key, データ) の並びを exe 埋め込み用 pak バイナリへ直列化する純関数。
15
+ * host 側 EmbeddedAssets.cpp の ParseEmbeddedPak と対になる。
16
+ * フォーマット (リトルエンディアン uint32):
17
+ * magic "N2DA" / version(=1) / count / [keyLen,key,dataLen,data]...
18
+ * Serialize (key, data) entries into the embedded pak binary.
19
+ *
20
+ * @param {Array<[string, Buffer]>} entries
21
+ * @return {Buffer}
22
+ * @method
23
+ * @public
24
+ */
25
+ export declare const buildPak: (entries: [string, Buffer][]) => Buffer;
26
+ /**
27
+ * @description assets.pak を RCDATA "N2DASSETS" として取り込む .rc の内容を生成する純関数。
28
+ * 相対パスだと rc.exe の CWD (build ディレクトリ) 基準で探して見つからない
29
+ * (RC2135) ため絶対パスを埋める。RC はフォワードスラッシュを受理する。
30
+ * 文字列は必ずダブルクォート (RC 仕様。シングルクォートは不可)。
31
+ * Render the .rc content that embeds assets.pak as RCDATA.
32
+ *
33
+ * @param {string} pakAbsPath assets.pak の絶対パス
34
+ * @return {string}
35
+ * @method
36
+ * @public
37
+ */
38
+ export declare const renderAssetsRc: (pakAbsPath: string) => string;
39
+ /**
40
+ * @description ホストスクリプト(js/bootstrap.js 等)を minify + 難読化する純関数。
41
+ * Oxc(vite 同梱)でコメント除去・空白圧縮・ローカル識別子マングルを行う。
42
+ * `globalThis.*` 等のグローバル名はゲームが参照するため保持される。
43
+ * 失敗時は元コードをそのまま返す(埋め込み自体は継続)。
44
+ * Minify/obfuscate a host script; returns the original on failure.
45
+ *
46
+ * @param {string} name ファイル名 (拡張子で構文判定)
47
+ * @param {string} code 元の JavaScript
48
+ * @return {string}
49
+ * @method
50
+ * @public
51
+ */
52
+ export declare const minifyJs: (name: string, code: string) => string;
53
+ /**
54
+ * @description Xbox(GDKネイティブ)用アプリの書き出し関数。
55
+ * V8にNext2DのJSを載せ、Dawn(WebGPU/D3D12)で描画するC++ホストをビルドする。
56
+ * Export function for Xbox (GDK native) apps.
57
+ *
58
+ * @return {Promise}
59
+ * @method
60
+ * @public
61
+ */
62
+ export declare const buildXbox: () => Promise<void>;