@motionskit/cli 0.2.5 → 0.2.7
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/index.js +51 -12
- package/dist/main.js +213 -42
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,8 +5,13 @@ import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, relative
|
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import {
|
|
7
7
|
BUILTIN_SOURCE_OPS,
|
|
8
|
+
bundleUploadProblem as bundleUploadProblem2,
|
|
8
9
|
CRM_WRITES,
|
|
9
10
|
crmProblems,
|
|
11
|
+
fileUploadProblems as fileUploadProblems2,
|
|
12
|
+
isValidTimeZone,
|
|
13
|
+
manifestUploadProblem as manifestUploadProblem2,
|
|
14
|
+
optionReasonProblems,
|
|
10
15
|
rulesVersion,
|
|
11
16
|
STEP_BUILD,
|
|
12
17
|
STEP_ENTRY_FILE,
|
|
@@ -219,7 +224,14 @@ function parseMotion(raw) {
|
|
|
219
224
|
import { createHash } from "crypto";
|
|
220
225
|
import { existsSync as existsSync2, mkdirSync, readdirSync as readdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
221
226
|
import { dirname, isAbsolute, join as join3, relative, resolve, sep } from "path";
|
|
222
|
-
import {
|
|
227
|
+
import {
|
|
228
|
+
bundleUploadProblem,
|
|
229
|
+
fileUploadProblems,
|
|
230
|
+
manifestUploadProblem,
|
|
231
|
+
parseDuration as parseDuration2,
|
|
232
|
+
validateSourceManifest,
|
|
233
|
+
versionId
|
|
234
|
+
} from "@motionskit/kernel";
|
|
223
235
|
import { build } from "esbuild";
|
|
224
236
|
import YAML from "yaml";
|
|
225
237
|
import { z as z2 } from "zod";
|
|
@@ -400,8 +412,6 @@ export default serveSource(def);
|
|
|
400
412
|
ops,
|
|
401
413
|
bundle: sha256(bundle2)
|
|
402
414
|
};
|
|
403
|
-
errors.push(...validateSourceManifest(manifest));
|
|
404
|
-
if (errors.length) throw new SourceErrors(where2, errors);
|
|
405
415
|
const files = {};
|
|
406
416
|
for (const input of Object.keys(out.metafile.inputs).map((p) => resolve(tenantDir, p))) {
|
|
407
417
|
const path = relative(root, input);
|
|
@@ -409,6 +419,12 @@ export default serveSource(def);
|
|
|
409
419
|
files[path.split(sep).join("/")] = readFileSync2(input, "utf8");
|
|
410
420
|
}
|
|
411
421
|
if (existsSync2(yamlPath)) files["source.yaml"] = readFileSync2(yamlPath, "utf8");
|
|
422
|
+
errors.push(...validateSourceManifest(manifest), ...fileUploadProblems(files));
|
|
423
|
+
const bundleProblem = bundleUploadProblem(manifest.bundle, bundle2);
|
|
424
|
+
if (bundleProblem) errors.push(bundleProblem);
|
|
425
|
+
const manifestProblem = manifestUploadProblem(manifest);
|
|
426
|
+
if (manifestProblem) errors.push(manifestProblem);
|
|
427
|
+
if (errors.length) throw new SourceErrors(where2, errors);
|
|
412
428
|
return { dir: root, manifest: { ...manifest, sha: versionId(manifest, files) }, bundle: bundle2, files };
|
|
413
429
|
}
|
|
414
430
|
async function compileSources(tenantDir, tenant) {
|
|
@@ -450,7 +466,20 @@ var tenantsDir = () => {
|
|
|
450
466
|
if (!existsSync3(dir)) throw new Error("no tenants directory; run this from a tenant, or from the motions repo");
|
|
451
467
|
return dir;
|
|
452
468
|
};
|
|
453
|
-
var readYaml = (path) =>
|
|
469
|
+
var readYaml = (path, label) => {
|
|
470
|
+
try {
|
|
471
|
+
return YAML2.parse(readFileSync3(path, "utf8"));
|
|
472
|
+
} catch (e) {
|
|
473
|
+
throw new Error(`${label ?? folderName(path)}: invalid YAML: ${e.message}`);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var readJson = (path, label) => {
|
|
477
|
+
try {
|
|
478
|
+
return JSON.parse(readFileSync3(path, "utf8"));
|
|
479
|
+
} catch (e) {
|
|
480
|
+
throw new Error(`${label}: invalid JSON: ${e.message}`);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
454
483
|
var grant = (g) => ({ read: g?.read ?? [], propose: g?.propose ?? [] });
|
|
455
484
|
async function bundle(stepFile, tenantDir) {
|
|
456
485
|
const result = await build2({
|
|
@@ -530,7 +559,17 @@ async function compileMotion(tenant, dir, catalog = new Set(BUILTIN_SOURCE_OPS))
|
|
|
530
559
|
steps,
|
|
531
560
|
queues
|
|
532
561
|
};
|
|
533
|
-
const errors =
|
|
562
|
+
const errors = [
|
|
563
|
+
...validateManifest(manifest, catalog),
|
|
564
|
+
...optionReasonProblems(manifest.reasons, files),
|
|
565
|
+
...fileUploadProblems2(files),
|
|
566
|
+
...Object.entries(bundles).flatMap(([sha, code]) => {
|
|
567
|
+
const p = bundleUploadProblem2(sha, code);
|
|
568
|
+
return p ? [p] : [];
|
|
569
|
+
})
|
|
570
|
+
];
|
|
571
|
+
const manifestProblem = manifestUploadProblem2(manifest);
|
|
572
|
+
if (manifestProblem) errors.push(manifestProblem);
|
|
534
573
|
if (errors.length) throw new MotionErrors(where2, errors);
|
|
535
574
|
return { dir: root, manifest: { ...manifest, sha: versionId2(manifest, files) }, bundles, files };
|
|
536
575
|
}
|
|
@@ -545,18 +584,18 @@ function compileInput(input) {
|
|
|
545
584
|
}
|
|
546
585
|
async function compileTenant(tenantDir) {
|
|
547
586
|
const dir = resolve2(tenantDir);
|
|
548
|
-
const meta = readYaml(join4(dir, "tenant.yaml")) ?? {};
|
|
587
|
+
const meta = readYaml(join4(dir, "tenant.yaml"), "tenant.yaml") ?? {};
|
|
549
588
|
const id2 = meta.id ?? folderName(tenantDir);
|
|
550
589
|
const timezone = meta.timezone ?? "America/Sao_Paulo";
|
|
551
|
-
|
|
590
|
+
if (typeof timezone !== "string" || !isValidTimeZone(timezone)) {
|
|
591
|
+
throw new Error(`tenant.yaml: timezone "${String(timezone)}" is not a valid IANA time zone`);
|
|
592
|
+
}
|
|
593
|
+
const connection = readYaml(join4(dir, "crm.yaml"), "crm.yaml");
|
|
552
594
|
const seedPath = join4(dir, "crm-seed.json");
|
|
553
|
-
const seed = existsSync3(seedPath) ?
|
|
595
|
+
const seed = existsSync3(seedPath) ? readJson(seedPath, "crm-seed.json") : null;
|
|
554
596
|
const fixtures = readTenantFixtures(dir, meta.sources);
|
|
555
597
|
const sources = await compileSources(dir, id2);
|
|
556
|
-
const catalog = /* @__PURE__ */ new Set([
|
|
557
|
-
...BUILTIN_SOURCE_OPS,
|
|
558
|
-
...sources.flatMap((s) => Object.keys(s.manifest.ops).map((op) => `${s.manifest.source}.${op}`))
|
|
559
|
-
]);
|
|
598
|
+
const catalog = /* @__PURE__ */ new Set([...BUILTIN_SOURCE_OPS, ...sources.flatMap((s) => Object.keys(s.manifest.ops).map((op) => `${s.manifest.source}.${op}`))]);
|
|
560
599
|
const motionsDir = join4(dir, "motions");
|
|
561
600
|
const motions = [];
|
|
562
601
|
for (const name of readdirSync3(motionsDir).sort()) {
|
package/dist/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync4 } from "fs";
|
|
5
|
-
import { dirname as dirname6, join as join9, resolve as resolve6 } from "path";
|
|
5
|
+
import { basename as basename2, dirname as dirname6, join as join9, resolve as resolve6 } from "path";
|
|
6
6
|
import { createInterface } from "readline/promises";
|
|
7
7
|
import { parseArgs } from "util";
|
|
8
8
|
|
|
@@ -27,9 +27,6 @@ async function openBatch(call, input) {
|
|
|
27
27
|
if (input.list !== void 0 && input.companies !== void 0) {
|
|
28
28
|
throw new Error("pass --list or --companies, not both");
|
|
29
29
|
}
|
|
30
|
-
if (input.again && input.list === void 0) {
|
|
31
|
-
throw new Error("--again requires --list <id-or-name>");
|
|
32
|
-
}
|
|
33
30
|
const base = `/api/tenants/${encodeURIComponent(input.tenant)}`;
|
|
34
31
|
const body = {};
|
|
35
32
|
if (input.label !== void 0) body.label = input.label;
|
|
@@ -45,7 +42,6 @@ async function openBatch(call, input) {
|
|
|
45
42
|
if (matched) {
|
|
46
43
|
body.fromList = { id: matched.id, ...input.again ? { again: true } : {} };
|
|
47
44
|
} else {
|
|
48
|
-
if (input.again) throw new Error(`no Motions list "${query}" in ${input.tenant}; --again only applies to Motions lists`);
|
|
49
45
|
body.list = query;
|
|
50
46
|
}
|
|
51
47
|
}
|
|
@@ -179,9 +175,25 @@ function formatDetails(details) {
|
|
|
179
175
|
if (Array.isArray(details)) return details.length ? `
|
|
180
176
|
${details.map(String).join("\n ")}` : "";
|
|
181
177
|
if (typeof details === "object") {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
const obj = details;
|
|
179
|
+
const lines = [];
|
|
180
|
+
if (Array.isArray(obj.issues)) {
|
|
181
|
+
for (const item of obj.issues) {
|
|
182
|
+
if (item && typeof item === "object") {
|
|
183
|
+
const issue = item;
|
|
184
|
+
const path = Array.isArray(issue.path) ? issue.path.map(String).filter(Boolean).join(".") : "";
|
|
185
|
+
const msg = typeof issue.message === "string" ? issue.message : String(issue.message ?? "");
|
|
186
|
+
if (path || msg) lines.push(path ? `${path}: ${msg}` : msg);
|
|
187
|
+
} else if (item !== void 0 && item !== null) {
|
|
188
|
+
lines.push(String(item));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (Array.isArray(obj.errors)) {
|
|
193
|
+
for (const err of obj.errors) lines.push(String(err));
|
|
194
|
+
}
|
|
195
|
+
if (lines.length) return `
|
|
196
|
+
${lines.join("\n ")}`;
|
|
185
197
|
}
|
|
186
198
|
return "";
|
|
187
199
|
}
|
|
@@ -234,8 +246,13 @@ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join5, relative
|
|
|
234
246
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
235
247
|
import {
|
|
236
248
|
BUILTIN_SOURCE_OPS,
|
|
249
|
+
bundleUploadProblem as bundleUploadProblem2,
|
|
237
250
|
CRM_WRITES,
|
|
238
251
|
crmProblems,
|
|
252
|
+
fileUploadProblems as fileUploadProblems2,
|
|
253
|
+
isValidTimeZone,
|
|
254
|
+
manifestUploadProblem as manifestUploadProblem2,
|
|
255
|
+
optionReasonProblems,
|
|
239
256
|
rulesVersion,
|
|
240
257
|
STEP_BUILD,
|
|
241
258
|
STEP_ENTRY_FILE,
|
|
@@ -460,7 +477,14 @@ function parseMotion(raw) {
|
|
|
460
477
|
import { createHash } from "crypto";
|
|
461
478
|
import { existsSync as existsSync3, mkdirSync, readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
462
479
|
import { dirname as dirname2, isAbsolute, join as join4, relative, resolve, sep } from "path";
|
|
463
|
-
import {
|
|
480
|
+
import {
|
|
481
|
+
bundleUploadProblem,
|
|
482
|
+
fileUploadProblems,
|
|
483
|
+
manifestUploadProblem,
|
|
484
|
+
parseDuration as parseDuration2,
|
|
485
|
+
validateSourceManifest,
|
|
486
|
+
versionId
|
|
487
|
+
} from "@motionskit/kernel";
|
|
464
488
|
import { build } from "esbuild";
|
|
465
489
|
import YAML from "yaml";
|
|
466
490
|
import { z as z2 } from "zod";
|
|
@@ -641,8 +665,6 @@ export default serveSource(def);
|
|
|
641
665
|
ops,
|
|
642
666
|
bundle: sha256(bundle2)
|
|
643
667
|
};
|
|
644
|
-
errors.push(...validateSourceManifest(manifest));
|
|
645
|
-
if (errors.length) throw new SourceErrors(where2, errors);
|
|
646
668
|
const files = {};
|
|
647
669
|
for (const input of Object.keys(out.metafile.inputs).map((p) => resolve(tenantDir, p))) {
|
|
648
670
|
const path = relative(root, input);
|
|
@@ -650,6 +672,12 @@ export default serveSource(def);
|
|
|
650
672
|
files[path.split(sep).join("/")] = readFileSync3(input, "utf8");
|
|
651
673
|
}
|
|
652
674
|
if (existsSync3(yamlPath)) files["source.yaml"] = readFileSync3(yamlPath, "utf8");
|
|
675
|
+
errors.push(...validateSourceManifest(manifest), ...fileUploadProblems(files));
|
|
676
|
+
const bundleProblem = bundleUploadProblem(manifest.bundle, bundle2);
|
|
677
|
+
if (bundleProblem) errors.push(bundleProblem);
|
|
678
|
+
const manifestProblem = manifestUploadProblem(manifest);
|
|
679
|
+
if (manifestProblem) errors.push(manifestProblem);
|
|
680
|
+
if (errors.length) throw new SourceErrors(where2, errors);
|
|
653
681
|
return { dir: root, manifest: { ...manifest, sha: versionId(manifest, files) }, bundle: bundle2, files };
|
|
654
682
|
}
|
|
655
683
|
async function compileSources(tenantDir, tenant) {
|
|
@@ -731,7 +759,20 @@ function tenantIdentity(dir) {
|
|
|
731
759
|
const motions = existsSync4(motionsDir) ? readdirSync3(motionsDir).filter((name) => existsSync4(join5(motionsDir, name, "motion.yaml"))).sort() : [];
|
|
732
760
|
return { id: meta.id ?? folderName(dir), motions };
|
|
733
761
|
}
|
|
734
|
-
var readYaml = (path) =>
|
|
762
|
+
var readYaml = (path, label) => {
|
|
763
|
+
try {
|
|
764
|
+
return YAML2.parse(readFileSync4(path, "utf8"));
|
|
765
|
+
} catch (e) {
|
|
766
|
+
throw new Error(`${label ?? folderName(path)}: invalid YAML: ${e.message}`);
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
var readJson = (path, label) => {
|
|
770
|
+
try {
|
|
771
|
+
return JSON.parse(readFileSync4(path, "utf8"));
|
|
772
|
+
} catch (e) {
|
|
773
|
+
throw new Error(`${label}: invalid JSON: ${e.message}`);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
735
776
|
var grant = (g) => ({ read: g?.read ?? [], propose: g?.propose ?? [] });
|
|
736
777
|
async function bundle(stepFile, tenantDir) {
|
|
737
778
|
const result = await build2({
|
|
@@ -811,7 +852,17 @@ async function compileMotion(tenant, dir, catalog = new Set(BUILTIN_SOURCE_OPS))
|
|
|
811
852
|
steps,
|
|
812
853
|
queues
|
|
813
854
|
};
|
|
814
|
-
const errors =
|
|
855
|
+
const errors = [
|
|
856
|
+
...validateManifest(manifest, catalog),
|
|
857
|
+
...optionReasonProblems(manifest.reasons, files),
|
|
858
|
+
...fileUploadProblems2(files),
|
|
859
|
+
...Object.entries(bundles).flatMap(([sha, code]) => {
|
|
860
|
+
const p = bundleUploadProblem2(sha, code);
|
|
861
|
+
return p ? [p] : [];
|
|
862
|
+
})
|
|
863
|
+
];
|
|
864
|
+
const manifestProblem = manifestUploadProblem2(manifest);
|
|
865
|
+
if (manifestProblem) errors.push(manifestProblem);
|
|
815
866
|
if (errors.length) throw new MotionErrors(where2, errors);
|
|
816
867
|
return { dir: root, manifest: { ...manifest, sha: versionId2(manifest, files) }, bundles, files };
|
|
817
868
|
}
|
|
@@ -826,18 +877,18 @@ function compileInput(input) {
|
|
|
826
877
|
}
|
|
827
878
|
async function compileTenant(tenantDir) {
|
|
828
879
|
const dir = resolve2(tenantDir);
|
|
829
|
-
const meta = readYaml(join5(dir, "tenant.yaml")) ?? {};
|
|
880
|
+
const meta = readYaml(join5(dir, "tenant.yaml"), "tenant.yaml") ?? {};
|
|
830
881
|
const id2 = meta.id ?? folderName(tenantDir);
|
|
831
882
|
const timezone = meta.timezone ?? "America/Sao_Paulo";
|
|
832
|
-
|
|
883
|
+
if (typeof timezone !== "string" || !isValidTimeZone(timezone)) {
|
|
884
|
+
throw new Error(`tenant.yaml: timezone "${String(timezone)}" is not a valid IANA time zone`);
|
|
885
|
+
}
|
|
886
|
+
const connection = readYaml(join5(dir, "crm.yaml"), "crm.yaml");
|
|
833
887
|
const seedPath = join5(dir, "crm-seed.json");
|
|
834
|
-
const seed = existsSync4(seedPath) ?
|
|
888
|
+
const seed = existsSync4(seedPath) ? readJson(seedPath, "crm-seed.json") : null;
|
|
835
889
|
const fixtures = readTenantFixtures(dir, meta.sources);
|
|
836
890
|
const sources = await compileSources(dir, id2);
|
|
837
|
-
const catalog = /* @__PURE__ */ new Set([
|
|
838
|
-
...BUILTIN_SOURCE_OPS,
|
|
839
|
-
...sources.flatMap((s) => Object.keys(s.manifest.ops).map((op) => `${s.manifest.source}.${op}`))
|
|
840
|
-
]);
|
|
891
|
+
const catalog = /* @__PURE__ */ new Set([...BUILTIN_SOURCE_OPS, ...sources.flatMap((s) => Object.keys(s.manifest.ops).map((op) => `${s.manifest.source}.${op}`))]);
|
|
841
892
|
const motionsDir = join5(dir, "motions");
|
|
842
893
|
const motions = [];
|
|
843
894
|
for (const name of readdirSync3(motionsDir).sort()) {
|
|
@@ -875,14 +926,22 @@ function tenantCrmProblems(tenant, systems = CRM_WRITES) {
|
|
|
875
926
|
}
|
|
876
927
|
|
|
877
928
|
// src/init.ts
|
|
878
|
-
import { execFileSync } from "child_process";
|
|
879
929
|
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync as readdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "fs";
|
|
880
930
|
import { basename, dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
881
931
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
882
932
|
var TENANT_ID = /^[a-z][a-z0-9_-]{0,62}$/;
|
|
883
933
|
var HANDLE = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
934
|
+
function readCliPackage() {
|
|
935
|
+
return JSON.parse(readFileSync5(fileURLToPath3(new URL("../package.json", import.meta.url)), "utf8"));
|
|
936
|
+
}
|
|
884
937
|
function cliVersion() {
|
|
885
|
-
return
|
|
938
|
+
return readCliPackage().version;
|
|
939
|
+
}
|
|
940
|
+
function sdkVersion() {
|
|
941
|
+
const pkg = readCliPackage();
|
|
942
|
+
const kernel = pkg.dependencies?.["@motionskit/kernel"];
|
|
943
|
+
if (kernel && /^\d+\.\d+\.\d+/.test(kernel)) return `^${kernel}`;
|
|
944
|
+
return `^${pkg.version}`;
|
|
886
945
|
}
|
|
887
946
|
function handleFrom(raw) {
|
|
888
947
|
if (!raw) return null;
|
|
@@ -890,13 +949,7 @@ function handleFrom(raw) {
|
|
|
890
949
|
return HANDLE.test(base) ? base : null;
|
|
891
950
|
}
|
|
892
951
|
function defaultApprover() {
|
|
893
|
-
|
|
894
|
-
const email = execFileSync("git", ["config", "user.email"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
895
|
-
const fromGit = handleFrom(email);
|
|
896
|
-
if (fromGit) return fromGit;
|
|
897
|
-
} catch {
|
|
898
|
-
}
|
|
899
|
-
return handleFrom(process.env.USER ?? process.env.USERNAME) ?? "member";
|
|
952
|
+
return handleFrom(process.env.MOTIONS_APPROVER) ?? "member";
|
|
900
953
|
}
|
|
901
954
|
var file = (dir, path, contents) => {
|
|
902
955
|
const dest = join6(dir, path);
|
|
@@ -991,7 +1044,7 @@ test("records the domain", async () => {
|
|
|
991
1044
|
private: true,
|
|
992
1045
|
type: "module",
|
|
993
1046
|
scripts: { check: "motions check", test: "motions test", typecheck: "tsc -p .", push: "motions push" },
|
|
994
|
-
devDependencies: { "@motionskit/cli": version, "@motionskit/sdk":
|
|
1047
|
+
devDependencies: { "@motionskit/cli": version, "@motionskit/sdk": sdkVersion(), typescript: "^5.9.3", vitest: "^5.1.0" }
|
|
995
1048
|
},
|
|
996
1049
|
null,
|
|
997
1050
|
2
|
|
@@ -1080,10 +1133,10 @@ jobs:
|
|
|
1080
1133
|
}
|
|
1081
1134
|
|
|
1082
1135
|
// src/origin.ts
|
|
1083
|
-
import { execFileSync
|
|
1136
|
+
import { execFileSync } from "child_process";
|
|
1084
1137
|
function git(dir, ...args2) {
|
|
1085
1138
|
try {
|
|
1086
|
-
return
|
|
1139
|
+
return execFileSync("git", ["-C", dir, ...args2], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trimEnd();
|
|
1087
1140
|
} catch {
|
|
1088
1141
|
return void 0;
|
|
1089
1142
|
}
|
|
@@ -1213,17 +1266,113 @@ function runTenantTests(dirs, spawn = spawnSync) {
|
|
|
1213
1266
|
var DEFAULT_URL = "https://motions.pruma.tech";
|
|
1214
1267
|
var LOCAL_URL = "http://localhost:8787";
|
|
1215
1268
|
var USAGE = `usage: motions <check|push|pull|test|open|retry|cancel|init|publish|help> \u2026
|
|
1216
|
-
check [tenant] compile the tenant in this directory, or every tenant in this repo
|
|
1217
|
-
push [--live] [-m message]
|
|
1269
|
+
check [tenant] compile and validate the tenant in this directory, or every tenant in this repo
|
|
1270
|
+
push [--live] [--draft] [-m message] [--reseed]
|
|
1271
|
+
publish a draft (or go live with --live) and print a link
|
|
1218
1272
|
pull <version> [--motion id] [--force]
|
|
1219
|
-
|
|
1273
|
+
pull a published motion version's files into this tenant
|
|
1274
|
+
test [tenant] run motions/*/tests with the tenant's vitest
|
|
1220
1275
|
open <tenant> <motion> [--list id-or-name | --companies id,id] [--label text] [--again]
|
|
1276
|
+
open a batch on the motion's live version
|
|
1221
1277
|
retry <batch> [--company id] [--step id]
|
|
1278
|
+
retry failed or stopped cells in a batch
|
|
1222
1279
|
cancel <batch> [--reason text] [--yes]
|
|
1280
|
+
permanently cancel a running batch
|
|
1223
1281
|
init [dir] [--approver handle] scaffold a tenant repo
|
|
1224
|
-
publish [tenant]
|
|
1225
|
-
|
|
1282
|
+
publish [tenant] [--draft] [-m message] [--reseed]
|
|
1283
|
+
from this repo, push --live over tenants/*
|
|
1284
|
+
help [command] print global usage or help for one command
|
|
1226
1285
|
--version, -v print the CLI version`;
|
|
1286
|
+
var COMMAND_HELP = {
|
|
1287
|
+
check: `usage: motions check [tenant] [--tenant <dir>]
|
|
1288
|
+
|
|
1289
|
+
Compile and validate the tenant in this directory (or every tenant in this repo) without contacting the server.
|
|
1290
|
+
Checks tenant.yaml, crm.yaml, crm-seed.json, fixtures, custom sources, motion manifests, step bundles, upload limits, and declared option reasons.
|
|
1291
|
+
|
|
1292
|
+
options:
|
|
1293
|
+
--tenant <dir> path to a tenant directory containing tenant.yaml
|
|
1294
|
+
-h, --help print this help`,
|
|
1295
|
+
push: `usage: motions push [--live | --draft] [-m <message>] [--reseed] [--tenant <dir>] [--url <url>]
|
|
1296
|
+
|
|
1297
|
+
Compile, dry-run on the server, and publish the tenant, its custom sources, and its motions.
|
|
1298
|
+
Publishes a draft by default; pass --live to promote to live (or --draft to force a draft).
|
|
1299
|
+
|
|
1300
|
+
options:
|
|
1301
|
+
--live promote pushed sources and motions to live
|
|
1302
|
+
--draft publish as a draft (default; overrides --live)
|
|
1303
|
+
-m, --message commit/version note recorded on pushed versions
|
|
1304
|
+
--reseed replace the in-memory CRM seed on the server
|
|
1305
|
+
--tenant <dir> path to a tenant directory containing tenant.yaml
|
|
1306
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${DEFAULT_URL})
|
|
1307
|
+
-h, --help print this help`,
|
|
1308
|
+
pull: `usage: motions pull <version> [--motion <id>] [--force] [--tenant <dir>] [--url <url>]
|
|
1309
|
+
|
|
1310
|
+
Write a published motion version's source files into motions/<motion>/.
|
|
1311
|
+
|
|
1312
|
+
options:
|
|
1313
|
+
--motion <id> motion id when the tenant has more than one motion
|
|
1314
|
+
--force overwrite files with uncommitted local changes
|
|
1315
|
+
--tenant <dir> path to a tenant directory containing tenant.yaml
|
|
1316
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${DEFAULT_URL})
|
|
1317
|
+
-h, --help print this help`,
|
|
1318
|
+
test: `usage: motions test [tenant] [--tenant <dir>]
|
|
1319
|
+
|
|
1320
|
+
Run motions/*/tests using the tenant's local Vitest installation.
|
|
1321
|
+
|
|
1322
|
+
options:
|
|
1323
|
+
--tenant <dir> path to a tenant directory containing tenant.yaml
|
|
1324
|
+
-h, --help print this help`,
|
|
1325
|
+
open: `usage: motions open <tenant> <motion> [--list <id-or-name> | --companies <id,id>] [--label <text>] [--again] [--url <url>]
|
|
1326
|
+
|
|
1327
|
+
Open a batch on the motion's live version and print its link.
|
|
1328
|
+
With neither --list nor --companies, opens on the motion's input.list.
|
|
1329
|
+
|
|
1330
|
+
options:
|
|
1331
|
+
--list <id-or-name> uploaded Motions list id/name (falls back to a CRM list)
|
|
1332
|
+
--companies <id,id> comma-separated CRM company ids (cannot be combined with --list)
|
|
1333
|
+
--label <text> custom label for the batch
|
|
1334
|
+
--again open a fresh batch instead of reusing an existing one (always opens fresh for --companies and CRM lists)
|
|
1335
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${DEFAULT_URL})
|
|
1336
|
+
-h, --help print this help`,
|
|
1337
|
+
retry: `usage: motions retry <batch> [--company <id>] [--step <id>] [--tenant <dir>] [--url <url>]
|
|
1338
|
+
|
|
1339
|
+
Retry failed or stopped cells in <batch>, or a specific --company and --step.
|
|
1340
|
+
|
|
1341
|
+
options:
|
|
1342
|
+
--company <id> company key (e.g. hubspot:101) or bare CRM id (101)
|
|
1343
|
+
--step <id> runnable step id to retry
|
|
1344
|
+
--tenant <dir> tenant directory used for local token resolution
|
|
1345
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${DEFAULT_URL})
|
|
1346
|
+
-h, --help print this help`,
|
|
1347
|
+
cancel: `usage: motions cancel <batch> [--reason <text>] [--yes] [--tenant <dir>] [--url <url>]
|
|
1348
|
+
|
|
1349
|
+
Permanently cancel a running batch.
|
|
1350
|
+
|
|
1351
|
+
options:
|
|
1352
|
+
--reason <text> optional note recorded on batch.canceled
|
|
1353
|
+
-y, --yes skip the interactive confirmation prompt
|
|
1354
|
+
--tenant <dir> tenant directory used for local token resolution
|
|
1355
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${DEFAULT_URL})
|
|
1356
|
+
-h, --help print this help`,
|
|
1357
|
+
init: `usage: motions init [dir] [--approver <handle>] [--url <url>]
|
|
1358
|
+
|
|
1359
|
+
Scaffold a new tenant repository in [dir] (defaults to the current directory).
|
|
1360
|
+
|
|
1361
|
+
options:
|
|
1362
|
+
--approver <handle> initial approver handle for motions/example/motion.yaml (defaults to MOTIONS_APPROVER, /api/me handle when MOTIONS_TOKEN is set, or "member")
|
|
1363
|
+
--url <url> Motions server URL used with MOTIONS_TOKEN to resolve your member handle
|
|
1364
|
+
-h, --help print this help`,
|
|
1365
|
+
publish: `usage: motions publish [tenant] [--draft] [-m <message>] [--reseed] [--url <url>]
|
|
1366
|
+
|
|
1367
|
+
From the motions monorepo, push --live over tenants/* (or one named tenant).
|
|
1368
|
+
|
|
1369
|
+
options:
|
|
1370
|
+
--draft publish as drafts instead of promoting to live
|
|
1371
|
+
-m, --message commit/version note recorded on pushed versions
|
|
1372
|
+
--reseed replace the in-memory CRM seed on the server
|
|
1373
|
+
--url <url> Motions server URL (defaults to MOTIONS_URL or ${LOCAL_URL})
|
|
1374
|
+
-h, --help print this help`
|
|
1375
|
+
};
|
|
1227
1376
|
var parsed = (() => {
|
|
1228
1377
|
try {
|
|
1229
1378
|
return parseArgs({
|
|
@@ -1263,7 +1412,19 @@ if (values.version) {
|
|
|
1263
1412
|
process.exit(0);
|
|
1264
1413
|
}
|
|
1265
1414
|
if (values.help || positionals[0] === "help") {
|
|
1266
|
-
|
|
1415
|
+
const topic = positionals[0] === "help" ? positionals[1] : positionals[0];
|
|
1416
|
+
if (!topic || topic === "help") {
|
|
1417
|
+
console.log(USAGE);
|
|
1418
|
+
process.exit(0);
|
|
1419
|
+
}
|
|
1420
|
+
const detail = COMMAND_HELP[topic];
|
|
1421
|
+
if (!detail) {
|
|
1422
|
+
console.error(`unknown command "${topic}"
|
|
1423
|
+
|
|
1424
|
+
${USAGE}`);
|
|
1425
|
+
process.exit(1);
|
|
1426
|
+
}
|
|
1427
|
+
console.log(detail);
|
|
1267
1428
|
process.exit(0);
|
|
1268
1429
|
}
|
|
1269
1430
|
var [command, ...args] = positionals;
|
|
@@ -1515,11 +1676,21 @@ var commands = {
|
|
|
1515
1676
|
open,
|
|
1516
1677
|
retry,
|
|
1517
1678
|
cancel,
|
|
1518
|
-
init: (dir) => {
|
|
1519
|
-
|
|
1520
|
-
|
|
1679
|
+
init: async (dir) => {
|
|
1680
|
+
let approver = values.approver ?? handleFrom(process.env.MOTIONS_APPROVER) ?? void 0;
|
|
1681
|
+
if (!approver && process.env.MOTIONS_TOKEN) {
|
|
1682
|
+
try {
|
|
1683
|
+
const tenantId = basename2(resolve6(dir ?? "."));
|
|
1684
|
+
const me = await api(url, "/api/me", void 0, tenantId);
|
|
1685
|
+
const match = me.memberships?.find((m) => m.tenant === tenantId) ?? me.memberships?.[0];
|
|
1686
|
+
approver = handleFrom(match?.handle) ?? void 0;
|
|
1687
|
+
} catch {
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
const resolved = approver ?? defaultApprover();
|
|
1691
|
+
const created = init(dir, { approver: resolved });
|
|
1521
1692
|
console.log(`created ${created}`);
|
|
1522
|
-
console.log(` approver set to "${
|
|
1693
|
+
console.log(` approver set to "${resolved}" in motions/example/motion.yaml (match your handle in Settings -> Members)`);
|
|
1523
1694
|
},
|
|
1524
1695
|
publish
|
|
1525
1696
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionskit/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"esbuild": "^0.28.2",
|
|
30
30
|
"yaml": "^2.9.1",
|
|
31
31
|
"zod": "^4.6.7",
|
|
32
|
-
"@motionskit/kernel": "0.2.
|
|
32
|
+
"@motionskit/kernel": "0.2.7"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^22.19.0",
|