@wraps.dev/cli 2.10.1 → 2.10.3

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/cli.js CHANGED
@@ -19425,7 +19425,7 @@ async function templatesPush(options) {
19425
19425
  }
19426
19426
  await pushToSES(compiled, progress);
19427
19427
  const token = await resolveTokenAsync({ token: options.token });
19428
- const apiResults = await pushToAPI(compiled, token, config2.org, progress);
19428
+ const apiResults = await pushToAPI(compiled, token, config2.org, progress, options.force);
19429
19429
  for (const t of compiled) {
19430
19430
  const apiResult = apiResults.find((r) => r.slug === t.slug);
19431
19431
  lockfile.templates[t.slug] = {
@@ -19664,7 +19664,7 @@ async function pushToSES(templates, progress) {
19664
19664
  }
19665
19665
  return results;
19666
19666
  }
19667
- async function pushToAPI(templates, token, _org, progress) {
19667
+ async function pushToAPI(templates, token, _org, progress, force) {
19668
19668
  if (!token) {
19669
19669
  progress.info(
19670
19670
  "No API token \u2014 skipping dashboard sync. Run: wraps auth login"
@@ -19694,19 +19694,45 @@ async function pushToAPI(templates, token, _org, progress) {
19694
19694
  variables: t.variables,
19695
19695
  sourceHash: t.sourceHash,
19696
19696
  sesTemplateName: t.sesTemplateName,
19697
- cliProjectPath: t.cliProjectPath
19697
+ cliProjectPath: t.cliProjectPath,
19698
+ force: force ?? false
19698
19699
  }))
19699
19700
  })
19700
19701
  });
19701
- if (!resp.ok) {
19702
+ if (Number(resp.status) === 409) {
19703
+ const data = await resp.json();
19704
+ for (const c of data.conflicts ?? []) {
19705
+ results.push({ slug: c.slug, success: false });
19706
+ }
19707
+ for (const r of data.results ?? []) {
19708
+ results.push({ slug: r.slug, id: r.id, success: true });
19709
+ }
19710
+ const successCount = data.results?.length ?? 0;
19711
+ const conflictCount = data.conflicts?.length ?? 0;
19712
+ if (successCount > 0 && conflictCount > 0) {
19713
+ progress.succeed(`Synced ${successCount} templates to dashboard`);
19714
+ for (const c of data.conflicts ?? []) {
19715
+ progress.fail(
19716
+ `${pc26.cyan(c.slug)} was edited on the dashboard. Use ${pc26.bold("--force")} to overwrite.`
19717
+ );
19718
+ }
19719
+ } else if (conflictCount > 0) {
19720
+ for (const c of data.conflicts ?? []) {
19721
+ progress.fail(
19722
+ `${pc26.cyan(c.slug)} was edited on the dashboard. Use ${pc26.bold("--force")} to overwrite.`
19723
+ );
19724
+ }
19725
+ }
19726
+ } else if (!resp.ok) {
19702
19727
  const body = await resp.text();
19703
19728
  throw new Error(`API returned ${resp.status}: ${body}`);
19729
+ } else {
19730
+ const data = await resp.json();
19731
+ for (const r of data.results) {
19732
+ results.push({ slug: r.slug, id: r.id, success: true });
19733
+ }
19734
+ progress.succeed(`Synced ${templates.length} templates to dashboard`);
19704
19735
  }
19705
- const data = await resp.json();
19706
- for (const r of data.results) {
19707
- results.push({ slug: r.slug, id: r.id, success: true });
19708
- }
19709
- progress.succeed(`Synced ${templates.length} templates to dashboard`);
19710
19736
  } catch (err) {
19711
19737
  const msg = err instanceof Error ? err.message : String(err);
19712
19738
  progress.fail(`Dashboard sync failed: ${msg}`);
@@ -19735,16 +19761,23 @@ async function pushToAPI(templates, token, _org, progress) {
19735
19761
  variables: t.variables,
19736
19762
  sourceHash: t.sourceHash,
19737
19763
  sesTemplateName: t.sesTemplateName,
19738
- cliProjectPath: t.cliProjectPath
19764
+ cliProjectPath: t.cliProjectPath,
19765
+ force: force ?? false
19739
19766
  })
19740
19767
  });
19741
- if (!resp.ok) {
19768
+ if (Number(resp.status) === 409) {
19769
+ results.push({ slug: t.slug, success: false });
19770
+ progress.fail(
19771
+ `${pc26.cyan(t.slug)} was edited on the dashboard since your last push. Use ${pc26.bold("--force")} to overwrite.`
19772
+ );
19773
+ } else if (!resp.ok) {
19742
19774
  const body = await resp.text();
19743
19775
  throw new Error(`API returned ${resp.status}: ${body}`);
19776
+ } else {
19777
+ const data = await resp.json();
19778
+ results.push({ slug: data.slug, id: data.id, success: true });
19779
+ progress.succeed(`Synced ${pc26.cyan(t.slug)} to dashboard`);
19744
19780
  }
19745
- const data = await resp.json();
19746
- results.push({ slug: data.slug, id: data.id, success: true });
19747
- progress.succeed(`Synced ${pc26.cyan(t.slug)} to dashboard`);
19748
19781
  } catch (err) {
19749
19782
  const msg = err instanceof Error ? err.message : String(err);
19750
19783
  results.push({ slug: t.slug, success: false });
@@ -19776,7 +19809,6 @@ async function findCliNodeModules() {
19776
19809
  const paths = [];
19777
19810
  try {
19778
19811
  const { createRequire } = await import("module");
19779
- const { fileURLToPath: fileURLToPath6 } = await import("url");
19780
19812
  const { dirname: dirname4 } = await import("path");
19781
19813
  for (const base of [
19782
19814
  // The current file's location (works when running from source)