miniray 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/bin/miniray +184 -80
  2. package/miniray.wasm +0 -0
  3. package/package.json +1 -1
package/bin/miniray CHANGED
@@ -6,8 +6,16 @@ const path = require('path');
6
6
  // Parse command line arguments
7
7
  const args = process.argv.slice(2);
8
8
 
9
+ // Check for reflect subcommand
10
+ if (args[0] === 'reflect') {
11
+ runReflect(args.slice(1));
12
+ } else {
13
+ runMinify(args);
14
+ }
15
+
9
16
  function printUsage() {
10
17
  console.log(`Usage: miniray [options] [file]
18
+ miniray reflect [options] [file]
11
19
 
12
20
  Options:
13
21
  -h, --help Show this help message
@@ -19,116 +27,212 @@ Options:
19
27
  --keep-names <names> Comma-separated list of names to preserve
20
28
  --config <file> Load config from JSON file
21
29
 
30
+ Subcommands:
31
+ reflect Extract bindings, struct layouts, and entry points as JSON
32
+ Run 'miniray reflect --help' for details
33
+
22
34
  If no file is specified, reads from stdin.
23
35
 
24
36
  Examples:
25
37
  miniray shader.wgsl
26
38
  miniray shader.wgsl -o shader.min.wgsl
39
+ miniray reflect shader.wgsl
27
40
  miniray --keep-names main,uniforms shader.wgsl
28
41
  cat shader.wgsl | miniray > shader.min.wgsl
29
42
  `);
30
43
  }
31
44
 
45
+ function printReflectUsage() {
46
+ console.log(`Usage: miniray reflect [options] [file]
47
+
48
+ Extract binding information, struct layouts, and entry points from WGSL source.
49
+
50
+ Options:
51
+ -h, --help Show this help message
52
+ -o, --output <file> Write JSON output to file (default: stdout)
53
+ --compact Output compact JSON (default: pretty-printed)
54
+
55
+ Output:
56
+ JSON object with bindings, structs, entryPoints, and errors.
57
+ Memory layouts follow WGSL specification (vec3 align=16, size=12, etc).
58
+
59
+ Examples:
60
+ miniray reflect shader.wgsl
61
+ miniray reflect shader.wgsl -o info.json
62
+ miniray reflect --compact shader.wgsl
63
+ `);
64
+ }
65
+
32
66
  function printVersion() {
33
67
  const pkg = require('../package.json');
34
68
  console.log(`miniray ${pkg.version}`);
35
69
  }
36
70
 
37
- // Parse options
38
- let inputFile = null;
39
- let outputFile = null;
40
- let options = {
41
- minifyWhitespace: true,
42
- minifyIdentifiers: true,
43
- minifySyntax: true,
44
- mangleExternalBindings: false,
45
- keepNames: []
46
- };
47
- let configFile = null;
48
-
49
- for (let i = 0; i < args.length; i++) {
50
- const arg = args[i];
51
-
52
- if (arg === '-h' || arg === '--help') {
53
- printUsage();
54
- process.exit(0);
55
- } else if (arg === '-v' || arg === '--version') {
56
- printVersion();
57
- process.exit(0);
58
- } else if (arg === '-o' || arg === '--output') {
59
- outputFile = args[++i];
60
- } else if (arg === '--no-mangle') {
61
- options.minifyIdentifiers = false;
62
- } else if (arg === '--no-whitespace') {
63
- options.minifyWhitespace = false;
64
- } else if (arg === '--mangle-external-bindings') {
65
- options.mangleExternalBindings = true;
66
- } else if (arg === '--keep-names') {
67
- options.keepNames = args[++i].split(',').map(s => s.trim());
68
- } else if (arg === '--config') {
69
- configFile = args[++i];
70
- } else if (!arg.startsWith('-')) {
71
- inputFile = arg;
72
- } else {
73
- console.error(`Unknown option: ${arg}`);
74
- process.exit(1);
71
+ function runReflect(args) {
72
+ let inputFile = null;
73
+ let outputFile = null;
74
+ let compact = false;
75
+
76
+ for (let i = 0; i < args.length; i++) {
77
+ const arg = args[i];
78
+
79
+ if (arg === '-h' || arg === '--help') {
80
+ printReflectUsage();
81
+ process.exit(0);
82
+ } else if (arg === '-v' || arg === '--version') {
83
+ printVersion();
84
+ process.exit(0);
85
+ } else if (arg === '-o' || arg === '--output') {
86
+ outputFile = args[++i];
87
+ } else if (arg === '--compact') {
88
+ compact = true;
89
+ } else if (!arg.startsWith('-')) {
90
+ inputFile = arg;
91
+ } else {
92
+ console.error(`Unknown option: ${arg}`);
93
+ process.exit(1);
94
+ }
75
95
  }
76
- }
77
96
 
78
- // Load config file if specified
79
- if (configFile) {
80
- try {
81
- const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
82
- if (config.minifyWhitespace !== undefined) options.minifyWhitespace = config.minifyWhitespace;
83
- if (config.minifyIdentifiers !== undefined) options.minifyIdentifiers = config.minifyIdentifiers;
84
- if (config.minifySyntax !== undefined) options.minifySyntax = config.minifySyntax;
85
- if (config.mangleExternalBindings !== undefined) options.mangleExternalBindings = config.mangleExternalBindings;
86
- if (config.keepNames) options.keepNames = [...options.keepNames, ...config.keepNames];
87
- } catch (err) {
88
- console.error(`Error loading config file: ${err.message}`);
89
- process.exit(1);
90
- }
91
- }
97
+ async function main() {
98
+ // Read input
99
+ let source;
100
+ if (inputFile) {
101
+ try {
102
+ source = fs.readFileSync(inputFile, 'utf8');
103
+ } catch (err) {
104
+ console.error(`Error reading file: ${err.message}`);
105
+ process.exit(1);
106
+ }
107
+ } else {
108
+ // Read from stdin
109
+ source = fs.readFileSync(0, 'utf8');
110
+ }
111
+
112
+ // Initialize WASM and reflect
113
+ const { initialize, reflect } = require('../lib/main.js');
92
114
 
93
- async function main() {
94
- // Read input
95
- let source;
96
- if (inputFile) {
97
115
  try {
98
- source = fs.readFileSync(inputFile, 'utf8');
116
+ await initialize();
117
+ const result = reflect(source);
118
+
119
+ // Format output
120
+ const output = compact
121
+ ? JSON.stringify(result)
122
+ : JSON.stringify(result, null, 2);
123
+
124
+ // Write output
125
+ if (outputFile) {
126
+ fs.writeFileSync(outputFile, output + '\n');
127
+ } else {
128
+ console.log(output);
129
+ }
99
130
  } catch (err) {
100
- console.error(`Error reading file: ${err.message}`);
131
+ console.error(`Reflection error: ${err.message}`);
101
132
  process.exit(1);
102
133
  }
103
- } else {
104
- // Read from stdin
105
- source = fs.readFileSync(0, 'utf8');
106
134
  }
107
135
 
108
- // Initialize WASM and minify
109
- const { initialize, minify } = require('../lib/main.js');
136
+ main();
137
+ }
110
138
 
111
- try {
112
- await initialize();
113
- const result = minify(source, options);
139
+ function runMinify(args) {
140
+ // Parse options
141
+ let inputFile = null;
142
+ let outputFile = null;
143
+ let options = {
144
+ minifyWhitespace: true,
145
+ minifyIdentifiers: true,
146
+ minifySyntax: true,
147
+ mangleExternalBindings: false,
148
+ keepNames: []
149
+ };
150
+ let configFile = null;
151
+
152
+ for (let i = 0; i < args.length; i++) {
153
+ const arg = args[i];
154
+
155
+ if (arg === '-h' || arg === '--help') {
156
+ printUsage();
157
+ process.exit(0);
158
+ } else if (arg === '-v' || arg === '--version') {
159
+ printVersion();
160
+ process.exit(0);
161
+ } else if (arg === '-o' || arg === '--output') {
162
+ outputFile = args[++i];
163
+ } else if (arg === '--no-mangle') {
164
+ options.minifyIdentifiers = false;
165
+ } else if (arg === '--no-whitespace') {
166
+ options.minifyWhitespace = false;
167
+ } else if (arg === '--mangle-external-bindings') {
168
+ options.mangleExternalBindings = true;
169
+ } else if (arg === '--keep-names') {
170
+ options.keepNames = args[++i].split(',').map(s => s.trim());
171
+ } else if (arg === '--config') {
172
+ configFile = args[++i];
173
+ } else if (!arg.startsWith('-')) {
174
+ inputFile = arg;
175
+ } else {
176
+ console.error(`Unknown option: ${arg}`);
177
+ process.exit(1);
178
+ }
179
+ }
114
180
 
115
- if (result.errors && result.errors.length > 0) {
116
- for (const err of result.errors) {
117
- console.error(`Error at line ${err.line}, column ${err.column}: ${err.message}`);
118
- }
181
+ // Load config file if specified
182
+ if (configFile) {
183
+ try {
184
+ const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
185
+ if (config.minifyWhitespace !== undefined) options.minifyWhitespace = config.minifyWhitespace;
186
+ if (config.minifyIdentifiers !== undefined) options.minifyIdentifiers = config.minifyIdentifiers;
187
+ if (config.minifySyntax !== undefined) options.minifySyntax = config.minifySyntax;
188
+ if (config.mangleExternalBindings !== undefined) options.mangleExternalBindings = config.mangleExternalBindings;
189
+ if (config.keepNames) options.keepNames = [...options.keepNames, ...config.keepNames];
190
+ } catch (err) {
191
+ console.error(`Error loading config file: ${err.message}`);
119
192
  process.exit(1);
120
193
  }
194
+ }
121
195
 
122
- // Write output
123
- if (outputFile) {
124
- fs.writeFileSync(outputFile, result.code);
196
+ async function main() {
197
+ // Read input
198
+ let source;
199
+ if (inputFile) {
200
+ try {
201
+ source = fs.readFileSync(inputFile, 'utf8');
202
+ } catch (err) {
203
+ console.error(`Error reading file: ${err.message}`);
204
+ process.exit(1);
205
+ }
125
206
  } else {
126
- process.stdout.write(result.code);
207
+ // Read from stdin
208
+ source = fs.readFileSync(0, 'utf8');
209
+ }
210
+
211
+ // Initialize WASM and minify
212
+ const { initialize, minify } = require('../lib/main.js');
213
+
214
+ try {
215
+ await initialize();
216
+ const result = minify(source, options);
217
+
218
+ if (result.errors && result.errors.length > 0) {
219
+ for (const err of result.errors) {
220
+ console.error(`Error at line ${err.line}, column ${err.column}: ${err.message}`);
221
+ }
222
+ process.exit(1);
223
+ }
224
+
225
+ // Write output
226
+ if (outputFile) {
227
+ fs.writeFileSync(outputFile, result.code);
228
+ } else {
229
+ process.stdout.write(result.code);
230
+ }
231
+ } catch (err) {
232
+ console.error(`Minification error: ${err.message}`);
233
+ process.exit(1);
127
234
  }
128
- } catch (err) {
129
- console.error(`Minification error: ${err.message}`);
130
- process.exit(1);
131
235
  }
132
- }
133
236
 
134
- main();
237
+ main();
238
+ }
package/miniray.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miniray",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "WGSL minifier for WebGPU shaders - WebAssembly build",
5
5
  "main": "lib/main.js",
6
6
  "module": "esm/browser.js",