Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

zh-cli

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zh-cli

脚手架,api文档生成工具

latest
Source
npmnpm
Version
2.4.15
Version published
Weekly downloads
21
-77.66%
Maintainers
1
Weekly downloads
 
Created
Source

zh-cli是什么

  • z-reactz-app 脚手架项目初始化工具。
  • 基于mkdocs的api文档生成工具。

工具实现参考了scion

如何使用

  • npm install zh-cli -g

初始化项目

api文档生成

  • pip install mkdocs
  • zcli mkdocs nodejs | c++

基于mkdocs生成api文档

项目根目录中增加配置文件mkdocs.json

{
  mkdocs: {
    "site_name": "z-seneca",
    "site_favicon": "favicon.ico",
    "copyright": "© Zz"
  }, // mkdocs配置,见官网
  apiCfgFilePath: "*.js", // api文件配置文件 glob pattern。如: "/Users/test/*/*.js"
  "indexFilePath": "../README.md",
  "mdFilePath": [
    "../header.md"
  ]
}

api配置文件:.js.json

例如定义部门相关api文件department.js

 module.exports = {
    name: '部门',
    groupName: "Department", // api组名
    description: "提供部门相关api", // api组描述

    // 定义一个类型
    Role: {
      description: "部门角色,如:组长,运营总监", // 类型描述
      propertys: { // 类型包含的属性
        name: {
          type: "String", // 类型
          descrpition: "角色名称", // 属性描述
        },
        status: {
          type: "Enum", // 类型
          description: "状态。1:可用,2:不可用", // 属性描述
          values: [1, 2]
        },
      }
    },

    // 定义一个方法
    create: {
      description: "创建一个部门",
      funcType: 'async', // async函数
      paramsIsObject: true, // 参数在一个object对象中传递
      method: 'post',
      url: '/departments',
      params: { // 参数
        name: {
          type: "String", // 类型
          descrpition: "名称", // 属性描述
          required: true, // 必填
        },
        status: {
          type: "Enum", // 类型
          description: "状态。1:可用,2:不可用", // 属性描述
          values: [1, 2],
          defaultValue: 1,
        },
        role: {
          type: "Role", // 自定义类型
        }
      },
      returns: { // 返回值
        name: {
          type: "String", // 类型
          descrpition: "名称", // 属性描述
          required: true, // 必填
        },
        status: {
          type: "Enum", // 类型
          description: "状态。1:可用,2:不可用", // 属性描述
          values: [1, 2],
          defaultValue: 1,
        }
      },
      exampleSuccess: [{
      desc: '成功时例子',
      params: {
        id: 1,
        status: 1
      },
      returns: {
        id: 1,
        status: 1,
        name: 'aa',
      }
    }, {
      desc: '成功时例子',
      params: {
        id: 1,
        status: 1
      },
      returns: {
        id: 1,
        status: 1,
        name: 'aa',
      }
    }],

    exampleFail: {
      desc: '失败时例子',
      params: {
        id: 1,
        status: 1
      },
      returns: {
        id: 1,
        status: 1,
        name: 'aa',
      }
    },
    }
  }

例如定义部门相关api文件department.json

{
  "name": "部门",
  "groupName": "Department",
  "description": "xxxxxxx",

  "Role": {
    "description": "部门角色。如:组长,运营总监",
    "propertys": {
      "name": {
        "type": "String",
        "descrpition": "角色名称"
      },
      "status": {
        "type": "Enum",
        "description": "状态。1:可用,2:不可用",
        "values": [1, 2]
      }
    }
  },

  "create": {
    "params": {
      "name": {
        "type": "String",
        "descrpition": "角色名称",
        "required": true
      },
      "status": {
        "type": "Enum",
        "description": "状态。1:可用,2:不可用",
        "values": [1, 2],
        "defaultValue": 1
      },
      "role": {
        "name": {
          "type": "String",
          "descrpition": "角色名称"
        },
        "status": {
          "type": "RoleStatus",
          "description": "角色状态"
        }
      }
    },
    "returns": {
      "name": {
        "type": "String",
        "descrpition": "角色名称",
        "required": true
      },
      "status": {
        "type": "Enum",
        "description": "状态。1:可用,2:不可用。",
        "values": [1, 2],
        "defaultValue": 1
      }
    }
  }
}

参数,返回值,属性type

支持常用的nodejs,c++等类型。自定义时传自定义类型的名称即可。 其他语言可自定义类型转换表。

引入内置类型:

  const dateTypes = require('zh-cli')

  dataTypes['c++'] // c++ 内置类型
  dataTypes['nodejs'] // nodejs 内置类型
  

nodejs支持type

  {
    String: 'String',
    Number: 'Number',
    Boolean: 'Boolean',
    Symbol: 'Symbol',
    Object: 'Object',
    Enum: 'Enum',
    Date: 'Date',
    DateTime: 'DateTime',
    Function: 'Function',

    FuncType: {
      kStatic: 'static',
      kAsync: 'async',
      kStaticAsync: 'static async',
    }
  }

c++支持type

{
  String: 'string',

  Int: 'int',
  UnsignedInt: 'unsigned int',
  SignedInt: 'signed int',
  ShortInt: 'short int',
  UnsignedShortInt: 'unsigned short int',
  SignedShortInt: 'signed short int',
  LongInt: 'long int',
  SignedLongInt : 'signed long int',
  UnsignedLongInt: 'unsigned long int',
  
  Float: 'float',
  
  Double: 'double',
  LongDouble: 'long double',
  
  Struct: 'struct',
  
  Boolean: 'bool',
  Bool: 'bool',
  
  Void: 'void',
  Wchar_t: 'wchar_t',
  Char: 'char',
  
  UnsignedChar: 'unsigned char',
  SignedChar: 'signed char',

  Enum: 'enum',
  Date: 'date',
  DateTime: 'date time',

  Function: 'function',
  FuncType: {
    kStatic: 'static',
    kVirtual: 'virtual',
  }
}

帮助

  • zcli -h

问题反馈

在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流

Keywords

cli

FAQs

Package last updated on 03 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts