| 208 | } |
| 209 | |
| 210 | function runTest(examplePath) { |
| 211 | return new Promise((resolve) => { |
| 212 | const startTime = Date.now(); |
| 213 | console.log(`\n========= Testing ${examplePath} =========`); |
| 214 | const manifestPath = path.join(examplePath, 'manifest.json'); |
| 215 | |
| 216 | let manifestRaw = ''; |
| 217 | try { |
| 218 | manifestRaw = fs.readFileSync(manifestPath, 'utf-8'); |
| 219 | } catch {} |
| 220 | |
| 221 | if (!manifestRaw.includes('manifest_base.json')) { |
| 222 | return resolve({ reason: 'NO_BASE_MANIFEST', log: '', durationMs: 0 }); |
| 223 | } |
| 224 | |
| 225 | const isNet = manifestRaw.includes('manifest_net.json'); |
| 226 | |
| 227 | let mcArgs = ['-dl', '-m', '-p', target]; |
| 228 | let onlyBuild = false; |
| 229 | |
| 230 | if (mode === 'build') { |
| 231 | mcArgs = ['-d', '-t', 'build', '-m', '-p', target]; |
| 232 | onlyBuild = true; |
| 233 | } |
| 234 | |
| 235 | if (isNet && isEmbedded) { |
| 236 | if (ssid && password && !onlyBuild) { |
| 237 | mcArgs.push(`ssid=${ssid}`, `password=${password}`); |
| 238 | } else if (!onlyBuild) { |
| 239 | mcArgs = ['-d', '-t', 'build', '-m', '-p', target]; |
| 240 | onlyBuild = true; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | |
| 245 | let originalXsdbConfig = null; |
| 246 | let xsdbConfigExisted = false; |
| 247 | const xsdbConfigPath = require('path').join(examplePath, '.xsdb.json'); |
| 248 | |
| 249 | try { |
| 250 | if (require('fs').existsSync(xsdbConfigPath)) { |
| 251 | xsdbConfigExisted = true; |
| 252 | originalXsdbConfig = require('fs').readFileSync(xsdbConfigPath, 'utf8'); |
| 253 | } |
| 254 | require('fs').writeFileSync(xsdbConfigPath, JSON.stringify({ exceptionsMode: 'off', outputFormat: 'json' })); |
| 255 | } catch {} |
| 256 | |
| 257 | const runMainBuild = () => { |
| 258 | const child = spawn('mcconfig', mcArgs, { |
| 259 | cwd: examplePath, |
| 260 | env: process.env, |
| 261 | shell: process.platform === 'win32' |
| 262 | }); |
| 263 | |
| 264 | let outputBuf = ''; |
| 265 | let isSetup = false; |
| 266 | |
| 267 | let exceptionOccurred = false; |