@lotics/cli 0.31.0 → 0.33.0

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.
Files changed (45) hide show
  1. package/README.md +27 -0
  2. package/dist/{src/app_commands.js → app_commands.js} +35 -0
  3. package/dist/cli.js +673 -0
  4. package/dist/{src/dev → dev}/wrapper_page.js +33 -5
  5. package/dist/docx.d.ts +2 -0
  6. package/dist/docx.js +341 -0
  7. package/dist/docx.test.d.ts +1 -0
  8. package/dist/docx.test.js +145 -0
  9. package/dist/file_command_io.d.ts +12 -0
  10. package/dist/file_command_io.js +34 -0
  11. package/dist/src/cli.js +46757 -500
  12. package/dist/{src/starter_template.d.ts → starter_template.d.ts} +16 -0
  13. package/dist/{src/starter_template.js → starter_template.js} +25 -2
  14. package/dist/starter_template.test.d.ts +1 -0
  15. package/dist/starter_template.test.js +32 -0
  16. package/dist/xlsx.d.ts +2 -0
  17. package/dist/xlsx.js +489 -0
  18. package/dist/xlsx.test.d.ts +1 -0
  19. package/dist/xlsx.test.js +131 -0
  20. package/package.json +6 -2
  21. /package/dist/{src/app_commands.d.ts → app_commands.d.ts} +0 -0
  22. /package/dist/{src/app_commands.test.d.ts → app_commands.test.d.ts} +0 -0
  23. /package/dist/{src/app_commands.test.js → app_commands.test.js} +0 -0
  24. /package/dist/{src/args.d.ts → args.d.ts} +0 -0
  25. /package/dist/{src/args.js → args.js} +0 -0
  26. /package/dist/{src/args.test.d.ts → args.test.d.ts} +0 -0
  27. /package/dist/{src/args.test.js → args.test.js} +0 -0
  28. /package/dist/{src/cli.d.ts → cli.d.ts} +0 -0
  29. /package/dist/{src/client.d.ts → client.d.ts} +0 -0
  30. /package/dist/{src/client.js → client.js} +0 -0
  31. /package/dist/{src/config.d.ts → config.d.ts} +0 -0
  32. /package/dist/{src/config.js → config.js} +0 -0
  33. /package/dist/{src/config.test.d.ts → config.test.d.ts} +0 -0
  34. /package/dist/{src/config.test.js → config.test.js} +0 -0
  35. /package/dist/{src/dev → dev}/rpc_handler.d.ts +0 -0
  36. /package/dist/{src/dev → dev}/rpc_handler.js +0 -0
  37. /package/dist/{src/dev → dev}/server.d.ts +0 -0
  38. /package/dist/{src/dev → dev}/server.js +0 -0
  39. /package/dist/{src/dev → dev}/wrapper_page.d.ts +0 -0
  40. /package/dist/{src/generate_app_queries_dts.d.ts → generate_app_queries_dts.d.ts} +0 -0
  41. /package/dist/{src/generate_app_queries_dts.js → generate_app_queries_dts.js} +0 -0
  42. /package/dist/{src/generate_app_workflows_dts.d.ts → generate_app_workflows_dts.d.ts} +0 -0
  43. /package/dist/{src/generate_app_workflows_dts.js → generate_app_workflows_dts.js} +0 -0
  44. /package/dist/{src/version.d.ts → version.d.ts} +0 -0
  45. /package/dist/{src/version.js → version.js} +0 -0
package/README.md CHANGED
@@ -101,6 +101,33 @@ lotics download <file_id> -o ./reports/
101
101
  LOTICS_API_KEY=ltk_... lotics run query_tables '{}'
102
102
  ```
103
103
 
104
+ ## Local .xlsx and .docx authoring
105
+
106
+ The CLI bundles Lotics's own xlsx and docx engines so you can read, write, and edit files on your local filesystem without installing `xlsx` / `exceljs` / `docx` from npm. Prefer these over third-party libraries — they round-trip faithfully with the Lotics editor, template engine, and formula engine.
107
+
108
+ ```bash
109
+ # .xlsx
110
+ lotics xlsx read ./report.xlsx # → JSON of sheets, cells, merges
111
+ lotics xlsx write ./out.xlsx '{"sheets":[{"name":"S1","cells":{"A1":"Hi","B1":42}}]}'
112
+ lotics xlsx set-cell ./report.xlsx 'Sheet1!A1' '=SUM(B:B)'
113
+ lotics xlsx add-sheet ./report.xlsx 'Summary'
114
+ lotics xlsx merge ./report.xlsx 'Sheet1!A1:C1'
115
+ lotics xlsx insert-rows ./report.xlsx Sheet1 5 3
116
+ lotics xlsx batch ./report.xlsx '[{"op":"set-cell","sheet":"Sheet1","ref":"A1","value":"Hi"}, {"op":"merge","sheet":"Sheet1","range":"A1:B1"}]'
117
+
118
+ # .docx
119
+ lotics docx read ./report.docx # → JSON of blocks with text + style
120
+ lotics docx write ./out.docx '{"blocks":[{"kind":"paragraph","text":"Title","style":"Heading1"}]}'
121
+ lotics docx append-paragraph ./report.docx 'New paragraph' --style=Heading2
122
+ lotics docx insert-paragraph ./report.docx 'Front matter' --at=0
123
+ lotics docx replace-text ./report.docx '{{name}}' 'Acme Inc.'
124
+ lotics docx batch ./report.docx '[{"op":"append-paragraph","text":"A","style":"Heading1"},{"op":"replace-text","search":"x","replace":"y"}]'
125
+ ```
126
+
127
+ Edits mutate the file in place via an atomic temp-file + rename. Unknown OOXML constructs (tables, SmartArt, custom XML) round-trip verbatim — they show up in `read` as `opaque_block` entries.
128
+
129
+ Run `lotics xlsx` or `lotics docx` with no subcommand for the full list.
130
+
104
131
  ## SDK
105
132
 
106
133
  ```typescript
@@ -19,6 +19,32 @@ import { buildStarterTemplate } from "./starter_template.js";
19
19
  import { startDevServer, openBrowser } from "./dev/server.js";
20
20
  import { generateAppWorkflowsDts } from "./generate_app_workflows_dts.js";
21
21
  import { generateAppQueriesDts } from "./generate_app_queries_dts.js";
22
+ /**
23
+ * Resolve the latest published version of a package from the npm registry.
24
+ * Returns null on any failure (network error, 404, malformed payload) so
25
+ * callers can fall back to a static pin rather than crashing `app create`.
26
+ *
27
+ * 1.5s timeout — npm registry is fast when reachable; the fallback is fine
28
+ * the rare times it isn't, and we don't want to block scaffold on a hang.
29
+ */
30
+ async function fetchLatestNpmVersion(packageName) {
31
+ try {
32
+ const controller = new AbortController();
33
+ const timeout = setTimeout(() => controller.abort(), 1500);
34
+ const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
35
+ signal: controller.signal,
36
+ headers: { accept: "application/json" },
37
+ });
38
+ clearTimeout(timeout);
39
+ if (!response.ok)
40
+ return null;
41
+ const body = (await response.json());
42
+ return typeof body.version === "string" ? body.version : null;
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
22
48
  /** Run `tar` and resolve when it exits cleanly. Throws with stderr on failure. */
23
49
  function runTar(args, cwd) {
24
50
  return new Promise((resolve, reject) => {
@@ -148,11 +174,20 @@ export async function appCreate(client, args) {
148
174
  // Server-side row first — if this fails, no local files have been touched.
149
175
  const app = await client.createApp({ name: args.name });
150
176
  console.error(`Created app: ${app.name} (${app.id})`);
177
+ // Resolve latest versions in parallel; null falls back to the static pin
178
+ // baked into the starter template. Lookups time out at 1.5s so an offline
179
+ // create still succeeds (with the fallback) instead of hanging.
180
+ const [uiLatest, sdkLatest] = await Promise.all([
181
+ fetchLatestNpmVersion("@lotics/ui"),
182
+ fetchLatestNpmVersion("@lotics/app-sdk"),
183
+ ]);
151
184
  // Scaffold the starter into the target directory.
152
185
  const files = buildStarterTemplate({
153
186
  app_name: args.name,
154
187
  app_id: app.id,
155
188
  workspace_id: app.workspace_id,
189
+ ui_version: uiLatest ? `^${uiLatest}` : undefined,
190
+ sdk_version: sdkLatest ? `^${sdkLatest}` : undefined,
156
191
  });
157
192
  for (const file of files) {
158
193
  const fullPath = path.join(targetPath, file.path);