complete-cli 1.0.31 → 1.1.0
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/commands/InitCommand.js +3 -0
- package/dist/commands/init/packageManager.js +11 -23
- package/dist/git.js +6 -6
- package/dist/prompt.js +5 -3
- package/package.json +10 -10
- package/src/commands/InitCommand.ts +4 -0
- package/src/commands/init/packageManager.ts +21 -48
- package/src/git.ts +6 -6
- package/src/prompt.ts +5 -3
|
@@ -35,6 +35,9 @@ export class InitCommand extends Command {
|
|
|
35
35
|
pnpm = Option.Boolean("--pnpm", false, {
|
|
36
36
|
description: "Use pnpm as the package manager.",
|
|
37
37
|
});
|
|
38
|
+
bun = Option.Boolean("--bun", false, {
|
|
39
|
+
description: "Use bun as the package manager.",
|
|
40
|
+
});
|
|
38
41
|
skipGit = Option.Boolean("--skip-git", false, {
|
|
39
42
|
description: "Do not initialize Git.",
|
|
40
43
|
});
|
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
import { getEnumValues } from "complete-common";
|
|
2
3
|
import { commandExists, PackageManager } from "complete-node";
|
|
3
4
|
import { DEFAULT_PACKAGE_MANAGER } from "../../constants.js";
|
|
4
5
|
import { promptError } from "../../prompt.js";
|
|
6
|
+
const PACKAGE_MANAGERS = getEnumValues(PackageManager);
|
|
5
7
|
export async function getPackageManagerUsedForNewProject(options) {
|
|
6
8
|
const packageManagerFromOptions = await getPackageManagerFromOptions(options);
|
|
7
|
-
|
|
8
|
-
return packageManagerFromOptions;
|
|
9
|
-
}
|
|
10
|
-
return DEFAULT_PACKAGE_MANAGER;
|
|
9
|
+
return packageManagerFromOptions ?? DEFAULT_PACKAGE_MANAGER;
|
|
11
10
|
}
|
|
12
11
|
async function getPackageManagerFromOptions(options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const yarnExists = await commandExists("yarn");
|
|
22
|
-
if (!yarnExists) {
|
|
23
|
-
promptError(`You specified the "--yarn" option, but "${chalk.green("yarn")}" does not seem to be a valid command.`);
|
|
24
|
-
}
|
|
25
|
-
return PackageManager.yarn;
|
|
26
|
-
}
|
|
27
|
-
if (options.pnpm) {
|
|
28
|
-
const pnpmExists = await commandExists("pnpm");
|
|
29
|
-
if (!pnpmExists) {
|
|
30
|
-
promptError(`You specified the "--pnpm" option, but "${chalk.green("pnpm")}" does not seem to be a valid command.`);
|
|
12
|
+
for (const packageManager of PACKAGE_MANAGERS) {
|
|
13
|
+
if (options[packageManager]) {
|
|
14
|
+
// eslint-disable-next-line no-await-in-loop
|
|
15
|
+
const exists = await commandExists(packageManager);
|
|
16
|
+
if (!exists) {
|
|
17
|
+
promptError(`You specified the "--${packageManager}" option, but "${chalk.green(packageManager)}" does not seem to be a valid command.`);
|
|
18
|
+
}
|
|
19
|
+
return packageManager;
|
|
31
20
|
}
|
|
32
|
-
return PackageManager.pnpm;
|
|
33
21
|
}
|
|
34
22
|
return undefined;
|
|
35
23
|
}
|
package/dist/git.js
CHANGED
|
@@ -119,15 +119,15 @@ export async function initGitRepository(projectPath, gitRemoteURL) {
|
|
|
119
119
|
if (gitRemoteURL === undefined) {
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
const $$ = $q({ cwd: projectPath });
|
|
123
|
-
await $$ `git init --initial-branch main`;
|
|
124
|
-
await $$ `git remote add origin ${gitRemoteURL}`;
|
|
122
|
+
const $$q = $q({ cwd: projectPath });
|
|
123
|
+
await $$q `git init --initial-branch main`;
|
|
124
|
+
await $$q `git remote add origin ${gitRemoteURL}`;
|
|
125
125
|
const gitNameAndEmailConfigured = await isGitNameAndEmailConfigured();
|
|
126
126
|
if (gitNameAndEmailConfigured) {
|
|
127
|
-
await $$ `git add --all`;
|
|
127
|
+
await $$q `git add --all`;
|
|
128
128
|
const commitMessage = `chore: add files from ${PROJECT_NAME} ${PROJECT_VERSION} template`;
|
|
129
|
-
await $$ `git commit --message ${commitMessage}`;
|
|
130
|
-
await $$ `git push --set-upstream origin main`;
|
|
129
|
+
await $$q `git commit --message ${commitMessage}`;
|
|
130
|
+
await $$q `git push --set-upstream origin main`;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
async function isGitNameAndEmailConfigured() {
|
package/dist/prompt.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Both the Inquirer.js library and the Prompts library have a bug where text is duplicated in a Git
|
|
2
2
|
// Bash terminal. Thus, we revert to using the simpler Prompt library.
|
|
3
|
-
import { cancel, confirm, intro, isCancel, log, outro, spinner, text, } from "@clack
|
|
3
|
+
import { cancel, confirm, intro, isCancel, log, outro, spinner, text, } from "@zamiell/clack-prompts";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { PROJECT_NAME } from "./constants.js";
|
|
6
6
|
export function promptStart() {
|
|
@@ -31,8 +31,10 @@ export async function getInputString(msg, defaultValue) {
|
|
|
31
31
|
cancel("Canceled.");
|
|
32
32
|
process.exit(1);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// The "text" return type is bugged: "input" is equal to "undefined" if the user did not enter any
|
|
35
|
+
// input.
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
37
|
+
if (input === undefined || input.trim() === "") {
|
|
36
38
|
promptError("You must enter a non-empty value.");
|
|
37
39
|
}
|
|
38
40
|
return input.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A command line tool for bootstrapping TypeScript projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -34,23 +34,23 @@
|
|
|
34
34
|
"test": "glob \"./src/**/*.test.ts\" --cmd=\"node --import tsx --test --test-reporter spec\""
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@clack
|
|
37
|
+
"@zamiell/clack-prompts": "0.10.2",
|
|
38
38
|
"chalk": "5.4.1",
|
|
39
39
|
"clipanion": "4.0.0-rc.4",
|
|
40
|
-
"complete-common": "1.
|
|
41
|
-
"complete-node": "5.1.
|
|
42
|
-
"klaw-sync": "
|
|
43
|
-
"yaml": "2.7.
|
|
40
|
+
"complete-common": "2.1.0",
|
|
41
|
+
"complete-node": "5.1.2",
|
|
42
|
+
"klaw-sync": "7.0.0",
|
|
43
|
+
"yaml": "2.7.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/klaw-sync": "6.0.5",
|
|
47
|
-
"@types/node": "22.
|
|
47
|
+
"@types/node": "22.14.1",
|
|
48
48
|
"glob": "11.0.1",
|
|
49
49
|
"ts-loader": "9.5.2",
|
|
50
50
|
"tsconfig-paths-webpack-plugin": "4.2.0",
|
|
51
|
-
"typescript": "5.8.
|
|
52
|
-
"typescript-eslint": "8.
|
|
53
|
-
"webpack": "5.
|
|
51
|
+
"typescript": "5.8.3",
|
|
52
|
+
"typescript-eslint": "8.30.1",
|
|
53
|
+
"webpack": "5.99.6",
|
|
54
54
|
"webpack-cli": "6.0.1",
|
|
55
55
|
"webpack-shebang-plugin": "1.1.8"
|
|
56
56
|
},
|
|
@@ -47,6 +47,10 @@ export class InitCommand extends Command {
|
|
|
47
47
|
description: "Use pnpm as the package manager.",
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
bun = Option.Boolean("--bun", false, {
|
|
51
|
+
description: "Use bun as the package manager.",
|
|
52
|
+
});
|
|
53
|
+
|
|
50
54
|
skipGit = Option.Boolean("--skip-git", false, {
|
|
51
55
|
description: "Do not initialize Git.",
|
|
52
56
|
});
|
|
@@ -1,63 +1,36 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
import type { ReadonlyRecord } from "complete-common";
|
|
3
|
+
import { getEnumValues } from "complete-common";
|
|
2
4
|
import { commandExists, PackageManager } from "complete-node";
|
|
3
5
|
import { DEFAULT_PACKAGE_MANAGER } from "../../constants.js";
|
|
4
6
|
import { promptError } from "../../prompt.js";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
npm: boolean;
|
|
8
|
-
yarn: boolean;
|
|
9
|
-
pnpm: boolean;
|
|
10
|
-
}
|
|
8
|
+
const PACKAGE_MANAGERS = getEnumValues(PackageManager);
|
|
11
9
|
|
|
12
10
|
export async function getPackageManagerUsedForNewProject(
|
|
13
|
-
options:
|
|
11
|
+
options: ReadonlyRecord<PackageManager, boolean>,
|
|
14
12
|
): Promise<PackageManager> {
|
|
15
13
|
const packageManagerFromOptions = await getPackageManagerFromOptions(options);
|
|
16
|
-
|
|
17
|
-
return packageManagerFromOptions;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return DEFAULT_PACKAGE_MANAGER;
|
|
14
|
+
return packageManagerFromOptions ?? DEFAULT_PACKAGE_MANAGER;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
async function getPackageManagerFromOptions(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!yarnExists) {
|
|
40
|
-
promptError(
|
|
41
|
-
`You specified the "--yarn" option, but "${chalk.green(
|
|
42
|
-
"yarn",
|
|
43
|
-
)}" does not seem to be a valid command.`,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return PackageManager.yarn;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (options.pnpm) {
|
|
51
|
-
const pnpmExists = await commandExists("pnpm");
|
|
52
|
-
if (!pnpmExists) {
|
|
53
|
-
promptError(
|
|
54
|
-
`You specified the "--pnpm" option, but "${chalk.green(
|
|
55
|
-
"pnpm",
|
|
56
|
-
)}" does not seem to be a valid command.`,
|
|
57
|
-
);
|
|
17
|
+
async function getPackageManagerFromOptions(
|
|
18
|
+
options: ReadonlyRecord<PackageManager, boolean>,
|
|
19
|
+
) {
|
|
20
|
+
for (const packageManager of PACKAGE_MANAGERS) {
|
|
21
|
+
if (options[packageManager]) {
|
|
22
|
+
// eslint-disable-next-line no-await-in-loop
|
|
23
|
+
const exists = await commandExists(packageManager);
|
|
24
|
+
if (!exists) {
|
|
25
|
+
promptError(
|
|
26
|
+
`You specified the "--${packageManager}" option, but "${chalk.green(
|
|
27
|
+
packageManager,
|
|
28
|
+
)}" does not seem to be a valid command.`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return packageManager;
|
|
58
33
|
}
|
|
59
|
-
|
|
60
|
-
return PackageManager.pnpm;
|
|
61
34
|
}
|
|
62
35
|
|
|
63
36
|
return undefined;
|
package/src/git.ts
CHANGED
|
@@ -163,17 +163,17 @@ export async function initGitRepository(
|
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
const $$ = $q({ cwd: projectPath });
|
|
166
|
+
const $$q = $q({ cwd: projectPath });
|
|
167
167
|
|
|
168
|
-
await
|
|
169
|
-
await
|
|
168
|
+
await $$q`git init --initial-branch main`;
|
|
169
|
+
await $$q`git remote add origin ${gitRemoteURL}`;
|
|
170
170
|
|
|
171
171
|
const gitNameAndEmailConfigured = await isGitNameAndEmailConfigured();
|
|
172
172
|
if (gitNameAndEmailConfigured) {
|
|
173
|
-
await
|
|
173
|
+
await $$q`git add --all`;
|
|
174
174
|
const commitMessage = `chore: add files from ${PROJECT_NAME} ${PROJECT_VERSION} template`;
|
|
175
|
-
await
|
|
176
|
-
await
|
|
175
|
+
await $$q`git commit --message ${commitMessage}`;
|
|
176
|
+
await $$q`git push --set-upstream origin main`;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
package/src/prompt.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
outro,
|
|
11
11
|
spinner,
|
|
12
12
|
text,
|
|
13
|
-
} from "@clack
|
|
13
|
+
} from "@zamiell/clack-prompts";
|
|
14
14
|
import chalk from "chalk";
|
|
15
15
|
import { PROJECT_NAME } from "./constants.js";
|
|
16
16
|
|
|
@@ -55,8 +55,10 @@ export async function getInputString(
|
|
|
55
55
|
process.exit(1);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// The "text" return type is bugged: "input" is equal to "undefined" if the user did not enter any
|
|
59
|
+
// input.
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
61
|
+
if (input === undefined || input.trim() === "") {
|
|
60
62
|
promptError("You must enter a non-empty value.");
|
|
61
63
|
}
|
|
62
64
|
|