@spica/cli 0.19.6 → 0.19.8
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 +144 -84
- 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 = {
|
|
@@ -3460,42 +3460,48 @@ var silentReporter = {
|
|
|
3460
3460
|
};
|
|
3461
3461
|
|
|
3462
3462
|
// packages/sync/dist/src/fs-utils.js
|
|
3463
|
-
import
|
|
3463
|
+
import fs10 from "fs";
|
|
3464
3464
|
import path9 from "path";
|
|
3465
3465
|
import yaml from "yaml";
|
|
3466
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
3467
|
+
|
|
3468
|
+
// packages/sync/dist/src/source.js
|
|
3469
|
+
import fs9 from "node:fs";
|
|
3470
|
+
var diskSource = {
|
|
3471
|
+
listFolders(dir) {
|
|
3472
|
+
if (!fs9.existsSync(dir))
|
|
3473
|
+
return [];
|
|
3474
|
+
return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
3475
|
+
},
|
|
3476
|
+
readText(filePath) {
|
|
3477
|
+
if (!fs9.existsSync(filePath))
|
|
3478
|
+
return null;
|
|
3479
|
+
return fs9.readFileSync(filePath, "utf-8");
|
|
3480
|
+
}
|
|
3481
|
+
};
|
|
3482
|
+
|
|
3483
|
+
// packages/sync/dist/src/fs-utils.js
|
|
3466
3484
|
function ensureDir(dir) {
|
|
3467
|
-
|
|
3468
|
-
}
|
|
3469
|
-
function listFolders(dir) {
|
|
3470
|
-
if (!fs9.existsSync(dir))
|
|
3471
|
-
return [];
|
|
3472
|
-
return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
3485
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
3473
3486
|
}
|
|
3474
3487
|
function readYaml(filePath) {
|
|
3475
|
-
|
|
3476
|
-
return null;
|
|
3477
|
-
return yaml.parse(fs9.readFileSync(filePath, "utf-8"));
|
|
3488
|
+
return readSourceYaml(diskSource, filePath);
|
|
3478
3489
|
}
|
|
3479
3490
|
function writeYaml(filePath, data) {
|
|
3480
3491
|
ensureDir(path9.dirname(filePath));
|
|
3481
|
-
|
|
3482
|
-
}
|
|
3483
|
-
function readText(filePath) {
|
|
3484
|
-
if (!fs9.existsSync(filePath))
|
|
3485
|
-
return null;
|
|
3486
|
-
return fs9.readFileSync(filePath, "utf-8");
|
|
3492
|
+
fs10.writeFileSync(filePath, yaml.stringify(data), "utf-8");
|
|
3487
3493
|
}
|
|
3488
3494
|
function writeText(filePath, content) {
|
|
3489
3495
|
ensureDir(path9.dirname(filePath));
|
|
3490
|
-
|
|
3496
|
+
fs10.writeFileSync(filePath, content, "utf-8");
|
|
3491
3497
|
}
|
|
3492
3498
|
function removeDir(dir) {
|
|
3493
|
-
if (
|
|
3494
|
-
|
|
3499
|
+
if (fs10.existsSync(dir)) {
|
|
3500
|
+
fs10.rmSync(dir, { recursive: true, force: true });
|
|
3495
3501
|
}
|
|
3496
3502
|
}
|
|
3497
3503
|
function omit(obj, fields) {
|
|
3498
|
-
const clone =
|
|
3504
|
+
const clone = cloneDeep(obj);
|
|
3499
3505
|
for (const f of fields)
|
|
3500
3506
|
delete clone[f];
|
|
3501
3507
|
return clone;
|
|
@@ -3513,17 +3519,21 @@ function unwrapList(res) {
|
|
|
3513
3519
|
const got = typeof body === "string" ? `${body.slice(0, 80).replace(/\s+/g, " ")}\u2026` : typeof body;
|
|
3514
3520
|
throw new Error(`Expected a list response but got: ${got}. Check that your context URL points at the Spica API (e.g. ".../api"), not the panel.`);
|
|
3515
3521
|
}
|
|
3516
|
-
async function readLocalSchemas(rootDir, moduleName) {
|
|
3522
|
+
async function readLocalSchemas(rootDir, moduleName, source = diskSource) {
|
|
3517
3523
|
const dir = path9.join(rootDir, moduleName);
|
|
3518
|
-
const slugs = listFolders(dir);
|
|
3524
|
+
const slugs = source.listFolders(dir);
|
|
3519
3525
|
const results = [];
|
|
3520
3526
|
for (const slug of slugs) {
|
|
3521
|
-
const data =
|
|
3527
|
+
const data = readSourceYaml(source, path9.join(dir, slug, "schema.yaml"));
|
|
3522
3528
|
if (data)
|
|
3523
3529
|
results.push({ slug, data });
|
|
3524
3530
|
}
|
|
3525
3531
|
return results;
|
|
3526
3532
|
}
|
|
3533
|
+
function readSourceYaml(source, filePath) {
|
|
3534
|
+
const text = source.readText(filePath);
|
|
3535
|
+
return text === null ? null : yaml.parse(text);
|
|
3536
|
+
}
|
|
3527
3537
|
function writeLocalSchema(rootDir, moduleName, remote) {
|
|
3528
3538
|
const dir = path9.join(rootDir, moduleName, remote.slug);
|
|
3529
3539
|
writeYaml(path9.join(dir, "schema.yaml"), remote.data);
|
|
@@ -3537,12 +3547,13 @@ import { bold as bold4, cyan, green as green4, red as red4, yellow as yellow2 }
|
|
|
3537
3547
|
import isEqual2 from "lodash/isEqual.js";
|
|
3538
3548
|
import { createTwoFilesPatch } from "diff";
|
|
3539
3549
|
import yaml2 from "yaml";
|
|
3540
|
-
async function buildPlan(modules, http2, rootDir,
|
|
3550
|
+
async function buildPlan(modules, http2, rootDir, options = {}) {
|
|
3551
|
+
const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY, source } = options;
|
|
3541
3552
|
const modulePlans = [];
|
|
3542
3553
|
for (const mod of modules) {
|
|
3543
3554
|
const [locals, remotes] = await Promise.all([
|
|
3544
|
-
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
|
|
3545
|
-
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2))
|
|
3555
|
+
reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir, source)),
|
|
3556
|
+
reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2, { concurrency }))
|
|
3546
3557
|
]);
|
|
3547
3558
|
const localBySlug = new Map(locals.map((l) => [l.slug, l]));
|
|
3548
3559
|
const remoteBySlug = new Map(remotes.map((r) => [r.slug, r]));
|
|
@@ -3740,7 +3751,7 @@ function renderUnifiedDiff(diff, reversed = false) {
|
|
|
3740
3751
|
}
|
|
3741
3752
|
}
|
|
3742
3753
|
async function applyPlan(plan2, http2, opts = {}) {
|
|
3743
|
-
const concurrency = opts.concurrency ??
|
|
3754
|
+
const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3744
3755
|
const reporter = opts.reporter ?? silentReporter;
|
|
3745
3756
|
const errors = [];
|
|
3746
3757
|
const handleErr = (label, e) => {
|
|
@@ -3766,7 +3777,7 @@ async function applyPlan(plan2, http2, opts = {}) {
|
|
|
3766
3777
|
return { errors };
|
|
3767
3778
|
}
|
|
3768
3779
|
async function fetchToDisk(plan2, http2, rootDir, opts = {}) {
|
|
3769
|
-
const concurrency = opts.concurrency ??
|
|
3780
|
+
const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3770
3781
|
const reporter = opts.reporter ?? silentReporter;
|
|
3771
3782
|
const errors = [];
|
|
3772
3783
|
let written = 0;
|
|
@@ -3866,8 +3877,8 @@ var bucketModule = {
|
|
|
3866
3877
|
displayName: "Bucket",
|
|
3867
3878
|
identityField: "title",
|
|
3868
3879
|
ignoredFields: IGNORED_FIELDS,
|
|
3869
|
-
readLocal(rootDir) {
|
|
3870
|
-
return readLocalSchemas(rootDir, "bucket");
|
|
3880
|
+
readLocal(rootDir, source) {
|
|
3881
|
+
return readLocalSchemas(rootDir, "bucket", source);
|
|
3871
3882
|
},
|
|
3872
3883
|
async readRemote(http2) {
|
|
3873
3884
|
const res = await http2.get("bucket");
|
|
@@ -3915,8 +3926,8 @@ var envVarModule = {
|
|
|
3915
3926
|
displayName: "Environment Variable",
|
|
3916
3927
|
identityField: "key",
|
|
3917
3928
|
ignoredFields: IGNORED_FIELDS2,
|
|
3918
|
-
readLocal(rootDir) {
|
|
3919
|
-
return readLocalSchemas(rootDir, "env-var");
|
|
3929
|
+
readLocal(rootDir, source) {
|
|
3930
|
+
return readLocalSchemas(rootDir, "env-var", source);
|
|
3920
3931
|
},
|
|
3921
3932
|
async readRemote(http2) {
|
|
3922
3933
|
const res = await http2.get("env-var");
|
|
@@ -3960,6 +3971,7 @@ var envVarModule = {
|
|
|
3960
3971
|
import path10 from "path";
|
|
3961
3972
|
import yaml3 from "yaml";
|
|
3962
3973
|
import isEqual3 from "lodash/isEqual.js";
|
|
3974
|
+
import semver2 from "semver";
|
|
3963
3975
|
import { bold as bold5, cyan as cyan2, green as green5, yellow as yellow3 } from "colorette";
|
|
3964
3976
|
var SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
|
|
3965
3977
|
function indexFilename(language) {
|
|
@@ -3971,35 +3983,66 @@ function extractId(v) {
|
|
|
3971
3983
|
}
|
|
3972
3984
|
return String(v);
|
|
3973
3985
|
}
|
|
3986
|
+
function byCodeUnit(a, b) {
|
|
3987
|
+
if (a === b)
|
|
3988
|
+
return 0;
|
|
3989
|
+
return a < b ? -1 : 1;
|
|
3990
|
+
}
|
|
3974
3991
|
function normalizeSchema(schema) {
|
|
3975
3992
|
const normalized = { ...schema };
|
|
3976
3993
|
if (Array.isArray(schema.env_vars)) {
|
|
3977
|
-
normalized.env_vars = schema.env_vars.map(extractId);
|
|
3994
|
+
normalized.env_vars = schema.env_vars.map(extractId).sort(byCodeUnit);
|
|
3978
3995
|
}
|
|
3979
3996
|
if (Array.isArray(schema.secrets)) {
|
|
3980
|
-
normalized.secrets = schema.secrets.map(extractId);
|
|
3997
|
+
normalized.secrets = schema.secrets.map(extractId).sort(byCodeUnit);
|
|
3981
3998
|
}
|
|
3982
3999
|
return normalized;
|
|
3983
4000
|
}
|
|
4001
|
+
async function mapInBatches(items, size, fn) {
|
|
4002
|
+
const limit = Math.max(1, size);
|
|
4003
|
+
const results = [];
|
|
4004
|
+
for (let i = 0; i < items.length; i += limit) {
|
|
4005
|
+
results.push(...await Promise.all(items.slice(i, i + limit).map(fn)));
|
|
4006
|
+
}
|
|
4007
|
+
return results;
|
|
4008
|
+
}
|
|
3984
4009
|
function isNotFoundError(error) {
|
|
3985
4010
|
if (!error || typeof error !== "object")
|
|
3986
4011
|
return false;
|
|
3987
4012
|
const c = error;
|
|
3988
4013
|
return c.status === 404 || c.statusCode === 404 || c.response?.status === 404 || c.response?.statusCode === 404;
|
|
3989
4014
|
}
|
|
4015
|
+
function dependencySatisfied(localSpec, remoteSpec) {
|
|
4016
|
+
if (remoteSpec === void 0)
|
|
4017
|
+
return false;
|
|
4018
|
+
if (localSpec === remoteSpec)
|
|
4019
|
+
return true;
|
|
4020
|
+
const installed = remoteSpec.startsWith("^") ? semver2.valid(remoteSpec.slice(1)) : null;
|
|
4021
|
+
const rewrittenByNpm = !!semver2.valid(localSpec) || localSpec.startsWith("^") && !!semver2.validRange(localSpec);
|
|
4022
|
+
return !!installed && rewrittenByNpm && semver2.satisfies(installed, localSpec);
|
|
4023
|
+
}
|
|
4024
|
+
function dependenciesMatch(local, remote) {
|
|
4025
|
+
const names = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
4026
|
+
return [...names].every((name) => name in local && dependencySatisfied(local[name], remote[name]));
|
|
4027
|
+
}
|
|
4028
|
+
var emptyIfMissing = (empty) => (error) => {
|
|
4029
|
+
if (isNotFoundError(error))
|
|
4030
|
+
return empty;
|
|
4031
|
+
throw error;
|
|
4032
|
+
};
|
|
3990
4033
|
var functionModule = {
|
|
3991
4034
|
name: "function",
|
|
3992
4035
|
displayName: "Function",
|
|
3993
4036
|
identityField: "name",
|
|
3994
4037
|
ignoredFields: SCHEMA_IGNORED,
|
|
3995
|
-
readSchema(rootDir, slug) {
|
|
3996
|
-
return
|
|
4038
|
+
readSchema(rootDir, slug, source = diskSource) {
|
|
4039
|
+
return readSourceYaml(source, path10.join(rootDir, "function", slug, "schema.yaml"));
|
|
3997
4040
|
},
|
|
3998
|
-
readIndex(rootDir, slug, language) {
|
|
3999
|
-
return readText(path10.join(rootDir, "function", slug, indexFilename(language))) ?? "";
|
|
4041
|
+
readIndex(rootDir, slug, language, source = diskSource) {
|
|
4042
|
+
return source.readText(path10.join(rootDir, "function", slug, indexFilename(language))) ?? "";
|
|
4000
4043
|
},
|
|
4001
|
-
readDependencies(rootDir, slug) {
|
|
4002
|
-
const pkgText = readText(path10.join(rootDir, "function", slug, "package.json"));
|
|
4044
|
+
readDependencies(rootDir, slug, source = diskSource) {
|
|
4045
|
+
const pkgText = source.readText(path10.join(rootDir, "function", slug, "package.json"));
|
|
4003
4046
|
if (!pkgText)
|
|
4004
4047
|
return {};
|
|
4005
4048
|
try {
|
|
@@ -4008,29 +4051,31 @@ var functionModule = {
|
|
|
4008
4051
|
return {};
|
|
4009
4052
|
}
|
|
4010
4053
|
},
|
|
4011
|
-
async readLocal(rootDir) {
|
|
4054
|
+
async readLocal(rootDir, source = diskSource) {
|
|
4012
4055
|
const dir = path10.join(rootDir, "function");
|
|
4013
|
-
const slugs = listFolders(dir);
|
|
4056
|
+
const slugs = source.listFolders(dir);
|
|
4014
4057
|
const results = [];
|
|
4015
4058
|
for (const slug of slugs) {
|
|
4016
|
-
const schema = this.readSchema(rootDir, slug);
|
|
4059
|
+
const schema = this.readSchema(rootDir, slug, source);
|
|
4017
4060
|
if (!schema)
|
|
4018
4061
|
continue;
|
|
4019
|
-
const index = this.readIndex(rootDir, slug, schema.language);
|
|
4020
|
-
const dependencies = this.readDependencies(rootDir, slug);
|
|
4062
|
+
const index = this.readIndex(rootDir, slug, schema.language, source);
|
|
4063
|
+
const dependencies = this.readDependencies(rootDir, slug, source);
|
|
4021
4064
|
results.push({ slug, data: { schema, index, dependencies } });
|
|
4022
4065
|
}
|
|
4023
4066
|
return results;
|
|
4024
4067
|
},
|
|
4025
|
-
async readRemote(http2) {
|
|
4068
|
+
async readRemote(http2, options = {}) {
|
|
4026
4069
|
const res = await http2.get("function");
|
|
4027
4070
|
const fns = unwrapList(res);
|
|
4028
|
-
return
|
|
4071
|
+
return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
|
|
4029
4072
|
const id = fn._id;
|
|
4030
4073
|
const [indexRes, depsRes] = await Promise.all([
|
|
4031
|
-
http2.get(`function/${id}/index`).catch((
|
|
4032
|
-
http2.get(`function/${id}/dependencies`).catch((
|
|
4033
|
-
])
|
|
4074
|
+
http2.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
|
|
4075
|
+
http2.get(`function/${id}/dependencies`).catch(emptyIfMissing([]))
|
|
4076
|
+
]).catch((error) => {
|
|
4077
|
+
throw new Error(`Could not read function "${fn.name}": ${error?.message ?? error}`);
|
|
4078
|
+
});
|
|
4034
4079
|
const dependencies = {};
|
|
4035
4080
|
for (const dep of depsRes) {
|
|
4036
4081
|
dependencies[dep.name] = dep.version;
|
|
@@ -4044,7 +4089,7 @@ var functionModule = {
|
|
|
4044
4089
|
dependencies
|
|
4045
4090
|
}
|
|
4046
4091
|
};
|
|
4047
|
-
})
|
|
4092
|
+
});
|
|
4048
4093
|
},
|
|
4049
4094
|
async create(http2, local) {
|
|
4050
4095
|
const id = await this.createSchema(http2, local.data.schema);
|
|
@@ -4097,10 +4142,7 @@ var functionModule = {
|
|
|
4097
4142
|
return;
|
|
4098
4143
|
throw error;
|
|
4099
4144
|
})));
|
|
4100
|
-
const toAdd = Object.entries(localDeps).filter(([n, v]) => {
|
|
4101
|
-
const cur = currentByName.get(n);
|
|
4102
|
-
return !cur || cur !== v;
|
|
4103
|
-
}).map(([n, v]) => `${n}@${v}`);
|
|
4145
|
+
const toAdd = Object.entries(localDeps).filter(([n, v]) => !dependencySatisfied(v, currentByName.get(n))).map(([n, v]) => `${n}@${v}`);
|
|
4104
4146
|
if (toAdd.length) {
|
|
4105
4147
|
await http2.post(`function/${remoteId}/dependencies`, { name: toAdd });
|
|
4106
4148
|
}
|
|
@@ -4131,7 +4173,7 @@ var functionModule = {
|
|
|
4131
4173
|
changed.push("schema");
|
|
4132
4174
|
if (local.index !== remote.index)
|
|
4133
4175
|
changed.push("index");
|
|
4134
|
-
if (!
|
|
4176
|
+
if (!dependenciesMatch(local.dependencies, remote.dependencies))
|
|
4135
4177
|
changed.push("dependencies");
|
|
4136
4178
|
const localEnvVars = local.schema.env_vars ?? [];
|
|
4137
4179
|
const remoteEnvVars = remote.schema.env_vars ?? [];
|
|
@@ -4154,9 +4196,9 @@ var functionModule = {
|
|
|
4154
4196
|
result["index"] = buildUnifiedDiff(remote.data.index, local.data.index, indexFilename(local.data.schema.language));
|
|
4155
4197
|
}
|
|
4156
4198
|
const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4199
|
+
if (!dependenciesMatch(local.data.dependencies, remote.data.dependencies)) {
|
|
4200
|
+
const localDepsYaml = yaml3.stringify(sortKeys(local.data.dependencies));
|
|
4201
|
+
const remoteDepsYaml = yaml3.stringify(sortKeys(remote.data.dependencies));
|
|
4160
4202
|
result["dependencies"] = buildUnifiedDiff(remoteDepsYaml, localDepsYaml, "package.json");
|
|
4161
4203
|
}
|
|
4162
4204
|
return result;
|
|
@@ -4256,8 +4298,8 @@ var policyModule = {
|
|
|
4256
4298
|
displayName: "Policy",
|
|
4257
4299
|
identityField: "name",
|
|
4258
4300
|
ignoredFields: IGNORED_FIELDS3,
|
|
4259
|
-
readLocal(rootDir) {
|
|
4260
|
-
return readLocalSchemas(rootDir, "policy");
|
|
4301
|
+
readLocal(rootDir, source) {
|
|
4302
|
+
return readLocalSchemas(rootDir, "policy", source);
|
|
4261
4303
|
},
|
|
4262
4304
|
async readRemote(http2) {
|
|
4263
4305
|
const res = await http2.get("passport/policy");
|
|
@@ -4307,8 +4349,8 @@ var secretModule = {
|
|
|
4307
4349
|
displayName: "Secret",
|
|
4308
4350
|
identityField: "key",
|
|
4309
4351
|
ignoredFields: IGNORED_FIELDS4,
|
|
4310
|
-
readLocal(rootDir) {
|
|
4311
|
-
return readLocalSchemas(rootDir, "secret");
|
|
4352
|
+
readLocal(rootDir, source) {
|
|
4353
|
+
return readLocalSchemas(rootDir, "secret", source);
|
|
4312
4354
|
},
|
|
4313
4355
|
async readRemote(http2) {
|
|
4314
4356
|
const res = await http2.get("secret");
|
|
@@ -4387,15 +4429,21 @@ var cliReporter = {
|
|
|
4387
4429
|
};
|
|
4388
4430
|
|
|
4389
4431
|
// apps/cli/src/commands/sync/plan.ts
|
|
4432
|
+
var { CaporalValidator: CaporalValidator4 } = caporalCore4;
|
|
4390
4433
|
async function plan({ args, options }) {
|
|
4391
4434
|
try {
|
|
4392
4435
|
const rootDir = path11.resolve(args.dir ?? process.cwd());
|
|
4393
4436
|
const detailed = !!options.detailed;
|
|
4394
4437
|
const json = !!options.json;
|
|
4438
|
+
const concurrency = options.concurrency;
|
|
4395
4439
|
const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
|
|
4396
4440
|
const modules = resolveModules(moduleFilter);
|
|
4397
4441
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4398
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4442
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4443
|
+
detailed,
|
|
4444
|
+
reporter: cliReporter,
|
|
4445
|
+
concurrency
|
|
4446
|
+
});
|
|
4399
4447
|
renderPlan(p, { detailed, json });
|
|
4400
4448
|
process.exitCode = 0;
|
|
4401
4449
|
} catch (err) {
|
|
@@ -4412,7 +4460,10 @@ function plan_default(program2) {
|
|
|
4412
4460
|
"--detailed",
|
|
4413
4461
|
"Show full unified diffs for changed resources instead of just field names.",
|
|
4414
4462
|
{ default: false }
|
|
4415
|
-
).option("--json", "Output the plan as JSON (machine-readable).", { default: false }).option(
|
|
4463
|
+
).option("--json", "Output the plan as JSON (machine-readable).", { default: false }).option("--concurrency <n>", "Maximum parallel API requests.", {
|
|
4464
|
+
default: DEFAULT_CONCURRENCY,
|
|
4465
|
+
validator: CaporalValidator4.NUMBER
|
|
4466
|
+
}).option(
|
|
4416
4467
|
"--module <name>",
|
|
4417
4468
|
`Filter to specific module(s). Available: ${MODULE_NAMES.join(", ")}.`,
|
|
4418
4469
|
{
|
|
@@ -4423,7 +4474,7 @@ function plan_default(program2) {
|
|
|
4423
4474
|
|
|
4424
4475
|
// apps/cli/src/commands/sync/apply.ts
|
|
4425
4476
|
import path12 from "path";
|
|
4426
|
-
import
|
|
4477
|
+
import caporalCore5 from "@caporal/core";
|
|
4427
4478
|
import { bold as bold7, green as green6, red as red5, yellow as yellow5 } from "colorette";
|
|
4428
4479
|
|
|
4429
4480
|
// apps/cli/src/commands/sync/prompt.ts
|
|
@@ -4439,18 +4490,22 @@ async function confirm(question) {
|
|
|
4439
4490
|
}
|
|
4440
4491
|
|
|
4441
4492
|
// apps/cli/src/commands/sync/apply.ts
|
|
4442
|
-
var { CaporalValidator:
|
|
4493
|
+
var { CaporalValidator: CaporalValidator5 } = caporalCore5;
|
|
4443
4494
|
async function apply2({ args, options }) {
|
|
4444
4495
|
const rootDir = path12.resolve(args.dir ?? process.cwd());
|
|
4445
4496
|
const autoApprove = !!options.autoApprove;
|
|
4446
|
-
const concurrency = options.concurrency
|
|
4497
|
+
const concurrency = options.concurrency;
|
|
4447
4498
|
const abortOnError = !!options.abortOnError;
|
|
4448
4499
|
const detailed = !!options.detailed;
|
|
4449
4500
|
const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
|
|
4450
4501
|
const modules = resolveModules(moduleFilter);
|
|
4451
4502
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4452
4503
|
console.log(bold7("\nBuilding plan\u2026"));
|
|
4453
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4504
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4505
|
+
detailed,
|
|
4506
|
+
reporter: cliReporter,
|
|
4507
|
+
concurrency
|
|
4508
|
+
});
|
|
4454
4509
|
const totalChanges = p.modules.reduce(
|
|
4455
4510
|
(n, m) => n + m.creates.length + m.updates.length + m.deletes.length,
|
|
4456
4511
|
0
|
|
@@ -4501,7 +4556,7 @@ function apply_default2(program2) {
|
|
|
4501
4556
|
default: false
|
|
4502
4557
|
}).option("--concurrency <n>", "Maximum parallel API requests.", {
|
|
4503
4558
|
default: 5,
|
|
4504
|
-
validator:
|
|
4559
|
+
validator: CaporalValidator5.NUMBER
|
|
4505
4560
|
}).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
4561
|
"--module <name>",
|
|
4507
4562
|
`Filter to specific module(s). Available: ${MODULE_NAMES.join(", ")}.`,
|
|
@@ -4513,13 +4568,13 @@ function apply_default2(program2) {
|
|
|
4513
4568
|
|
|
4514
4569
|
// apps/cli/src/commands/sync/fetch.ts
|
|
4515
4570
|
import path13 from "path";
|
|
4516
|
-
import
|
|
4571
|
+
import caporalCore6 from "@caporal/core";
|
|
4517
4572
|
import { bold as bold8, green as green7, red as red6, yellow as yellow6 } from "colorette";
|
|
4518
|
-
var { CaporalValidator:
|
|
4573
|
+
var { CaporalValidator: CaporalValidator6 } = caporalCore6;
|
|
4519
4574
|
async function fetch_({ args, options }) {
|
|
4520
4575
|
const rootDir = path13.resolve(args.dir ?? process.cwd());
|
|
4521
4576
|
const autoApprove = !!options.autoApprove;
|
|
4522
|
-
const concurrency = options.concurrency
|
|
4577
|
+
const concurrency = options.concurrency;
|
|
4523
4578
|
const abortOnError = !!options.abortOnError;
|
|
4524
4579
|
const detailed = !!options.detailed;
|
|
4525
4580
|
const clean = !!options.clean;
|
|
@@ -4527,7 +4582,12 @@ async function fetch_({ args, options }) {
|
|
|
4527
4582
|
const modules = resolveModules(moduleFilter);
|
|
4528
4583
|
const http2 = await httpService.createFromCurrentCtx();
|
|
4529
4584
|
console.log(bold8("\nBuilding plan\u2026"));
|
|
4530
|
-
const p = await buildPlan(modules, http2, rootDir,
|
|
4585
|
+
const p = await buildPlan(modules, http2, rootDir, {
|
|
4586
|
+
detailed,
|
|
4587
|
+
detectRenames: false,
|
|
4588
|
+
reporter: cliReporter,
|
|
4589
|
+
concurrency
|
|
4590
|
+
});
|
|
4531
4591
|
const toWrite = p.modules.reduce((n, m) => n + m.deletes.length + m.updates.length, 0);
|
|
4532
4592
|
const toDelete = p.modules.reduce((n, m) => n + m.creates.length, 0);
|
|
4533
4593
|
const effectiveChanges = toWrite + (clean ? toDelete : 0);
|
|
@@ -4574,9 +4634,9 @@ ${bold8(red6(`\u2717 ${msg}`))}`);
|
|
|
4574
4634
|
function fetch_default(program2) {
|
|
4575
4635
|
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
4636
|
default: false
|
|
4577
|
-
}).option("--concurrency <n>", "Maximum parallel file writes.", {
|
|
4578
|
-
default:
|
|
4579
|
-
validator:
|
|
4637
|
+
}).option("--concurrency <n>", "Maximum parallel API requests and file writes.", {
|
|
4638
|
+
default: DEFAULT_CONCURRENCY,
|
|
4639
|
+
validator: CaporalValidator6.NUMBER
|
|
4580
4640
|
}).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
4641
|
default: false
|
|
4582
4642
|
}).option(
|
|
@@ -4849,7 +4909,7 @@ ${bold9(red7(`\u2717 ${formatError2(err)}`))}`);
|
|
|
4849
4909
|
console.log(bold9("\nBuilding plan\u2026"));
|
|
4850
4910
|
let plan2;
|
|
4851
4911
|
try {
|
|
4852
|
-
plan2 = await buildPlan(modules, http2, rootDir,
|
|
4912
|
+
plan2 = await buildPlan(modules, http2, rootDir, { reporter: cliReporter });
|
|
4853
4913
|
} catch (err) {
|
|
4854
4914
|
console.log(`
|
|
4855
4915
|
${bold9(red7(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
|
|
@@ -4961,7 +5021,7 @@ function readPackageVersion(baseUrl) {
|
|
|
4961
5021
|
}
|
|
4962
5022
|
|
|
4963
5023
|
// apps/cli/index.ts
|
|
4964
|
-
var { program } =
|
|
5024
|
+
var { program } = caporalCore7;
|
|
4965
5025
|
function run(argv) {
|
|
4966
5026
|
program.version(readPackageVersion(import.meta.url)).name("spica").bin("spica").description("Command line interface for spica.");
|
|
4967
5027
|
apply_default(program);
|