contribute-now 0.4.0-dev.c791252 → 0.4.0-dev.d24b735

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.
Files changed (2) hide show
  1. package/dist/index.js +120 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { defineCommand } from "citty";
10
10
  import pc2 from "picocolors";
11
11
 
12
12
  // src/utils/config.ts
13
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
13
+ import { appendFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
14
14
  import { join } from "node:path";
15
15
  var CONFIG_FILENAME = ".contributerc.json";
16
16
  function getConfigPath(cwd = process.cwd()) {
@@ -86,6 +86,23 @@ function isGitignored(cwd = process.cwd()) {
86
86
  return false;
87
87
  }
88
88
  }
89
+ function ensureGitignored(cwd = process.cwd()) {
90
+ if (isGitignored(cwd))
91
+ return false;
92
+ const gitignorePath = join(cwd, ".gitignore");
93
+ const line = `${CONFIG_FILENAME}
94
+ `;
95
+ if (!existsSync(gitignorePath)) {
96
+ writeFileSync(gitignorePath, line, "utf-8");
97
+ return true;
98
+ }
99
+ const content = readFileSync(gitignorePath, "utf-8");
100
+ const needsLeadingNewline = content.length > 0 && !content.endsWith(`
101
+ `);
102
+ appendFileSync(gitignorePath, `${needsLeadingNewline ? `
103
+ ` : ""}${line}`, "utf-8");
104
+ return true;
105
+ }
89
106
  function getDefaultConfig() {
90
107
  return {
91
108
  workflow: "clean-flow",
@@ -2001,7 +2018,7 @@ import pc7 from "picocolors";
2001
2018
  // package.json
2002
2019
  var package_default = {
2003
2020
  name: "contribute-now",
2004
- version: "0.4.0-dev.c791252",
2021
+ version: "0.4.0-dev.d24b735",
2005
2022
  description: "Git workflow CLI for squash-merge two-branch models. Keeps dev in sync with main after squash merges.",
2006
2023
  type: "module",
2007
2024
  bin: {
@@ -2660,6 +2677,40 @@ function colorizeSubject(subject) {
2660
2677
  // src/commands/setup.ts
2661
2678
  import { defineCommand as defineCommand7 } from "citty";
2662
2679
  import pc10 from "picocolors";
2680
+ async function shouldContinueSetupWithExistingConfig(options) {
2681
+ const {
2682
+ existingConfig,
2683
+ hasConfigFile,
2684
+ confirm: confirm2,
2685
+ ensureIgnored,
2686
+ onInfo,
2687
+ onWarn,
2688
+ onSuccess,
2689
+ summary
2690
+ } = options;
2691
+ if (existingConfig) {
2692
+ onInfo("Existing .contributerc.json detected:");
2693
+ summary(existingConfig);
2694
+ const shouldContinue = await confirm2("Continue setup and overwrite existing config?");
2695
+ if (!shouldContinue) {
2696
+ if (ensureIgnored()) {
2697
+ onInfo("Added .contributerc.json to .gitignore to avoid committing personal config.");
2698
+ }
2699
+ onSuccess("Keeping existing setup.");
2700
+ return false;
2701
+ }
2702
+ return true;
2703
+ }
2704
+ if (hasConfigFile) {
2705
+ onWarn("Found .contributerc.json but it appears invalid.");
2706
+ const shouldContinue = await confirm2("Continue setup and overwrite invalid config?");
2707
+ if (!shouldContinue) {
2708
+ onInfo("Keeping existing file. Run setup again when ready to repair it.");
2709
+ return false;
2710
+ }
2711
+ }
2712
+ return true;
2713
+ }
2663
2714
  var setup_default = defineCommand7({
2664
2715
  meta: {
2665
2716
  name: "setup",
@@ -2671,6 +2722,20 @@ var setup_default = defineCommand7({
2671
2722
  process.exit(1);
2672
2723
  }
2673
2724
  heading("\uD83D\uDD27 contribute-now setup");
2725
+ const existingConfig = readConfig();
2726
+ const shouldContinue = await shouldContinueSetupWithExistingConfig({
2727
+ existingConfig,
2728
+ hasConfigFile: configExists(),
2729
+ confirm: confirmPrompt,
2730
+ ensureIgnored: ensureGitignored,
2731
+ onInfo: info,
2732
+ onWarn: warn,
2733
+ onSuccess: success,
2734
+ summary: logConfigSummary
2735
+ });
2736
+ if (!shouldContinue) {
2737
+ return;
2738
+ }
2674
2739
  const workflowChoice = await selectPrompt("Which git workflow does this project use?", [
2675
2740
  "Clean Flow — main + dev, squash features into dev, merge dev into main (recommended)",
2676
2741
  "GitHub Flow — main + feature branches, squash/merge into main",
@@ -2700,31 +2765,42 @@ var setup_default = defineCommand7({
2700
2765
  info(`Found remotes: ${remotes.join(", ")}`);
2701
2766
  let detectedRole = null;
2702
2767
  let detectionSource = "";
2703
- const ghInstalled = await checkGhInstalled();
2704
- if (ghInstalled && await checkGhAuth()) {
2705
- const isFork = await isRepoFork();
2706
- if (isFork === true) {
2707
- detectedRole = "contributor";
2708
- detectionSource = "gh CLI (fork detected)";
2709
- } else if (isFork === false) {
2710
- const repoInfo = await getCurrentRepoInfo();
2711
- if (repoInfo) {
2712
- const perms = await checkRepoPermissions(repoInfo.owner, repoInfo.repo);
2713
- if (perms?.admin || perms?.push) {
2714
- detectedRole = "maintainer";
2715
- detectionSource = "gh CLI (admin/push permissions)";
2768
+ const roleSpinner = createSpinner("Detecting your role...");
2769
+ try {
2770
+ roleSpinner.update("Checking GitHub CLI and auth...");
2771
+ const ghInstalled = await checkGhInstalled();
2772
+ if (ghInstalled && await checkGhAuth()) {
2773
+ roleSpinner.update("Inspecting repository relationship (fork/permissions)...");
2774
+ const isFork = await isRepoFork();
2775
+ if (isFork === true) {
2776
+ detectedRole = "contributor";
2777
+ detectionSource = "gh CLI (fork detected)";
2778
+ } else if (isFork === false) {
2779
+ const repoInfo = await getCurrentRepoInfo();
2780
+ if (repoInfo) {
2781
+ const perms = await checkRepoPermissions(repoInfo.owner, repoInfo.repo);
2782
+ if (perms?.admin || perms?.push) {
2783
+ detectedRole = "maintainer";
2784
+ detectionSource = "gh CLI (admin/push permissions)";
2785
+ }
2716
2786
  }
2717
2787
  }
2718
2788
  }
2719
- }
2720
- if (detectedRole === null) {
2721
- if (remotes.includes("upstream")) {
2722
- detectedRole = "contributor";
2723
- detectionSource = "heuristic (upstream remote exists)";
2724
- } else if (remotes.includes("origin") && remotes.length === 1) {
2725
- detectedRole = "maintainer";
2726
- detectionSource = "heuristic (only origin remote)";
2789
+ if (detectedRole === null) {
2790
+ roleSpinner.update("Analyzing git remotes...");
2791
+ if (remotes.includes("upstream")) {
2792
+ detectedRole = "contributor";
2793
+ detectionSource = "heuristic (upstream remote exists)";
2794
+ } else if (remotes.includes("origin") && remotes.length === 1) {
2795
+ detectedRole = "maintainer";
2796
+ detectionSource = "heuristic (only origin remote)";
2797
+ }
2727
2798
  }
2799
+ roleSpinner.success("Role detection complete.");
2800
+ } catch {
2801
+ roleSpinner.fail("Role detection failed; falling back to manual selection.");
2802
+ detectedRole = null;
2803
+ detectionSource = "";
2728
2804
  }
2729
2805
  if (detectedRole === null) {
2730
2806
  const roleChoice = await selectPrompt("What is your role in this project?", [
@@ -2742,16 +2818,20 @@ var setup_default = defineCommand7({
2742
2818
  }
2743
2819
  }
2744
2820
  const defaultConfig = getDefaultConfig();
2745
- const mainBranch = await inputPrompt("Main branch name", defaultConfig.mainBranch);
2821
+ info(pc10.dim("Tip: press Enter to keep the default branch name shown in each prompt."));
2822
+ const mainBranchDefault = defaultConfig.mainBranch;
2823
+ const mainBranch = await inputPrompt(`Main branch name (default: ${mainBranchDefault} — press Enter to keep)`, mainBranchDefault);
2746
2824
  let devBranch;
2747
2825
  if (hasDevBranch(workflow)) {
2748
2826
  const defaultDev = workflow === "git-flow" ? "develop" : "dev";
2749
- devBranch = await inputPrompt("Dev/develop branch name", defaultDev);
2827
+ devBranch = await inputPrompt(`Dev/develop branch name (default: ${defaultDev} — press Enter to keep)`, defaultDev);
2750
2828
  }
2751
- const originRemote = await inputPrompt("Origin remote name", defaultConfig.origin);
2829
+ const originRemoteDefault = defaultConfig.origin;
2830
+ const originRemote = await inputPrompt(`Origin remote name (default: ${originRemoteDefault} — press Enter to keep)`, originRemoteDefault);
2752
2831
  let upstreamRemote = defaultConfig.upstream;
2753
2832
  if (detectedRole === "contributor") {
2754
- upstreamRemote = await inputPrompt("Upstream remote name", defaultConfig.upstream);
2833
+ const upstreamRemoteDefault = defaultConfig.upstream;
2834
+ upstreamRemote = await inputPrompt(`Upstream remote name (default: ${upstreamRemoteDefault} — press Enter to keep)`, upstreamRemoteDefault);
2755
2835
  if (!remotes.includes(upstreamRemote)) {
2756
2836
  warn(`Remote "${upstreamRemote}" not found.`);
2757
2837
  const originUrl = await getRemoteUrl(originRemote);
@@ -2799,9 +2879,8 @@ var setup_default = defineCommand7({
2799
2879
  warn("Config was saved — verify the branch name and re-run setup if needed.");
2800
2880
  }
2801
2881
  }
2802
- if (!isGitignored()) {
2803
- warn(".contributerc.json is not in .gitignore. Add it to avoid committing personal config.");
2804
- warn(' echo ".contributerc.json" >> .gitignore');
2882
+ if (ensureGitignored()) {
2883
+ info("Added .contributerc.json to .gitignore to avoid committing personal config.");
2805
2884
  }
2806
2885
  console.log();
2807
2886
  info(`Workflow: ${pc10.bold(WORKFLOW_DESCRIPTIONS[config.workflow])}`);
@@ -2815,6 +2894,17 @@ var setup_default = defineCommand7({
2815
2894
  info(`Origin: ${pc10.bold(config.origin)}${config.role === "contributor" ? ` | Upstream: ${pc10.bold(config.upstream)}` : ""}`);
2816
2895
  }
2817
2896
  });
2897
+ function logConfigSummary(config) {
2898
+ info(`Workflow: ${pc10.bold(WORKFLOW_DESCRIPTIONS[config.workflow])}`);
2899
+ info(`Convention: ${pc10.bold(CONVENTION_DESCRIPTIONS[config.commitConvention])}`);
2900
+ info(`Role: ${pc10.bold(config.role)}`);
2901
+ if (config.devBranch) {
2902
+ info(`Main: ${pc10.bold(config.mainBranch)} | Dev: ${pc10.bold(config.devBranch)}`);
2903
+ } else {
2904
+ info(`Main: ${pc10.bold(config.mainBranch)}`);
2905
+ }
2906
+ info(`Origin: ${pc10.bold(config.origin)}${config.role === "contributor" ? ` | Upstream: ${pc10.bold(config.upstream)}` : ""}`);
2907
+ }
2818
2908
 
2819
2909
  // src/commands/start.ts
2820
2910
  import { defineCommand as defineCommand8 } from "citty";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contribute-now",
3
- "version": "0.4.0-dev.c791252",
3
+ "version": "0.4.0-dev.d24b735",
4
4
  "description": "Git workflow CLI for squash-merge two-branch models. Keeps dev in sync with main after squash merges.",
5
5
  "type": "module",
6
6
  "bin": {