works on windows i guess?!

materials
Valerie 2021-07-26 00:18:21 -04:00
parent 730ba1af3f
commit 076dcb9aaa
10 changed files with 4589 additions and 4546 deletions

View File

@ -10,9 +10,11 @@
"@nodegui/nodegui": "^0.34.0", "@nodegui/nodegui": "^0.34.0",
"@rollup/plugin-alias": "^3.1.4", "@rollup/plugin-alias": "^3.1.4",
"@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-json": "^4.1.0",
"@types/blessed": "^0.1.17", "@types/blessed": "^0.1.17",
"@types/bonjour": "^3.5.8", "@types/bonjour": "^3.5.8",
"@types/chai": "^4.2.19", "@types/chai": "^4.2.19",
"@types/chokidar": "^2.1.3",
"@types/faker": "^5.5.6", "@types/faker": "^5.5.6",
"@types/fs-extra": "^9.0.11", "@types/fs-extra": "^9.0.11",
"@types/mocha": "^8.2.2", "@types/mocha": "^8.2.2",
@ -50,13 +52,13 @@
}, },
"scripts": { "scripts": {
"compile": "yarn tsc & yarn rollup", "compile": "yarn tsc & yarn rollup",
"start": "yarn qode bin/app.bundle.js", "start": "yarn qode bin/app.bundle.cjs",
"dev": "yarn x bin/ipc-tower.bundle.js", "dev": "yarn x bin/ipc-tower.bundle.cjs",
"prod": "git fetch && git pull && yarn && tsc && yarn start", "prod": "git fetch && git pull && yarn && tsc && yarn start",
"test": "mocha", "test": "mocha",
"lint": "eslint src/**/*.ts", "lint": "eslint src/**/*.ts",
"web": "web-dev-server --open index.html --node-resolve --watch", "web": "web-dev-server --open index.html --node-resolve --watch",
"profile": "yarn qode --inspect-brk bin/app.bundle.js", "profile": "yarn qode --inspect-brk bin/app.bundle.cjs",
"qode": "qode", "qode": "qode",
"x": "node", "x": "node",
"tsc": "tsc", "tsc": "tsc",

View File

@ -17,9 +17,20 @@ const shared = {
alias({ alias({
entries: [ entries: [
...aliases, ...aliases,
{ find: 'frigid', replacement: resolve(__dirname, 'node_modules/frigid/out/index.js') } {
find: 'frigid',
replacement: resolve(__dirname, 'node_modules/frigid/out/index.js')
},
{
find: 'node-ipc',
replacement: resolve(__dirname, 'node_modules/node-ipc/node-ipc.js')
},
{
find: 'event-pubsub',
replacement: resolve(__dirname, 'node_modules/event-pubsub/index.js')
},
] ]
}) }),
], ],
watch: { watch: {
include: 'out/**/*' include: 'out/**/*'
@ -31,16 +42,16 @@ export default [
...shared, ...shared,
input: './out/src/index.js', input: './out/src/index.js',
output: { output: {
file: 'bin/app.bundle.js', file: 'bin/app.bundle.cjs',
format: 'es' format: 'cjs'
} }
}, },
{ {
...shared, ...shared,
input: './out/src/hot-index.js', input: './out/src/hot-index.js',
output: { output: {
file: 'bin/ipc-tower.bundle.js', file: 'bin/ipc-tower.bundle.cjs',
format: 'es' format: 'cjs'
} }
} }
]; ];

View File

@ -1,4 +1,4 @@
import { Frigid, Serializable } from 'frigid'; import { Frigid } from 'frigid';
import { Pawn } from './Pawn.js'; import { Pawn } from './Pawn.js';
import { TaskList } from './TaskList.js'; import { TaskList } from './TaskList.js';
import { Inventory } from './Inventory.js'; import { Inventory } from './Inventory.js';

View File

@ -13,7 +13,9 @@ let connected = false;
class ProcessManagerClass extends EventEmitter { class ProcessManagerClass extends EventEmitter {
quit() { quit() {
if (connected) { if (connected) {
console.log('client sending quit event')
ipc.of[name].emit(IPC_QUIT_EVENT); ipc.of[name].emit(IPC_QUIT_EVENT);
process.exit(0);
} else { } else {
process.exit(0); process.exit(0);
} }
@ -21,9 +23,12 @@ class ProcessManagerClass extends EventEmitter {
restart() { restart() {
if (connected) { if (connected) {
console.log('client emitting ipc restart')
ipc.of[name].emit(IPC_RESTART_EVENT); ipc.of[name].emit(IPC_RESTART_EVENT);
process.exit(0);
} else { } else {
process.exit(1); console.log('eh?! not connected to tower... closing')
process.exit(0);
} }
} }
} }
@ -40,4 +45,6 @@ ipc.connectTo(name, () => {
ipc.of[name].on(IPC_REQUEST_RESTART, () => { ipc.of[name].on(IPC_REQUEST_RESTART, () => {
ProcessManager.emit('reload'); ProcessManager.emit('reload');
}) })
}); });
/////////////

View File

@ -7,13 +7,14 @@ import {
} from './Constants.js'; } from './Constants.js';
import { spawn, ChildProcess } from 'child_process'; import { spawn, ChildProcess } from 'child_process';
import watch from 'watch'; import watch from 'watch';
import chokidar from 'chokidar';
import chalk from 'chalk'; import chalk from 'chalk';
ipc.config.silent = true; // ipc.config.silent = true;
const exec = 'yarn' + (process.platform === "win32" ? '.cmd' : ''); const exec = 'qode' + (process.platform === "win32" ? '.cmd' : '');
const args = [ const args = [
'start' 'bin/app.bundle.cjs'
] ]
ipc.serve(IPC_PATH, () => { ipc.serve(IPC_PATH, () => {
@ -25,15 +26,14 @@ ipc.serve(IPC_PATH, () => {
ipc.server.on(IPC_RESTART_EVENT, restart) ipc.server.on(IPC_RESTART_EVENT, restart)
}); });
console.log('started ipc tower server!')
ipc.server.start(); ipc.server.start();
let proc: ChildProcess = null; let proc: ChildProcess = null;
function startProcess() { function startProcess() {
proc = spawn(exec, args, { proc = spawn(exec, args, {
stdio: 'inherit', stdio: 'inherit'
cwd: process.cwd(),
env: process.env
}); });
console.log(`[${proc.pid}] ${chalk.grey(`${exec} ${args.join(' ')}`)}`); console.log(`[${proc.pid}] ${chalk.grey(`${exec} ${args.join(' ')}`)}`);
proc.on('exit', () => { proc.on('exit', () => {
@ -46,23 +46,22 @@ async function killProcess() {
if(proc) { if(proc) {
console.log('killing process...'); console.log('killing process...');
const killedPromise = new Promise((res) => { const killedPromise = new Promise((res) => {
proc.on('exit', () => { proc.on('exit', (code, sig) => {
res(void 0); res(code || sig);
}) })
}) })
proc.kill(); proc.kill();
await killedPromise; console.log('process died with code', await killedPromise);
proc = null; proc = null;
console.log()
} }
} }
async function restart() { async function restart() {
if(proc) { console.log('received restart event');
await killProcess(); await killProcess();
startProcess(); console.log('')
} else { startProcess();
startProcess();
}
} }
startProcess(); startProcess();
@ -70,14 +69,20 @@ startProcess();
let restartTimer: NodeJS.Timeout = null; let restartTimer: NodeJS.Timeout = null;
function fileChange() { function fileChange() {
console.log('changes detected');
// appendFileSync('log.log', evt + ' ' + path + '\n'); // appendFileSync('log.log', evt + ' ' + path + '\n');
// console.log(cluster.isMaster, evt, path); // console.log(cluster.isMaster, evt, path);
if(restartTimer) clearTimeout(restartTimer) if(restartTimer) clearTimeout(restartTimer)
restartTimer = setTimeout(() => { restartTimer = setTimeout(() => {
ipc.server.broadcast(IPC_REQUEST_RESTART); console.log('changes detected');
if(proc) {
ipc.server.broadcast(IPC_REQUEST_RESTART);
} else {
startProcess();
}
restartTimer = null; restartTimer = null;
}, 1000); }, 100);
} }
// chokidar.watch('./out').on('all', fileChange); chokidar.watch('./out').on('all', fileChange);
watch.watchTree('./bin', fileChange); // watch.watchTree('./bin', fileChange);

View File

@ -9,6 +9,7 @@ import {
setView, setView,
start start
} from '@ui'; } from '@ui';
// @ts-ignore
import ansi from 'sisteransi'; import ansi from 'sisteransi';
// HACK static extension loading // HACK static extension loading

View File

@ -1,8 +1,12 @@
import { QGridLayout, QLabel, QMainWindow, QPushButton, QWidget } from "@nodegui/nodegui"; import { FocusReason, QGridLayout, QLabel, QMainWindow, QPushButton, QWidget } from "@nodegui/nodegui";
import { ProcessManager } from "../ProcessManager"; import { ProcessManager } from "../ProcessManager";
export class RequestReloadPopup { export class RequestReloadPopup {
static exists = false;
static show() { static show() {
if(this.exists) return;
this.exists = true;
const window = new QMainWindow(); const window = new QMainWindow();
window.setFixedSize(200, 100); window.setFixedSize(200, 100);
const root = new QWidget(); const root = new QWidget();
@ -16,6 +20,7 @@ export class RequestReloadPopup {
reloadButton.setText('Reload'); reloadButton.setText('Reload');
layout.addWidget(reloadButton, 4, 2, 1, 1); layout.addWidget(reloadButton, 4, 2, 1, 1);
window.show(); window.show();
window.setWindowTitle('Reload?');
reloadButton.addEventListener('clicked', () => { reloadButton.addEventListener('clicked', () => {
ProcessManager.restart(); ProcessManager.restart();
@ -23,4 +28,4 @@ export class RequestReloadPopup {
} }
} }
// //////

View File

@ -1,4 +1,5 @@
import { QGridLayout, QMainWindow, QWidget } from "@nodegui/nodegui"; import { QGridLayout, QMainWindow, QWidget, WindowState } from "@nodegui/nodegui";
import { QEvent } from "@nodegui/nodegui/dist/lib/QtGui/QEvent/QEvent";
import { win } from "@ui"; import { win } from "@ui";
export abstract class View { export abstract class View {

View File

@ -12,40 +12,40 @@ export { Popup } from './Popup.js';
export const win = new QMainWindow(); export const win = new QMainWindow();
win.setFixedSize(800, 600); win.setFixedSize(800, 600);
win.setWindowTitle(APPLICATION_NAME); win.setWindowTitle(APPLICATION_NAME);
win.setStyleSheet(` // win.setStyleSheet(`
#root { // #root {
background-color: black; // background-color: black;
height: '100%'; // height: '100%';
} // }
QPushButton { // QPushButton {
background: #333333; // background: #333333;
} // }
QPushButton:pressed { // QPushButton:pressed {
background: cyan; // background: cyan;
color: black; // color: black;
} // }
* { // * {
font-family: 'MxPlus IBM VGA 8x16'; // font-family: 'MxPlus IBM VGA 8x16';
font-size: 16px; // font-size: 16px;
} // }
QTabWidget { // QTabWidget {
border: 1px solid white; // border: 1px solid white;
} // }
QTabWidget::pane { // QTabWidget::pane {
background: black; // background: black;
border: none; // border: none;
border-radius: 0px; // border-radius: 0px;
} // }
QTabBar::tab { // QTabBar::tab {
background: black; // background: black;
color: cyan; // color: cyan;
padding: 4px 12px; // padding: 4px 12px;
} // }
QTabBar::tab:selected { // QTabBar::tab:selected {
background: cyan; // background: cyan;
color: black; // color: black;
} // }
`); // `);
win.show(); win.show();
(global as any).win = win; (global as any).win = win;
win.addEventListener(WidgetEventTypes.Paint, _ => _); win.addEventListener(WidgetEventTypes.Paint, _ => _);
@ -77,13 +77,14 @@ export function update() {
} }
export function isStarted() { export function isStarted() {
return true;
return win.isVisible(); return win.isVisible();
} }
ProcessManager.on('reload', () => { ProcessManager.on('reload', () => {
RequestReloadPopup.show(); RequestReloadPopup.show();
// //
}) });
// HACK this is bullshit, :) // HACK this is bullshit, :)

8962
yarn.lock

File diff suppressed because it is too large Load Diff