JSPM

  • Created
  • Published
  • Downloads 2707
  • Score
    100M100P100Q116002F
  • License ISC

The toolbox for cloudbase

Package Exports

  • @cloudbase/toolbox

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cloudbase/toolbox) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Cloudbase Toolbox

云开发 Node Toolbox,工具合集,仅支持 Node 8.9+ 以上版本。

V2 配置解析器

@cloudbase/toolbox 0.4.0版本起,支持了新的 cloudbaserc 配置解析器,使用方法如下:

import { ConfigParser } from '@cloudbase/toolbox'

const configParser = new ConfigParser({
    // 当前工作目录,搜索配置文件,.env 文件,默认为 process.cwd
    cwd: '',
    // 写本地配置时,遇到相同 key 时的处理策略
    cover: false,
    // 直接指定配置文件的路径,否则在 cwd 目录下尝试查找配置文件
    configPath: ''
})

// 获取全部配置文件
await configParser.get()
// 获取 envId
await configParser.get('envId')
// 获取第一个函数的超时时间,如果不存在,则返回默认值 3
await configParser.get('functions[0].timeout', 3)

await configParser.update('functions[0].timeout', 5)

直接使用静态方法

import { ConfigParser } from '@cloudbase/toolbox'

// 获取全部配置文件
await ConfigParser.get()
// 获取 envId
await ConfigParser.get('envId')
// 获取第一个函数的超时时间,如果不存在,则返回默认值 3
await ConfigParser.get('functions[0].timeout', 3)

支持变量

通过 命名空间.变量名 使用,如 {{tcb.envId}}

命名空间 变量名 含义
tcb envId 配置文件或通过命令行参数指定的环境 Id
util uid 24 位的随机字符串
env * .env 文件中加载的环境变量

说明:

  • 可以通过 —-env 参数指定需要加载的 .env 文件后缀,如 --env test 加载 .env.test 文件中的变量,默认加载 .env 文件中的变量