create-yeow 0.2.122 → 0.2.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-yeow",
3
- "version": "0.2.122",
3
+ "version": "0.2.124",
4
4
  "description": "Scaffold a Yeow plugin project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -148,9 +148,9 @@ function download(url, dest, agent) {
148
148
  if (res.statusCode !== 200) { f.close(); reject(new Error(`HTTP ${res.statusCode}`)); return; }
149
149
  const total = parseInt(res.headers['content-length'], 10);
150
150
  let dl = 0;
151
- res.on('data', chunk => { dl += chunk.length; if (total) process.stdout.write(`\r ${c.B}Downloading...${c.r} ${(dl / 1024 / 1024).toFixed(1)}MB / ${(total / 1024 / 1024).toFixed(1)}MB`); });
151
+ res.on('data', chunk => { dl += chunk.length; if (total && !HEADLESS) process.stdout.write(`\r ${c.B}Downloading...${c.r} ${(dl / 1024 / 1024).toFixed(1)}MB / ${(total / 1024 / 1024).toFixed(1)}MB`); });
152
152
  res.pipe(f);
153
- f.on('finish', () => { f.close(); process.stdout.write('\n'); resolve(); });
153
+ f.on('finish', () => { f.close(); if (!HEADLESS) process.stdout.write('\n'); resolve(); });
154
154
  }).on('error', e => { f.close(); reject(e); });
155
155
  });
156
156
  }
@@ -159,19 +159,19 @@ async function ensurePaper() {
159
159
  if (PAPER_URL) {
160
160
  // User-specified URL or file path
161
161
  if (PAPER_URL.startsWith('http://') || PAPER_URL.startsWith('https://')) {
162
- if (existsSync(PAPER_PATH) && statSync(PAPER_PATH).size > 1_000_000) { ok('Paper found in cache'); return; }
162
+ if (existsSync(PAPER_PATH) && statSync(PAPER_PATH).size > 1_000_000) { if (!HEADLESS) ok('Paper found in cache'); return; }
163
163
  mkdirSync(CACHE, { recursive: true });
164
164
  let agent = null;
165
165
  if (PROXY) { info(`Proxy: ${PROXY}`); try { const { HttpsProxyAgent } = await import('https-proxy-agent'); agent = new HttpsProxyAgent(PROXY); } catch {} }
166
- info('Downloading Paper...');
167
- try { await download(PAPER_URL, PAPER_PATH, agent); ok('Paper downloaded'); }
166
+ if (!HEADLESS) info('Downloading Paper...');
167
+ try { await download(PAPER_URL, PAPER_PATH, agent); if (!HEADLESS) ok('Paper downloaded'); }
168
168
  catch (e) { fail('Download failed: ' + e.message); console.log(' Manually: ' + PAPER_PATH); process.exit(1); }
169
169
  } else {
170
170
  if (!existsSync(PAPER_PATH)) { fail(`Paper JAR not found: ${PAPER_PATH}`); process.exit(1); }
171
- ok('Paper found at specified path');
171
+ if (!HEADLESS) ok('Paper found at specified path');
172
172
  }
173
173
  } else {
174
- if (existsSync(PAPER_PATH) && statSync(PAPER_PATH).size > 1_000_000) { ok('Paper found in cache'); return; }
174
+ if (existsSync(PAPER_PATH) && statSync(PAPER_PATH).size > 1_000_000) { if (!HEADLESS) ok('Paper found in cache'); return; }
175
175
  mkdirSync(CACHE, { recursive: true });
176
176
  info('Downloading Paper...');
177
177
  try {
@@ -180,7 +180,7 @@ async function ensurePaper() {
180
180
  const latestBuild = versions.builds[versions.builds.length - 1];
181
181
  const dlUrl = `https://api.papermc.io/v2/projects/paper/versions/${PAPER_VERSION}/builds/${latestBuild}/downloads/paper-${PAPER_VERSION}-${latestBuild}.jar`;
182
182
  await download(dlUrl, PAPER_PATH, null);
183
- ok('Paper downloaded');
183
+ if (!HEADLESS) ok('Paper downloaded');
184
184
  } catch (e) {
185
185
  fail('Download failed: ' + e.message);
186
186
  console.log(' Manually download to: ' + PAPER_PATH);
@@ -221,7 +221,7 @@ async function initServer() {
221
221
  const eula = resolve(SERVER, 'eula.txt');
222
222
  if (existsSync(eula) && readFileSync(eula, 'utf-8').includes('eula=true')) return;
223
223
 
224
- if (YES) {
224
+ if (EULA) {
225
225
  if (!existsSync(resolve(SERVER, 'server.properties'))) {
226
226
  info('Initializing...');
227
227
  await new Promise(r => { const p = spawn('java', ['-Xmx4G', '-Xms4G', '-jar', jar, '--nogui'], { cwd: SERVER, stdio: ['pipe', 'inherit', 'inherit'] }); setTimeout(() => { p.kill(); r(); }, 120000); p.on('exit', r); p.on('error', r); });
@@ -429,7 +429,7 @@ async function printFormattedError(err) {
429
429
  }
430
430
 
431
431
  function startServer() {
432
- const jvmArgs = ['-Xmx4G', '-Xms4G', '-Dyeow.dev=true', '-Dyeow.ws.port=' + WS_PORT];
432
+ const jvmArgs = ['-Xmx4G', '-Xms4G', '-Dfile.encoding=UTF-8', '-Dstdout.encoding=UTF-8', '-Dyeow.dev=true', '-Dyeow.ws.port=' + WS_PORT];
433
433
  info(`\nStarting Paper ${PAPER_VERSION} server...`);
434
434
  proc = spawn('java', [...jvmArgs, '-jar', resolve(SERVER, PAPER_JAR), '--nogui'], { cwd: SERVER, stdio: ['pipe', 'inherit', 'inherit'] });
435
435
  proc.on('exit', code => { warn(`Server exited (${code})`); if (wss) wss.close(); process.exit(0); });
@@ -478,17 +478,24 @@ async function runHeadless() {
478
478
  copyToYeowDir(resolve(ROOT, 'dist', 'plugins', `${cfg.name}-${cfg.version}.yeow.zip`), 'Plugin (.yeow.zip → plugins/Yeow/)');
479
479
  copyToPlugins(RUNTIME, 'Runtime');
480
480
 
481
- const jvmArgs = ['-Xmx4G', '-Xms4G', '-Dyeow.dev=true', '-Dyeow.ws.port=' + WS_PORT];
481
+ // 编码:确保子进程 stdout UTF-8 输出(Windows 下避免中文字符乱码)
482
+ const jvmArgs = ['-Xmx4G', '-Xms4G', '-Dfile.encoding=UTF-8', '-Dstdout.encoding=UTF-8',
483
+ '-Dyeow.dev=true', '-Dyeow.ws.port=' + WS_PORT];
482
484
  info(`正在启动 Paper ${PAPER_VERSION}...`);
483
485
  proc = spawn('java', [...jvmArgs, '-jar', resolve(SERVER, PAPER_JAR), '--nogui'], { cwd: SERVER, stdio: ['ignore', 'pipe', 'pipe'] });
484
486
  info(`Server PID: ${proc.pid}`);
485
487
 
486
488
  let started = false, done = false, waitTimer = null;
489
+ const finish = (code) => {
490
+ if (waitTimer) clearTimeout(waitTimer);
491
+ try { if (log) log.end(); } catch {}
492
+ process.exit(code);
493
+ };
487
494
  const failTimer = setTimeout(() => {
488
495
  if (done) return;
489
496
  fail(`服务器在 ${TIMEOUT}s 内未完成加载——请检查网络/依赖下载,或加大超时(--timeout=3m)`);
490
497
  killProc();
491
- process.exit(1);
498
+ finish(1);
492
499
  }, TIMEOUT * 1000);
493
500
 
494
501
  const onLine = (line) => {
@@ -503,20 +510,17 @@ async function runHeadless() {
503
510
  info(`加载完成——等待 ${WAIT}s 后命令结束${KEEP ? '(--keep 保留服务器进程)' : '(关闭服务器进程)'}…`);
504
511
  waitTimer = setTimeout(() => {
505
512
  info(`等待结束。日志${OUTFILE ? ':' + OUTFILE : '输出于上方'};PID=${proc.pid}${KEEP ? '(服务器仍在运行,按需 kill)' : ''}`);
506
- if (log) log.end();
507
- if (KEEP) process.exit(0);
508
- killProc();
509
- process.exit(0);
513
+ if (!KEEP) killProc();
514
+ finish(0);
510
515
  }, WAIT * 1000);
511
516
  }
512
517
  };
513
- readline.createInterface({ input: proc.stdout }).on('line', onLine);
514
- if (proc.stderr) readline.createInterface({ input: proc.stderr }).on('line', (l) => out('[err] ' + l));
518
+ createInterface({ input: proc.stdout }).on('line', onLine);
519
+ if (proc.stderr) createInterface({ input: proc.stderr }).on('line', (l) => out('[err] ' + l));
515
520
 
516
521
  proc.on('exit', (code) => {
517
522
  if (!done) fail(`服务器提前退出(code ${code})——见${OUTFILE ? '日志 ' + OUTFILE : '上方输出'}`);
518
- if (log) log.end();
519
- process.exit(1);
523
+ finish(1);
520
524
  });
521
525
  }
522
526