-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmws.run.mjs
More file actions
executable file
·37 lines (32 loc) · 1021 Bytes
/
Copy pathmws.run.mjs
File metadata and controls
executable file
·37 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
//@ts-check
import { existsSync, readFileSync, } from "fs";
const cwd = process.cwd();
/** @type {import("./package.json") | null} */
const pkg = existsSync(`${cwd}/package.json`) && tryParseJSON(readFileSync(`${cwd}/package.json`, "utf8")) || null;
if(pkg && pkg.name === "@tiddlywiki/mws" && existsSync(`${cwd}/mws.dev.mjs`)) {
console.error("This appears to be a development version of MWS.");
process.exit(1);
}
if(pkg && pkg.name === "@tiddlywiki/mws-instance" && pkg.private) {
// need absolute path because of cwd
import(`file://${cwd}/node_modules/@tiddlywiki/mws/dist/mws.js`)
.then(mws => mws.default())
.catch(console.error);
} else {
console.error("This does not appear to be a valid MWS data folder.");
console.error("Please run this command in the root of your MWS data folder.");
process.exit(1);
}
/**
*
* @param {string} file
* @returns
*/
function tryParseJSON(file) {
try {
return JSON.parse(file);
} catch(e) {
return undefined;
}
}