一个简单的工具箱。
pnpm i fire-keeper首先,在代码中引入模块。
import $ from 'fire-keeper'之后就可以愉快地玩耍啦。
$.echo('hello world')当然,也可以按需加载。
import echo from 'fire-keeper/dist/echo'
echo('hello world')npm run buildnpm run test- argv
- backup
- copy
- download
- echo
- exec
- getBasename
- getDirname
- getExtname
- getFilename
- getName
- getType
- glob
- home
- isExist
- isSame
- link
- mkdir
- move
- normalizePath
- os
- prompt
- read
- recover
- remove
- rename
- root
- sleep
- stat
- toArray
- toDate
- toJson
- toString
- watch
- write
- zip
获取argv。
const argv = $.argv()备份文件。
await $.backup('./readme.md') // 生成`./readme.md.bak`复制文件。
await $.copy('./readme.md', './temp')下载文件。
await $.download('http://example.com', './temp')在控制台显示信息。
$.echo('hello world')
$.echo('error', 'a error message')执行命令。
await $.exec('npm run build')获取basename。
const basename = $.getBasename('./readme.md') // `readme`获取dirname。
const dirname = $.getDirname('./readme.md') // `./`的绝对路径获取extname。
const extname = $.getExtname('./readme.md') // `.md`获取filename。
const filename = $.getFilename('./readme.md') // `readme.md`获取文件名。
const name = $.getName('./readme.md')获取类型。
const type = $.getType(42) // number获取文件列表。
const listSource = await $.glob('./source/**/*')获取用户主目录。
const home = $.home()判断文件是否存在。
const isExist = await $.isExist('./readme.md')判断两个文件是否相同。
const isSame = await $.isSame('./readme.md', './readme.md.bak')创建软链接。
await $.link('./readme.md', './temp/readme.md')创建目录。
await $.mkdir('./temp')移动文件。
await $.move('./readme.md', './temp')规范化路径。
const path = $.normalizePath('./readme.md')获取操作系统类型。
const os = $.os()提示用户输入。
const answer = await $.prompt({
list: ['a', 'b', 'c'],
message: 'choose a letter',
type: 'select',
})读取文件。
const content = await $.read('./readme.md')恢复文件。
await $.recover('./readme.md') // 从`./readme.md.bak`恢复删除文件。
await $.remove('./temp')重命名文件。
await $.rename('./readme.md', 'readme-new.md')获取项目根目录。
const root = $.root()休眠。
await $.sleep(1e3)获取文件状态。
const stat = await $.stat('./readme.md')转换为数组。
const list = $.toArray('hello world') // `['hello world']`转换为日期。
const date = $.toDate('2020-01-01') // `new Date('2020-01-01')`转换为JSON。
const json = $.toJson('{"a":1}') // `{a:1}`转换为字符串。
const string = $.toString(42) // `'42'`监听文件变化。
$.watch('./source/**/*', (path) => $.echo(path))写入文件。
await $.write('./readme.md', 'hello world')压缩文件。
await $.zip('./source/**/*', './temp/source.zip')