create-yeow 0.2.12 → 0.2.14
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
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, copyFileSync, writeFileSync, readFileSync, createWriteStream, statSync } from 'fs';
|
|
1
|
+
import { existsSync, mkdirSync, copyFileSync, writeFileSync, readFileSync, createWriteStream, statSync, watch } from 'fs';
|
|
2
2
|
import { resolve, dirname, join, basename } from 'path';
|
|
3
3
|
import { spawn, execSync } from 'child_process';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
@@ -29,6 +29,8 @@ const fail = msg => log(`${c.fail} ${msg}`, c.R);
|
|
|
29
29
|
const info = msg => log(`${c.info} ${msg}`, c.C);
|
|
30
30
|
const warn = msg => log(`${c.warn} ${msg}`, c.y);
|
|
31
31
|
|
|
32
|
+
let proc = null;
|
|
33
|
+
|
|
32
34
|
function download(url, dest, agent) {
|
|
33
35
|
return new Promise((resolve, reject) => {
|
|
34
36
|
const f = createWriteStream(dest);
|
|
@@ -94,10 +96,38 @@ function serverProps(port) {
|
|
|
94
96
|
writeFileSync(f, out);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
function startHotReload() {
|
|
100
|
+
const srcDir = resolve(ROOT, 'src');
|
|
101
|
+
if (!existsSync(srcDir)) return;
|
|
102
|
+
const devDir = resolve(SERVER, 'plugins', 'Yeow-Dev', cfg.name);
|
|
103
|
+
mkdirSync(devDir, { recursive: true });
|
|
104
|
+
let timer = null;
|
|
105
|
+
let building = false;
|
|
106
|
+
const ext = existsSync(resolve(srcDir, 'index.ts')) ? 'ts' : 'js';
|
|
107
|
+
watch(srcDir, { recursive: true }, (event, file) => {
|
|
108
|
+
if (!file || !file.endsWith('.' + ext) || building) return;
|
|
109
|
+
if (timer) clearTimeout(timer);
|
|
110
|
+
timer = setTimeout(() => {
|
|
111
|
+
building = true;
|
|
112
|
+
info('Source changed, rebuilding...');
|
|
113
|
+
try {
|
|
114
|
+
execSync('node .yeow/build.js', { cwd: ROOT, stdio: 'pipe' });
|
|
115
|
+
const compiled = resolve(ROOT, 'dist', '.yeow', 'main.js');
|
|
116
|
+
if (existsSync(compiled)) {
|
|
117
|
+
copyFileSync(compiled, resolve(devDir, 'main.js'));
|
|
118
|
+
ok('Hot reload updated');
|
|
119
|
+
}
|
|
120
|
+
} catch (e) { fail('Build failed: ' + e.message); }
|
|
121
|
+
building = false;
|
|
122
|
+
}, 1000);
|
|
123
|
+
});
|
|
124
|
+
info(`Watching src/ for changes (hot reload)`);
|
|
125
|
+
}
|
|
126
|
+
|
|
98
127
|
function startServer() {
|
|
128
|
+
const jvmArgs = ['-Xmx4G', '-Xms4G', '-Dyeow.dev=true'];
|
|
99
129
|
info(`\nStarting Paper ${PAPER} server...`);
|
|
100
|
-
proc = spawn('java', [
|
|
130
|
+
proc = spawn('java', [...jvmArgs, '-jar', resolve(SERVER, JAR), '--nogui'], { cwd: SERVER, stdio: ['pipe', 'inherit', 'inherit'] });
|
|
101
131
|
proc.on('exit', code => { warn(`Server exited (${code})`); process.exit(0); });
|
|
102
132
|
process.stdin.on('data', d => { if (proc && !proc.killed) proc.stdin.write(d); });
|
|
103
133
|
if (STOP) { info(`Auto-stop in ${STOP}s`); setTimeout(() => { warn('Auto-stop'); if (proc && !proc.killed) proc.stdin.write('stop\n'); setTimeout(() => { if (proc && !proc.killed) proc.kill(); process.exit(0); }, 10000); }, STOP * 1000); }
|
|
@@ -115,6 +145,7 @@ async function main() {
|
|
|
115
145
|
copyToPlugins(resolve(ROOT, 'dist', `${cfg.name}-${cfg.version}.jar`), 'Plugin');
|
|
116
146
|
copyToPlugins(RUNTIME, 'Runtime');
|
|
117
147
|
|
|
148
|
+
startHotReload();
|
|
118
149
|
startServer();
|
|
119
150
|
}
|
|
120
151
|
|