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

require-code-gen-watcher

v0.0.2

Published

根据文件生成 index.js require 内容

Downloads

6

Readme

require-code-gen-watcher

根据文件生成指定内容.

思路

参考以下目录结构:

index.js
login.js
user.js
route.js
subject.js

针对大项目开发, 我们往往需要将仅暴露 index.js 作为唯一输出文件, 其余文件仅仅只是私有存在. 所以我们在 index.js 手动完成一下代码.

// index.js
const models = [
	require('./../login.js'),
	require('./../route.js'),
	require('./../subject.js'),
	require('./../user.js'),
];
module.exports = models;
module.exports.default = models;

这时候问题来了, 针对大项目我们需要不断拓展该文件夹, 我们可能会有更多的如 a.js, b.js, c.js 甚至更多. 这样我们总是需要反复的去维护 index.js.

为了简化这类型工作, 简单花费一点小时间完成该工具的 demo 版本 (请不要用于生产环境).

安装

npm install require-code-gen-watcher -D

使用

可以通过 clone 当前项目安装后运行 npm test 进行测试理解, 或:

const watcher = require('require-code-gen-watcher');
const path = require('path');

watcher(
	path.resolve(__dirname, '../tmp/*.js'),
	{
		exportName: 'models',
		loopFiles: path.resolve(__dirname, '../tmp/*.js'),
		relativePath: path.resolve(__dirname, '../tmp'),
		excludeCondition: (filename) => /index\.js/g.test(filename),
		writePath: path.resolve(__dirname, '../tmp/index.js')
	},
);

作者

She Ailun