-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Migrate the whole project from cjs to esm (#137)
- Loading branch information
Showing
10 changed files
with
119 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
/** | ||
* Ensure the file exists, if not, create it and its directory. | ||
* @param {string} filePath - The path to the file. | ||
*/ | ||
export function ensureFileSync(filePath) { | ||
try { | ||
// Check if the file already exists | ||
if (!existsSync(filePath)) { | ||
// Get the directory name of the file | ||
const dir = path.dirname(filePath); | ||
|
||
// Recursively create the directory if it doesn't exist | ||
if (!existsSync(dir)) { | ||
mkdirSync(dir, { recursive: true }); | ||
} | ||
|
||
// Create an empty file | ||
writeFileSync(filePath, ''); | ||
} | ||
} catch (error) { | ||
console.error(`Error ensuring file: ${error.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
"author": "afc163 <[email protected]>", | ||
"license": "MIT", | ||
"bin": { | ||
"fy": "bin/fanyi.js", | ||
"fanyi": "bin/fanyi.js" | ||
"fy": "bin/fanyi.mjs", | ||
"fanyi": "bin/fanyi.mjs" | ||
}, | ||
"keywords": ["chinese", "translator", "iciba", "groq", "llama", "cli", "fanyi"], | ||
"engines": { | ||
|
@@ -20,35 +20,37 @@ | |
"readmeFilename": "README.md", | ||
"files": ["index.js", "bin", "lib"], | ||
"dependencies": { | ||
"chalk": "^4.1.2", | ||
"chalk": "^5.3.0", | ||
"commander": "^12.1.0", | ||
"dayjs": "^1.11.13", | ||
"fast-xml-parser": "^4.5.0", | ||
"fs-extra": "^11.2.0", | ||
"gradient-string": "^2.0.2", | ||
"groq-sdk": "^0.7.0", | ||
"node-fetch": "^3.3.2", | ||
"ora": "^5.4.1", | ||
"update-notifier": "^5.1.0" | ||
"ora": "^8.1.0", | ||
"update-notifier": "^7.3.1" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts,json,yml}": ["biome check --write --files-ignore-unknown=true"] | ||
"*.{js,mjs,ts,json,yml}": [ | ||
"biome check --write --files-ignore-unknown=true --no-errors-on-unmatched" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.0", | ||
"@biomejs/biome": "^1.9.2", | ||
"c8": "^10.1.2", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10", | ||
"np": "^10.0.7", | ||
"vitest": "^2.1.0" | ||
"vitest": "^2.1.1" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test": "vitest run --test-timeout=20000", | ||
"coverage": "c8 --reporter=lcov --reporter=text npm test", | ||
"lint": "biome check .", | ||
"format": "biome check . --write", | ||
"prepublishOnly": "np --no-cleanup --no-publish", | ||
"lint-staged": "lint-staged", | ||
"prepare": "husky" | ||
} | ||
}, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters