Needle Engine

Changes between version 3.39.0-alpha.1 and 3.39.0-alpha.2
Files changed (1) hide show
  1. plugins/vite/build-pipeline.js +20 -8
plugins/vite/build-pipeline.js CHANGED
@@ -1,4 +1,4 @@
1
- import { exec, spawn } from 'child_process';
1
+ import { ChildProcess, exec, execSync, spawn } from 'child_process';
2
2
  import { getOutputDirectory, loadConfig, tryLoadProjectConfig } from './config.js';
3
3
  import { existsSync, readdirSync } from 'fs';
4
4
 
@@ -65,15 +65,17 @@
65
65
  }
66
66
 
67
67
  /**
68
- * @param {*} opts
68
+ * @param {{}} opts
69
69
  * @returns {Promise<boolean>}
70
70
  */
71
71
  async function invokeBuildPipeline(opts) {
72
72
  const installPath = "node_modules/@needle-tools/gltf-build-pipeline";
73
73
  const fullInstallPath = process.cwd() + "/" + installPath;
74
- if (!existsSync(fullInstallPath)) {
75
- throw new Error(`ERR: Build pipeline not found at \"${fullInstallPath}\". \nTo disable this plugin you can pass \"noBuildPipeline: true\" to the needle config in vite.config.js`);
76
- return;
74
+ const existsLocally = existsSync(fullInstallPath);
75
+ if (!existsLocally) {
76
+ // await execSync("npx --yes @needle-tools/n")
77
+ // throw new Error(`ERR: Build pipeline not found at \"${fullInstallPath}\". \nTo disable this plugin you can pass \"noBuildPipeline: true\" to the needle config in vite.config.js`);
78
+ warn("@needle-tools/gltf-build-pipeline not found in package - using latest version")
77
79
  }
78
80
  await wait(500);
79
81
  const outputDirectory = getOutputDirectory() + "/assets";
@@ -95,9 +97,19 @@
95
97
  const files = readdirSync(outputDirectory).filter(f => f.endsWith(".glb") || f.endsWith(".gltf"));
96
98
  log(files.length + " file(s) to process");
97
99
 
98
- const cmd = `needle-gltf transform "${outputDirectory}"`;
99
- log("Running command \"" + cmd + "\" at " + process.cwd() + "...");
100
- const sub = exec(cmd, { cwd: installPath });
100
+ /** @type {null | ChildProcess} */
101
+ let sub = null;
102
+
103
+ if (existsLocally) {
104
+ const cmd = `needle-gltf transform "${outputDirectory}"`;
105
+ log("Running command \"" + cmd + "\" at " + process.cwd() + "...");
106
+ sub = exec(cmd, { cwd: installPath });
107
+ }
108
+ else {
109
+ const cmd = `npx --yes @needle-tools/gltf-build-pipeline@latest transform "${outputDirectory}"`;
110
+ log("Running command \"" + cmd + "\" at " + process.cwd() + "...");
111
+ sub = exec(cmd);
112
+ }
101
113
  sub.stdout.on('data', data => {
102
114
  if (data.length <= 0) return;
103
115
  // ensure that it doesnt end with a newline