🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@cubetool/base

Package Overview
Dependencies
Maintainers
9
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cubetool/base

开发者工具核心

npmnpm
Version
2.0.0-beta.1
Version published
Weekly downloads
176
-59.07%
Maintainers
9
Weekly downloads
 
Created
Source

cubetool 开发者工具核心

cubetool 开发者工具核心模块,可集成到各应用场景进行 cube 项目开发管理。

使用示例

import cubeTool from '@cubetool/base';

const myCubeTool = cubeTool('myapp/v1', {
  logPath: '/var/log/cubetool',
});
const {ENV, log, config, plugin, Project} = myCubeTool;

const cubeProject = new Project(process.cwd());

FUNCTION cubeTool(name, options)

  • @param {string} name 应用名称标识,建议使用“名称/v版本形式”
  • @param {object} options = {} 配置参数
  • @return {object} result 返回结果

options 配置项

keytypedescdefaul
spathstring项目配置目录$HOME/.cubetool
pluginsPathstring插件安装目录$HOME/.cubetool/plugins
logLevelstringlog 目录$HOME/.cubetool/plugins
logPrintbool是否打印日志false
logLevelstring日志记录级别'warn'

日志级别支持:debug、info、notice、warn、error

result 返回值

objectdesc
ENV运行环境常量
loglog 对象,使用参考 npmlog
config配置对象
plugin插件实例
Project项目类

具体信息请参考开发文档

OBJECT utils{}

为方便开发,提供的工具函数集,可使用如下方法引入:

import {utils} from '@cubetool/base';

utils.exec(command, options = {}, argvs = [])

执行命令。返回 child_process,并且添加promise()方法,如:

let execProcess = utils.exec('ls', { cwd: '/home' }, ['-la']);
let { stdout, stderr } = await execProcess.promise();

utils.request(url, options={})

发起网络请求。

  • @param {string} url 请求 url
  • @param {object} options = {} 参考 got

utils.mkdir(path)

创建目录,如果父目录不存在将递归创建父级目录。

utils.touchFile(path, content = '')

如果文件不存在则使用指定 content 内容在 path 下创建文件。

utils.uniqId(len = 10)

使用指定 len 长度生成随机字符串 id。

utils.getPackageData(path)

获取指定路径模块信息。

utils.getResolveModulePath(path)

根据指定位置往上查找最近的 node_modules 文件夹。

utils.log

log 对象,使用参考 npmlog

utils.conf(opts)

返回 conf 实例,使用参考 conf

utils.npm

npm 操作,cubetool 底层的插件等功能使用该模块实现。 npm.setRegistry(registry) 设置全局registry
npm.install(name, options, argvs) 安装模块
npm.uninstall(name, options, argvs) 卸载模块
npm.update(name, options, argvs) 更新模块
install、uninstall、update 方法底层调用 utils.exec() 方法,其参数:

  • @param {string} name 模块
  • @param {object} options = {} child_process.exec()
  • @param {array} argvs = [] 命令参数

插件开发

请参考插件开发文档。

Keywords

cube

FAQs

Package last updated on 20 Nov 2020

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