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

reps

v1.0.6

Published

简单的文件查找和替换命令行

Downloads

8

Readme

文件递归替换

简单的文件查找和替换命令行

业务场景:要将目录下所有的文件(js、CSS等等)中的'a.com'替换成'b.net'等。支持正则匹配。

思路是这样的:

  1. 首先将根据目标目录,生成镜像文件夹结构;此时只有文件夹,没有文件;
  2. 遍历这些文件,读取到内存中
  3. 使用replace方法,替换字符串
  4. 输出到目标文件。

如何使用?

首先全局安装:

npm install -g reps

切换到具体目录,试一下下面的命令:

命令行格式:

reps origin [dest] [--old oldStr] [--new newStr] [--reg]

或:

reps origin dest --o oldStr --n newStr  [-r]

【参数解释】

  • origin必须。表示要处理文件的文件夹
  • dest可选。如果不传目标目录dest,则表示就地替换;
  • --old -o可选。如果不传,则不替换;
  • --new -n: 可选,默认值是空字符。
  • --reg -r: 可选,表示是否是按正则方式匹配

reps origin:直接返回。

reps origin dest : 相当于递归拷贝文件夹,不作替换

reps origin -o "a.com" : 相当于原地去除文件中所有的 a.com字样

【示例】

定位到ori所在的目录,运行命令:

reps tests/ori tests/dest --old a.com --new b.net

该语句的含义是,将tests/ori中所有文件内的'a.com'字符替换成'b.net'后,镜像到 tests/dest 目录(该目录如果不存在会自动创建)中,而原来的tests/ori文件夹内容不变。看上去,相当于将 文件夹 ori 重命名成dest

【如何使用本示例】

  1. 切换到bin/目录下
  2. 正则示例:node reps.js ../tests/ori ../go -o '\d{2,3}' -n 'jscon' -r 将会使用正则匹配;
  3. 非正则匹配示例:node reps.js ../tests/ori ./go -o 'jscon' -n 'boyc'

Changelog

2015.04.17(星期五) 兼容linux下的环境 2015.04.16(星期四) 创建此脚本,修复相对路径,使用 process.cwd() 代替 __dirname变量