Skip to content

Commit 40a905b

Browse files
committed
chore: tweaks > bun.lock package.json clone.ts index.ts
bun.lock package.json src/commands/clone.ts src/index.ts
1 parent 0e7f76c commit 40a905b

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

bun.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"": {
55
"name": "gitpick",
66
"dependencies": {
7+
"@clack/prompts": "^0.10.0",
78
"chalk": "^5.4.1",
89
"commander": "^13.1.0",
910
"inquirer": "^12.5.0",
@@ -44,6 +45,10 @@
4445

4546
"@babel/types": ["@babel/types@7.26.7", "", { "dependencies": { "@babel/helper-string-parser": "^7.25.9", "@babel/helper-validator-identifier": "^7.25.9" } }, "sha512-t8kDRGrKXyp6+tjUh7hw2RLyclsW4TRoRvRHtSyAX9Bb5ldlFh+90YAYY6awRXrlB4G5G2izNeGySpATlFzmOg=="],
4647

48+
"@clack/core": ["@clack/core@0.4.1", "", { "dependencies": { "picocolors": "^1.0.0", "sisteransi": "^1.0.5" } }, "sha512-Pxhij4UXg8KSr7rPek6Zowm+5M22rbd2g1nfojHJkxp5YkFqiZ2+YLEM/XGVIzvGOcM0nqjIFxrpDwWRZYWYjA=="],
49+
50+
"@clack/prompts": ["@clack/prompts@0.10.0", "", { "dependencies": { "@clack/core": "0.4.1", "picocolors": "^1.0.0", "sisteransi": "^1.0.5" } }, "sha512-H3rCl6CwW1NdQt9rE3n373t7o5cthPv7yUoxF2ytZvyvlJv89C5RYMJu83Hed8ODgys5vpBU0GKxIRG83jd8NQ=="],
51+
4752
"@commitlint/cli": ["@commitlint/cli@19.8.0", "", { "dependencies": { "@commitlint/format": "^19.8.0", "@commitlint/lint": "^19.8.0", "@commitlint/load": "^19.8.0", "@commitlint/read": "^19.8.0", "@commitlint/types": "^19.8.0", "tinyexec": "^0.3.0", "yargs": "^17.0.0" }, "bin": { "commitlint": "./cli.js" } }, "sha512-t/fCrLVu+Ru01h0DtlgHZXbHV2Y8gKocTR5elDOqIRUzQd0/6hpt2VIWOj9b3NDo7y4/gfxeR2zRtXq/qO6iUg=="],
4853

4954
"@commitlint/config-conventional": ["@commitlint/config-conventional@19.8.0", "", { "dependencies": { "@commitlint/types": "^19.8.0", "conventional-changelog-conventionalcommits": "^7.0.2" } }, "sha512-9I2kKJwcAPwMoAj38hwqFXG0CzS2Kj+SAByPUQ0SlHTfb7VUhYVmo7G2w2tBrqmOf7PFd6MpZ/a1GQJo8na8kw=="],
@@ -536,6 +541,8 @@
536541

537542
"simple-git-hooks": ["simple-git-hooks@2.12.1", "", { "bin": { "simple-git-hooks": "cli.js" } }, "sha512-NB3V4XyCOrWTIhjh85DyEoVlM3adHWwqQXKYHmuegy/108bJPP6YxuPGm4ZKBq1+GVKRbKJuzNY//09cMJYp+A=="],
538543

544+
"sisteransi": ["sisteransi@1.0.5", "", {}, "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="],
545+
539546
"slice-ansi": ["slice-ansi@5.0.0", "", { "dependencies": { "ansi-styles": "^6.0.0", "is-fullwidth-code-point": "^4.0.0" } }, "sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ=="],
540547

541548
"sort-object-keys": ["sort-object-keys@1.1.3", "", {}, "sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg=="],

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444
"commit-msg": "npx commitlint --edit $1"
4545
},
4646
"dependencies": {
47+
"@clack/prompts": "^0.10.0",
4748
"chalk": "^5.4.1",
4849
"commander": "^13.1.0",
49-
"inquirer": "^12.5.0",
50-
"ora": "^8.2.0",
5150
"simple-git": "^3.27.0",
5251
"terminal-link": "^4.0.0",
5352
"zod": "^3.24.2",

src/commands/clone.ts

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import os from "os"
33
import path from "path"
44
import { parseTimeString } from "@/utils/parse-time-string"
55
import { githubConfigFromUrl } from "@/utils/transform-url"
6+
import { cancel, confirm, intro, isCancel, log, spinner } from "@clack/prompts"
67
import chalk from "chalk"
78
import { Command } from "commander"
8-
import inquirer from "inquirer"
9-
import ora, { Ora } from "ora"
109
import simpleGit from "simple-git"
1110
import { z } from "zod"
1211
import { fromError } from "zod-validation-error"
@@ -42,10 +41,13 @@ export const clone = new Command()
4241
url,
4342
target,
4443
branch: options.branch,
45-
overwrite: options.overwrite || options.force,
44+
overwrite: options.overwrite,
45+
force: options.force,
4646
watch: options.watch,
4747
})
4848

49+
options.overwrite = options.overwrite || options.force
50+
4951
if (options.watch) {
5052
if (typeof options.watch === "boolean") options.watch = "1m"
5153

@@ -59,7 +61,7 @@ export const clone = new Command()
5961
target,
6062
})
6163

62-
console.log(
64+
intro(
6365
`${chalk.bold(config.owner)}/${chalk.bold(config.repository)} ${chalk.green(
6466
`<${config.type}:${config.branch}>`,
6567
)} ${
@@ -73,14 +75,9 @@ export const clone = new Command()
7375
}`,
7476
)}`
7577
}`,
76-
"\n",
7778
)
7879

79-
const spinner = ora().start()
80-
8180
try {
82-
spinner.stop()
83-
8481
const targetPath = path.resolve(config.target)
8582

8683
if (options.watch) options.overwrite = true
@@ -100,44 +97,44 @@ export const clone = new Command()
10097
? "The target directory is not empty. Do you want to overwrite the files?"
10198
: "The target file already exists. Do you want to overwrite the file?"
10299

103-
const { overwrite } = await inquirer.prompt([
104-
{
105-
type: "confirm",
106-
name: "overwrite",
107-
message,
108-
default: false,
109-
},
110-
])
100+
const overwrite = await confirm({
101+
message,
102+
})
103+
104+
if (isCancel(overwrite)) {
105+
cancel("Operation cancelled.")
106+
process.exit(0)
107+
}
111108

112109
if (!overwrite) {
113-
throw new Error("Chose not to overwrite files")
110+
log.info("Chose not to overwrite files.")
111+
process.exit(0)
114112
}
115113

116-
spinner.info(
117-
"You can use -o | --overwrite or -f | --force flag to skip this prompt",
114+
log.info(
115+
"You can use -o | --overwrite or -f | --force flag to skip this prompt next time.",
118116
)
119117
}
120118

121-
await cloneAction(spinner, config, options, targetPath)
119+
await cloneAction(config, options, targetPath)
122120

123121
if (options.watch) {
124122
const watchInterval = parseTimeString(options.watch)
125123
setInterval(
126-
async () => await cloneAction(spinner, config, options, targetPath),
124+
async () => await cloneAction(config, options, targetPath),
127125
watchInterval,
128126
)
129127
}
130128
} catch (err) {
131-
console.log("\n")
132-
spinner.fail("Level 1: An error occurred")
129+
log.error("Level 1: An error occurred")
133130

134131
if (err instanceof z.ZodError) {
135132
const validationError = fromError(err)
136-
console.error("\nValidation Error: " + validationError.toString())
133+
log.error("Validation Error: " + validationError.toString())
137134
} else if (err instanceof Error) {
138-
console.error("\nError: " + err.message)
135+
log.error("Error: " + err.message)
139136
} else {
140-
console.error("\nUnexpected Error: " + JSON.stringify(err, null, 2))
137+
log.error("Unexpected Error: " + JSON.stringify(err, null, 2))
141138
}
142139

143140
process.exit(1)
@@ -163,7 +160,6 @@ async function copyDir(src: string, dest: string) {
163160
}
164161

165162
const cloneAction = async (
166-
spinner: Ora,
167163
config: {
168164
token: string
169165
owner: string
@@ -177,7 +173,11 @@ const cloneAction = async (
177173
},
178174
targetPath: string,
179175
) => {
176+
const s = spinner()
177+
180178
try {
179+
const start = performance.now()
180+
181181
const git = simpleGit()
182182

183183
if (process.platform === "win32") {
@@ -191,7 +191,7 @@ const cloneAction = async (
191191
)
192192

193193
if (!options.watch)
194-
spinner.start(
194+
s.start(
195195
`Picking ${config.type}${config.type === "repository" ? " without .git" : " from repository"}`,
196196
)
197197

@@ -206,6 +206,7 @@ const cloneAction = async (
206206
const sourcePath = path.join(tempDir, config.path)
207207

208208
const sourceStat = await fs.promises.stat(sourcePath)
209+
209210
if (sourceStat.isDirectory()) {
210211
await fs.promises.mkdir(targetPath, { recursive: true })
211212
await copyDir(sourcePath, targetPath)
@@ -218,21 +219,24 @@ const cloneAction = async (
218219
targetPath + "/" + config.path.split("/").pop(),
219220
)
220221
}
222+
221223
if (!options.watch) {
222-
spinner.succeed(
223-
`Picked ${config.type}${config.type === "repository" ? " without .git!" : " from repository!"}`,
224+
s.stop(
225+
`Picked ${config.type}${config.type === "repository" ? " without .git!" : " from repository"} in ${(
226+
(performance.now() - start) /
227+
1000
228+
).toFixed(2)} seconds!`,
224229
)
225-
} else spinner.succeed("Synced at " + new Date().toLocaleTimeString())
230+
} else log.success("Synced at " + new Date().toLocaleTimeString())
226231

227232
await fs.promises.rm(tempDir, { recursive: true, force: true })
228233
} catch (err) {
229-
console.log("\n")
230-
spinner.fail("Level 2: An error occurred!")
234+
s.stop("Level 2: An error occurred while cloning!")
231235

232236
if (err instanceof Error) {
233-
console.error("\nError: " + err.message)
237+
log.error("Error: " + err.message)
234238
} else {
235-
console.error("\nUnexpected Error: " + JSON.stringify(err, null, 2))
239+
log.error("Unexpected Error: " + JSON.stringify(err, null, 2))
236240
}
237241

238242
process.exit(1)

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ ${chalk.bold("Examples:")}
6161
})
6262

6363
console.log(
64-
chalk.dim(
65-
`\n${terminalLink("GitPick ↗️ ", "https://github.com/nrjdalal/gitpick")} - Clone specific directories or files from GitHub!\n`,
66-
),
64+
`\n${terminalLink("GitPick ↗️ ", "https://github.com/nrjdalal/gitpick")} - Clone specific directories or files from GitHub!\n`,
6765
)
6866

6967
program.parse()

0 commit comments

Comments
 (0)