@mog-sdk/cli 0.8.0 → 0.9.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/LICENSE +201 -0
- package/README.md +8 -3
- package/dist/mog.cjs +43 -21
- package/dist/mog.cjs.map +1 -1
- package/package.json +12 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Mog CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line interface for operating Mog workbooks with the headless SDK.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install
|
|
7
|
-
mog
|
|
6
|
+
npm install --prefix "$HOME/.mog/npm" @mog-sdk/cli
|
|
7
|
+
export PATH="$HOME/.mog/npm/node_modules/.bin:$PATH"
|
|
8
|
+
mog --help
|
|
8
9
|
```
|
|
10
|
+
|
|
11
|
+
The `mog` command creates or loads workbook handles in a local daemon, executes
|
|
12
|
+
code against the public `@mog-sdk/sdk` workbook API, commits changes to `.xlsx`,
|
|
13
|
+
and unloads handles when work is complete.
|
package/dist/mog.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var import_promises = require("fs/promises");
|
|
|
35
35
|
var import_node_net = __toESM(require("net"), 1);
|
|
36
36
|
var import_node_path2 = require("path");
|
|
37
37
|
var import_node_url = require("url");
|
|
38
|
-
var import_node = require("@mog-sdk/node");
|
|
38
|
+
var import_node = require("@mog-sdk/sdk/node");
|
|
39
39
|
|
|
40
40
|
// src/protocol.ts
|
|
41
41
|
var import_node_crypto = require("crypto");
|
|
@@ -94,11 +94,19 @@ ${usage()}`);
|
|
|
94
94
|
function stateKeyForCwd(cwd = process.cwd()) {
|
|
95
95
|
return (0, import_node_crypto.createHash)("sha256").update(cwd).digest("hex").slice(0, 20);
|
|
96
96
|
}
|
|
97
|
-
function socketPathForState(stateKey) {
|
|
98
|
-
|
|
97
|
+
function socketPathForState(stateKey, options = {}) {
|
|
98
|
+
const env = options.env ?? process.env;
|
|
99
|
+
if (env.MOG_CLI_SOCKET) return env.MOG_CLI_SOCKET;
|
|
100
|
+
const platform = options.platform ?? process.platform;
|
|
101
|
+
if (platform === "win32") return `\\\\.\\pipe\\mog-${stateKey}`;
|
|
102
|
+
return (0, import_node_path.join)(options.tmpDir ?? (0, import_node_os.tmpdir)(), `mog-${stateKey}.sock`);
|
|
99
103
|
}
|
|
100
|
-
function pidPathForState(stateKey) {
|
|
101
|
-
|
|
104
|
+
function pidPathForState(stateKey, options = {}) {
|
|
105
|
+
const env = options.env ?? process.env;
|
|
106
|
+
return env.MOG_CLI_PID ?? (0, import_node_path.join)(options.tmpDir ?? (0, import_node_os.tmpdir)(), `mog-${stateKey}.pid`);
|
|
107
|
+
}
|
|
108
|
+
function isNamedPipePath(path) {
|
|
109
|
+
return path.startsWith("\\\\.\\pipe\\") || path.startsWith("\\\\?\\pipe\\");
|
|
102
110
|
}
|
|
103
111
|
function toJsonSafe(value) {
|
|
104
112
|
return toJsonSafeInner(value, /* @__PURE__ */ new WeakSet());
|
|
@@ -322,9 +330,16 @@ function sendRequest(stateKey, request) {
|
|
|
322
330
|
async function runDaemon(stateKey) {
|
|
323
331
|
const socketPath = socketPathForState(stateKey);
|
|
324
332
|
const pidPath = pidPathForState(stateKey);
|
|
325
|
-
if ((
|
|
333
|
+
if (!isNamedPipePath(socketPath)) {
|
|
334
|
+
await (0, import_promises.mkdir)((0, import_node_path2.dirname)(socketPath), { recursive: true });
|
|
335
|
+
}
|
|
336
|
+
await (0, import_promises.mkdir)((0, import_node_path2.dirname)(pidPath), { recursive: true });
|
|
337
|
+
if (!isNamedPipePath(socketPath) && (0, import_node_fs.existsSync)(socketPath)) {
|
|
326
338
|
(0, import_node_fs.unlinkSync)(socketPath);
|
|
327
339
|
}
|
|
340
|
+
if ((0, import_node_fs.existsSync)(pidPath)) {
|
|
341
|
+
(0, import_node_fs.unlinkSync)(pidPath);
|
|
342
|
+
}
|
|
328
343
|
const server = import_node_net.default.createServer({ allowHalfOpen: true }, (socket) => {
|
|
329
344
|
let data = "";
|
|
330
345
|
socket.setEncoding("utf8");
|
|
@@ -332,7 +347,7 @@ async function runDaemon(stateKey) {
|
|
|
332
347
|
data += chunk;
|
|
333
348
|
});
|
|
334
349
|
socket.on("end", () => {
|
|
335
|
-
void handleRawRequest(data, server).then((response) => {
|
|
350
|
+
void handleRawRequest(data, server, { socketPath, pidPath }).then((response) => {
|
|
336
351
|
socket.end(JSON.stringify(response));
|
|
337
352
|
});
|
|
338
353
|
});
|
|
@@ -346,12 +361,8 @@ async function runDaemon(stateKey) {
|
|
|
346
361
|
});
|
|
347
362
|
});
|
|
348
363
|
const cleanup = async () => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
workbooks.clear();
|
|
353
|
-
await (0, import_promises.unlink)(socketPath).catch(() => void 0);
|
|
354
|
-
await (0, import_promises.unlink)(pidPath).catch(() => void 0);
|
|
364
|
+
await disposeAllWorkbooks();
|
|
365
|
+
await cleanupStateFiles(socketPath, pidPath);
|
|
355
366
|
};
|
|
356
367
|
process.once("SIGTERM", () => {
|
|
357
368
|
void cleanup().finally(() => process.exit(0));
|
|
@@ -360,10 +371,10 @@ async function runDaemon(stateKey) {
|
|
|
360
371
|
void cleanup().finally(() => process.exit(0));
|
|
361
372
|
});
|
|
362
373
|
}
|
|
363
|
-
async function handleRawRequest(raw, server) {
|
|
374
|
+
async function handleRawRequest(raw, server, stateFiles) {
|
|
364
375
|
try {
|
|
365
376
|
const request = JSON.parse(raw);
|
|
366
|
-
return { ok: true, result: await handleRequest(request, server) };
|
|
377
|
+
return { ok: true, result: await handleRequest(request, server, stateFiles) };
|
|
367
378
|
} catch (error) {
|
|
368
379
|
return {
|
|
369
380
|
ok: false,
|
|
@@ -374,7 +385,7 @@ async function handleRawRequest(raw, server) {
|
|
|
374
385
|
};
|
|
375
386
|
}
|
|
376
387
|
}
|
|
377
|
-
async function handleRequest(request, server) {
|
|
388
|
+
async function handleRequest(request, server, stateFiles) {
|
|
378
389
|
switch (request.method) {
|
|
379
390
|
case "ping":
|
|
380
391
|
return { status: "ok", handles: workbooks.size };
|
|
@@ -441,14 +452,25 @@ ${request.code}`
|
|
|
441
452
|
case "list":
|
|
442
453
|
return [...workbooks.values()].map(describeEntry);
|
|
443
454
|
case "shutdown":
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
server.close();
|
|
455
|
+
await disposeAllWorkbooks();
|
|
456
|
+
server.close(() => {
|
|
457
|
+
void cleanupStateFiles(stateFiles.socketPath, stateFiles.pidPath);
|
|
458
|
+
});
|
|
449
459
|
return { shutdown: true };
|
|
450
460
|
}
|
|
451
461
|
}
|
|
462
|
+
async function disposeAllWorkbooks() {
|
|
463
|
+
for (const entry of workbooks.values()) {
|
|
464
|
+
await Promise.resolve(entry.workbook.dispose());
|
|
465
|
+
}
|
|
466
|
+
workbooks.clear();
|
|
467
|
+
}
|
|
468
|
+
async function cleanupStateFiles(socketPath, pidPath) {
|
|
469
|
+
if (!isNamedPipePath(socketPath)) {
|
|
470
|
+
await (0, import_promises.unlink)(socketPath).catch(() => void 0);
|
|
471
|
+
}
|
|
472
|
+
await (0, import_promises.unlink)(pidPath).catch(() => void 0);
|
|
473
|
+
}
|
|
452
474
|
function requireWorkbook(id) {
|
|
453
475
|
const entry = workbooks.get(id);
|
|
454
476
|
if (!entry) throw new Error(`Unknown workbook id: ${id}`);
|
package/dist/mog.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.58.7_@types+node@25.9.1__jiti@2.7.0_postcss@8.5.15_tsx@4.22.3_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","../src/mog.ts","../src/protocol.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","#!/usr/bin/env node\nimport { spawn } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { mkdir, readFile, stat, unlink } from 'node:fs/promises';\nimport net from 'node:net';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { api, createWorkbook, Utils, type Workbook } from '@mog-sdk/node';\nimport {\n parseCliArgs,\n pidPathForState,\n socketPathForState,\n stateKeyForCwd,\n toJsonSafe,\n usage,\n type DaemonRequest,\n type DaemonResponse,\n} from './protocol';\n\ntype WorkbookEntry = {\n id: string;\n path: string;\n workbook: Workbook;\n loadedAt: string;\n};\n\nconst workbooks = new Map<string, WorkbookEntry>();\n\nasync function main(): Promise<void> {\n const command = parseCliArgs(process.argv.slice(2));\n\n if (command.kind === 'help') {\n console.log(usage());\n return;\n }\n\n if (command.kind === 'daemon') {\n await runDaemon(command.stateKey);\n return;\n }\n\n const stateKey = stateKeyForCwd();\n const request = await commandToRequest(command);\n const response = await sendWithAutoStart(stateKey, request);\n if (!response.ok) {\n console.error(JSON.stringify(response, null, 2));\n process.exitCode = 1;\n return;\n }\n console.log(JSON.stringify(response.result, null, 2));\n}\n\nasync function commandToRequest(\n command: Exclude<ReturnType<typeof parseCliArgs>, { kind: 'help' | 'daemon' }>,\n): Promise<DaemonRequest> {\n switch (command.kind) {\n case 'create':\n return {\n method: 'create',\n path: command.path,\n ...(command.name ? { name: command.name } : {}),\n };\n case 'load':\n return { method: 'load', path: command.path };\n case 'execute': {\n const code = command.codeFile\n ? await readFile(resolve(command.codeFile), 'utf8')\n : command.code;\n if (!code) {\n throw new Error('Usage: mog execute --id <workbookId> --code <code>');\n }\n return { method: 'execute', id: command.id, code };\n }\n case 'commit':\n return {\n method: 'commit',\n id: command.id,\n ...(command.path ? { path: resolve(command.path) } : {}),\n };\n case 'unload':\n return { method: 'unload', id: command.id };\n case 'list':\n return { method: 'list' };\n case 'shutdown':\n return { method: 'shutdown' };\n }\n}\n\nasync function sendWithAutoStart(\n stateKey: string,\n request: DaemonRequest,\n): Promise<DaemonResponse> {\n try {\n return await sendRequest(stateKey, request);\n } catch {\n await startDaemon(stateKey);\n await waitForDaemon(stateKey);\n return sendRequest(stateKey, request);\n }\n}\n\nasync function startDaemon(stateKey: string): Promise<void> {\n const cliPath = fileURLToPath(import.meta.url);\n const child = spawn(process.execPath, [cliPath, '_daemon', stateKey], {\n detached: true,\n stdio: 'ignore',\n env: process.env,\n });\n child.unref();\n}\n\nasync function waitForDaemon(stateKey: string): Promise<void> {\n const started = Date.now();\n let lastError: unknown;\n while (Date.now() - started < 5000) {\n try {\n await sendRequest(stateKey, { method: 'ping' });\n return;\n } catch (error) {\n lastError = error;\n await new Promise((resolveWait) => setTimeout(resolveWait, 100));\n }\n }\n throw new Error(`Mog daemon did not start: ${String(lastError)}`);\n}\n\nfunction sendRequest(stateKey: string, request: DaemonRequest): Promise<DaemonResponse> {\n const socketPath = socketPathForState(stateKey);\n return new Promise((resolveRequest, rejectRequest) => {\n const client = net.createConnection(socketPath);\n let data = '';\n client.setEncoding('utf8');\n client.setTimeout(5000);\n client.on('connect', () => {\n client.end(JSON.stringify(request));\n });\n client.on('data', (chunk) => {\n data += chunk;\n });\n client.on('end', () => {\n try {\n resolveRequest(JSON.parse(data) as DaemonResponse);\n } catch (error) {\n rejectRequest(error);\n }\n });\n client.on('timeout', () => {\n client.destroy(new Error('Timed out waiting for Mog daemon response.'));\n });\n client.on('error', rejectRequest);\n });\n}\n\nasync function runDaemon(stateKey: string): Promise<void> {\n const socketPath = socketPathForState(stateKey);\n const pidPath = pidPathForState(stateKey);\n if (existsSync(socketPath)) {\n unlinkSync(socketPath);\n }\n\n const server = net.createServer({ allowHalfOpen: true }, (socket) => {\n let data = '';\n socket.setEncoding('utf8');\n socket.on('data', (chunk) => {\n data += chunk;\n });\n socket.on('end', () => {\n void handleRawRequest(data, server).then((response) => {\n socket.end(JSON.stringify(response));\n });\n });\n });\n\n await new Promise<void>((resolveListen, rejectListen) => {\n server.once('error', rejectListen);\n server.listen(socketPath, () => {\n server.off('error', rejectListen);\n writeFileSync(pidPath, String(process.pid));\n resolveListen();\n });\n });\n\n const cleanup = async () => {\n for (const entry of workbooks.values()) {\n await Promise.resolve(entry.workbook.dispose());\n }\n workbooks.clear();\n await unlink(socketPath).catch(() => undefined);\n await unlink(pidPath).catch(() => undefined);\n };\n\n process.once('SIGTERM', () => {\n void cleanup().finally(() => process.exit(0));\n });\n process.once('SIGINT', () => {\n void cleanup().finally(() => process.exit(0));\n });\n}\n\nasync function handleRawRequest(raw: string, server: net.Server): Promise<DaemonResponse> {\n try {\n const request = JSON.parse(raw) as DaemonRequest;\n return { ok: true, result: await handleRequest(request, server) };\n } catch (error) {\n return {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n };\n }\n}\n\nasync function handleRequest(request: DaemonRequest, server: net.Server): Promise<unknown> {\n switch (request.method) {\n case 'ping':\n return { status: 'ok', handles: workbooks.size };\n case 'create': {\n if (existsSync(request.path)) {\n throw new Error(`Workbook already exists: ${request.path}`);\n }\n await mkdir(dirname(request.path), { recursive: true });\n const workbook = request.name\n ? await createWorkbook({ documentId: request.name })\n : await createWorkbook();\n await workbook.save(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'load': {\n await stat(request.path);\n const workbook = await createWorkbook(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'execute': {\n const entry = requireWorkbook(request.id);\n const logs: string[] = [];\n const scopedConsole = makeScopedConsole(logs);\n const AsyncFunction = Object.getPrototypeOf(async function () {\n // TypeScript target helper.\n }).constructor as new (...args: string[]) => (...args: unknown[]) => Promise<unknown>;\n const fn = new AsyncFunction(\n 'wb',\n 'workbook',\n 'ws',\n 'activeSheet',\n 'api',\n 'Utils',\n 'console',\n `\"use strict\";\\n${request.code}`,\n );\n const result = await fn(\n entry.workbook,\n entry.workbook,\n entry.workbook.activeSheet,\n entry.workbook.activeSheet,\n api,\n Utils,\n scopedConsole,\n );\n return { result: toJsonSafe(result), logs };\n }\n case 'commit': {\n const entry = requireWorkbook(request.id);\n const path = request.path ?? entry.path;\n const bytes = await entry.workbook.save(path);\n return { id: entry.id, path, bytes: bytes.byteLength };\n }\n case 'unload': {\n const entry = requireWorkbook(request.id);\n await Promise.resolve(entry.workbook.dispose());\n workbooks.delete(entry.id);\n return { id: entry.id, unloaded: true };\n }\n case 'list':\n return [...workbooks.values()].map(describeEntry);\n case 'shutdown':\n for (const entry of workbooks.values()) {\n await Promise.resolve(entry.workbook.dispose());\n }\n workbooks.clear();\n server.close();\n return { shutdown: true };\n }\n}\n\nfunction requireWorkbook(id: string): WorkbookEntry {\n const entry = workbooks.get(id);\n if (!entry) throw new Error(`Unknown workbook id: ${id}`);\n return entry;\n}\n\nfunction describeEntry(entry: WorkbookEntry): object {\n return {\n id: entry.id,\n path: entry.path,\n loadedAt: entry.loadedAt,\n };\n}\n\nfunction makeScopedConsole(logs: string[]): Pick<Console, 'log' | 'warn' | 'error' | 'info'> {\n const push = (level: string, args: unknown[]) => {\n logs.push(`[${level}] ${args.map(formatLogArg).join(' ')}`);\n };\n return {\n log: (...args: unknown[]) => push('log', args),\n info: (...args: unknown[]) => push('info', args),\n warn: (...args: unknown[]) => push('warn', args),\n error: (...args: unknown[]) => push('error', args),\n };\n}\n\nfunction formatLogArg(arg: unknown): string {\n if (typeof arg === 'string') return arg;\n try {\n return JSON.stringify(toJsonSafe(arg));\n } catch {\n return String(arg);\n }\n}\n\nmain().catch((error) => {\n console.error(\n JSON.stringify(\n {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n },\n null,\n 2,\n ),\n );\n process.exitCode = 1;\n});\n","import { createHash } from 'node:crypto';\nimport { tmpdir } from 'node:os';\nimport { basename, join, resolve } from 'node:path';\n\nexport type CliCommand =\n | { kind: 'help' }\n | { kind: 'daemon'; stateKey: string }\n | { kind: 'create'; path: string; name?: string }\n | { kind: 'load'; path: string }\n | { kind: 'execute'; id: string; code?: string; codeFile?: string }\n | { kind: 'commit'; id: string; path?: string }\n | { kind: 'unload'; id: string }\n | { kind: 'list' }\n | { kind: 'shutdown' };\n\nexport type DaemonRequest =\n | { method: 'ping' }\n | { method: 'create'; path: string; name?: string }\n | { method: 'load'; path: string }\n | { method: 'execute'; id: string; code: string }\n | { method: 'commit'; id: string; path?: string }\n | { method: 'unload'; id: string }\n | { method: 'list' }\n | { method: 'shutdown' };\n\nexport type DaemonResponse =\n | { ok: true; result: unknown }\n | { ok: false; error: { message: string; stack?: string } };\n\nexport function parseCliArgs(argv: readonly string[]): CliCommand {\n const [command, ...rest] = argv;\n\n switch (command) {\n case undefined:\n case '-h':\n case '--help':\n case 'help':\n return { kind: 'help' };\n case '_daemon': {\n const stateKey = rest[0];\n if (!stateKey) throw new Error('Internal error: _daemon requires a state key.');\n return { kind: 'daemon', stateKey };\n }\n case 'create': {\n return parseCreateCommand(rest);\n }\n case 'load': {\n const path = rest[0];\n if (!path) throw new Error('Usage: mog load <path>');\n return { kind: 'load', path: resolve(path) };\n }\n case 'execute': {\n return {\n kind: 'execute',\n id: requiredOption(rest, '--id', 'Usage: mog execute --id <workbookId> --code <code>'),\n code: optionalOption(rest, '--code'),\n codeFile: optionalOption(rest, '--code-file'),\n };\n }\n case 'commit':\n return {\n kind: 'commit',\n id: requiredOption(rest, '--id', 'Usage: mog commit --id <workbookId> [--path <path>]'),\n path: optionalOption(rest, '--path'),\n };\n case 'unload':\n return {\n kind: 'unload',\n id: requiredOption(rest, '--id', 'Usage: mog unload --id <workbookId>'),\n };\n case 'list':\n return { kind: 'list' };\n case 'shutdown':\n return { kind: 'shutdown' };\n default:\n throw new Error(`Unknown command: ${command}\\n\\n${usage()}`);\n }\n}\n\nexport function stateKeyForCwd(cwd = process.cwd()): string {\n return createHash('sha256').update(cwd).digest('hex').slice(0, 20);\n}\n\nexport function socketPathForState(stateKey: string): string {\n return process.env.MOG_CLI_SOCKET ?? join(tmpdir(), `mog-${stateKey}.sock`);\n}\n\nexport function pidPathForState(stateKey: string): string {\n return process.env.MOG_CLI_PID ?? join(tmpdir(), `mog-${stateKey}.pid`);\n}\n\nexport function toJsonSafe(value: unknown): unknown {\n return toJsonSafeInner(value, new WeakSet<object>());\n}\n\nexport function usage(): string {\n return [\n 'Usage:',\n ' mog create <path>',\n ' mog create --name <workbookName> --path <directory>',\n ' mog load <path>',\n ' mog execute --id <workbookId> --code <code>',\n ' mog execute --id <workbookId> --code-file <path>',\n ' mog commit --id <workbookId> [--path <path>]',\n ' mog unload --id <workbookId>',\n ' mog list',\n '',\n 'Execute code runs inside the Mog daemon with these bindings:',\n ' wb, workbook, ws, activeSheet, api, Utils, console',\n '',\n 'Example:',\n ' mog execute --id abc --code \"await ws.setCell(\\\\\"A1\\\\\", 42); return ws.getValue(\\\\\"A1\\\\\");\"',\n ].join('\\n');\n}\n\nfunction parseCreateCommand(args: readonly string[]): Extract<CliCommand, { kind: 'create' }> {\n const directPath = args[0] && !args[0].startsWith('--') ? args[0] : undefined;\n const name = optionalOption(args, '--name');\n const directory = optionalOption(args, '--path');\n\n if (directPath) {\n if (name || directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n return {\n kind: 'create',\n path: resolve(directPath),\n name: workbookNameFromPath(directPath),\n };\n }\n\n if (!name || !directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n\n return {\n kind: 'create',\n path: resolve(directory, workbookFileName(name)),\n name: workbookNameFromPath(name),\n };\n}\n\nfunction requiredOption(args: readonly string[], name: string, errorMessage: string): string {\n const value = optionalOption(args, name);\n if (!value) throw new Error(errorMessage);\n return value;\n}\n\nfunction optionalOption(args: readonly string[], name: string): string | undefined {\n const index = args.indexOf(name);\n if (index === -1) return undefined;\n const value = args[index + 1];\n if (!value || value.startsWith('--')) {\n throw new Error(`Missing value for ${name}`);\n }\n return value;\n}\n\nfunction workbookFileName(name: string): string {\n const trimmed = name.trim();\n if (!trimmed) throw new Error('Workbook name must not be empty.');\n if (trimmed.includes('/') || trimmed.includes('\\\\')) {\n throw new Error('Workbook name must not contain path separators.');\n }\n return trimmed.toLowerCase().endsWith('.xlsx') ? trimmed : `${trimmed}.xlsx`;\n}\n\nfunction workbookNameFromPath(path: string): string {\n return basename(path).replace(/\\.xlsx$/i, '');\n}\n\nfunction toJsonSafeInner(value: unknown, seen: WeakSet<object>): unknown {\n if (value == null) return value;\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'bigint') return value.toString();\n if (typeof value === 'function') {\n return `[Function ${(value as { name?: string }).name || 'anonymous'}]`;\n }\n if (value instanceof Date) return value.toISOString();\n if (value instanceof Uint8Array) {\n return {\n type: 'Uint8Array',\n length: value.byteLength,\n base64: Buffer.from(value).toString('base64'),\n };\n }\n if (Array.isArray(value)) return value.map((entry) => toJsonSafeInner(entry, seen));\n if (value instanceof Map) {\n return Object.fromEntries(\n [...value.entries()].map(([key, entry]) => [String(key), toJsonSafeInner(entry, seen)]),\n );\n }\n if (value instanceof Set) return [...value].map((entry) => toJsonSafeInner(entry, seen));\n if (typeof value === 'object') {\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, toJsonSafeInner(entry, seen)]),\n );\n }\n return String(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACX9D,gCAAsB;AACtB,IAAAA,sBAA2B;AAC3B,qBAAsD;AACtD,sBAA8C;AAC9C,sBAAgB;AAChB,IAAAC,oBAAiC;AACjC,sBAA8B;AAC9B,kBAA0D;;;ACR1D,yBAA2B;AAC3B,qBAAuB;AACvB,uBAAwC;AA2BjC,SAAS,aAAa,MAAqC;AAChE,QAAM,CAAC,SAAS,GAAG,IAAI,IAAI;AAE3B,UAAQ,SAAS;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,MAAM,OAAO;AAAA,IACxB,KAAK,WAAW;AACd,YAAM,WAAW,KAAK,CAAC;AACvB,UAAI,CAAC,SAAU,OAAM,IAAI,MAAM,+CAA+C;AAC9E,aAAO,EAAE,MAAM,UAAU,SAAS;AAAA,IACpC;AAAA,IACA,KAAK,UAAU;AACb,aAAO,mBAAmB,IAAI;AAAA,IAChC;AAAA,IACA,KAAK,QAAQ;AACX,YAAM,OAAO,KAAK,CAAC;AACnB,UAAI,CAAC,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,YAAY,EAAE,KAAK,GAAG,CAAC,EAAE;AAAA,EAC5D;AACA,SAAO;AAAA,IACL,KAAK,IAAI,SAAoB,KAAK,OAAO,IAAI;AAAA,IAC7C,MAAM,IAAI,SAAoB,KAAK,QAAQ,IAAI;AAAA,IAC/C,MAAM,IAAI,SAAoB,KAAK,QAAQ,IAAI;AAAA,IAC/C,OAAO,IAAI,SAAoB,KAAK,SAAS,IAAI;AAAA,EACnD;AACF;AAEA,SAAS,aAAa,KAAsB;AAC1C,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,MAAI;AACF,WAAO,KAAK,UAAU,WAAW,GAAG,CAAC;AAAA,EACvC,QAAQ;AACN,WAAO,OAAO,GAAG;AAAA,EACnB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ;AAAA,IACN,KAAK;AAAA,MACH;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,UACL,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAC9D,GAAI,iBAAiB,SAAS,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,QACxE;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,UAAQ,WAAW;AACrB,CAAC;","names":["import_node_crypto","import_node_path","net"]}
|
|
1
|
+
{"version":3,"sources":["../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.58.7_@types+node@25.9.1__jiti@2.7.0_postcss@8.5.15_tsx@4.22.3_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","../src/mog.ts","../src/protocol.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","#!/usr/bin/env node\nimport { spawn } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { mkdir, readFile, stat, unlink } from 'node:fs/promises';\nimport net from 'node:net';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { api, createWorkbook, Utils, type Workbook } from '@mog-sdk/sdk/node';\nimport {\n isNamedPipePath,\n parseCliArgs,\n pidPathForState,\n socketPathForState,\n stateKeyForCwd,\n toJsonSafe,\n usage,\n type DaemonRequest,\n type DaemonResponse,\n} from './protocol';\n\ntype WorkbookEntry = {\n id: string;\n path: string;\n workbook: Workbook;\n loadedAt: string;\n};\n\nconst workbooks = new Map<string, WorkbookEntry>();\n\nasync function main(): Promise<void> {\n const command = parseCliArgs(process.argv.slice(2));\n\n if (command.kind === 'help') {\n console.log(usage());\n return;\n }\n\n if (command.kind === 'daemon') {\n await runDaemon(command.stateKey);\n return;\n }\n\n const stateKey = stateKeyForCwd();\n const request = await commandToRequest(command);\n const response = await sendWithAutoStart(stateKey, request);\n if (!response.ok) {\n console.error(JSON.stringify(response, null, 2));\n process.exitCode = 1;\n return;\n }\n console.log(JSON.stringify(response.result, null, 2));\n}\n\nasync function commandToRequest(\n command: Exclude<ReturnType<typeof parseCliArgs>, { kind: 'help' | 'daemon' }>,\n): Promise<DaemonRequest> {\n switch (command.kind) {\n case 'create':\n return {\n method: 'create',\n path: command.path,\n ...(command.name ? { name: command.name } : {}),\n };\n case 'load':\n return { method: 'load', path: command.path };\n case 'execute': {\n const code = command.codeFile\n ? await readFile(resolve(command.codeFile), 'utf8')\n : command.code;\n if (!code) {\n throw new Error('Usage: mog execute --id <workbookId> --code <code>');\n }\n return { method: 'execute', id: command.id, code };\n }\n case 'commit':\n return {\n method: 'commit',\n id: command.id,\n ...(command.path ? { path: resolve(command.path) } : {}),\n };\n case 'unload':\n return { method: 'unload', id: command.id };\n case 'list':\n return { method: 'list' };\n case 'shutdown':\n return { method: 'shutdown' };\n }\n}\n\nasync function sendWithAutoStart(\n stateKey: string,\n request: DaemonRequest,\n): Promise<DaemonResponse> {\n try {\n return await sendRequest(stateKey, request);\n } catch {\n await startDaemon(stateKey);\n await waitForDaemon(stateKey);\n return sendRequest(stateKey, request);\n }\n}\n\nasync function startDaemon(stateKey: string): Promise<void> {\n const cliPath = fileURLToPath(import.meta.url);\n const child = spawn(process.execPath, [cliPath, '_daemon', stateKey], {\n detached: true,\n stdio: 'ignore',\n env: process.env,\n });\n child.unref();\n}\n\nasync function waitForDaemon(stateKey: string): Promise<void> {\n const started = Date.now();\n let lastError: unknown;\n while (Date.now() - started < 5000) {\n try {\n await sendRequest(stateKey, { method: 'ping' });\n return;\n } catch (error) {\n lastError = error;\n await new Promise((resolveWait) => setTimeout(resolveWait, 100));\n }\n }\n throw new Error(`Mog daemon did not start: ${String(lastError)}`);\n}\n\nfunction sendRequest(stateKey: string, request: DaemonRequest): Promise<DaemonResponse> {\n const socketPath = socketPathForState(stateKey);\n return new Promise((resolveRequest, rejectRequest) => {\n const client = net.createConnection(socketPath);\n let data = '';\n client.setEncoding('utf8');\n client.setTimeout(5000);\n client.on('connect', () => {\n client.end(JSON.stringify(request));\n });\n client.on('data', (chunk) => {\n data += chunk;\n });\n client.on('end', () => {\n try {\n resolveRequest(JSON.parse(data) as DaemonResponse);\n } catch (error) {\n rejectRequest(error);\n }\n });\n client.on('timeout', () => {\n client.destroy(new Error('Timed out waiting for Mog daemon response.'));\n });\n client.on('error', rejectRequest);\n });\n}\n\nasync function runDaemon(stateKey: string): Promise<void> {\n const socketPath = socketPathForState(stateKey);\n const pidPath = pidPathForState(stateKey);\n if (!isNamedPipePath(socketPath)) {\n await mkdir(dirname(socketPath), { recursive: true });\n }\n await mkdir(dirname(pidPath), { recursive: true });\n\n if (!isNamedPipePath(socketPath) && existsSync(socketPath)) {\n unlinkSync(socketPath);\n }\n if (existsSync(pidPath)) {\n unlinkSync(pidPath);\n }\n\n const server = net.createServer({ allowHalfOpen: true }, (socket) => {\n let data = '';\n socket.setEncoding('utf8');\n socket.on('data', (chunk) => {\n data += chunk;\n });\n socket.on('end', () => {\n void handleRawRequest(data, server, { socketPath, pidPath }).then((response) => {\n socket.end(JSON.stringify(response));\n });\n });\n });\n\n await new Promise<void>((resolveListen, rejectListen) => {\n server.once('error', rejectListen);\n server.listen(socketPath, () => {\n server.off('error', rejectListen);\n writeFileSync(pidPath, String(process.pid));\n resolveListen();\n });\n });\n\n const cleanup = async () => {\n await disposeAllWorkbooks();\n await cleanupStateFiles(socketPath, pidPath);\n };\n\n process.once('SIGTERM', () => {\n void cleanup().finally(() => process.exit(0));\n });\n process.once('SIGINT', () => {\n void cleanup().finally(() => process.exit(0));\n });\n}\n\nasync function handleRawRequest(\n raw: string,\n server: net.Server,\n stateFiles: { socketPath: string; pidPath: string },\n): Promise<DaemonResponse> {\n try {\n const request = JSON.parse(raw) as DaemonRequest;\n return { ok: true, result: await handleRequest(request, server, stateFiles) };\n } catch (error) {\n return {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n };\n }\n}\n\nasync function handleRequest(\n request: DaemonRequest,\n server: net.Server,\n stateFiles: { socketPath: string; pidPath: string },\n): Promise<unknown> {\n switch (request.method) {\n case 'ping':\n return { status: 'ok', handles: workbooks.size };\n case 'create': {\n if (existsSync(request.path)) {\n throw new Error(`Workbook already exists: ${request.path}`);\n }\n await mkdir(dirname(request.path), { recursive: true });\n const workbook = request.name\n ? await createWorkbook({ documentId: request.name })\n : await createWorkbook();\n await workbook.save(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'load': {\n await stat(request.path);\n const workbook = await createWorkbook(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'execute': {\n const entry = requireWorkbook(request.id);\n const logs: string[] = [];\n const scopedConsole = makeScopedConsole(logs);\n const AsyncFunction = Object.getPrototypeOf(async function () {\n // TypeScript target helper.\n }).constructor as new (...args: string[]) => (...args: unknown[]) => Promise<unknown>;\n const fn = new AsyncFunction(\n 'wb',\n 'workbook',\n 'ws',\n 'activeSheet',\n 'api',\n 'Utils',\n 'console',\n `\"use strict\";\\n${request.code}`,\n );\n const result = await fn(\n entry.workbook,\n entry.workbook,\n entry.workbook.activeSheet,\n entry.workbook.activeSheet,\n api,\n Utils,\n scopedConsole,\n );\n return { result: toJsonSafe(result), logs };\n }\n case 'commit': {\n const entry = requireWorkbook(request.id);\n const path = request.path ?? entry.path;\n const bytes = await entry.workbook.save(path);\n return { id: entry.id, path, bytes: bytes.byteLength };\n }\n case 'unload': {\n const entry = requireWorkbook(request.id);\n await Promise.resolve(entry.workbook.dispose());\n workbooks.delete(entry.id);\n return { id: entry.id, unloaded: true };\n }\n case 'list':\n return [...workbooks.values()].map(describeEntry);\n case 'shutdown':\n await disposeAllWorkbooks();\n server.close(() => {\n void cleanupStateFiles(stateFiles.socketPath, stateFiles.pidPath);\n });\n return { shutdown: true };\n }\n}\n\nasync function disposeAllWorkbooks(): Promise<void> {\n for (const entry of workbooks.values()) {\n await Promise.resolve(entry.workbook.dispose());\n }\n workbooks.clear();\n}\n\nasync function cleanupStateFiles(socketPath: string, pidPath: string): Promise<void> {\n if (!isNamedPipePath(socketPath)) {\n await unlink(socketPath).catch(() => undefined);\n }\n await unlink(pidPath).catch(() => undefined);\n}\n\nfunction requireWorkbook(id: string): WorkbookEntry {\n const entry = workbooks.get(id);\n if (!entry) throw new Error(`Unknown workbook id: ${id}`);\n return entry;\n}\n\nfunction describeEntry(entry: WorkbookEntry): object {\n return {\n id: entry.id,\n path: entry.path,\n loadedAt: entry.loadedAt,\n };\n}\n\nfunction makeScopedConsole(logs: string[]): Pick<Console, 'log' | 'warn' | 'error' | 'info'> {\n const push = (level: string, args: unknown[]) => {\n logs.push(`[${level}] ${args.map(formatLogArg).join(' ')}`);\n };\n return {\n log: (...args: unknown[]) => push('log', args),\n info: (...args: unknown[]) => push('info', args),\n warn: (...args: unknown[]) => push('warn', args),\n error: (...args: unknown[]) => push('error', args),\n };\n}\n\nfunction formatLogArg(arg: unknown): string {\n if (typeof arg === 'string') return arg;\n try {\n return JSON.stringify(toJsonSafe(arg));\n } catch {\n return String(arg);\n }\n}\n\nmain().catch((error) => {\n console.error(\n JSON.stringify(\n {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n },\n null,\n 2,\n ),\n );\n process.exitCode = 1;\n});\n","import { createHash } from 'node:crypto';\nimport { tmpdir } from 'node:os';\nimport { basename, join, resolve } from 'node:path';\n\nexport type CliCommand =\n | { kind: 'help' }\n | { kind: 'daemon'; stateKey: string }\n | { kind: 'create'; path: string; name?: string }\n | { kind: 'load'; path: string }\n | { kind: 'execute'; id: string; code?: string; codeFile?: string }\n | { kind: 'commit'; id: string; path?: string }\n | { kind: 'unload'; id: string }\n | { kind: 'list' }\n | { kind: 'shutdown' };\n\nexport type DaemonRequest =\n | { method: 'ping' }\n | { method: 'create'; path: string; name?: string }\n | { method: 'load'; path: string }\n | { method: 'execute'; id: string; code: string }\n | { method: 'commit'; id: string; path?: string }\n | { method: 'unload'; id: string }\n | { method: 'list' }\n | { method: 'shutdown' };\n\nexport type DaemonResponse =\n | { ok: true; result: unknown }\n | { ok: false; error: { message: string; stack?: string } };\n\nexport function parseCliArgs(argv: readonly string[]): CliCommand {\n const [command, ...rest] = argv;\n\n switch (command) {\n case undefined:\n case '-h':\n case '--help':\n case 'help':\n return { kind: 'help' };\n case '_daemon': {\n const stateKey = rest[0];\n if (!stateKey) throw new Error('Internal error: _daemon requires a state key.');\n return { kind: 'daemon', stateKey };\n }\n case 'create': {\n return parseCreateCommand(rest);\n }\n case 'load': {\n const path = rest[0];\n if (!path) throw new Error('Usage: mog load <path>');\n return { kind: 'load', path: resolve(path) };\n }\n case 'execute': {\n return {\n kind: 'execute',\n id: requiredOption(rest, '--id', 'Usage: mog execute --id <workbookId> --code <code>'),\n code: optionalOption(rest, '--code'),\n codeFile: optionalOption(rest, '--code-file'),\n };\n }\n case 'commit':\n return {\n kind: 'commit',\n id: requiredOption(rest, '--id', 'Usage: mog commit --id <workbookId> [--path <path>]'),\n path: optionalOption(rest, '--path'),\n };\n case 'unload':\n return {\n kind: 'unload',\n id: requiredOption(rest, '--id', 'Usage: mog unload --id <workbookId>'),\n };\n case 'list':\n return { kind: 'list' };\n case 'shutdown':\n return { kind: 'shutdown' };\n default:\n throw new Error(`Unknown command: ${command}\\n\\n${usage()}`);\n }\n}\n\nexport function stateKeyForCwd(cwd = process.cwd()): string {\n return createHash('sha256').update(cwd).digest('hex').slice(0, 20);\n}\n\nexport type DaemonStatePathOptions = {\n env?: Partial<Pick<NodeJS.ProcessEnv, 'MOG_CLI_SOCKET' | 'MOG_CLI_PID'>>;\n platform?: NodeJS.Platform;\n tmpDir?: string;\n};\n\nexport function socketPathForState(stateKey: string, options: DaemonStatePathOptions = {}): string {\n const env = options.env ?? process.env;\n if (env.MOG_CLI_SOCKET) return env.MOG_CLI_SOCKET;\n\n const platform = options.platform ?? process.platform;\n if (platform === 'win32') return `\\\\\\\\.\\\\pipe\\\\mog-${stateKey}`;\n\n return join(options.tmpDir ?? tmpdir(), `mog-${stateKey}.sock`);\n}\n\nexport function pidPathForState(stateKey: string, options: DaemonStatePathOptions = {}): string {\n const env = options.env ?? process.env;\n return env.MOG_CLI_PID ?? join(options.tmpDir ?? tmpdir(), `mog-${stateKey}.pid`);\n}\n\nexport function isNamedPipePath(path: string): boolean {\n return path.startsWith('\\\\\\\\.\\\\pipe\\\\') || path.startsWith('\\\\\\\\?\\\\pipe\\\\');\n}\n\nexport function toJsonSafe(value: unknown): unknown {\n return toJsonSafeInner(value, new WeakSet<object>());\n}\n\nexport function usage(): string {\n return [\n 'Usage:',\n ' mog create <path>',\n ' mog create --name <workbookName> --path <directory>',\n ' mog load <path>',\n ' mog execute --id <workbookId> --code <code>',\n ' mog execute --id <workbookId> --code-file <path>',\n ' mog commit --id <workbookId> [--path <path>]',\n ' mog unload --id <workbookId>',\n ' mog list',\n '',\n 'Execute code runs inside the Mog daemon with these bindings:',\n ' wb, workbook, ws, activeSheet, api, Utils, console',\n '',\n 'Example:',\n ' mog execute --id abc --code \"await ws.setCell(\\\\\"A1\\\\\", 42); return ws.getValue(\\\\\"A1\\\\\");\"',\n ].join('\\n');\n}\n\nfunction parseCreateCommand(args: readonly string[]): Extract<CliCommand, { kind: 'create' }> {\n const directPath = args[0] && !args[0].startsWith('--') ? args[0] : undefined;\n const name = optionalOption(args, '--name');\n const directory = optionalOption(args, '--path');\n\n if (directPath) {\n if (name || directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n return {\n kind: 'create',\n path: resolve(directPath),\n name: workbookNameFromPath(directPath),\n };\n }\n\n if (!name || !directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n\n return {\n kind: 'create',\n path: resolve(directory, workbookFileName(name)),\n name: workbookNameFromPath(name),\n };\n}\n\nfunction requiredOption(args: readonly string[], name: string, errorMessage: string): string {\n const value = optionalOption(args, name);\n if (!value) throw new Error(errorMessage);\n return value;\n}\n\nfunction optionalOption(args: readonly string[], name: string): string | undefined {\n const index = args.indexOf(name);\n if (index === -1) return undefined;\n const value = args[index + 1];\n if (!value || value.startsWith('--')) {\n throw new Error(`Missing value for ${name}`);\n }\n return value;\n}\n\nfunction workbookFileName(name: string): string {\n const trimmed = name.trim();\n if (!trimmed) throw new Error('Workbook name must not be empty.');\n if (trimmed.includes('/') || trimmed.includes('\\\\')) {\n throw new Error('Workbook name must not contain path separators.');\n }\n return trimmed.toLowerCase().endsWith('.xlsx') ? trimmed : `${trimmed}.xlsx`;\n}\n\nfunction workbookNameFromPath(path: string): string {\n return basename(path).replace(/\\.xlsx$/i, '');\n}\n\nfunction toJsonSafeInner(value: unknown, seen: WeakSet<object>): unknown {\n if (value == null) return value;\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'bigint') return value.toString();\n if (typeof value === 'function') {\n return `[Function ${(value as { name?: string }).name || 'anonymous'}]`;\n }\n if (value instanceof Date) return value.toISOString();\n if (value instanceof Uint8Array) {\n return {\n type: 'Uint8Array',\n length: value.byteLength,\n base64: Buffer.from(value).toString('base64'),\n };\n }\n if (Array.isArray(value)) return value.map((entry) => toJsonSafeInner(entry, seen));\n if (value instanceof Map) {\n return Object.fromEntries(\n [...value.entries()].map(([key, entry]) => [String(key), toJsonSafeInner(entry, seen)]),\n );\n }\n if (value instanceof Set) return [...value].map((entry) => toJsonSafeInner(entry, seen));\n if (typeof value === 'object') {\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, toJsonSafeInner(entry, seen)]),\n );\n }\n return String(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACX9D,gCAAsB;AACtB,IAAAA,sBAA2B;AAC3B,qBAAsD;AACtD,sBAA8C;AAC9C,sBAAgB;AAChB,IAAAC,oBAAiC;AACjC,sBAA8B;AAC9B,kBAA0D;;;ACR1D,yBAA2B;AAC3B,qBAAuB;AACvB,uBAAwC;AA2BjC,SAAS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Y,EAAE,KAAK,GAAG,CAAC,EAAE;AAAA,EAC5D;AACA,SAAO;AAAA,IACL,KAAK,IAAI,SAAoB,KAAK,OAAO,IAAI;AAAA,IAC7C,MAAM,IAAI,SAAoB,KAAK,QAAQ,IAAI;AAAA,IAC/C,MAAM,IAAI,SAAoB,KAAK,QAAQ,IAAI;AAAA,IAC/C,OAAO,IAAI,SAAoB,KAAK,SAAS,IAAI;AAAA,EACnD;AACF;AAEA,SAAS,aAAa,KAAsB;AAC1C,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,MAAI;AACF,WAAO,KAAK,UAAU,WAAW,GAAG,CAAC;AAAA,EACvC,QAAQ;AACN,WAAO,OAAO,GAAG;AAAA,EACnB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ;AAAA,IACN,KAAK;AAAA,MACH;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,UACL,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,UAC9D,GAAI,iBAAiB,SAAS,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,QACxE;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,UAAQ,WAAW;AACrB,CAAC;","names":["import_node_crypto","import_node_path","net"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mog-sdk/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "
|
|
3
|
+
"version": "0.9.2",
|
|
4
|
+
"description": "Command-line interface for operating Mog workbooks with the headless SDK",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"bin": {
|
|
8
8
|
"mog": "./dist/mog.cjs"
|
|
@@ -22,7 +22,14 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"spreadsheet",
|
|
27
|
+
"excel",
|
|
28
|
+
"xlsx",
|
|
29
|
+
"cli",
|
|
30
|
+
"mog"
|
|
31
|
+
],
|
|
25
32
|
"dependencies": {
|
|
26
|
-
"@mog-sdk/
|
|
33
|
+
"@mog-sdk/sdk": "0.9.2"
|
|
27
34
|
}
|
|
28
|
-
}
|
|
35
|
+
}
|