Skip to content

Commit

Permalink
refactor: replace fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 9, 2024
1 parent 1267166 commit 831d214
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 48 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@
"dependencies": {
"commander": "^12.0.0",
"execa": "^8.0.1",
"fs-extra": "^11.2.0",
"picocolors": "^1.0.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@jest/types": "^29.6.3",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.17",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
42 changes: 1 addition & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { fileURLToPath } from "node:url";

import { Command, Option } from "commander";
import { execa } from "execa";
import { copy, ensureFile, remove } from "fs-extra";
import { readdir, readFile } from "fs/promises";
import { existsSync } from "node:fs";
import { readdir, readFile, cp, rm, mkdir, writeFile } from "node:fs/promises";
import { Logger } from "./log.js";

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -47,7 +47,7 @@ const main = async () => {

logger.group(`Copying \`${STARTER}\``);
const [voidd, pm] = await Promise.all([

Check warning on line 49 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint

'voidd' is assigned a value but never used
copy(STARTER_DIR, initOptions.blogPath)
cp(STARTER_DIR, initOptions.blogPath)
.then(() => {
logger.log(`Copied \`${STARTER}\` to "${initOptions.blogPath}"`);
})
Expand Down Expand Up @@ -216,7 +216,7 @@ const post = () => {

RM_FILES.forEach((item) => {
ls.push(
remove(pathResolve(initOptions.blogPath, item))
rm(pathResolve(initOptions.blogPath, item), { force: true, recursive: true })

Check failure on line 219 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·force:·true,·recursive:·true` with `⏎········force:·true,⏎········recursive:·true,⏎·····`
.then(() => {
logger.log(`remove "${item}" success!`);
})
Expand All @@ -227,8 +227,16 @@ const post = () => {
});

ADD_FILES.forEach((item) => {
const file = pathResolve(initOptions.blogPath, item);
const dir = dirname(file);

ls.push(
ensureFile(pathResolve(initOptions.blogPath, item))
mkdir(dir, { recursive: true })
.then(() => {
if (!existsSync(file)) {
return writeFile(file, "");
}
})
.then(() => {
logger.log(`add "${item}" success!`);
})
Expand Down

0 comments on commit 831d214

Please sign in to comment.