mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-03-25 08:34:16 +08:00
add repl version
This commit is contained in:
30
repl/index.js
Normal file
30
repl/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import App from './app.js';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
|
||||
async function main() {
|
||||
|
||||
try {
|
||||
global.localStorage = JSON.parse(await readFile('__localStorage.json'));
|
||||
} catch (e) {
|
||||
global.localStorage = {};
|
||||
}
|
||||
|
||||
global.dumpLocalStorage = async ()=>await writeFile('__localStorage.json', JSON.stringify( global.localStorage))
|
||||
|
||||
const app = new App();
|
||||
app.io(
|
||||
repl => process.stdin.on('data', data=>repl(data.toString().trim())),
|
||||
(data, isRepl) => process.stdout.write(`${data}${isRepl?'\n>':''}`),
|
||||
code=>process.exit(code)
|
||||
)
|
||||
await app.initial();
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
// process.stdin.setRawMode(true);
|
||||
|
||||
// process.openStdin().on('keypress', function (chunk, key) {
|
||||
// process.stdout.write('Get Chunk: ' + chunk + '\n');
|
||||
// if (key && key.ctrl && key.name == 'c') process.exit();
|
||||
// });
|
||||
Reference in New Issue
Block a user