Skip to content

Commit

Permalink
🐳 chore: 优化了log提示
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuuuuyu committed Jul 25, 2024
1 parent 1f78436 commit c40db94
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-cleaned",
"version": "1.0.21",
"version": "1.0.26",
"private": false,
"description": "",
"main": "./dist/vite-plugin-cleaned.umd.js",
Expand All @@ -15,8 +15,7 @@
}
},
"scripts": {
"build": "vite build",
"publish:patch": "npm version patch && npm publish --access public"
"build": "vite build"
},
"files": [
"dist",
Expand Down Expand Up @@ -50,12 +49,9 @@
"vite-plugin-dts": "4.0.0-beta.1",
"vite-plugin-node-polyfills": "^0.22.0"
},
"bundledDependencies": [
"ora",
"chalk"
],
"peerDependencies": {
"ora": "^5.0.0",
"chalk": "^4.0.0"
"chalk": "^4.0.0",
"fs-extra": "^11.2.0"
}
}
}
29 changes: 20 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,42 @@ export default function vitePluginClean(options: PluginOptions = {}): Plugin {
)
}
const folders = typeof folder === "string" ? [folder] : folder
let spinner = ora("Loading...")
let spinner = ora()

return {
name: "vite-plugin-cleaned",
enforce: "pre",
async buildStart() {
log(
chalk.blue("\n[vite:cleaned]"),
chalk.green(`Start cleaning: ${folders.join(", ")}`)
chalk.green(`Start cleaning: [${folders}]`)
)
spinner = ora("Loading...").start()

for (const folder of folders) {
const folderPath = path.resolve(process.cwd(), folder)
await deleteFolderRecursive(folderPath)
try {
for (const folder of folders) {
const folderPath = path.resolve(process.cwd(), folder)
spinner.text = `Deleting ${folderPath}...`
await deleteFolderRecursive(folderPath)

spinner.succeed(`Deleted: ${folderPath}`)
spinner.start()
}
spinner.succeed(`Cleaned ${folders.length} folders!`)
spinner.stop()

log(
chalk.blue("\n[vite:cleaned]"),
chalk.green.bold(`Successfully deleted: ${folderPath}`)
chalk.blue("[vite:cleaned]"),
chalk.green("Completed successfully!")
)
} catch (error: any) {
spinner.fail("Cleaning failed!") // 失败时更新 spinner 状态
log(chalk.red(`Error: ${error.message}`)) // 记录错误信息
}
if (hooks.buildStart) {
await hooks.buildStart()
}
},
closeBundle() {
spinner.stop()
if (hooks.closeBundle) {
hooks.closeBundle()
}
Expand Down
5 changes: 1 addition & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import vitePluginClean from "./src/index"
import { nodePolyfills } from "vite-plugin-node-polyfills"

export default defineConfig({
// optimizeDeps: {
// include: ["fs-extra", "ora", "path"],
// },
plugins: [
vitePluginClean({
folder: "dist",
folder: ["dist", "dist-types"],
}),
dts({
entryRoot: "src",
Expand Down

0 comments on commit c40db94

Please sign in to comment.