@spica/cli 0.19.6 → 0.19.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/index.js +65 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// apps/cli/index.ts
|
|
2
|
-
import
|
|
2
|
+
import caporalCore7 from "@caporal/core";
|
|
3
3
|
|
|
4
4
|
// apps/cli/src/console.ts
|
|
5
5
|
import { blue, bold, red, yellow } from "colorette";
|
|
@@ -184,11 +184,9 @@ var httpService;
|
|
|
184
184
|
return Promise.reject(error);
|
|
185
185
|
}
|
|
186
186
|
const data = error.response.data || error.response;
|
|
187
|
-
if (data instanceof Error) {
|
|
188
|
-
return Promise.reject(data);
|
|
189
|
-
}
|
|
190
187
|
const message = typeof data === "string" ? data : data?.message || data?.error || JSON.stringify(data);
|
|
191
|
-
|
|
188
|
+
const rejection = data instanceof Error ? data : new Error(message);
|
|
189
|
+
return Promise.reject(Object.assign(rejection, { status: error.response.status }));
|
|
192
190
|
}
|
|
193
191
|
);
|
|
194
192
|
instance.defaults.headers.common["Authorization"] = authorization;
|
|
@@ -3434,6 +3432,7 @@ function upgrade_default(program2) {
|
|
|
3434
3432
|
|
|
3435
3433
|
// apps/cli/src/commands/sync/plan.ts
|
|
3436
3434
|
import path11 from "path";
|
|
3435
|
+
import caporalCore4 from "@caporal/core";
|
|
3437
3436
|
|
|
3438
3437
|
// packages/sync/dist/src/types.js
|
|
3439
3438
|
var ChangeKind;
|
|
@@ -3442,6 +3441,7 @@ var ChangeKind;
|
|
|
3442
3441
|
ChangeKind2["Update"] = "update";
|
|
3443
3442
|
ChangeKind2["Delete"] = "delete";
|
|
3444
3443
|
})(ChangeKind || (ChangeKind = {}));
|
|
3444
|
+
var DEFAULT_CONCURRENCY = 10;
|
|
3445
3445
|
|
|
3446
3446
|
// packages/sync/dist/src/reporter.js
|
|
3447
3447
|
var noopProgress = {
|
|
@@ -3537,12 +3537,13 @@ import { bold as bold4, cyan, green as green4, red as red4, yellow as yellow2 }
|
|
|
3537
3537
|
import isEqual2 from "lodash/isEqual.js";
|
|
3538
3538
|
import { createTwoFilesPatch } from "diff";
|
|
3539
3539
|
import yaml2 from "yaml";
|
|
3540
|
-
async function buildPlan(modules, http2, rootDir,
|
|
3540
|
+
async function buildPlan(modules, http2, rootDir, options = {}) {
|
|
3541
|
+
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY } = options;
|
|
3541
3542
|
const modulePlans = [];
|
|
3542
3543
|
for (const mod of modules) {
|
|
3543
3544
|
const [locals, remotes] = await Promise.all([
|
|
3544
3545
|
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
|
|
3545
|
-
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2))
|
|
3546
|
+
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2, { concurrency }))
|
|
3546
3547
|
]);
|
|
3547
3548
|
const localBySlug = new Map(locals.map((l) => [l.slug, l]));
|
|
3548
3549
|
const remoteBySlug = new Map(remotes.map((r) => [r.slug, r]));
|
|
@@ -3740,7 +3741,7 @@ function renderUnifiedDiff(diff, reversed = false) {
|
|
|
3740
3741
|
}
|
|
3741
3742
|
}
|
|
3742
3743
|
async function applyPlan(plan2, http2, opts = {}) {
|
|
3743
|
-
const concurrency = opts.concurrency ??
|
|
3744
|
+
const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3744
3745
|
const reporter = opts.reporter ?? silentReporter;
|
|
3745
3746
|
const errors = [];
|
|
3746
3747
|
const handleErr = (label, e) => {
|
|
@@ -3766,7 +3767,7 @@ async function applyPlan(plan2, http2, opts = {}) {
|
|
|
3766
3767
|
return { errors };
|
|
3767
3768
|
}
|
|
3768
3769
|
async function fetchToDisk(plan2, http2, rootDir, opts = {}) {
|
|
3769
|
-
const concurrency = opts.concurrency ??
|
|
3770
|
+
const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3770
3771
|
const reporter = opts.reporter ?? silentReporter;
|
|
3771
3772
|
const errors = [];
|
|
3772
3773
|
let written = 0;
|
|
@@ -3981,12 +3982,25 @@ function normalizeSchema(schema) {
|
|
|
3981
3982
|
}
|
|
3982
3983
|
return normalized;
|
|
3983
3984
|
}
|
|
3985
|
+
async function mapInBatches(items, size, fn) {
|
|
3986
|
+
const limit = Math.max(1, size);
|
|
3987
|
+
const results = [];
|
|
3988
|
+
for (let i = 0; i < items.length; i += limit) {
|
|
3989
|
+
results.push(...await Promise.all(items.slice(i, i + limit).map(fn)));
|
|
3990
|
+
}
|
|
3991
|
+
return results;
|
|
3992
|
+
}
|
|
3984
3993
|
function isNotFoundError(error) {
|
|
3985
3994
|
if (!error || typeof error !== "object")
|
|
3986
3995
|
return false;
|
|
3987
3996
|
const c = error;
|
|
3988
3997
|
return c.status === 404 || c.statusCode === 404 || c.response?.status === 404 || c.response?.statusCode === 404;
|
|
3989
3998
|
}
|
|
3999
|
+
var emptyIfMissing = (empty) => (error) => {
|
|
4000
|
+
if (isNotFoundError(error))
|
|
4001
|
+
return empty;
|
|
4002
|
+
throw error;
|
|
4003
|
+
};
|
|
3990
4004
|
var functionModule = {
|
|
3991
4005
|
name: "function",
|
|
3992
4006
|
displayName: "Function",
|
|
@@ -4022,15 +4036,17 @@ var functionModule = {
|
|
|
4022
4036
|
}
|
|
4023
4037
|
return results;
|
|
4024
4038
|
},
|
|
4025
|
-
async readRemote(http2) {
|
|
4039
|
+
async readRemote(http2, options = {}) {
|
|
4026
4040
|
const res = await http2.get("function");
|
|
4027
4041
|
const fns = unwrapList(res);
|
|
4028
|
-
return
|
|
4042
|
+
return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
|
|
4029
4043
|
const id = fn._id;
|
|
4030
4044
|
const [indexRes, depsRes] = await Promise.all([
|
|
4031
|
-
http2.get(`function/${id}/index`).catch((
|
|
4032
|
-
http2.get(`function/${id}/dependencies`).catch((
|
|
4033
|
-
])
|
|
4045
|
+
http2.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
|
|
4046
|
+
http2.get(`function/${id}/dependencies`).catch(emptyIfMissing([]))
|
|
4047
|
+
]).catch((error) => {
|
|
4048
|
+
throw new Error(`Could not read function "${fn.name}": ${error?.message ?? error}`);
|
|
4049
|
+
});
|
|
4034
4050
|
const dependencies = {};
|
|
4035
4051
|
for (const dep of depsRes) {
|
|
4036
4052
|
dependencies[dep.name] = dep.version;
|
|
@@ -4044,7 +4060,7 @@ var functionModule = {
|
|
|
4044
4060
|
dependencies
|
|
4045
4061
|
}
|
|
4046
4062
|
};
|
|
4047
|
-
})
|
|
4063
|
+
});
|
|
4048
4064
|
},
|
|
4049
4065
|
async create(http2, local) {
|
|
4050
4066
|
const id = await this.createSchema(http2, local.data.schema);
|
|
@@ -4387,15 +4403,21 @@ var cliReporter = {
|
|
|
4387
4403
|
};
|
|
4388
4404
|
|
|
4389
4405
|
// apps/cli/src/commands/sync/plan.ts
|
|
4406
|
+
var { CaporalValidator: CaporalValidator4 } = caporalCore4;
|
|
4390
4407
|
async function plan({ args, options }) {
|
|
4391
4408
|
try {
|
|
4392
4409
|
const rootDir = path11.resolve(args.dir ?? process.cwd());
|
|
4393
4410
|
const detailed = !!options.detailed;
|
|
4394
4411
|
const json = !!options.json;
|
|
4412
|
+
const concurrency = options.concurrency;
|
|
4395
4413
|
const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
|
|
4396
4414
|
const modules = resolveModules(moduleFilter);
|
|
4397
4415
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4398
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4416
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4417
|
+
detailed,
|
|
4418
|
+
reporter: cliReporter,
|
|
4419
|
+
concurrency
|
|
4420
|
+
});
|
|
4399
4421
|
renderPlan(p, { detailed, json });
|
|
4400
4422
|
process.exitCode = 0;
|
|
4401
4423
|
} catch (err) {
|
|
@@ -4412,7 +4434,10 @@ function plan_default(program2) {
|
|
|
4412
4434
|
"--detailed",
|
|
4413
4435
|
"Show full unified diffs for changed resources instead of just field names.",
|
|
4414
4436
|
{ default: false }
|
|
4415
|
-
).option("--json", "Output the plan as JSON (machine-readable).", { default: false }).option(
|
|
4437
|
+
).option("--json", "Output the plan as JSON (machine-readable).", { default: false }).option("--concurrency <n>", "Maximum parallel API requests.", {
|
|
4438
|
+
default: DEFAULT_CONCURRENCY,
|
|
4439
|
+
validator: CaporalValidator4.NUMBER
|
|
4440
|
+
}).option(
|
|
4416
4441
|
"--module <name>",
|
|
4417
4442
|
`Filter to specific module(s). Available: ${MODULE_NAMES.join(", ")}.`,
|
|
4418
4443
|
{
|
|
@@ -4423,7 +4448,7 @@ function plan_default(program2) {
|
|
|
4423
4448
|
|
|
4424
4449
|
// apps/cli/src/commands/sync/apply.ts
|
|
4425
4450
|
import path12 from "path";
|
|
4426
|
-
import
|
|
4451
|
+
import caporalCore5 from "@caporal/core";
|
|
4427
4452
|
import { bold as bold7, green as green6, red as red5, yellow as yellow5 } from "colorette";
|
|
4428
4453
|
|
|
4429
4454
|
// apps/cli/src/commands/sync/prompt.ts
|
|
@@ -4439,18 +4464,22 @@ async function confirm(question) {
|
|
|
4439
4464
|
}
|
|
4440
4465
|
|
|
4441
4466
|
// apps/cli/src/commands/sync/apply.ts
|
|
4442
|
-
var { CaporalValidator:
|
|
4467
|
+
var { CaporalValidator: CaporalValidator5 } = caporalCore5;
|
|
4443
4468
|
async function apply2({ args, options }) {
|
|
4444
4469
|
const rootDir = path12.resolve(args.dir ?? process.cwd());
|
|
4445
4470
|
const autoApprove = !!options.autoApprove;
|
|
4446
|
-
const concurrency = options.concurrency
|
|
4471
|
+
const concurrency = options.concurrency;
|
|
4447
4472
|
const abortOnError = !!options.abortOnError;
|
|
4448
4473
|
const detailed = !!options.detailed;
|
|
4449
4474
|
const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
|
|
4450
4475
|
const modules = resolveModules(moduleFilter);
|
|
4451
4476
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4452
4477
|
console.log(bold7("\nBuilding plan\u2026"));
|
|
4453
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4478
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4479
|
+
detailed,
|
|
4480
|
+
reporter: cliReporter,
|
|
4481
|
+
concurrency
|
|
4482
|
+
});
|
|
4454
4483
|
const totalChanges = p.modules.reduce(
|
|
4455
4484
|
(n, m) => n + m.creates.length + m.updates.length + m.deletes.length,
|
|
4456
4485
|
0
|
|
@@ -4501,7 +4530,7 @@ function apply_default2(program2) {
|
|
|
4501
4530
|
default: false
|
|
4502
4531
|
}).option("--concurrency <n>", "Maximum parallel API requests.", {
|
|
4503
4532
|
default: 5,
|
|
4504
|
-
validator:
|
|
4533
|
+
validator: CaporalValidator5.NUMBER
|
|
4505
4534
|
}).option("--abort-on-error", "Stop immediately if any operation fails.", { default: false }).option("--detailed", "Show full unified diffs in the plan before applying.", { default: false }).option(
|
|
4506
4535
|
"--module <name>",
|
|
4507
4536
|
`Filter to specific module(s). Available: ${MODULE_NAMES.join(", ")}.`,
|
|
@@ -4513,13 +4542,13 @@ function apply_default2(program2) {
|
|
|
4513
4542
|
|
|
4514
4543
|
// apps/cli/src/commands/sync/fetch.ts
|
|
4515
4544
|
import path13 from "path";
|
|
4516
|
-
import
|
|
4545
|
+
import caporalCore6 from "@caporal/core";
|
|
4517
4546
|
import { bold as bold8, green as green7, red as red6, yellow as yellow6 } from "colorette";
|
|
4518
|
-
var { CaporalValidator:
|
|
4547
|
+
var { CaporalValidator: CaporalValidator6 } = caporalCore6;
|
|
4519
4548
|
async function fetch_({ args, options }) {
|
|
4520
4549
|
const rootDir = path13.resolve(args.dir ?? process.cwd());
|
|
4521
4550
|
const autoApprove = !!options.autoApprove;
|
|
4522
|
-
const concurrency = options.concurrency
|
|
4551
|
+
const concurrency = options.concurrency;
|
|
4523
4552
|
const abortOnError = !!options.abortOnError;
|
|
4524
4553
|
const detailed = !!options.detailed;
|
|
4525
4554
|
const clean = !!options.clean;
|
|
@@ -4527,7 +4556,12 @@ async function fetch_({ args, options }) {
|
|
|
4527
4556
|
const modules = resolveModules(moduleFilter);
|
|
4528
4557
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4529
4558
|
console.log(bold8("\nBuilding plan\u2026"));
|
|
4530
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4559
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4560
|
+
detailed,
|
|
4561
|
+
detectRenames: false,
|
|
4562
|
+
reporter: cliReporter,
|
|
4563
|
+
concurrency
|
|
4564
|
+
});
|
|
4531
4565
|
const toWrite = p.modules.reduce((n, m) => n + m.deletes.length + m.updates.length, 0);
|
|
4532
4566
|
const toDelete = p.modules.reduce((n, m) => n + m.creates.length, 0);
|
|
4533
4567
|
const effectiveChanges = toWrite + (clean ? toDelete : 0);
|
|
@@ -4574,9 +4608,9 @@ ${bold8(red6(`\u2717 ${msg}`))}`);
|
|
|
4574
4608
|
function fetch_default(program2) {
|
|
4575
4609
|
return program2.command("fetch", "Export remote Spica resources into local project files.").argument("[dir]", "Project directory (default: current working directory)").option("--auto-approve, -y", "Skip confirmation prompt and write immediately.", {
|
|
4576
4610
|
default: false
|
|
4577
|
-
}).option("--concurrency <n>", "Maximum parallel file writes.", {
|
|
4578
|
-
default:
|
|
4579
|
-
validator:
|
|
4611
|
+
}).option("--concurrency <n>", "Maximum parallel API requests and file writes.", {
|
|
4612
|
+
default: DEFAULT_CONCURRENCY,
|
|
4613
|
+
validator: CaporalValidator6.NUMBER
|
|
4580
4614
|
}).option("--abort-on-error", "Stop immediately if any operation fails.", { default: false }).option("--detailed", "Show full unified diffs in the plan before writing.", { default: false }).option("--clean", "Remove local resource folders that no longer exist remotely.", {
|
|
4581
4615
|
default: false
|
|
4582
4616
|
}).option(
|
|
@@ -4849,7 +4883,7 @@ ${bold9(red7(`\u2717 ${formatError2(err)}`))}`);
|
|
|
4849
4883
|
console.log(bold9("\nBuilding plan\u2026"));
|
|
4850
4884
|
let plan2;
|
|
4851
4885
|
try {
|
|
4852
|
-
plan2 = await buildPlan(modules, http2, rootDir,
|
|
4886
|
+
plan2 = await buildPlan(modules, http2, rootDir, { reporter: cliReporter });
|
|
4853
4887
|
} catch (err) {
|
|
4854
4888
|
console.log(`
|
|
4855
4889
|
${bold9(red7(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
|
|
@@ -4961,7 +4995,7 @@ function readPackageVersion(baseUrl) {
|
|
|
4961
4995
|
}
|
|
4962
4996
|
|
|
4963
4997
|
// apps/cli/index.ts
|
|
4964
|
-
var { program } =
|
|
4998
|
+
var { program } = caporalCore7;
|
|
4965
4999
|
function run(argv) {
|
|
4966
5000
|
program.version(readPackageVersion(import.meta.url)).name("spica").bin("spica").description("Command line interface for spica.");
|
|
4967
5001
|
apply_default(program);
|