complete-cli 1.0.19 → 1.0.20

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 (3) hide show
  1. package/dist/git.js +46 -41
  2. package/package.json +1 -1
  3. package/src/git.ts +55 -56
package/dist/git.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from "chalk";
2
- import { $, commandExists, isFileAsync, readFileAsync } from "complete-node";
2
+ import { $q, commandExists, isFileAsync, readFileAsync } from "complete-node";
3
3
  import path from "node:path";
4
4
  import yaml from "yaml";
5
5
  import { HOME_DIR, PROJECT_NAME, PROJECT_VERSION } from "./constants.js";
@@ -60,48 +60,53 @@ export async function promptGitHubRepoOrGitRemoteURL(projectName, yes, skipGit)
60
60
  return undefined;
61
61
  }
62
62
  const gitHubUsername = await getGitHubUsername();
63
- if (gitHubUsername !== undefined) {
64
- const { exitCode } = await $ `gh repo view ${projectName}`;
65
- const gitHubRepoExists = exitCode === 0;
66
- const url = `https://github.com/${gitHubUsername}/${projectName}`;
67
- if (gitHubRepoExists) {
68
- promptLog(`Detected an existing GitHub repository at: ${chalk.green(url)}`);
69
- const guessedRemoteURL = getGitRemoteURL(projectName, gitHubUsername);
70
- if (yes) {
71
- promptLog(`Using a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
72
- return guessedRemoteURL;
73
- }
74
- const shouldUseGuessedURL = await getInputYesNo(`Do you want to use a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
75
- if (shouldUseGuessedURL) {
76
- return guessedRemoteURL;
77
- }
78
- // Assume that since they do not want to connect this project to the existing GitHub
79
- // repository, they do not want to initialize a remote Git URL at all.
80
- return undefined;
81
- }
63
+ if (gitHubUsername === undefined) {
64
+ const gitRemoteURL = await getInputString(`Paste in the remote Git URL for your project.
65
+ For example, if you have an SSH key, it would be something like:
66
+ ${chalk.green("git@github.com:Alice/green-candle.git")}
67
+ If you do not have an SSH key, it would be something like:
68
+ ${chalk.green("https://github.com/Alice/green-candle.git")}
69
+ If you do not want to initialize a Git repository for this project, press enter to skip.
70
+ `);
71
+ return gitRemoteURL === "" ? undefined : gitRemoteURL;
72
+ }
73
+ const url = `https://github.com/${gitHubUsername}/${projectName}`;
74
+ let gitHubRepositoryExists = true;
75
+ try {
76
+ await $q `gh repo view ${projectName}`;
77
+ }
78
+ catch {
79
+ gitHubRepositoryExists = false;
80
+ }
81
+ if (gitHubRepositoryExists) {
82
+ promptLog(`Detected an existing GitHub repository at: ${chalk.green(url)}`);
83
+ const guessedRemoteURL = getGitRemoteURL(projectName, gitHubUsername);
82
84
  if (yes) {
83
- await $ `gh repo create ${projectName} --public`;
84
- promptLog(`Created a new GitHub repository at: ${chalk.green(url)}`);
85
- return getGitRemoteURL(projectName, gitHubUsername);
85
+ promptLog(`Using a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
86
+ return guessedRemoteURL;
86
87
  }
87
- const createNewGitHubRepo = await getInputYesNo(`Would you like to create a new GitHub repository at: ${chalk.green(url)}`);
88
- if (createNewGitHubRepo) {
89
- await $ `gh repo create ${projectName} --public`;
90
- promptLog("Successfully created a new GitHub repository.");
91
- return getGitRemoteURL(projectName, gitHubUsername);
88
+ const shouldUseGuessedURL = await getInputYesNo(`Do you want to use a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
89
+ if (shouldUseGuessedURL) {
90
+ return guessedRemoteURL;
92
91
  }
93
- // Assume that since they do not want to create a new GitHub repository, they do not want to
94
- // initialize a remote Git URL at all.
92
+ // Assume that since they do not want to connect this project to the existing GitHub repository,
93
+ // they do not want to initialize a remote Git URL at all.
95
94
  return undefined;
96
95
  }
97
- const gitRemoteURL = await getInputString(`Paste in the remote Git URL for your project.
98
- For example, if you have an SSH key, it would be something like:
99
- ${chalk.green("git@github.com:Alice/green-candle.git")}
100
- If you don't have an SSH key, it would be something like:
101
- ${chalk.green("https://github.com/Alice/green-candle.git")}
102
- If you don't want to initialize a Git repository for this project, press enter to skip.
103
- `);
104
- return gitRemoteURL === "" ? undefined : gitRemoteURL;
96
+ if (yes) {
97
+ await $q `gh repo create ${projectName} --public`;
98
+ promptLog(`Created a new GitHub repository at: ${chalk.green(url)}`);
99
+ return getGitRemoteURL(projectName, gitHubUsername);
100
+ }
101
+ const createNewGitHubRepo = await getInputYesNo(`Would you like to create a new GitHub repository at: ${chalk.green(url)}`);
102
+ if (createNewGitHubRepo) {
103
+ await $q `gh repo create ${projectName} --public`;
104
+ promptLog("Successfully created a new GitHub repository.");
105
+ return getGitRemoteURL(projectName, gitHubUsername);
106
+ }
107
+ // Assume that since they do not want to create a new GitHub repository, they do not want to
108
+ // initialize a remote Git URL at all.
109
+ return undefined;
105
110
  }
106
111
  function getGitRemoteURL(projectName, gitHubUsername) {
107
112
  return `git@github.com:${gitHubUsername}/${projectName}.git`;
@@ -114,7 +119,7 @@ export async function initGitRepository(projectPath, gitRemoteURL) {
114
119
  if (gitRemoteURL === undefined) {
115
120
  return;
116
121
  }
117
- const $$ = $({ cwd: projectPath });
122
+ const $$ = $q({ cwd: projectPath });
118
123
  await $$ `git init --initial-branch main`;
119
124
  await $$ `git remote add origin ${gitRemoteURL}`;
120
125
  const gitNameAndEmailConfigured = await isGitNameAndEmailConfigured();
@@ -126,7 +131,7 @@ export async function initGitRepository(projectPath, gitRemoteURL) {
126
131
  }
127
132
  }
128
133
  async function isGitNameAndEmailConfigured() {
129
- const { exitCode: nameExitCode } = await $ `git config --global user.name`;
130
- const { exitCode: emailExitCode } = await $ `git config --global user.email`;
134
+ const { exitCode: nameExitCode } = await $q `git config --global user.name`;
135
+ const { exitCode: emailExitCode } = await $q `git config --global user.email`;
131
136
  return nameExitCode === 0 && emailExitCode === 0;
132
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "complete-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "A command line tool for bootstrapping TypeScript projects.",
5
5
  "keywords": [
6
6
  "typescript"
package/src/git.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from "chalk";
2
- import { $, commandExists, isFileAsync, readFileAsync } from "complete-node";
2
+ import { $q, commandExists, isFileAsync, readFileAsync } from "complete-node";
3
3
  import path from "node:path";
4
4
  import yaml from "yaml";
5
5
  import { HOME_DIR, PROJECT_NAME, PROJECT_VERSION } from "./constants.js";
@@ -81,70 +81,69 @@ export async function promptGitHubRepoOrGitRemoteURL(
81
81
  }
82
82
 
83
83
  const gitHubUsername = await getGitHubUsername();
84
- if (gitHubUsername !== undefined) {
85
- const { exitCode } = await $`gh repo view ${projectName}`;
86
- const gitHubRepoExists = exitCode === 0;
87
- const url = `https://github.com/${gitHubUsername}/${projectName}`;
88
-
89
- if (gitHubRepoExists) {
90
- promptLog(
91
- `Detected an existing GitHub repository at: ${chalk.green(url)}`,
92
- );
93
- const guessedRemoteURL = getGitRemoteURL(projectName, gitHubUsername);
94
-
95
- if (yes) {
96
- promptLog(
97
- `Using a Git remote URL of: ${chalk.green(guessedRemoteURL)}`,
98
- );
99
- return guessedRemoteURL;
100
- }
101
-
102
- const shouldUseGuessedURL = await getInputYesNo(
103
- `Do you want to use a Git remote URL of: ${chalk.green(
104
- guessedRemoteURL,
105
- )}`,
106
- );
107
- if (shouldUseGuessedURL) {
108
- return guessedRemoteURL;
109
- }
110
-
111
- // Assume that since they do not want to connect this project to the existing GitHub
112
- // repository, they do not want to initialize a remote Git URL at all.
113
- return undefined;
114
- }
84
+ if (gitHubUsername === undefined) {
85
+ const gitRemoteURL =
86
+ await getInputString(`Paste in the remote Git URL for your project.
87
+ For example, if you have an SSH key, it would be something like:
88
+ ${chalk.green("git@github.com:Alice/green-candle.git")}
89
+ If you do not have an SSH key, it would be something like:
90
+ ${chalk.green("https://github.com/Alice/green-candle.git")}
91
+ If you do not want to initialize a Git repository for this project, press enter to skip.
92
+ `);
93
+
94
+ return gitRemoteURL === "" ? undefined : gitRemoteURL;
95
+ }
96
+
97
+ const url = `https://github.com/${gitHubUsername}/${projectName}`;
98
+
99
+ let gitHubRepositoryExists = true;
100
+ try {
101
+ await $q`gh repo view ${projectName}`;
102
+ } catch {
103
+ gitHubRepositoryExists = false;
104
+ }
105
+
106
+ if (gitHubRepositoryExists) {
107
+ promptLog(`Detected an existing GitHub repository at: ${chalk.green(url)}`);
108
+ const guessedRemoteURL = getGitRemoteURL(projectName, gitHubUsername);
115
109
 
116
110
  if (yes) {
117
- await $`gh repo create ${projectName} --public`;
118
- promptLog(`Created a new GitHub repository at: ${chalk.green(url)}`);
119
- return getGitRemoteURL(projectName, gitHubUsername);
111
+ promptLog(`Using a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
112
+ return guessedRemoteURL;
120
113
  }
121
114
 
122
- const createNewGitHubRepo = await getInputYesNo(
123
- `Would you like to create a new GitHub repository at: ${chalk.green(
124
- url,
115
+ const shouldUseGuessedURL = await getInputYesNo(
116
+ `Do you want to use a Git remote URL of: ${chalk.green(
117
+ guessedRemoteURL,
125
118
  )}`,
126
119
  );
127
- if (createNewGitHubRepo) {
128
- await $`gh repo create ${projectName} --public`;
129
- promptLog("Successfully created a new GitHub repository.");
130
- return getGitRemoteURL(projectName, gitHubUsername);
120
+ if (shouldUseGuessedURL) {
121
+ return guessedRemoteURL;
131
122
  }
132
123
 
133
- // Assume that since they do not want to create a new GitHub repository, they do not want to
134
- // initialize a remote Git URL at all.
124
+ // Assume that since they do not want to connect this project to the existing GitHub repository,
125
+ // they do not want to initialize a remote Git URL at all.
135
126
  return undefined;
136
127
  }
137
128
 
138
- const gitRemoteURL =
139
- await getInputString(`Paste in the remote Git URL for your project.
140
- For example, if you have an SSH key, it would be something like:
141
- ${chalk.green("git@github.com:Alice/green-candle.git")}
142
- If you don't have an SSH key, it would be something like:
143
- ${chalk.green("https://github.com/Alice/green-candle.git")}
144
- If you don't want to initialize a Git repository for this project, press enter to skip.
145
- `);
129
+ if (yes) {
130
+ await $q`gh repo create ${projectName} --public`;
131
+ promptLog(`Created a new GitHub repository at: ${chalk.green(url)}`);
132
+ return getGitRemoteURL(projectName, gitHubUsername);
133
+ }
134
+
135
+ const createNewGitHubRepo = await getInputYesNo(
136
+ `Would you like to create a new GitHub repository at: ${chalk.green(url)}`,
137
+ );
138
+ if (createNewGitHubRepo) {
139
+ await $q`gh repo create ${projectName} --public`;
140
+ promptLog("Successfully created a new GitHub repository.");
141
+ return getGitRemoteURL(projectName, gitHubUsername);
142
+ }
146
143
 
147
- return gitRemoteURL === "" ? undefined : gitRemoteURL;
144
+ // Assume that since they do not want to create a new GitHub repository, they do not want to
145
+ // initialize a remote Git URL at all.
146
+ return undefined;
148
147
  }
149
148
 
150
149
  function getGitRemoteURL(projectName: string, gitHubUsername: string) {
@@ -164,7 +163,7 @@ export async function initGitRepository(
164
163
  return;
165
164
  }
166
165
 
167
- const $$ = $({ cwd: projectPath });
166
+ const $$ = $q({ cwd: projectPath });
168
167
 
169
168
  await $$`git init --initial-branch main`;
170
169
  await $$`git remote add origin ${gitRemoteURL}`;
@@ -179,8 +178,8 @@ export async function initGitRepository(
179
178
  }
180
179
 
181
180
  async function isGitNameAndEmailConfigured(): Promise<boolean> {
182
- const { exitCode: nameExitCode } = await $`git config --global user.name`;
183
- const { exitCode: emailExitCode } = await $`git config --global user.email`;
181
+ const { exitCode: nameExitCode } = await $q`git config --global user.name`;
182
+ const { exitCode: emailExitCode } = await $q`git config --global user.email`;
184
183
 
185
184
  return nameExitCode === 0 && emailExitCode === 0;
186
185
  }