kintone-migrator 0.31.4 → 0.31.5

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.mjs CHANGED
@@ -2036,8 +2036,15 @@ async function executeMultiApp(plan, executor) {
2036
2036
  continue;
2037
2037
  }
2038
2038
  try {
2039
- await executor(app);
2040
- results.push({
2039
+ const outcome = await executor(app);
2040
+ if (outcome && outcome.ok === false) {
2041
+ results.push({
2042
+ name: app.name,
2043
+ status: "failed",
2044
+ error: outcome.error
2045
+ });
2046
+ failed = true;
2047
+ } else results.push({
2041
2048
  name: app.name,
2042
2049
  status: "succeeded"
2043
2050
  });
@@ -2662,7 +2669,7 @@ async function routeMultiApp(values, handlers) {
2662
2669
  async function runMultiAppWithHeaders(plan, executor, successMessage) {
2663
2670
  await runMultiAppWithFailCheck(plan, async (app) => {
2664
2671
  printAppHeader(app.name, app.appId);
2665
- await executor(app);
2672
+ return executor(app);
2666
2673
  }, successMessage);
2667
2674
  }
2668
2675
  /**
@@ -5741,6 +5748,7 @@ function buildPhases(args) {
5741
5748
  name: "Schema",
5742
5749
  tasks: [{
5743
5750
  domain: "schema",
5751
+ storageExists: async () => (await c.schema.schemaStorage.get()).exists,
5744
5752
  run: async () => {
5745
5753
  await executeMigration({ container: c.schema });
5746
5754
  }
@@ -5750,6 +5758,7 @@ function buildPhases(args) {
5750
5758
  name: "Views & Customization",
5751
5759
  tasks: [{
5752
5760
  domain: "customize",
5761
+ storageExists: async () => (await c.customization.customizationStorage.get()).exists,
5753
5762
  run: async () => {
5754
5763
  await applyCustomization({
5755
5764
  container: c.customization,
@@ -5758,6 +5767,7 @@ function buildPhases(args) {
5758
5767
  }
5759
5768
  }, {
5760
5769
  domain: "view",
5770
+ storageExists: async () => (await c.view.viewStorage.get()).exists,
5761
5771
  run: async () => {
5762
5772
  await applyView({ container: c.view });
5763
5773
  }
@@ -5768,18 +5778,21 @@ function buildPhases(args) {
5768
5778
  tasks: [
5769
5779
  {
5770
5780
  domain: "field-acl",
5781
+ storageExists: async () => (await c.fieldPermission.fieldPermissionStorage.get()).exists,
5771
5782
  run: async () => {
5772
5783
  await applyFieldPermission({ container: c.fieldPermission });
5773
5784
  }
5774
5785
  },
5775
5786
  {
5776
5787
  domain: "app-acl",
5788
+ storageExists: async () => (await c.appPermission.appPermissionStorage.get()).exists,
5777
5789
  run: async () => {
5778
5790
  await applyAppPermission({ container: c.appPermission });
5779
5791
  }
5780
5792
  },
5781
5793
  {
5782
5794
  domain: "record-acl",
5795
+ storageExists: async () => (await c.recordPermission.recordPermissionStorage.get()).exists,
5783
5796
  run: async () => {
5784
5797
  await applyRecordPermission({ container: c.recordPermission });
5785
5798
  }
@@ -5791,42 +5804,49 @@ function buildPhases(args) {
5791
5804
  tasks: [
5792
5805
  {
5793
5806
  domain: "settings",
5807
+ storageExists: async () => (await c.settings.generalSettingsStorage.get()).exists,
5794
5808
  run: async () => {
5795
5809
  await applyGeneralSettings({ container: c.settings });
5796
5810
  }
5797
5811
  },
5798
5812
  {
5799
5813
  domain: "notification",
5814
+ storageExists: async () => (await c.notification.notificationStorage.get()).exists,
5800
5815
  run: async () => {
5801
5816
  await applyNotification({ container: c.notification });
5802
5817
  }
5803
5818
  },
5804
5819
  {
5805
5820
  domain: "report",
5821
+ storageExists: async () => (await c.report.reportStorage.get()).exists,
5806
5822
  run: async () => {
5807
5823
  await applyReport({ container: c.report });
5808
5824
  }
5809
5825
  },
5810
5826
  {
5811
5827
  domain: "action",
5828
+ storageExists: async () => (await c.action.actionStorage.get()).exists,
5812
5829
  run: async () => {
5813
5830
  await applyAction({ container: c.action });
5814
5831
  }
5815
5832
  },
5816
5833
  {
5817
5834
  domain: "process",
5835
+ storageExists: async () => (await c.process.processManagementStorage.get()).exists,
5818
5836
  run: async () => {
5819
5837
  await applyProcessManagement({ container: c.process });
5820
5838
  }
5821
5839
  },
5822
5840
  {
5823
5841
  domain: "admin-notes",
5842
+ storageExists: async () => (await c.adminNotes.adminNotesStorage.get()).exists,
5824
5843
  run: async () => {
5825
5844
  await applyAdminNotes({ container: c.adminNotes });
5826
5845
  }
5827
5846
  },
5828
5847
  {
5829
5848
  domain: "plugin",
5849
+ storageExists: async () => (await c.plugin.pluginStorage.get()).exists,
5830
5850
  run: async () => {
5831
5851
  await applyPlugin({ container: c.plugin });
5832
5852
  }
@@ -5837,6 +5857,7 @@ function buildPhases(args) {
5837
5857
  name: "Seed Data",
5838
5858
  tasks: [{
5839
5859
  domain: "seed",
5860
+ storageExists: async () => (await c.seed.seedStorage.get()).exists,
5840
5861
  run: async () => {
5841
5862
  await upsertSeed({
5842
5863
  container: c.seed,
@@ -5858,7 +5879,7 @@ function buildSkippedPhaseResult(phase, state) {
5858
5879
  domain: task.domain,
5859
5880
  success: false,
5860
5881
  error: skipError,
5861
- skipped: true
5882
+ skipped: "aborted"
5862
5883
  }))
5863
5884
  };
5864
5885
  }
@@ -5867,24 +5888,34 @@ function toError(error) {
5867
5888
  }
5868
5889
  async function executeSchemaPhase(phase, containers, state) {
5869
5890
  const results = [];
5870
- for (const task of phase.tasks) try {
5871
- await task.run();
5872
- await deployApp({ container: containers.schema });
5873
- results.push({
5874
- domain: task.domain,
5875
- success: true
5876
- });
5877
- } catch (error) {
5878
- const err = toError(error);
5879
- results.push({
5880
- domain: task.domain,
5881
- success: false,
5882
- error: err,
5883
- skipped: false
5884
- });
5885
- state.aborted = true;
5886
- state.reason = err;
5887
- state.phaseName = phase.name;
5891
+ for (const task of phase.tasks) {
5892
+ if (!await task.storageExists()) {
5893
+ results.push({
5894
+ domain: task.domain,
5895
+ success: false,
5896
+ skipped: "not-found"
5897
+ });
5898
+ continue;
5899
+ }
5900
+ try {
5901
+ await task.run();
5902
+ await deployApp({ container: containers.schema });
5903
+ results.push({
5904
+ domain: task.domain,
5905
+ success: true
5906
+ });
5907
+ } catch (error) {
5908
+ const err = toError(error);
5909
+ results.push({
5910
+ domain: task.domain,
5911
+ success: false,
5912
+ error: err,
5913
+ skipped: false
5914
+ });
5915
+ state.aborted = true;
5916
+ state.reason = err;
5917
+ state.phaseName = phase.name;
5918
+ }
5888
5919
  }
5889
5920
  return {
5890
5921
  phase: phase.name,
@@ -5899,7 +5930,15 @@ async function executeStandardPhase(phase, state) {
5899
5930
  domain: task.domain,
5900
5931
  success: false,
5901
5932
  error: createSkipError(state),
5902
- skipped: true
5933
+ skipped: "aborted"
5934
+ });
5935
+ continue;
5936
+ }
5937
+ if (!await task.storageExists()) {
5938
+ results.push({
5939
+ domain: task.domain,
5940
+ success: false,
5941
+ skipped: "not-found"
5903
5942
  });
5904
5943
  continue;
5905
5944
  }
@@ -8159,7 +8198,8 @@ const domainDisplayName$1 = {
8159
8198
  function formatTaskResult(result) {
8160
8199
  const name = domainDisplayName$1[result.domain];
8161
8200
  if (result.success) return ` ${pc.green("✓")} ${name}`;
8162
- if (result.skipped) return ` ${pc.yellow("⊘")} ${name} ${pc.dim("—")} ${pc.yellow("skipped")}`;
8201
+ if (result.skipped === "not-found") return ` ${pc.yellow("⊘")} ${name} ${pc.dim("—")} ${pc.yellow("skipped (file not found)")}`;
8202
+ if (result.skipped === "aborted") return ` ${pc.yellow("⊘")} ${name} ${pc.dim("—")} ${pc.yellow("skipped")}`;
8163
8203
  return ` ${pc.red("✗")} ${name} ${pc.dim("—")} ${pc.red(`failed (${formatErrorForDisplay(result.error)})`)}`;
8164
8204
  }
8165
8205
  function printPhaseResult(phaseResult) {
@@ -8180,6 +8220,7 @@ function printApplyAllResults(output) {
8180
8220
  const skipped = allResults.filter((r) => !r.success && r.skipped).length;
8181
8221
  if (output.deployed) p.log.success("Deployed to production.");
8182
8222
  else if (output.deployError) p.log.warn(`Deployment failed: ${formatErrorForDisplay(output.deployError)}`);
8223
+ else if (succeeded === 0 && failed === 0 && skipped > 0) p.log.info("No config files found. Nothing to apply.");
8183
8224
  else if (succeeded === 0) p.log.warn("Not deployed due to errors.");
8184
8225
  else if (failed > 0 || skipped > 0) p.log.info("Deployment skipped (no Phase 2-4 changes applied successfully).");
8185
8226
  const parts = [];
@@ -8319,19 +8360,20 @@ async function runApplyAll(cliConfig, appName, options) {
8319
8360
  const diffFailCount = diffResults.filter((r) => !r.success).length;
8320
8361
  ds.stop(`Comparison complete.${diffFailCount > 0 ? ` (${diffFailCount} failed)` : ""}`);
8321
8362
  printDiffAllResults(diffResults);
8322
- p.log.info("Note: Seed data will be upserted (no diff preview available).");
8363
+ const seedExists = (await containers.seed.seedStorage.get()).exists;
8364
+ if (seedExists) p.log.info("Note: Seed data will be upserted (no diff preview available).");
8323
8365
  const hasChanges = diffResults.some((r) => r.success && !r.result.isEmpty);
8324
- if (!hasChanges) p.log.success("No changes detected. Seed data will still be upserted.");
8366
+ if (!hasChanges) p.log.success(seedExists ? "No changes detected. Seed data will still be upserted." : "No changes detected.");
8325
8367
  if (options.dryRun) {
8326
8368
  p.log.info("Dry run complete. No changes will be applied.");
8327
- if (!hasChanges) p.log.info("Note: Seed data would still be upserted when running without --dry-run.");
8328
- return;
8369
+ if (!hasChanges && seedExists) p.log.info("Note: Seed data would still be upserted when running without --dry-run.");
8370
+ return { ok: true };
8329
8371
  }
8330
8372
  if (!options.skipConfirm) {
8331
8373
  const shouldContinue = await p.confirm({ message: "Apply these changes?" });
8332
8374
  if (p.isCancel(shouldContinue) || !shouldContinue) {
8333
8375
  p.cancel("Apply cancelled.");
8334
- return;
8376
+ return { ok: true };
8335
8377
  }
8336
8378
  }
8337
8379
  const as = p.spinner();
@@ -8340,10 +8382,14 @@ async function runApplyAll(cliConfig, appName, options) {
8340
8382
  containers,
8341
8383
  customizeBasePath
8342
8384
  });
8343
- const applyFailCount = output.phases.flatMap((pr) => pr.results).filter((r) => !r.success).length;
8385
+ const applyFailCount = output.phases.flatMap((pr) => pr.results).filter((r) => !r.success && r.skipped !== "not-found").length;
8344
8386
  as.stop(`Apply complete.${applyFailCount > 0 ? ` (${applyFailCount} failed)` : ""}`);
8345
8387
  printApplyAllResults(output);
8346
- if (output.phases.flatMap((pr) => pr.results).some((r) => !r.success) || !output.deployed) process.exitCode = 1;
8388
+ if (output.phases.flatMap((pr) => pr.results).some((r) => !r.success && r.skipped !== "not-found") || output.deployError) return {
8389
+ ok: false,
8390
+ error: output.deployError ?? new SystemError(SystemErrorCode.ExecutionError, `Apply failed for ${appName}.`)
8391
+ };
8392
+ return { ok: true };
8347
8393
  }
8348
8394
  var apply_default$10 = define({
8349
8395
  name: "apply",
@@ -8360,16 +8406,16 @@ var apply_default$10 = define({
8360
8406
  process.exitCode = 1;
8361
8407
  },
8362
8408
  singleApp: async (app, projectConfig) => {
8363
- await runApplyAll(resolveAppCliConfig(app, projectConfig, values), app.name, {
8409
+ if (!(await runApplyAll(resolveAppCliConfig(app, projectConfig, values), app.name, {
8364
8410
  skipConfirm,
8365
8411
  dryRun
8366
- });
8412
+ })).ok) process.exitCode = 1;
8367
8413
  },
8368
8414
  multiApp: async (plan, projectConfig) => {
8369
8415
  await runMultiAppWithFailCheck(plan, async (app) => {
8370
8416
  const cliConfig = resolveAppCliConfig(app, projectConfig, values);
8371
8417
  printAppHeader(app.name, app.appId);
8372
- await runApplyAll(cliConfig, app.name, {
8418
+ return runApplyAll(cliConfig, app.name, {
8373
8419
  skipConfirm,
8374
8420
  dryRun
8375
8421
  });