@joycostudio/chopper 0.2.0 → 0.4.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/codecs/manifest.json +1 -1
- package/dist/browser/{chunk-SKV4J3KF.js → chunk-M7J64NCO.js} +3 -3
- package/dist/browser/{chunk-SKV4J3KF.js.map → chunk-M7J64NCO.js.map} +1 -1
- package/dist/browser/{in-process-5733VKVB.js → in-process-7XITYSC4.js} +3 -3
- package/dist/browser/{in-process-5733VKVB.js.map → in-process-7XITYSC4.js.map} +1 -1
- package/dist/browser/index.js +2 -2
- package/dist/browser/worker.js +1 -1
- package/dist/browser/worker.js.map +1 -1
- package/dist/cli/index.js +20 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +3 -8
- package/dist/config/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +3 -7
- package/dist/node/index.js +20 -8
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFile, readdir, mkdir, copyFile, mkdtemp, writeFile, rename, rm } from 'fs/promises';
|
|
3
|
-
import { extname, parse, join, dirname, resolve, relative, basename } from 'path';
|
|
3
|
+
import { extname, parse, join, dirname, resolve, relative, isAbsolute, sep, basename } from 'path';
|
|
4
4
|
import { PropertyType, NodeIO } from '@gltf-transform/core';
|
|
5
5
|
import { ALL_EXTENSIONS, EXTTextureWebP, EXTTextureAVIF, KHRTextureBasisu } from '@gltf-transform/extensions';
|
|
6
6
|
import draco3d from 'draco3dgltf';
|
|
@@ -103,7 +103,7 @@ function outputMimeType(encoding) {
|
|
|
103
103
|
|
|
104
104
|
// package.json
|
|
105
105
|
var package_default = {
|
|
106
|
-
version: "0.
|
|
106
|
+
version: "0.4.0"};
|
|
107
107
|
|
|
108
108
|
// src/codecs/manifest.ts
|
|
109
109
|
var CODEC_MANIFEST_HASH = "2046d60deb0f9f224743f4404f3c6e8ba5399f81b2811fa50466e93fce3bd322";
|
|
@@ -1156,10 +1156,18 @@ async function runConfig(options = {}) {
|
|
|
1156
1156
|
loaded.data.concurrency ?? 2,
|
|
1157
1157
|
(asset) => executeAsset(asset, mode, cwd, chopper2)
|
|
1158
1158
|
);
|
|
1159
|
-
return success({ mode, files, totals: summarize(files) });
|
|
1159
|
+
return success({ mode, output: relative(cwd, resolve(cwd, loaded.data.output)), files, totals: summarize(files) });
|
|
1160
1160
|
}
|
|
1161
1161
|
async function planAssets(config, cwd) {
|
|
1162
1162
|
const planned = [];
|
|
1163
|
+
if (typeof config.output !== "string" || !config.output) {
|
|
1164
|
+
return failure("invalid_recipe", "Config output directory is required");
|
|
1165
|
+
}
|
|
1166
|
+
const outputRoot = resolve(cwd, config.output);
|
|
1167
|
+
const relativeRoot = relative(cwd, outputRoot);
|
|
1168
|
+
if (isAbsolute(relativeRoot) || relativeRoot === ".." || relativeRoot.startsWith(`..${sep}`)) {
|
|
1169
|
+
return failure("invalid_recipe", `Output directory must be inside the project: ${config.output}`);
|
|
1170
|
+
}
|
|
1163
1171
|
for (const rule of config.rules) {
|
|
1164
1172
|
const valid = validateRecipe(rule.recipe);
|
|
1165
1173
|
if (!valid.ok) return valid;
|
|
@@ -1169,9 +1177,14 @@ async function planAssets(config, cwd) {
|
|
|
1169
1177
|
onlyFiles: true
|
|
1170
1178
|
});
|
|
1171
1179
|
for (const match of matches.sort()) {
|
|
1180
|
+
const output = resolveOutput(rule, match, outputRoot);
|
|
1181
|
+
const relativeOutput = relative(outputRoot, output);
|
|
1182
|
+
if (isAbsolute(relativeOutput) || relativeOutput === ".." || relativeOutput.startsWith(`..${sep}`)) {
|
|
1183
|
+
return failure("invalid_recipe", `Output path must stay inside ${config.output}: ${rule.path}`);
|
|
1184
|
+
}
|
|
1172
1185
|
planned.push({
|
|
1173
1186
|
input: resolve(cwd, match),
|
|
1174
|
-
output
|
|
1187
|
+
output,
|
|
1175
1188
|
rule
|
|
1176
1189
|
});
|
|
1177
1190
|
}
|
|
@@ -1234,14 +1247,13 @@ async function executeAsset(asset, mode, cwd, chopper2) {
|
|
|
1234
1247
|
};
|
|
1235
1248
|
}
|
|
1236
1249
|
}
|
|
1237
|
-
function resolveOutput(rule, input,
|
|
1238
|
-
if (rule.output.mode === "replace") return resolve(cwd, input);
|
|
1250
|
+
function resolveOutput(rule, input, outputRoot) {
|
|
1239
1251
|
const extension = rule.recipe.kind === "glb" ? ".glb" : outputExtension(rule.recipe.encode);
|
|
1240
1252
|
const inputDirectory = dirname(input) === "." ? "" : dirname(input);
|
|
1241
1253
|
const name = basename(input, extname(input));
|
|
1242
1254
|
return resolve(
|
|
1243
|
-
|
|
1244
|
-
rule.
|
|
1255
|
+
outputRoot,
|
|
1256
|
+
(rule.path ?? "{dir}/{name}.{ext}").replaceAll("{dir}", inputDirectory).replaceAll("{name}", name).replaceAll("{ext}", extension.slice(1))
|
|
1245
1257
|
);
|
|
1246
1258
|
}
|
|
1247
1259
|
async function writeAtomic(path, bytes) {
|