npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-cmd

v0.1.0

Published

a tool to handle file like cmd

Downloads

7

Readme

file-cmd

a tool to handle file like cmd , Generator/async friendly !

LinuxShell命令行一样的Node.js文件系统操作函数库,Generator/async友好,可以放入Generator或Async函数中使用,极大的方便Node.js文件操作 !

安装

npm install file-cmd --save

使用

file-cmd 可以单独使用,也可以放入Generator/async函数中使用,因为其函数都返回一个Promise对象

let fileCmd = require('file-cmd')
let path = require('path')
let co = require('co')


//类似co的Generator和async函数是Node.js文件IO编程的未来,建议将file-cmd放入之中使用
co(function* () {
    try {
        //mkdir 创建文件夹
        //fileCmd.mkdir(要创建的文件夹的绝对路径)
        yield fileCmd.mkdir(path.join(__dirname, 'tttt'))

        //cat 写入或读取文件
        //fileCmd.cat(要读取的文件的绝对路径)=>返回读取文件获得的数据
        //fileCmd.cat(要写入的文件的绝对路径,要写入的数据)
        let text = yield fileCmd.cat(path.join(__dirname, 'README.md'))
        console.log(text.toString())
        yield fileCmd.cat(path.join(__dirname, 'package.json'), 'hello')

        //rm 删除文件或文件夹
        //fileCmd.rm(要删除的文件或文件夹的绝对路径)
        yield fileCmd.rm(path.join(__dirname, 'te'))

        //rmdir 删除文件夹
        //fileCmd.rmdir(要删除的文件夹的绝对路径)
        yield fileCmd.rmdir(path.join(__dirname, 'testdir'))

        //cp 复制文件或文件夹
        //fileCmd.cp(要复制的文件或文件夹,要复制到的路径)
        //fileCmd.cp(要复制的文件或文件夹,要复制到的路径,对被复制后的文件或文件夹重命名)
        //若不传入第三个参数,复制的文件或文件夹沿用之前的名字
        yield fileCmd.cp(
            path.join(__dirname, 'node_modules'),
            path.join(__dirname, 'sdf'),
            'test_modules'
        )

        //cpf 强制复制文件或文件夹(若复制的是文件夹,将覆盖原有文件夹)
        yield fileCmd.cpf(
            path.join(__dirname, 'node_modules'),
            path.join(__dirname, 'sdf'),
            'test_modules'
        )

        //ls 遍历文件夹
        //fileCmd.ls(要遍历的文件夹的绝对路径)=>返回文件夹下根目录文件/文件夹名组成的数组
        let files = fileCmd.ls(path.join(__dirname, ''))
        console.log(files)

        //mv 移动文件或文件夹
        //fileCmd.mv(要移动的文件或文件夹,要移动到的路径)
        //fileCmd.mv(要移动的文件或文件夹,要移动到的路径,对被移动后的文件或文件夹重命名)
        //若不传入第三个参数,移动后的文件或文件夹沿用之前的名字
        yield fileCmd.mv(path.join(__dirname, 'b'), path.join(__dirname, '../'))

        //wait 暂停程序执行指定时间
        //fileCmd.wait(指定时间,单位ms)
        yield fileCmd.wait(2000)

    } catch (e) {
        console.error(e)
    }
})

//如果想独立使用file-cmd也可以
fileCmd.cat(path.join(__dirname, 'README.md'))
    .then(function (data) {
        console.log(data.toString())
    })