Code Monkey home page Code Monkey logo

more-copy.js's Introduction

@more-copy

npm npm node-current

简介

基于 Node.js 的数据处理的工具

利用 more-copy,可以很容易实现一个类似 VSCode、Pycharm、PHPStrom、Idea...中的代码片段,

它依赖 Node.js,而不依赖任何编辑器,可以用于任何模式代码生成

简单的处理步骤:

  • 输入数据 data
  • 插件处理 plugins

安装

# 建议全局安装
npm i @more-copy/cli -g
$ npx mcp -h
Usage: mcp [options]

Options:
  -V, --version             output the version number
  -c, --config <config...>  config filenames (default: ["more-copy.config.js","more-copy.config.cjs"])
  -m, --mode <mode>         mode name
  -h, --help                display help for command

简单的示例

安装插件

npm i @more-copy/console-plugin @more-copy/time-plugin
// more-copy.config.js
const ConsolePlugin = require('@more-copy/console-plugin')
const TimePlugin = require('@more-copy/time-plugin')

module.exports = {
  // 数据
  data: {
    name: 'Tom',
  },

  // 使用插件,从上往下执行
  // 后面的插件,可以依赖前面插件的输出
  plugins: [new TimePlugin(), new ConsolePlugin()],
}

执行命令,运行 more-copy

$ mcp
{
  data: { name: 'Tom' },
  plugins: [
    TimePlugin { options: {} },
    ConsolePlugin { options: {} } ]
}

ConsolePlugin: {
  "name": "Tom",
  "time": {
    "date": "2022-11-08",
    "time": "19:08:40",
    "datetime": "2022-11-08 19:08:40"
  }
}

和代码模板一起使用

做一个快乐的 curd boy/girl

https://github.com/mouday/code-template

Plugin 插件

插件三要素:

  • 参数:由new Plugin(options)传入,可以理解为插件的配置
  • 依赖:由 data 对象提供,由前面的 Plugin 提供,可以理解为插件的输入
  • 挂载:可以再全局的 data 对象上绑定数据,用于传递数据给后面的插件使用,可以理解为插件的输出

已实现的插件

插件名称 说明
ApiPlugin api 接口生成
ConsolePlugin 用于输出当前 data 的值
MkdirPlugin 自动创建目录
NamingPlugin 命名转换
NunjucksPlugin 模板渲染
ReadDataPlugin 读取 json 文件
MySQLPlugin 查询 MySQL 数据
TablePlugin 获取 MySQL 表字段
TimePlugin 基于 dayjs 的时间插件
WriteDataPlugin 输出 json 文件

自定义插件

用户可以使用插件来处理输出

插件约定添加 data 对象上的属性,以插件名命名,特殊除外。

例如:

使用 CustomPlugin 将会添加属性data.custom

custom-plugin.js 用来处理模板入参

// 继承基类
class CustomPlugin {
  apply(data) {
    // 挂载自定义数据
    data.custom = {
      name: 'Tom',
    }
  }
}

module.exports = CustomPlugin

其他版本:

备注

运行单个脚本

pnpm  --filter <package_name> run test

# eg:
pnpm  --filter nunjucks-plugin run test

安装模块

pnpm add @more-copy/utils --filter @more-copy/nunjucks-plugin

安装模块

# 全局暴露
pnpm link -g

# 安装到本地
pnpm link -g @more-copy/utils

more-copy.js's People

Contributors

mouday avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.