miijs 2.5.2 → 2.5.3
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/.github/workflows/npm-publish.yml +25 -0
- package/build-browser.js +186 -0
- package/crown.jpg +0 -0
- package/formats.js +3480 -0
- package/ideal.jsonc +91 -0
- package/miiFemaleBody.glb +0 -0
- package/miiMaleBody.glb +0 -0
- package/miijs.png +0 -0
- package/package.json +1 -13
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Node.js Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: '20'
|
|
21
|
+
registry-url: 'https://registry.npmjs.org'
|
|
22
|
+
|
|
23
|
+
- run: npm ci
|
|
24
|
+
- run: npm run build
|
|
25
|
+
- run: npm publish --provenance
|
package/build-browser.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
const esbuild = require('esbuild');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const isServe = process.argv.includes('--serve');
|
|
7
|
+
const port = 8080;
|
|
8
|
+
|
|
9
|
+
// Plugin to replace Node.js-only modules with stubs
|
|
10
|
+
const nodeShimPlugin = {
|
|
11
|
+
name: 'node-shim',
|
|
12
|
+
setup(build) {
|
|
13
|
+
// Shim built-in Node.js modules (except crypto which is used by amiiboHandler with Web Crypto API)
|
|
14
|
+
const emptyModules = ['fs', 'canvas', 'gl', 'jimp', 'jsdom', 'https'];
|
|
15
|
+
|
|
16
|
+
emptyModules.forEach(mod => {
|
|
17
|
+
build.onResolve({ filter: new RegExp(`^${mod}$`) }, () => ({
|
|
18
|
+
path: path.resolve(__dirname, 'shims/empty.js'),
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Shim crypto with browser-compatible version (allows crypto.subtle passthrough)
|
|
23
|
+
build.onResolve({ filter: /^crypto$/ }, () => ({
|
|
24
|
+
path: path.resolve(__dirname, 'shims/crypto-browser.js'),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
// Shim path with browser version
|
|
28
|
+
build.onResolve({ filter: /^path$/ }, () => ({
|
|
29
|
+
path: path.resolve(__dirname, 'shims/path-browser.js'),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
// Shim FFL.js modules
|
|
33
|
+
build.onResolve({ filter: /ffl\.js\/examples\/ffl-emscripten-single-file\.js$/ }, () => ({
|
|
34
|
+
path: path.resolve(__dirname, 'shims/empty.js'),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
build.onResolve({ filter: /ffl\.js\/FFLShaderMaterial\.js$/ }, () => ({
|
|
38
|
+
path: path.resolve(__dirname, 'shims/empty.js'),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
build.onResolve({ filter: /ffl\.js\/ffl\.js$/ }, () => ({
|
|
42
|
+
path: path.resolve(__dirname, 'shims/empty.js'),
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
// Shim fflWrapper.js
|
|
46
|
+
build.onResolve({ filter: /\.\/fflWrapper\.js$/ }, () => ({
|
|
47
|
+
path: path.resolve(__dirname, 'shims/ffl-wrapper-stub.js'),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
// Note: amiiboHandler.js is now cross-platform, no need to shim
|
|
51
|
+
|
|
52
|
+
// Shim struct-fu
|
|
53
|
+
build.onResolve({ filter: /^struct-fu$/ }, () => ({
|
|
54
|
+
path: path.resolve(__dirname, 'shims/empty.js'),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Build configuration for browser bundle
|
|
60
|
+
const buildOptions = {
|
|
61
|
+
entryPoints: ['./index.js'],
|
|
62
|
+
bundle: true,
|
|
63
|
+
outfile: './dist/miijs.browser.js',
|
|
64
|
+
format: 'iife',
|
|
65
|
+
globalName: 'MiiJS',
|
|
66
|
+
platform: 'browser',
|
|
67
|
+
target: ['es2020'],
|
|
68
|
+
sourcemap: true,
|
|
69
|
+
minify: !isServe,
|
|
70
|
+
define: {
|
|
71
|
+
'process.versions': 'undefined',
|
|
72
|
+
},
|
|
73
|
+
plugins: [nodeShimPlugin],
|
|
74
|
+
loader: {
|
|
75
|
+
'.json': 'json'
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Also build an ESM version
|
|
80
|
+
const esmBuildOptions = {
|
|
81
|
+
...buildOptions,
|
|
82
|
+
outfile: './dist/miijs.browser.esm.js',
|
|
83
|
+
format: 'esm',
|
|
84
|
+
globalName: undefined
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
async function build() {
|
|
88
|
+
try {
|
|
89
|
+
// Create dist directory if it doesn't exist
|
|
90
|
+
if (!fs.existsSync('./dist')) {
|
|
91
|
+
fs.mkdirSync('./dist');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Build IIFE version
|
|
95
|
+
await esbuild.build(buildOptions);
|
|
96
|
+
console.log('✓ Built dist/miijs.browser.js (IIFE)');
|
|
97
|
+
|
|
98
|
+
// Build ESM version
|
|
99
|
+
await esbuild.build(esmBuildOptions);
|
|
100
|
+
console.log('✓ Built dist/miijs.browser.esm.js (ESM)');
|
|
101
|
+
|
|
102
|
+
console.log('Build complete!');
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Build failed:', error);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function serve() {
|
|
110
|
+
try {
|
|
111
|
+
// Create dist directory
|
|
112
|
+
if (!fs.existsSync('./dist')) {
|
|
113
|
+
fs.mkdirSync('./dist');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Start esbuild in watch mode
|
|
117
|
+
const ctx = await esbuild.context({
|
|
118
|
+
...buildOptions,
|
|
119
|
+
minify: false,
|
|
120
|
+
});
|
|
121
|
+
await ctx.watch();
|
|
122
|
+
console.log('✓ Watching for changes...');
|
|
123
|
+
|
|
124
|
+
// Also build ESM version
|
|
125
|
+
const ctxEsm = await esbuild.context({
|
|
126
|
+
...esmBuildOptions,
|
|
127
|
+
minify: false,
|
|
128
|
+
});
|
|
129
|
+
await ctxEsm.watch();
|
|
130
|
+
|
|
131
|
+
// Create a simple HTTP server
|
|
132
|
+
const server = http.createServer((req, res) => {
|
|
133
|
+
let filePath = req.url === '/' ? '/webpage-example/index.html' : req.url;
|
|
134
|
+
filePath = path.join(__dirname, filePath);
|
|
135
|
+
|
|
136
|
+
// Get file extension
|
|
137
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
138
|
+
const mimeTypes = {
|
|
139
|
+
'.html': 'text/html',
|
|
140
|
+
'.js': 'text/javascript',
|
|
141
|
+
'.css': 'text/css',
|
|
142
|
+
'.json': 'application/json',
|
|
143
|
+
'.png': 'image/png',
|
|
144
|
+
'.jpg': 'image/jpeg',
|
|
145
|
+
'.gif': 'image/gif',
|
|
146
|
+
'.svg': 'image/svg+xml',
|
|
147
|
+
'.mii': 'application/octet-stream',
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const contentType = mimeTypes[ext] || 'application/octet-stream';
|
|
151
|
+
|
|
152
|
+
fs.readFile(filePath, (error, content) => {
|
|
153
|
+
if (error) {
|
|
154
|
+
if (error.code === 'ENOENT') {
|
|
155
|
+
res.writeHead(404);
|
|
156
|
+
res.end('File not found: ' + req.url);
|
|
157
|
+
} else {
|
|
158
|
+
res.writeHead(500);
|
|
159
|
+
res.end('Server error: ' + error.code);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
res.writeHead(200, {
|
|
163
|
+
'Content-Type': contentType,
|
|
164
|
+
'Access-Control-Allow-Origin': '*'
|
|
165
|
+
});
|
|
166
|
+
res.end(content, 'utf-8');
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
server.listen(port, () => {
|
|
172
|
+
console.log(`\n🚀 Dev server running at http://localhost:${port}`);
|
|
173
|
+
console.log(` Open http://localhost:${port} to view the example\n`);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error('Serve failed:', error);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isServe) {
|
|
183
|
+
serve();
|
|
184
|
+
} else {
|
|
185
|
+
build();
|
|
186
|
+
}
|
package/crown.jpg
ADDED
|
Binary file
|