0.2.3 • Published 1 year ago

@humbird/fim v0.2.3

Weekly downloads
152
License
ISC
Repository
-
Last release
1 year ago

简介

fim是为了提高开前端发效率及标准化前端基本操作的一个工具。

除去本身提供的基础能力外,还拥有插件机制,支持对工具能力的拓展,同时也避免了工具本身过于庞大臃肿的麻烦。

工具本身支持多样化的配置,可以根据需求定制不同的内容。

安装

sudo npm i -g @humbird/fim

命令

init

fim init \
--name=projectName
  • name - 项目名称

create

fim create \
--name=index \
--type=page \
--framework=react \
--path=./src/view \
--morePorps=xxx

以下参数都是非必传参数。

在模板源入口文件和资源文件内可以访问到这些参数,如果需要更多自定义内容,可以传入更多的参数(--morePorps=xxx)。

  • name - 页面/组件名称,不能以数字开头。
  • type - 创建的类型。仅支持pagecomponent
  • framework - 运行框架。不传时,提供 react vue dingApplet wechatApplet
  • path - 创建的入口路径。不传时,默认在执行命令的目录作为入口路径。

publish

fim publish \
--username=root \
--host=111.111.111.11 \
--port=22 \
--localDir=./dist \
--remoteDir=/dist \
--password='xxxx' \ # 或 --privateKey="xxx" 使用私钥登录服务器
--exec="yarn build"
  • username - 登录服务器用户名
  • host - 服务器 IP 地址
  • port - 服务器端口
  • password - 服务器登录密码
  • privateKey - 本地私钥。 如果存在,则使用私钥私钥登录,可不传入密码
  • localDir - 需要上传的目录。默认为dist
  • remoteDir - 服务器接收的目录
  • exec - 发布前执行的命令。一般为构建的命令。process.env.NODE_ENV值为production时,默认执行yarn build:pro。否则执行yarn build:dev
  • mode - 发布的模式。这个需要配合配置文件的publish配置。可以根据匹配到的不同mode执行发布任务。例如:
  • backup - 备份上一次迭代文件
  • backupTag - 指定备份名称。形如 0.0.1
module.exports = {
  publish: {
    // fim publish --mode=dev
    dev: {
      backup: true, // 开启备份
      exec: "yarn build:dev", // 执行的命令
      localDir: "./dist", // 需要上传的目录
      remoteDir: "xxx/dev", // 远程目录
      connect: {
        host: "xxx.xxx.xxx.xx", // 服务器 ip
        port: 22, // 端口号
        username: "root", // 登录用户名
        password: "xxx", // 登录密码
        privateKey: "xxx", // 如果不提供密码,也可以使用 ssh 的本地私钥登录(确保自己的秘钥上传到了服务器)
      },
    },
    // fim publish --mode=pro
    pro: {
      exec: "yarn build:pro", // 执行的命令
      localDir: "./dist", // 需要上传的目录
      remoteDir: "xxx/pro", // 远程目录
      connect: {
        host: "xxx.xxx.xxx.xx", // 服务器 ip
        port: 22, // 端口号
        username: "root", // 登录用户名
        password: "xxx", // 登录密码
        privateKey: "xxx", // 如果不提供密码,也可以使用 ssh 的本地私钥登录(确保自己的秘钥上传到了服务器)
      },
    },
  },
};

rollback

fim rollback \
--mode=doc \ // 指定回滚发布的模式
--rollbackTag=0.0.1 // 指定要回滚的版本
--list // 选择要回滚的版本。如果存在 rollbackTag 则忽略 list
  • rollbackTag - 指定要回滚的版本
  • list - 选择要回滚的版本。如果存在 rollbackTag 则忽略 list

config

fim config -h

管理 fim 全局配置

配置

配置文件支持两种格式fim.config.jsonfim.config.js

创建页面/组件(create)

创建页面或组件的入口路径。若不配置,则默认在执行命令的目录作为入口路径。

module.exports = {
  create: {
    page: {
      // 创建页面输出的目录
      path: "src/pages",
    },
    component: {
      // 创建组件输出的目录
      path: "src/components",
    },
  },
};

模板源(templateSource)

创建页面或者组件的模板源。默认值为direct:http:/x.xx.xxxx/great/xfw-front/fim-project-templates.git#master。项目的远程地址,协议为 http。

module.exports = {
  templateSource:
    "direct:http://x.xx.xxxx/great/xfw-front/fim-project-templates.git#master",
};

单个模板源目录结构

文件的内容均是ejs语法。

├── component
│   ├── index.js
│   ├── index.json
│   └── index.scss
├── page
│   ├── index.js
│   └── index.scss
└── template_creator.js // 模板入口文件

模板入口文件template_creator.js。入口文件会暴露出创建组件和页面所需要的文件。

module.exports = {
  pageFiles: ["./page/index.js", "./page/index.scss"],
  componentFiles: [
    "./component/index.js",
    "./component/index.scss",
    "./component/index.json",
  ],
  handler: {
    // 运行平台(framework)为 钉钉小程序 或 微信小程序
    // true 则创建返回 `./component/index.json` 文件
    // false 则不返回
    "./component/index.json": ({ framework }) => {
      ..
      return framework === "DingApplet" || framework === "WechatApplet";
    },
  },
};
  • pageFiles - 创建page需要的文件
  • componentFiles - 创建component需要的文件
  • handler - 根据传入的不同参数,选择是否创建文件

多个模板源目录结构

如果模板源是一个模板的组合,根目录则可以存在多个目录。每个目录都会被当做一个模板源,每个模板源都需要一个入口文件template_creator.js

├── xinyingxiao
│   ├── component
│   │   ├── index.js
│   │   ├── index.json
│   │   └── index.scss
│   ├── page
│   │   ├── index.js
│   │   └── index.scss
│   └── template_creator.js
└── xinzichan
    ├── component
    │   ├── index.js
    │   ├── index.json
    │   └── index.scss
    ├── page
    │   ├── index.js
    │   └── index.scss
    └── template_creator.js

发布(publish)

发布提供了多个模式 mode,可以根据需求定制发布执行的命令、目标文件、远程地址等。

module.exports = {
  publish: {
    dev: {
      exec: "yarn build:dev", // 执行的命令
      localDir: "./dist", // 需要上传的目录
      remoteDir: "xxx", // 远程目录
      connect: {
        host: "xxx.xxx.xxx.xx", // 服务器 ip
        port: 22, // 端口号
        username: "root", // 登录用户名
        password: "xxx", // 登录密码
        privateKey: "xxx", // 如果不提供密码,也可以使用 ssh 的本地私钥登录(确保自己的秘钥上传到了服务器)
      },
    },
  },
};
  • exec - 执行的命令。process.env.NODE_ENV值为production时,默认执行yarn build:pro。否则执行yarn build:dev
  • localDir - 默认值为dist
0.2.3

1 year ago

0.1.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.2.2

2 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.19

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago