@opentig/cli 0.1.3 → 0.1.5
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/README.md +73 -17
- package/dist/bin.mjs +2 -2
- package/dist/chunks/{cli-DaYybBfs.mjs → cli-D_aggpu2.mjs} +232 -57
- package/dist/chunks/service-manager-DkpSHxsP.mjs +394 -0
- package/dist/client/assets/App-CeDVj5Hh.js +118 -0
- package/dist/client/assets/{CreatePullRequestDialog-CGnY6nrw.js → CreatePullRequestDialog-DMHY_u8X.js} +2 -2
- package/dist/client/assets/{DiffWorkspace-1ZAh7eFX.js → DiffWorkspace-CeYQ0YtE.js} +1 -1
- package/dist/client/assets/{EditableFileViewer-DOnxE6ty.js → EditableFileViewer-BhwE-QMO.js} +1 -1
- package/dist/client/assets/{File-DM0fcPqi.js → File-C10_BxOu.js} +1 -1
- package/dist/client/assets/{FilesView-BuTZiUd4.js → FilesView-BT4eHbFo.js} +1 -1
- package/dist/client/assets/{GitHubAvatar-BIZ8KlZ9.js → GitHubAvatar-Ch_PaCv3.js} +1 -1
- package/dist/client/assets/{HistoryView-BTo2h2ee.js → HistoryView-CivGwdxV.js} +1 -1
- package/dist/client/assets/{HtmlFileViewer-tEtrcHdG.js → HtmlFileViewer-Cufzaec9.js} +1 -1
- package/dist/client/assets/{IconEdit-DtVD7NDP.js → IconEdit-RxH71_V-.js} +1 -1
- package/dist/client/assets/{IconFolderPlus-D5cPTAyD.js → IconFolderPlus-DSSB-ikf.js} +1 -1
- package/dist/client/assets/{ImageFileViewer-C56bQ88S.js → ImageFileViewer-CFUkcXLH.js} +1 -1
- package/dist/client/assets/{LocalRefsDialog-DwhpiSyu.js → LocalRefsDialog-B2jUCKTx.js} +1 -1
- package/dist/client/assets/{MarkdownFileViewer-BxQfoNnS.js → MarkdownFileViewer-BLfJ-Vof.js} +2 -2
- package/dist/client/assets/{PairingPage-Cu1KraeJ.js → PairingPage-C5Ggk-Z_.js} +1 -1
- package/dist/client/assets/{PierreDiffViewer-B9IrAdjM.js → PierreDiffViewer-DYj1ZThr.js} +1 -1
- package/dist/client/assets/{PierreEditBoundary-DDJlRbaP.js → PierreEditBoundary-UfvbKDbd.js} +1 -1
- package/dist/client/assets/{PierreWorkerPool-BJhmuZSy.js → PierreWorkerPool-7EVoquIB.js} +1 -1
- package/dist/client/assets/{PullRequestDiff-Di1_Wv1o.js → PullRequestDiff-DxLTcm6L.js} +1 -1
- package/dist/client/assets/{PullRequestViewer-CuH0Ze12.js → PullRequestViewer-CyW39MuF.js} +2 -2
- package/dist/client/assets/{PullRequestsView-DRKuy94k.js → PullRequestsView-BHcnarLS.js} +1 -1
- package/dist/client/assets/{QuickOpenDialog-DSdrgS2H.js → QuickOpenDialog-CasQU7pk.js} +1 -1
- package/dist/client/assets/{RepositoryProjectsDialog-CWcakQRC.js → RepositoryProjectsDialog-VAiZrDlA.js} +1 -1
- package/dist/client/assets/{SearchView-Btqv-BZZ.js → SearchView-Bv4bA4UJ.js} +1 -1
- package/dist/client/assets/{SettingsDialog-CV7hRbtK.js → SettingsDialog-D33V9Fry.js} +2 -2
- package/dist/client/assets/{Viewer-bchsRyMu.js → Viewer-I1lC_oJU.js} +2 -2
- package/dist/client/assets/{abnfDiagram-N423BO3Z-D6JAOs-X.js → abnfDiagram-N423BO3Z-DrlQwm7W.js} +1 -1
- package/dist/client/assets/{arc-YncG-7Bc.js → arc-B9cXI-QL.js} +1 -1
- package/dist/client/assets/{architectureDiagram-T3A2C74G-Ckf8dhax.js → architectureDiagram-T3A2C74G-DZz7ZXbI.js} +1 -1
- package/dist/client/assets/{blockDiagram-VBNYF7ZC-CGQa9zHO.js → blockDiagram-VBNYF7ZC-DZFMT63B.js} +1 -1
- package/dist/client/assets/{c4Diagram-5PPSVZJV-Ctgat2YZ.js → c4Diagram-5PPSVZJV-BnHIZMZp.js} +1 -1
- package/dist/client/assets/channel-CE-pdA-6.js +1 -0
- package/dist/client/assets/{checkbox-D5IGxs1d.js → checkbox-BpmQTxn7.js} +1 -1
- package/dist/client/assets/{chunk-2GRJ4B5K-CyDC0FQq.js → chunk-2GRJ4B5K-CJOlpI9g.js} +1 -1
- package/dist/client/assets/{chunk-2Q5K7J3B-DqYRVN1X.js → chunk-2Q5K7J3B-DhsnoUrJ.js} +1 -1
- package/dist/client/assets/{chunk-5RXB4S5H-BtrE-Jqe.js → chunk-5RXB4S5H-Nwsk3OIu.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-CEVyxEEH.js → chunk-5VM5RSS4-Dk9FYU9b.js} +1 -1
- package/dist/client/assets/{chunk-6Q2QTUOP-CR_RRfTb.js → chunk-6Q2QTUOP-C8lX8T87.js} +1 -1
- package/dist/client/assets/{chunk-GF5L2VYU-Uoc_Vpub.js → chunk-GF5L2VYU-DWHvTG6c.js} +1 -1
- package/dist/client/assets/{chunk-JWPE2WC7-BAhDzsCx.js → chunk-JWPE2WC7-BLu2-FJl.js} +1 -1
- package/dist/client/assets/{chunk-KBJHAD2P-DkGEUlle.js → chunk-KBJHAD2P-CEOb10I1.js} +1 -1
- package/dist/client/assets/{chunk-RYQCIY6F-doFXXAJb.js → chunk-RYQCIY6F-BcdMrb_e.js} +1 -1
- package/dist/client/assets/{chunk-XXDRQBXY-B44pCuJx.js → chunk-XXDRQBXY-CzPimvfs.js} +1 -1
- package/dist/client/assets/classDiagram-JCYQIIEL-2elbt6qi.js +1 -0
- package/dist/client/assets/classDiagram-v2-OCEON4UE-2elbt6qi.js +1 -0
- package/dist/client/assets/{cose-bilkent-JH36ORCC-CymnJ1xN.js → cose-bilkent-JH36ORCC-BYfzHUkR.js} +1 -1
- package/dist/client/assets/{cynefin-VYW2F7L2-BT5dARHp.js → cynefin-VYW2F7L2-B4mEAleX.js} +1 -1
- package/dist/client/assets/{cynefinDiagram-MW4NZA55-DVrhZ1A4.js → cynefinDiagram-MW4NZA55-CioMvT6V.js} +1 -1
- package/dist/client/assets/{dagre-VZM6K2ZE-BET0T1KQ.js → dagre-VZM6K2ZE-DWPgHi5i.js} +1 -1
- package/dist/client/assets/{diagram-7IWD3JNH-mIl4bvgD.js → diagram-7IWD3JNH-94i9EwB_.js} +1 -1
- package/dist/client/assets/{diagram-B4RE2ZJO-DKSi3zok.js → diagram-B4RE2ZJO-BRgMOgy8.js} +1 -1
- package/dist/client/assets/{diagram-LBJQPF4R-DFzvqR_V.js → diagram-LBJQPF4R-DHaXTl1T.js} +1 -1
- package/dist/client/assets/{diagram-Q27KOJAE-C8UUiNSc.js → diagram-Q27KOJAE-DtLuyYm1.js} +1 -1
- package/dist/client/assets/{diagram-UB23O5K3-CYuQnggB.js → diagram-UB23O5K3-D8R3grCW.js} +1 -1
- package/dist/client/assets/{ebnfDiagram-BXEA7PRR-orsOZEt3.js → ebnfDiagram-BXEA7PRR-voe5GU7W.js} +1 -1
- package/dist/client/assets/{erDiagram-JOGREHBK-BPxNY3Or.js → erDiagram-JOGREHBK-BShMJhmY.js} +1 -1
- package/dist/client/assets/{flowDiagram-UKHOOZJN-Dj_tbpt_.js → flowDiagram-UKHOOZJN-DASXB2wV.js} +1 -1
- package/dist/client/assets/{ganttDiagram-PKOTCBZU-BhG_1m3O.js → ganttDiagram-PKOTCBZU-Da1ElnJN.js} +1 -1
- package/dist/client/assets/{gh-utils-CR5JRkW2.js → gh-utils-D00lyruw.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-DS77QQ5N-B6i118FC.js → gitGraphDiagram-DS77QQ5N-DoGRli0p.js} +1 -1
- package/dist/client/assets/{index-C_D1kOlX.js → index-BdjG_WtS.js} +2 -2
- package/dist/client/assets/{index-CE9Jcx4e.css → index-Uku28hIV.css} +1 -1
- package/dist/client/assets/{infoDiagram-6WML65LV-DhHBZSVb.js → infoDiagram-6WML65LV-CxkxF5pn.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-WSZJBQD7-6Vd6XOG_.js → ishikawaDiagram-WSZJBQD7-l6dk2-PS.js} +1 -1
- package/dist/client/assets/{journeyDiagram-NVQOT4AX-uH71A9mr.js → journeyDiagram-NVQOT4AX-wJY4ZF5o.js} +1 -1
- package/dist/client/assets/{kanban-definition-27J2QSJJ-DbxRwp0h.js → kanban-definition-27J2QSJJ-CIcwUmJo.js} +1 -1
- package/dist/client/assets/{linear-CFzmLtpp.js → linear-Tf-dXwQ9.js} +1 -1
- package/dist/client/assets/{mermaid.core-B_Mv_eHi.js → mermaid.core-DnaJSnLe.js} +4 -4
- package/dist/client/assets/{mindmap-definition-FAOFIHXS-DQf1s9U3.js → mindmap-definition-FAOFIHXS-jFdJ2bLh.js} +1 -1
- package/dist/client/assets/{pegDiagram-VL7TDLO6-BxFVTcDJ.js → pegDiagram-VL7TDLO6-vq0WE66k.js} +1 -1
- package/dist/client/assets/{pieDiagram-7S7Q4E2Y-CCNbxGSk.js → pieDiagram-7S7Q4E2Y-3edKDMpI.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-CIZ2JOQS-BVhzcmm1.js → quadrantDiagram-CIZ2JOQS-B6M8U4XV.js} +1 -1
- package/dist/client/assets/{railroadDiagram-AXF67PYL-D3R2-3Og.js → railroadDiagram-AXF67PYL-C-d5-0YS.js} +1 -1
- package/dist/client/assets/{render-markdown-DcHo7ihS.js → render-markdown-GXIpf9CM.js} +1 -1
- package/dist/client/assets/{requirementDiagram-LRYGKXZP-B-NkzvnF.js → requirementDiagram-LRYGKXZP-FVzmEbFu.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-W5VNT64P-BRpIzFiP.js → sankeyDiagram-W5VNT64P-B-qcUamt.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-SI44F4Z6-B7cBRL6x.js → sequenceDiagram-SI44F4Z6-DgFXRLSt.js} +1 -1
- package/dist/client/assets/{sizeCapture-X5ZJPWSS-BZ6DbjJ6.js → sizeCapture-X5ZJPWSS-CWi_pMb2.js} +1 -1
- package/dist/client/assets/{stateDiagram-OKZ733FA-x8ChPNdG.js → stateDiagram-OKZ733FA-amQwzlgU.js} +1 -1
- package/dist/client/assets/{stateDiagram-v2-UEYNNEHI-BlYlvm69.js → stateDiagram-v2-UEYNNEHI-TdV8eIV2.js} +1 -1
- package/dist/client/assets/{swimlanes-SLNWSIFB-DR21moSS.js → swimlanes-SLNWSIFB-L88WlaUb.js} +2 -2
- package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-AWimqvIC.js +8 -0
- package/dist/client/assets/{timeline-definition-Z64GVDOM-UlAkswoH.js → timeline-definition-Z64GVDOM-D4TJxxc3.js} +1 -1
- package/dist/client/assets/{vennDiagram-T6HMQDX7-91kBYEFr.js → vennDiagram-T6HMQDX7-ClJWOyzQ.js} +1 -1
- package/dist/client/assets/{viewer-tabs-BHvOJKLx.js → viewer-tabs-Cp_MC_J3.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-T6FBY63Y-CqAHibOn.js → wardleyDiagram-T6FBY63Y-Cxfjpd6V.js} +1 -1
- package/dist/client/assets/{xychartDiagram-ELKLHX3M-BMFs9l78.js → xychartDiagram-ELKLHX3M-BYqbTvmt.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/dev.mjs +4 -4
- package/dist/manifest.json +1 -1
- package/dist/server.mjs +5 -5
- package/dist/service-update.mjs +12 -10
- package/package.json +1 -1
- package/dist/chunks/cli-service-CDd3ZvGV.mjs +0 -237
- package/dist/client/assets/App-C7Yf3r-l.js +0 -118
- package/dist/client/assets/channel-B31JCSE_.js +0 -1
- package/dist/client/assets/classDiagram-JCYQIIEL-C6tU-sLq.js +0 -1
- package/dist/client/assets/classDiagram-v2-OCEON4UE-C6tU-sLq.js +0 -1
- package/dist/client/assets/swimlanesDiagram-ULZ7WXOC-DbXYPHRv.js +0 -8
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { readFile, writeFile, rename, access, rm, mkdir, cp, chmod } from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import process$1 from "node:process";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { promisify } from "node:util";
|
|
8
|
-
const version = "0.1.3";
|
|
9
|
-
const packageMetadata = {
|
|
10
|
-
version
|
|
11
|
-
};
|
|
12
|
-
const OPEN_TIG_APP_VERSION = packageMetadata.version;
|
|
13
|
-
const execute = promisify(execFile);
|
|
14
|
-
const SERVICE_NAME = "opentig.service";
|
|
15
|
-
const serviceUnitPath = () => path.join(os.homedir(), ".config/systemd/user", SERVICE_NAME);
|
|
16
|
-
const stableVersion = (value) => typeof value === "string" && /^\d+\.\d+\.\d+$/.test(value);
|
|
17
|
-
function newerVersion(a, b) {
|
|
18
|
-
if (!stableVersion(a) || !stableVersion(b)) return false;
|
|
19
|
-
const left = a.split(".").map(Number), right = b.split(".").map(Number);
|
|
20
|
-
for (let i = 0; i < 3; i++) if (left[i] !== right[i]) return left[i] > right[i];
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
function packageDirectory(home, install) {
|
|
24
|
-
if (!stableVersion(install.version) || !["flat", "npm"].includes(install.layout)) throw new Error("Invalid managed service version.");
|
|
25
|
-
const base = path.join(home, "service", `app-${install.version}`);
|
|
26
|
-
return install.layout === "flat" ? base : path.join(base, "node_modules/@opentig/cli");
|
|
27
|
-
}
|
|
28
|
-
async function readInstallation(home) {
|
|
29
|
-
let value;
|
|
30
|
-
try {
|
|
31
|
-
value = JSON.parse(await readFile(path.join(home, "service/installation.json"), "utf8"));
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (error.code === "ENOENT") return null;
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
if (value.schema !== 1 || !stableVersion(value.version) || !["flat", "npm"].includes(value.layout) || typeof value.host !== "string" || !/^[a-zA-Z0-9.:[\]-]+$/.test(value.host) || !Number.isInteger(value.port) || value.port < 1 || value.port > 65535 || typeof value.node !== "string" || !path.isAbsolute(value.node) || /[\0\r\n]/.test(value.node)) throw new Error("Invalid managed service installation.");
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
async function atomicWrite(file, contents) {
|
|
40
|
-
const temporary = `${file}.${process.pid}.tmp`;
|
|
41
|
-
await writeFile(temporary, contents, { mode: 384 });
|
|
42
|
-
await rename(temporary, file);
|
|
43
|
-
}
|
|
44
|
-
async function saveInstallation(home, installation) {
|
|
45
|
-
await atomicWrite(path.join(home, "service/installation.json"), JSON.stringify(installation));
|
|
46
|
-
}
|
|
47
|
-
async function systemctl(...args) {
|
|
48
|
-
return (await execute("systemctl", ["--user", ...args], { timeout: 3e4 })).stdout.trim();
|
|
49
|
-
}
|
|
50
|
-
const UNIT_NAME = "opentig.service";
|
|
51
|
-
async function manageCliService(config, io) {
|
|
52
|
-
if (process$1.platform !== "linux") {
|
|
53
|
-
throw new Error("Background service management currently supports Linux with systemd. On this platform, start OpenTig with your preferred service manager.");
|
|
54
|
-
}
|
|
55
|
-
const action = config.serviceAction;
|
|
56
|
-
if (!action) throw new Error("A service action is required.");
|
|
57
|
-
const unitPath = path.join(os.homedir(), ".config", "systemd", "user", UNIT_NAME);
|
|
58
|
-
if (action === "status") return serviceStatus(unitPath, io);
|
|
59
|
-
if (action === "uninstall") return uninstallService(config.home, unitPath, io);
|
|
60
|
-
return installService(config, unitPath, io);
|
|
61
|
-
}
|
|
62
|
-
async function installService(config, unitPath, io) {
|
|
63
|
-
const installed = await readInstallation(config.home);
|
|
64
|
-
if (installed && newerVersion(installed.version, OPEN_TIG_APP_VERSION)) throw new Error("A newer managed service is installed. Use its CLI to administer it; downgrades are not automatic.");
|
|
65
|
-
try {
|
|
66
|
-
await access(path.join(config.home, "service/update-lock"));
|
|
67
|
-
throw new Error("An update is already being applied.");
|
|
68
|
-
} catch (error) {
|
|
69
|
-
if (error.code !== "ENOENT") throw error;
|
|
70
|
-
}
|
|
71
|
-
const packageRoot = await findPackageRoot(fileURLToPath(import.meta.url));
|
|
72
|
-
await assertPackageBuild(packageRoot);
|
|
73
|
-
const serviceRoot = path.join(config.home, "service");
|
|
74
|
-
const reuse = installed?.version === OPEN_TIG_APP_VERSION;
|
|
75
|
-
const target = reuse ? packageDirectory(config.home, installed) : path.join(serviceRoot, `app-${OPEN_TIG_APP_VERSION}`);
|
|
76
|
-
const temporary = path.join(serviceRoot, `.install-${process$1.pid}-${Date.now()}`);
|
|
77
|
-
await mkdir(serviceRoot, { recursive: true, mode: 448 });
|
|
78
|
-
await rm(temporary, { recursive: true, force: true });
|
|
79
|
-
try {
|
|
80
|
-
if (!reuse) {
|
|
81
|
-
await mkdir(temporary, { recursive: true, mode: 448 });
|
|
82
|
-
await cp(path.join(packageRoot, "dist"), path.join(temporary, "dist"), { recursive: true, force: true });
|
|
83
|
-
for (const name of ["package.json", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md"]) {
|
|
84
|
-
await cp(path.join(packageRoot, name), path.join(temporary, name), { force: true });
|
|
85
|
-
}
|
|
86
|
-
await installProductionDependencies(temporary);
|
|
87
|
-
await rm(target, { recursive: true, force: true });
|
|
88
|
-
await rename(temporary, target);
|
|
89
|
-
}
|
|
90
|
-
} catch (error) {
|
|
91
|
-
await rm(temporary, { recursive: true, force: true });
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
const unit = renderSystemdUnit({
|
|
95
|
-
nodeExecutable: process$1.execPath,
|
|
96
|
-
cliEntrypoint: path.join(target, "dist", "bin.mjs"),
|
|
97
|
-
host: config.host,
|
|
98
|
-
port: config.port,
|
|
99
|
-
home: config.home
|
|
100
|
-
});
|
|
101
|
-
await mkdir(path.dirname(unitPath), { recursive: true, mode: 448 });
|
|
102
|
-
const temporaryUnit = `${unitPath}.${process$1.pid}.tmp`;
|
|
103
|
-
await writeFile(temporaryUnit, unit, { encoding: "utf8", mode: 384 });
|
|
104
|
-
await rename(temporaryUnit, unitPath);
|
|
105
|
-
await chmod(unitPath, 384);
|
|
106
|
-
await saveInstallation(config.home, { schema: 1, version: OPEN_TIG_APP_VERSION, layout: reuse ? installed.layout : "flat", host: config.host, port: config.port, node: process$1.execPath });
|
|
107
|
-
await runRequired("systemctl", ["--user", "daemon-reload"]);
|
|
108
|
-
await runRequired("systemctl", ["--user", "enable", UNIT_NAME]);
|
|
109
|
-
await runRequired("systemctl", ["--user", "restart", UNIT_NAME]);
|
|
110
|
-
await runRequired("loginctl", ["enable-linger"]);
|
|
111
|
-
io.out(`OpenTig service installed and started on ${config.host}:${config.port}.`);
|
|
112
|
-
io.out(`Unit: ${unitPath}`);
|
|
113
|
-
io.out(`Pair another browser with: opentig pair --home ${config.home}`);
|
|
114
|
-
return 0;
|
|
115
|
-
}
|
|
116
|
-
async function serviceStatus(unitPath, io) {
|
|
117
|
-
try {
|
|
118
|
-
await access(unitPath);
|
|
119
|
-
} catch {
|
|
120
|
-
io.out("OpenTig service is not installed.");
|
|
121
|
-
return 1;
|
|
122
|
-
}
|
|
123
|
-
const enabled = await run("systemctl", ["--user", "is-enabled", UNIT_NAME]);
|
|
124
|
-
const active = await run("systemctl", ["--user", "is-active", UNIT_NAME]);
|
|
125
|
-
io.out(`OpenTig service: ${active.stdout.trim() || "unknown"} (${enabled.stdout.trim() || "unknown"}).`);
|
|
126
|
-
io.out(`Unit: ${unitPath}`);
|
|
127
|
-
return active.code === 0 ? 0 : 1;
|
|
128
|
-
}
|
|
129
|
-
async function uninstallService(home, unitPath, io) {
|
|
130
|
-
await run("systemctl", ["--user", "disable", "--now", UNIT_NAME]);
|
|
131
|
-
await rm(unitPath, { force: true });
|
|
132
|
-
await runRequired("systemctl", ["--user", "daemon-reload"]);
|
|
133
|
-
await rm(path.join(home, "service"), { recursive: true, force: true });
|
|
134
|
-
io.out("OpenTig service removed. Repository settings and paired sessions were kept.");
|
|
135
|
-
return 0;
|
|
136
|
-
}
|
|
137
|
-
function renderSystemdUnit(input) {
|
|
138
|
-
const args = [
|
|
139
|
-
input.nodeExecutable,
|
|
140
|
-
input.cliEntrypoint,
|
|
141
|
-
"serve",
|
|
142
|
-
"--host",
|
|
143
|
-
input.host,
|
|
144
|
-
"--port",
|
|
145
|
-
String(input.port),
|
|
146
|
-
"--home",
|
|
147
|
-
input.home
|
|
148
|
-
];
|
|
149
|
-
return `[Unit]
|
|
150
|
-
Description=OpenTig browser Git client
|
|
151
|
-
After=network.target
|
|
152
|
-
|
|
153
|
-
[Service]
|
|
154
|
-
Type=simple
|
|
155
|
-
WorkingDirectory=${systemdWorkingDirectory(input.home)}
|
|
156
|
-
ExecStart=${args.map(systemdQuote).join(" ")}
|
|
157
|
-
Environment=NODE_ENV=production
|
|
158
|
-
Restart=on-failure
|
|
159
|
-
RestartSec=3
|
|
160
|
-
KillSignal=SIGTERM
|
|
161
|
-
TimeoutStopSec=10
|
|
162
|
-
|
|
163
|
-
[Install]
|
|
164
|
-
WantedBy=default.target
|
|
165
|
-
`;
|
|
166
|
-
}
|
|
167
|
-
function systemdQuote(value) {
|
|
168
|
-
if (value.includes("\0") || value.includes("\r") || value.includes("\n")) throw new Error("Service paths and arguments cannot contain control characters.");
|
|
169
|
-
return `"${value.replaceAll("%", "%%").replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
|
|
170
|
-
}
|
|
171
|
-
function systemdWorkingDirectory(value) {
|
|
172
|
-
if (!path.isAbsolute(value) || /[\0\r\n]/.test(value)) throw new Error("Service home must be an absolute single-line path.");
|
|
173
|
-
return `${value.replaceAll("%", "%%")}/`;
|
|
174
|
-
}
|
|
175
|
-
async function assertPackageBuild(packageRoot) {
|
|
176
|
-
await Promise.all([
|
|
177
|
-
access(path.join(packageRoot, "dist", "bin.mjs")),
|
|
178
|
-
access(path.join(packageRoot, "dist", "client", "index.html")),
|
|
179
|
-
readFile(path.join(packageRoot, "package.json"), "utf8")
|
|
180
|
-
]).catch(() => {
|
|
181
|
-
throw new Error("The OpenTig package is incomplete and cannot be installed as a service.");
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
async function findPackageRoot(modulePath) {
|
|
185
|
-
let directory = path.dirname(modulePath);
|
|
186
|
-
for (let depth = 0; depth < 4; depth += 1) {
|
|
187
|
-
try {
|
|
188
|
-
await Promise.all([
|
|
189
|
-
access(path.join(directory, "package.json")),
|
|
190
|
-
access(path.join(directory, "dist", "bin.mjs"))
|
|
191
|
-
]);
|
|
192
|
-
return directory;
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
const parent = path.dirname(directory);
|
|
196
|
-
if (parent === directory) break;
|
|
197
|
-
directory = parent;
|
|
198
|
-
}
|
|
199
|
-
throw new Error("Could not locate the installed OpenTig package.");
|
|
200
|
-
}
|
|
201
|
-
async function installProductionDependencies(directory) {
|
|
202
|
-
const npmCli = process$1.env.npm_execpath;
|
|
203
|
-
if (npmCli) {
|
|
204
|
-
await runRequired(process$1.execPath, [npmCli, "install", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund"], directory);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
await runRequired("npm", ["install", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund"], directory);
|
|
208
|
-
}
|
|
209
|
-
function runRequired(command, args, cwd) {
|
|
210
|
-
return run(command, args, cwd).then((result) => {
|
|
211
|
-
if (result.code !== 0) throw new Error(`${command} failed: ${result.stderr.trim() || result.stdout.trim() || `exit code ${result.code}`}`);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function run(command, args, cwd) {
|
|
215
|
-
return new Promise((resolve, reject) => {
|
|
216
|
-
execFile(command, args, { cwd, timeout: 12e4, windowsHide: true }, (error, stdout, stderr) => {
|
|
217
|
-
const code = typeof error?.code === "number" ? error.code : error ? 1 : 0;
|
|
218
|
-
if (error && error.code === "ENOENT") return reject(new Error(`${command} is required but was not found.`));
|
|
219
|
-
resolve({ code, stdout, stderr });
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
export {
|
|
224
|
-
OPEN_TIG_APP_VERSION as O,
|
|
225
|
-
SERVICE_NAME as S,
|
|
226
|
-
serviceUnitPath as a,
|
|
227
|
-
atomicWrite as b,
|
|
228
|
-
stableVersion as c,
|
|
229
|
-
saveInstallation as d,
|
|
230
|
-
execute as e,
|
|
231
|
-
renderSystemdUnit as f,
|
|
232
|
-
manageCliService as m,
|
|
233
|
-
newerVersion as n,
|
|
234
|
-
packageDirectory as p,
|
|
235
|
-
readInstallation as r,
|
|
236
|
-
systemctl as s
|
|
237
|
-
};
|