@rafiqui987/markode 0.4.1 → 0.4.2
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/dist/cli.js +45 -39
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1834,9 +1834,42 @@ function keepLanguage(root2, rel) {
|
|
|
1834
1834
|
|
|
1835
1835
|
// src/core/server.ts
|
|
1836
1836
|
import { spawn } from "child_process";
|
|
1837
|
+
import fs18 from "fs";
|
|
1838
|
+
import path18 from "path";
|
|
1839
|
+
|
|
1840
|
+
// src/core/update.ts
|
|
1841
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
1837
1842
|
import fs17 from "fs";
|
|
1838
1843
|
import path17 from "path";
|
|
1839
|
-
var
|
|
1844
|
+
var PKG = JSON.parse(fs17.readFileSync(path17.join(PKG_ROOT, "package.json"), "utf8"));
|
|
1845
|
+
var CURRENT_VERSION = PKG.version;
|
|
1846
|
+
function installer() {
|
|
1847
|
+
const dir = PKG_ROOT.split(path17.sep).join("/");
|
|
1848
|
+
if (dir.includes("/_npx/")) return "npx";
|
|
1849
|
+
if (!dir.includes("/node_modules/")) return null;
|
|
1850
|
+
return dir.includes("/pnpm/") || dir.includes("/.pnpm/") ? "pnpm" : "npm";
|
|
1851
|
+
}
|
|
1852
|
+
async function latestVersion() {
|
|
1853
|
+
const res = await fetch(`https://registry.npmjs.org/${PKG.name}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(15e3) });
|
|
1854
|
+
if (!res.ok) throw new Error(`The npm registry answered ${res.status}`);
|
|
1855
|
+
return (await res.json()).version;
|
|
1856
|
+
}
|
|
1857
|
+
function isNewer(a, b) {
|
|
1858
|
+
const pa = a.split(".").map((n) => parseInt(n, 10));
|
|
1859
|
+
const pb = b.split(".").map((n) => parseInt(n, 10));
|
|
1860
|
+
for (let i = 0; i < 3; i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) > (pb[i] ?? 0);
|
|
1861
|
+
return false;
|
|
1862
|
+
}
|
|
1863
|
+
function installCommand2(via, version) {
|
|
1864
|
+
const spec = `${PKG.name}@${version}`;
|
|
1865
|
+
return via === "pnpm" ? ["pnpm", "add", "-g", spec, "--config.minimum-release-age=0"] : ["npm", "install", "-g", spec, "--min-release-age=0", "--prefer-online"];
|
|
1866
|
+
}
|
|
1867
|
+
function runInstall(cmd) {
|
|
1868
|
+
return spawnSync2(cmd[0], cmd.slice(1), { stdio: "inherit", shell: process.platform === "win32" }).status === 0;
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
// src/core/server.ts
|
|
1872
|
+
var serverFile = (root2) => path18.join(stateDir(root2), "server.json");
|
|
1840
1873
|
var isAlive = (pid) => {
|
|
1841
1874
|
try {
|
|
1842
1875
|
process.kill(pid, 0);
|
|
@@ -1847,18 +1880,18 @@ var isAlive = (pid) => {
|
|
|
1847
1880
|
};
|
|
1848
1881
|
function recordServer(root2, port) {
|
|
1849
1882
|
const file = serverFile(root2);
|
|
1850
|
-
|
|
1883
|
+
fs18.mkdirSync(path18.dirname(file), { recursive: true });
|
|
1851
1884
|
assertInside(file);
|
|
1852
|
-
|
|
1885
|
+
fs18.writeFileSync(file, JSON.stringify({ port, pid: process.pid, version: CURRENT_VERSION }));
|
|
1853
1886
|
process.once("exit", () => {
|
|
1854
|
-
if (runningServer(root2)?.pid === process.pid)
|
|
1887
|
+
if (runningServer(root2)?.pid === process.pid) fs18.rmSync(file, { force: true });
|
|
1855
1888
|
});
|
|
1856
1889
|
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) process.once(sig, () => process.exit(130));
|
|
1857
1890
|
}
|
|
1858
1891
|
function runningServer(root2) {
|
|
1859
1892
|
try {
|
|
1860
|
-
const s = JSON.parse(
|
|
1861
|
-
return Number.isInteger(s.port) && Number.isInteger(s.pid) && isAlive(s.pid) ? { port: s.port, pid: s.pid } : null;
|
|
1893
|
+
const s = JSON.parse(fs18.readFileSync(serverFile(root2), "utf8"));
|
|
1894
|
+
return Number.isInteger(s.port) && Number.isInteger(s.pid) && isAlive(s.pid) ? { port: s.port, pid: s.pid, version: s.version } : null;
|
|
1862
1895
|
} catch {
|
|
1863
1896
|
return null;
|
|
1864
1897
|
}
|
|
@@ -1872,7 +1905,11 @@ async function responds(port) {
|
|
|
1872
1905
|
}
|
|
1873
1906
|
async function ensureServer(root2, cli2, port) {
|
|
1874
1907
|
const running = runningServer(root2);
|
|
1875
|
-
if (running &&
|
|
1908
|
+
if (running && running.version !== CURRENT_VERSION) {
|
|
1909
|
+
process.kill(running.pid);
|
|
1910
|
+
for (let i = 0; i < 50 && isAlive(running.pid); i++) await new Promise((r) => setTimeout(r, 100));
|
|
1911
|
+
port = running.port;
|
|
1912
|
+
} else if (running && await responds(running.port)) return running;
|
|
1876
1913
|
const child = spawn(process.execPath, [...process.execArgv, cli2, "serve", "--no-open", "--port", String(port)], {
|
|
1877
1914
|
cwd: root2,
|
|
1878
1915
|
env: { ...process.env, MARKODE_ROOT: root2 },
|
|
@@ -1889,37 +1926,6 @@ async function ensureServer(root2, cli2, port) {
|
|
|
1889
1926
|
}
|
|
1890
1927
|
var editorUrl = (port, doc) => `http://localhost:${port}/${doc ? `open?path=${encodeURIComponent(doc).replace(/%2F/g, "/")}` : ""}`;
|
|
1891
1928
|
|
|
1892
|
-
// src/core/update.ts
|
|
1893
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
1894
|
-
import fs18 from "fs";
|
|
1895
|
-
import path18 from "path";
|
|
1896
|
-
var PKG = JSON.parse(fs18.readFileSync(path18.join(PKG_ROOT, "package.json"), "utf8"));
|
|
1897
|
-
var CURRENT_VERSION = PKG.version;
|
|
1898
|
-
function installer() {
|
|
1899
|
-
const dir = PKG_ROOT.split(path18.sep).join("/");
|
|
1900
|
-
if (dir.includes("/_npx/")) return "npx";
|
|
1901
|
-
if (!dir.includes("/node_modules/")) return null;
|
|
1902
|
-
return dir.includes("/pnpm/") || dir.includes("/.pnpm/") ? "pnpm" : "npm";
|
|
1903
|
-
}
|
|
1904
|
-
async function latestVersion() {
|
|
1905
|
-
const res = await fetch(`https://registry.npmjs.org/${PKG.name}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(15e3) });
|
|
1906
|
-
if (!res.ok) throw new Error(`The npm registry answered ${res.status}`);
|
|
1907
|
-
return (await res.json()).version;
|
|
1908
|
-
}
|
|
1909
|
-
function isNewer(a, b) {
|
|
1910
|
-
const pa = a.split(".").map((n) => parseInt(n, 10));
|
|
1911
|
-
const pb = b.split(".").map((n) => parseInt(n, 10));
|
|
1912
|
-
for (let i = 0; i < 3; i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) > (pb[i] ?? 0);
|
|
1913
|
-
return false;
|
|
1914
|
-
}
|
|
1915
|
-
function installCommand2(via, version) {
|
|
1916
|
-
const spec = `${PKG.name}@${version}`;
|
|
1917
|
-
return via === "pnpm" ? ["pnpm", "add", "-g", spec, "--config.minimum-release-age=0"] : ["npm", "install", "-g", spec, "--min-release-age=0", "--prefer-online"];
|
|
1918
|
-
}
|
|
1919
|
-
function runInstall(cmd) {
|
|
1920
|
-
return spawnSync2(cmd[0], cmd.slice(1), { stdio: "inherit", shell: process.platform === "win32" }).status === 0;
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
1929
|
// src/core/wait.ts
|
|
1924
1930
|
import fs19 from "fs";
|
|
1925
1931
|
import path19 from "path";
|
|
@@ -3031,7 +3037,7 @@ async function update() {
|
|
|
3031
3037
|
if (!via) return console.log("This copy runs from a clone of the repository: pull and build it, or install it with `markode update --pnpm` (or --npm).");
|
|
3032
3038
|
const cmd = installCommand2(via, latest);
|
|
3033
3039
|
console.log(`$ ${cmd.join(" ")}`);
|
|
3034
|
-
if (runInstall(cmd)) return console.log(`Updated to ${latest}.
|
|
3040
|
+
if (runInstall(cmd)) return console.log(`Updated to ${latest}. The next \`markode url\` (or /markode) restarts a running editor with it.`);
|
|
3035
3041
|
console.error("The install failed; the output above says why.");
|
|
3036
3042
|
process.exitCode = 1;
|
|
3037
3043
|
}
|
package/package.json
CHANGED