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

sofa-new-plugins

v1.0.6

Published

首先为什么叫new-plugins,是由于插件模式的方案讨论了比较多轮,最终使用的方案与前期讨论的差距较大,所以最终叫了new-plugins的名字。

Downloads

11

Readme

sofa-new-plugins

首先为什么叫new-plugins,是由于插件模式的方案讨论了比较多轮,最终使用的方案与前期讨论的差距较大,所以最终叫了new-plugins的名字。

sofa的插件是用以进行除git操作、文件复制以外的文件内容处理的,主要被用在create命令中。sofa内置了一些同步、异步插件,帮助模板开发者快速达成自定义create模式的目的。

需要注意的是,多个插件会按序同步执行。

内置插件

ReplaceKeywordPlugin

关键字替换插件

const { Sofa } = require("sofa-new-plugins");

module.exports = {
  name: "sofa-module-cv",
  type: "module",
  frame: "react",
  isTs: 1,
  isBlank: false,
  description: "Connect-View 页面模板;",
  plugins: [
    new Sofa.Plugins.ReplaceKeywordPlugin([
      {
        // 源字符串
        originStr: "EventManage",
        // 目标字符串
        targetStr: "$$moduleName$$",
      }
    ]),
    ……

传参:替换对儿数组,可以替换多个关键字。

CollectParamsPlugin

参数收集插件

与用户交互,得到其他参数,插件的参数与inquirer一致即可。

  new Sofa.Plugins.CollectParamsPlugin([
    {
      type: "input",
      message: "请输入module的中文名称",
      name: "moduleChineseName",
      default: "$$moduleName$$"
    }
  ]),

InsertCodePlugin

代码生成插件

寻找指定的变量(导出变量,export default均可),在变量之上插入新的数组元素或者Object的键值对。

  new Sofa.Plugins.InsertCodePlugin({
    filePath: "$$projectRoot$$/src/config/menu.conf.js",
    findType: "identify",
    findName: "menu",
    insertValue: {
      key: "$$moduleName$$",
      icon: "tool"
    }
  }),
  new Sofa.Plugins.InsertCodePlugin({
    filePath: "$$projectRoot$$/src/config/menu.conf.js",
    findType: "identify",
    findName: "messagesMap",
    insertKey: "$$moduleName$$",
    insertValue: {
      id: "sofa.config.$$moduleName$$",
      defaultMessage: "$$moduleChineseName$$"
    }
  })

替换字符串

sofa-new-plugins预置了一种特殊的替换字符串语法,在插件的配置参数中将$$包裹的变量进行替换,例如在项目'test'中,$$projectName$$会被替换为test。

下面列出了可被替换的变量名称:

number | name | description -|-|- 1 | operator | 操作者 2 | email | 操作者Email 3 | operator | 操作者 4 | projectName | 项目名称 5 | moduleName | 模块名称 6 | projectRoot | 项目路径

此外任何其他需要收集的变量信息都可以通过CollectParamsPlugin插件与用户交互进行收集。

用户自定义插件

插件的开发非常简单,在类中实现如下apply方法即可:

class BasePlugin {
  /**
   * 构造函数
   * @param {*} params 初始化参数
   */
  constructor(params) {
    this.params = params;
  }

  /**
   * 核心执行函数
   * @param {object} files file列表
   * @param {Sofa} sofaEntity Sofa实体,用以传递Sofa执行参数
   * @param {function} callback 回调函数,需在执行末尾调用
   */
  apply(files, sofaEntity, callback) {
    // core code
    callback(error, files);
  }
}