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.
- package/dist/git.js +46 -41
- package/package.json +1 -1
- package/src/git.ts +55 -56
package/dist/git.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
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
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
return getGitRemoteURL(projectName, gitHubUsername);
|
|
85
|
+
promptLog(`Using a Git remote URL of: ${chalk.green(guessedRemoteURL)}`);
|
|
86
|
+
return guessedRemoteURL;
|
|
86
87
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
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
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
${chalk.green(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
package/src/git.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
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
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
|
123
|
-
`
|
|
124
|
-
|
|
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 (
|
|
128
|
-
|
|
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
|
|
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
|
-
|
|
139
|
-
await
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
|
183
|
-
const { exitCode: emailExitCode } = await
|
|
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
|
}
|