@textmode/build 0.1.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/LICENSE ADDED
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @textmode/build
2
+
3
+ <div align="center">
4
+
5
+ | [![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?logo=javascript&logoColor=black)](https://developer.mozilla.org/en-US/docs/Web/JavaScript) [![Vite](https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white)](https://vitejs.dev/) [![Vitest](https://img.shields.io/badge/Vitest-6E9F18?logo=vitest&logoColor=white)](https://vitest.dev/) | [![docs](https://img.shields.io/badge/docs-vitepress-646cff?logo=vitepress&logoColor=white)](https://code.textmode.art/) [![Discord](https://img.shields.io/discord/1357070706181017691?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/sjrw8QXNks) | [![ko-fi](https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi)](https://ko-fi.com/V7V8JG2FY) [![GitHub-sponsors](https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/humanbydefinition) |
6
+ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
+
8
+ </div>
9
+
10
+ `@textmode/build` owns build, dev, preview, and test tooling for the [`textmode.js`](https://github.com/humanbydefinition/textmode.js) ecosystem. It bundles [Vite](https://vitejs.dev/), [Vitest](https://vitest.dev/), Terser, jsdom, and the shared GLSL plugin behind one `textmode-build` command, so consumers no longer install or configure the engines themselves.
11
+
12
+ Use it to give every repository the same library build, dev server, preview, and test behavior without repeating engine dependencies or config files.
13
+
14
+ ## Features
15
+
16
+ - **One package, multiple engines** - Vite, Vitest, Terser, jsdom, `@vitest/coverage-v8`, and `@mapwhit/glsl-minify` are implementation dependencies, not peer dependencies. Consumers install only `@textmode/build`.
17
+ - **One command** - `textmode-build build`, `dev`, `preview`, `test`, and `test:watch` cover the whole surface.
18
+ - **Zero config** - Conventional library projects need no Vite or Vitest configuration; the shared `defineTextmodeLibrary` and `defineTextmodeProject` helpers ship in the package.
19
+ - **Shared GLSL pipeline** - The `textmodeGlsl` plugin (loading, composition, minification, and identifier coordination) is included.
20
+ - **Backward compatible behavior** - The build contract, test helper, and GLSL plugin are identical to the previous `@textmode/vite-config`, `@textmode/vitest-config`, and `@textmode/vite-plugin-glsl` packages.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install -D @textmode/build
26
+ ```
27
+
28
+ No engine dependencies are required.
29
+
30
+ ## Usage
31
+
32
+ Conventional projects create a `vite.config.ts` that uses the shared library helper:
33
+
34
+ ```ts
35
+ import { defineTextmodeLibrary } from '@textmode/build';
36
+
37
+ export default defineTextmodeLibrary({
38
+ globalName: 'TextmodeLibrary',
39
+ });
40
+ ```
41
+
42
+ Add-ons with shaders compose the GLSL plugin:
43
+
44
+ ```ts
45
+ import { defineTextmodeLibrary, textmodeGlsl } from '@textmode/build';
46
+
47
+ export default defineTextmodeLibrary({
48
+ globalName: 'TextmodeFilters',
49
+ plugins: [
50
+ textmodeGlsl({
51
+ shaderRoots: ['src/shaders'],
52
+ includeRoots: ['src/shaders'],
53
+ }),
54
+ ],
55
+ });
56
+ ```
57
+
58
+ Projects with a Vitest workspace create a `vitest.config.ts`:
59
+
60
+ ```ts
61
+ import { defineTextmodeProject } from '@textmode/build';
62
+
63
+ export default defineTextmodeProject({
64
+ projects: [
65
+ {
66
+ test: {
67
+ name: 'unit',
68
+ include: ['tests/unit/**/*.test.ts'],
69
+ },
70
+ },
71
+ ],
72
+ });
73
+ ```
74
+
75
+ Then delegate the standard scripts:
76
+
77
+ ```json
78
+ {
79
+ "scripts": {
80
+ "dev": "textmode-build dev --port 5177 --host",
81
+ "build:bundle": "textmode-build build",
82
+ "preview": "textmode-build preview",
83
+ "test": "textmode-build test",
84
+ "test:watch": "textmode-build test:watch",
85
+ "test:unit": "textmode-build test --project unit"
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## Commands
91
+
92
+ ```text
93
+ textmode-build build [args...]
94
+ textmode-build dev [args...]
95
+ textmode-build preview [args...]
96
+ textmode-build test [args...]
97
+ textmode-build test:watch [args...]
98
+ ```
99
+
100
+ - `build` runs a production Vite build.
101
+ - `dev` starts the Vite dev server.
102
+ - `preview` starts the Vite preview server.
103
+ - `test` runs Vitest once.
104
+ - `test:watch` runs Vitest in watch mode.
105
+
106
+ Every argument after the command is forwarded to the underlying engine, so
107
+ `textmode-build test --project unit`, `textmode-build test --coverage`, and
108
+ `textmode-build dev --port 5177 --host` work without special handling.
109
+
110
+ Every command accepts `--cwd <directory>`, `--help`, and `--version`. Exit
111
+ status `0` means success, `1` means the engine reported a problem, and `2`
112
+ means the invocation was invalid.
113
+
114
+ ## Configuration
115
+
116
+ ### Library builds
117
+
118
+ `defineTextmodeLibrary` derives the output contract from `package.json`:
119
+
120
+ - `src/index.ts` is the library entry.
121
+ - `package.json#main` must point to `./dist/<name>.umd.js`.
122
+ - `package.json#module` must point to `./dist/<name>.esm.js`.
123
+ - `package.json#exports["."]` must declare matching `import` and `require` outputs.
124
+
125
+ It emits ESM and UMD bundles with Terser minification, externalizes `textmode.js`
126
+ when it is a declared peer dependency, maps the peer to the `textmode` UMD
127
+ global, and sets `__TEXTMODE_VERSION__` and `IS_MINIFIED` build constants.
128
+
129
+ ### Tests
130
+
131
+ `defineTextmodeProject` uses Vitest with a jsdom environment and `globals`,
132
+ applies a `@` alias to `src`, and supports `projects`, `coverage`, `plugins`,
133
+ `setupFiles`, and custom `alias` entries.
134
+
135
+ ### GLSL
136
+
137
+ `textmodeGlsl` requires project-relative `shaderRoots` (and optional
138
+ `includeRoots`). It rewrites bare `.glsl`/`.vert`/`.frag` imports into
139
+ coordinated modules, resolves `#include` graphs, minifies shaders, and
140
+ optionally rewrites private host identifiers when `hostIdentifiers.sourceRoots`
141
+ is provided.
142
+
143
+ ## Configuration ownership
144
+
145
+ - `@textmode/build` owns the Vite build contract, the Vitest helper, the GLSL
146
+ plugin, and command behavior.
147
+ - `vite.config.ts` and `vitest.config.ts` own only project-specific options
148
+ (globals, ports, shader roots, test lanes).
149
+
150
+ Consumers should not declare `vite`, `vitest`, `terser`, `jsdom`, or the former
151
+ `@textmode/vite-config`, `@textmode/vitest-config`, and
152
+ `@textmode/vite-plugin-glsl` packages.
153
+
154
+ ## Related packages
155
+
156
+ `@textmode/build` works with the following textmode-tooling packages:
157
+
158
+ | Package | Relationship |
159
+ | ------------------------------------------------------------------- | -------------------------------------------------------- |
160
+ | [`@textmode/tooling-scripts`](../tooling-scripts/README.md) | `textmode-project check` runs the `test` and `build` scripts |
161
+ | [`@textmode/tsconfig`](../tsconfig/README.md) | Library builds compile against the shared TypeScript policy |
162
+
163
+ ## License
164
+
165
+ The `@textmode/build` package is licensed under the [CC0 1.0 Universal](./LICENSE).
166
+
167
+ ## Acknowledgements
168
+
169
+ - **[Vite](https://vitejs.dev/)**
170
+ - The bundler and dev server behind `textmode-build build`, `dev`, and `preview`.
171
+ - License: [MIT](https://github.com/vitejs/vite/blob/main/LICENSE).
172
+ - **[Vitest](https://vitest.dev/)**
173
+ - The test runner behind `textmode-build test` and `test:watch`.
174
+ - License: [MIT](https://github.com/vitest-dev/vitest/blob/main/LICENSE).
175
+ - **[`glsl-minify`](https://github.com/mapwhit/glsl-minify)**
176
+ - The GLSL minifier used by the shared plugin.
177
+ - License: [MIT](https://github.com/mapwhit/glsl-minify/blob/main/LICENSE).
package/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import type { Plugin, PluginOption, UserConfig } from 'vite';
2
+ import type { defineConfig, UserWorkspaceConfig } from 'vitest/config';
3
+
4
+ export interface TextmodeLibraryOptions {
5
+ globalName: string;
6
+ plugins?: PluginOption[];
7
+ root?: string;
8
+ }
9
+
10
+ export declare function defineTextmodeLibrary(options: TextmodeLibraryOptions): UserConfig;
11
+
12
+ export interface TextmodeGlslOptions {
13
+ shaderRoots: readonly string[];
14
+ includeRoots?: readonly string[];
15
+ publicSymbols?: readonly string[];
16
+ hostIdentifiers?: {
17
+ sourceRoots: readonly string[];
18
+ };
19
+ }
20
+
21
+ export declare function textmodeGlsl(options: TextmodeGlslOptions): Plugin;
22
+
23
+ export interface TextmodeWorkspaceProject extends UserWorkspaceConfig {
24
+ extends?: boolean | string;
25
+ }
26
+
27
+ export interface TextmodeProjectOptions {
28
+ alias?: Record<string, string>;
29
+ coverage?: Record<string, unknown>;
30
+ plugins?: PluginOption[];
31
+ projects?: TextmodeWorkspaceProject[];
32
+ setupFiles?: string[];
33
+ }
34
+
35
+ export declare function defineTextmodeProject(options?: TextmodeProjectOptions): ReturnType<typeof defineConfig>;
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { defineTextmodeLibrary } from './src/lib/vite-config.js';
2
+ export { defineTextmodeProject } from './src/lib/vitest-config.js';
3
+ export { textmodeGlsl } from './src/lib/glsl/plugin.js';
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@textmode/build",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "CC0-1.0",
6
+ "description": "Shared build, dev, and test tooling for the textmode.js ecosystem (Vite, Vitest, GLSL).",
7
+ "keywords": [
8
+ "textmode",
9
+ "vite",
10
+ "vitest",
11
+ "glsl",
12
+ "build",
13
+ "test"
14
+ ],
15
+ "author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
16
+ "homepage": "https://code.textmode.art",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/textmode-art/tooling.git",
20
+ "directory": "packages/build"
21
+ },
22
+ "engines": {
23
+ "node": ">=24 <25"
24
+ },
25
+ "bin": {
26
+ "textmode-build": "src/cli/textmode-build.mjs"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./index.d.ts",
31
+ "import": "./index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "src",
37
+ "index.js",
38
+ "index.d.ts",
39
+ "README.md"
40
+ ],
41
+ "dependencies": {
42
+ "@mapwhit/glsl-minify": "^1.0.0",
43
+ "@vitest/coverage-v8": "^4.1.10",
44
+ "jsdom": "^30.0.0",
45
+ "terser": "^5.46.1",
46
+ "vite": "^8.1.3",
47
+ "vitest": "^4.1.10"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^26.1.2",
51
+ "typescript": "^6.0.3"
52
+ },
53
+ "scripts": {
54
+ "check": "pnpm run check:format && pnpm run lint && pnpm run check:types && pnpm run test && pnpm run check:package && pnpm run check:pack",
55
+ "check:format": "prettier --check .",
56
+ "check:package": "node scripts/check-package.mjs",
57
+ "check:pack": "node scripts/pack-smoke.mjs",
58
+ "check:types": "tsc --noEmit --strict --module NodeNext --moduleResolution NodeNext --target ES2022 test/types/consumer.ts",
59
+ "lint": "node --check src/cli/textmode-build.mjs && node --check src/internal/engines.mjs && node --check src/lib/*.js && node --check src/lib/glsl/*.js",
60
+ "test": "vitest run"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ }
65
+ }
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import process from 'node:process';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ import { runEngine } from '../internal/engines.mjs';
9
+
10
+ const PACKAGE_JSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
11
+
12
+ const COMMANDS = new Set(['build', 'dev', 'preview', 'test', 'test:watch']);
13
+
14
+ function printGeneralHelp() {
15
+ console.log(`@textmode/build ${PACKAGE_JSON.version}`);
16
+ console.log('');
17
+ console.log('Usage: textmode-build <command> [options]');
18
+ console.log('');
19
+ console.log('Commands:');
20
+ console.log(' build [args...] Build the library with Vite');
21
+ console.log(' dev [args...] Run the Vite dev server');
22
+ console.log(' preview [args...] Preview the production build with Vite');
23
+ console.log(' test [args...] Run tests with Vitest (single run)');
24
+ console.log(' test:watch [args...] Run tests with Vitest in watch mode');
25
+ console.log('');
26
+ console.log('Common options:');
27
+ console.log(' --cwd <directory> Directory to run the engine in');
28
+ console.log(' --help, -h Show help');
29
+ console.log(' --version, -v Show version');
30
+ console.log('');
31
+ console.log('Every argument after the command is forwarded to the underlying engine.');
32
+ }
33
+
34
+ function printCommandHelp(command) {
35
+ const usage = {
36
+ build: 'textmode-build build [args...]',
37
+ dev: 'textmode-build dev [args...]',
38
+ preview: 'textmode-build preview [args...]',
39
+ test: 'textmode-build test [args...]',
40
+ 'test:watch': 'textmode-build test:watch [args...]',
41
+ };
42
+ console.log(`Usage: ${usage[command]}`);
43
+ }
44
+
45
+ function parseArgv(argv) {
46
+ const values = { cwd: undefined, help: false, version: false };
47
+ const rest = [];
48
+ let commandSeen = false;
49
+
50
+ for (let index = 0; index < argv.length; index += 1) {
51
+ const arg = argv[index];
52
+ if (arg === '--cwd') {
53
+ if (index + 1 >= argv.length || argv[index + 1].startsWith('-')) {
54
+ throw new Error('--cwd requires a directory value.');
55
+ }
56
+ values.cwd = argv[index + 1];
57
+ index += 1;
58
+ continue;
59
+ }
60
+ if (!commandSeen) {
61
+ if (arg === '--help' || arg === '-h') {
62
+ values.help = true;
63
+ continue;
64
+ }
65
+ if (arg === '--version' || arg === '-v') {
66
+ values.version = true;
67
+ continue;
68
+ }
69
+ if (!arg.startsWith('-')) {
70
+ commandSeen = true;
71
+ }
72
+ }
73
+ rest.push(arg);
74
+ }
75
+
76
+ const [command, ...forwarded] = rest;
77
+ if (command !== undefined && !COMMANDS.has(command)) {
78
+ throw new Error(`Unknown command "${command}".`);
79
+ }
80
+
81
+ return { command, forwarded, values };
82
+ }
83
+
84
+ function engineAndArgs(command, forwarded) {
85
+ switch (command) {
86
+ case 'build':
87
+ return { engine: 'vite', args: ['build', ...forwarded] };
88
+ case 'dev':
89
+ return { engine: 'vite', args: forwarded };
90
+ case 'preview':
91
+ return { engine: 'vite', args: ['preview', ...forwarded] };
92
+ case 'test':
93
+ return { engine: 'vitest', args: ['run', ...forwarded] };
94
+ case 'test:watch':
95
+ return { engine: 'vitest', args: forwarded };
96
+ default:
97
+ throw new Error(`Unsupported command "${command}".`);
98
+ }
99
+ }
100
+
101
+ function main(argv) {
102
+ let parsed;
103
+ try {
104
+ parsed = parseArgv(argv);
105
+ } catch (error) {
106
+ console.error(error instanceof Error ? error.message : String(error));
107
+ return 2;
108
+ }
109
+
110
+ const { command, forwarded, values } = parsed;
111
+ const cwd = values.cwd ? path.resolve(values.cwd) : process.cwd();
112
+
113
+ if (values.version && command === undefined) {
114
+ console.log(PACKAGE_JSON.version);
115
+ return 0;
116
+ }
117
+ if (values.help && command === undefined) {
118
+ printGeneralHelp();
119
+ return 0;
120
+ }
121
+ if (command === undefined) {
122
+ console.error('Missing command. Run textmode-build --help for usage.');
123
+ return 2;
124
+ }
125
+ if (values.help) {
126
+ printCommandHelp(command);
127
+ return 0;
128
+ }
129
+
130
+ const { engine, args } = engineAndArgs(command, forwarded);
131
+ return runEngine(engine, args, { cwd });
132
+ }
133
+
134
+ process.exitCode = main(process.argv.slice(2));
@@ -0,0 +1,43 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+
6
+ const require = createRequire(import.meta.url);
7
+
8
+ const ENGINE_BIN_NAME = {
9
+ vite: 'vite',
10
+ vitest: 'vitest',
11
+ };
12
+
13
+ function resolveEngineBinary(packageName, binName) {
14
+ let manifestPath;
15
+ try {
16
+ manifestPath = require.resolve(`${packageName}/package.json`);
17
+ } catch {
18
+ manifestPath = path.join(path.dirname(require.resolve(packageName)), 'package.json');
19
+ }
20
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
21
+ const bin = typeof manifest.bin === 'string' ? manifest.bin : manifest.bin[binName];
22
+ if (typeof bin !== 'string') {
23
+ throw new Error(`Cannot resolve ${packageName} binary ${binName}.`);
24
+ }
25
+ return path.resolve(path.dirname(manifestPath), bin);
26
+ }
27
+
28
+ export function resolveEngine(name) {
29
+ return resolveEngineBinary(name, ENGINE_BIN_NAME[name]);
30
+ }
31
+
32
+ export function runEngine(name, args, { cwd = process.cwd() } = {}) {
33
+ const bin = resolveEngine(name);
34
+ const result = spawnSync(process.execPath, [bin, ...args], {
35
+ cwd,
36
+ stdio: 'inherit',
37
+ });
38
+ if (result.error) {
39
+ console.error(`Unable to run ${name}: ${result.error.message}`);
40
+ return 2;
41
+ }
42
+ return result.status ?? 1;
43
+ }
@@ -0,0 +1,6 @@
1
+ declare module '@mapwhit/glsl-minify' {
2
+ export class GlslMinify {
3
+ constructor(options?: Record<string, unknown>);
4
+ execute(source: string): Promise<unknown>;
5
+ }
6
+ }
@@ -0,0 +1,15 @@
1
+ export function rewriteHostIdentifiers(code, lookup) {
2
+ const replaceName = (name) => lookup(name) ?? name;
3
+
4
+ code = code.replace(/\._setUniform\s*\(\s*(['\"])(u_[A-Za-z0-9_]+)\1/g, (match, quote, name) =>
5
+ match.replace(`${quote}${name}${quote}`, `${quote}${replaceName(name)}${quote}`)
6
+ );
7
+ code = code.replace(/\.getAttribLocation\s*\([^,]+,\s*(['\"])(a_[A-Za-z0-9_]+)\1\s*\)/g, (match, quote, name) =>
8
+ match.replace(`${quote}${name}${quote}`, `${quote}${replaceName(name)}${quote}`)
9
+ );
10
+ code = code.replace(/(['\"])((?:u_|a_)[A-Za-z0-9_]+)\1(?=\s*:)/g, (_match, quote, name) => {
11
+ return `${quote}${replaceName(name)}${quote}`;
12
+ });
13
+ code = code.replace(/(?<![\w$])((?:u_|a_)[A-Za-z0-9_]+)(?=\s*:)/g, (name) => replaceName(name));
14
+ return code;
15
+ }