app-lib-node v1.0.31
一、背景介绍
二、功能描述
三、注意事项
四、使用案列
五、todo列表
六、API
Constants
Functions
NODE_INNER_MODULES
nodejs内置所有模块
- 常用于webpack编译umd排除使用
Kind: global constant
isExistFile(path) ⇒ boolean
同步判断磁盘文件是否存在
Kind: global function
Returns: boolean - 是否存在 true 存在 false 不存在
Param | Type | Description |
---|---|---|
path | string | 相对路径 |
resolve(pathName) ⇒ string
相对路径获取的据对路径
Kind: global function
Returns: string - 据对路径地址
Param | Type | Description |
---|---|---|
pathName | string | 相对路径地址 |
isGlobalInstall() ⇒ boolean
判断当前命令是否未全局安装
- 向上两层判断是否存在node.exe
Kind: global function
Returns: boolean - 是否为全局安装
isExistBin(relativePath, name) ⇒ boolean
是否存在bind
Kind: global function
Returns: boolean - 是否存在bin
Param | Type | Description |
---|---|---|
relativePath | string | 相对路径 |
name | string | 组件名称 |
getBin(compnentName) ⇒ string
获取nodejs的bin执行位置
Kind: global function
Returns: string - 组件的路径
- tips
- 开发模式直接获取当前目录的下的指定配置路径
- 局部查找
- 全局组件内部
- 全局外部
Param | Type | Description |
---|---|---|
compnentName | string | 组件名称 |
isDev() ⇒ boolean
是否为app 定义的开发模式
Kind: global function
Returns: boolean - 是否为开发模式
- tips
- cross-env 中不支持中划线 eg:APP-MODLE
- MODE 或在 M 值为 DEV 或者DEVELOP, develop,dev
- 主要用于该工程的开发模式
getTemplate() ⇒ string
获取模版位置
Kind: global function
Returns: string - 模版位置
readFile(path, options) ⇒ promise
读文件【异步】
Kind: global function
Returns: promise - data | 读取的文件内容
- tips
- string|Buffer|URL|integer filename or file descriptor
- https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback
Param | Type | Description |
---|---|---|
path | string | Buffer | URL | integer | 文件路径 |
options | object | ndoejs的配置 |
readFileSync(path, options) ⇒ string
读文件【同步】
Kind: global function
Returns: string - 文件内容
- tips
- string|Buffer|URL|integer filename or file descriptor
- https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback
Param | Type | Description |
---|---|---|
path | string | Buffer | URL | integer | 文件路径 |
options | object | ndoejs的配置 |
writeFile(path, options) ⇒ promise
写文件【异步】
Kind: global function
Returns: promise - data | 读取的文件内容
- tips
- string|Buffer|URL|integer filename or file descriptor
- https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback
Param | Type | Description |
---|---|---|
path | string | Buffer | URL | integer | 文件路径 |
options | object | ndoejs的配置 |
writeFileSync(path, options) ⇒ string
写文件【同步】
Kind: global function
Returns: string - 文件内容
- tips
- string|Buffer|URL|integer filename or file descriptor
- https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_fs_readfile_path_options_callback
Param | Type | Description |
---|---|---|
path | string | Buffer | URL | integer | 文件路径 |
options | object | ndoejs的配置 |
writeFileSyncAndCreate(path, options) ⇒ string
写文件【同步】 不存在文件夹则创建
Kind: global function
Returns: string - 文件内容
Param | Type | Description |
---|---|---|
path | string | Buffer | URL | integer | 文件路径 |
options | object | ndoejs的配置 |
isExistDir(path) ⇒ boolean
是否为文件夹
Kind: global function
Returns: boolean - 是否为文件夹
Param | Type | Description |
---|---|---|
path | string | 文件夹路径 |
getParentDir(path, dirName, layer) ⇒ object
获取指定路径的父级目录包含的文件夹名
Kind: global function
Returns: object - 找的父级的路径
- example
{
path : null 标识不存在 否则标识存在的路径
layer: number 查到的层级
}
Param | Type | Default | Description |
---|---|---|---|
path | string | 当前的路径 | |
dirName | string | 文件夹名称 | |
layer | number | 0 | 当前目录到找到目录目录的层级 |
copyFile(src, dest, isForce, flags) ⇒ promise
复制文件
- 不存在目录则创建 但是一定是两边都包含文件 否则会报错 operation not permitted, copyfile xxx
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
src | string | 源地址 | |
dest | string | 目标地址 | |
isForce | string | 文件存在是否强制覆盖 默认false | |
flags | number | 0 | 复制标识 |
copyFileSync(src, dest)
单文件强制复制文件
不存在目录则创建 但是一定是两边都包含文件 否则会报错 operation not permitted, copyfile xxx
Kind: global function
Param | Type | Description |
---|---|---|
src | string | 源文件路径 |
dest | string | 目标文件路径 |
mkdir(path, options) ⇒ null
创建目录【同步】
Kind: global function
Returns: null - 无返回
- tips
Param | Type | Description |
---|---|---|
path | string | 路径 |
options | object | 参数 |
yesOrNo(tips, defaultValue) ⇒ promise
录取用户输入
Kind: global function
Returns: promise - 读取结果
Param | Type | Default | Description |
---|---|---|---|
tips | string | 提示信息 | |
defaultValue | string | "yes" | 默认值 |
readline(tips, isAlowEmpty) ⇒ promise
录取用户输入
Kind: global function
Returns: promise - 读取结果
Param | Type | Default | Description |
---|---|---|---|
tips | string | 提示信息 | |
isAlowEmpty | boolean | false | 运行为空 |
updateContent(options) ⇒ string
文本中添加或者覆盖指定内容
Kind: global function
Returns: string - 新文本
Param | Type | Description |
---|---|---|
options | object | 参数 |
options.content | object | 文本内容 |
options.startflag | object | 开始标识 |
options.endFalg | object | 结束标识 |
options.appContent | object | 最佳或者替换的内容 |
options.isRepalce | object | 是否为替换 默认是追加 false |
options.isStart | object | 不存在时 追加最前面 默认是后面 |
options.isInnerStart | object | 追加文档时 追加在heade与oldcontent之间 默认在尾部 |
options.space | object | 与标识符的间隔 |
options.newHeader | object | 不存在时候 添加头部内容 |
getRootPath(relativePath) ⇒ string
获取安装类库的据对目录
Kind: global function
Returns: string - 主目录路径
Param | Type | Default | Description |
---|---|---|---|
relativePath | string | "./" | 执行文件的相对目录 默认 ../../ |
getMainPath(relativePath) ⇒ string
当前安装 或者执行命令 的路径
Kind: global function
Returns: string - 新路径
- tips 默认执行的bin文件 在工程目录的下两层 到当前组件的跟目录层 上一侧目录都为当前组件的目录
Param | Type | Default | Description |
---|---|---|---|
relativePath | string | "../../" | 相对路径 |
getBinPath() ⇒ string
获取当前组件bin的路径
Kind: global function
Returns: string - bin路径
readdirSync(path) ⇒ array
读取目录【同步】
Kind: global function
Returns: array - 文件目录
Param | Type | Description |
---|---|---|
path | string | 目录路径 * @param {object} options 读取配置 |
delDir(path)
嵌套删除子文件夹和文件
Kind: global function
Param | Type | Description |
---|---|---|
path | string | 路径 |
delFile(path)
删除文件【同步】
Kind: global function
Param | Type | Description |
---|---|---|
path | string | 文件路径 |
isSysUsePort(port) ⇒ boolean
系统判断端口使用 // TODO 采用静态编译方式 处理静态文件
Kind: global function
Returns: boolean - 事都被占用
Param | Type | Description |
---|---|---|
port | number | 端口号 |
getCanUsePort(port) ⇒ number
获取到能够使用的端口
- 动态自增的方式 直到可用的端口
Kind: global function
Returns: number - 可用的端口
Param | Type |
---|---|
port | number |
copyProjectFile(from, to, defaultIsSucess)
复制文件 【异步】
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
from | string | 相对发布组件的目录 | |
to | string | 相对生成的目录 | |
defaultIsSucess | boolean | 0 | 不存在文件的时候是否默认为成功 默认为成功 |
copyProjectFileSync(from, to, defaultIsSucess)
复制文件 【同步】
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
from | string | 相对发布组件的目录 | |
to | string | 相对生成的目录 | |
defaultIsSucess | boolean | 0 | 不存在文件的时候是否默认为成功 默认为成功 |
copyFolder(source, target)
嵌套复制文件夹 【同步】
Kind: global function
Param | Type | Description |
---|---|---|
source | string | 源路径 |
target | string | 目标路径 |
getLocalIP() ⇒ string
获取本机IP
- windows验证 其他环境还未验证
Kind: global function
Returns: string - ip地址
- tips
- 目前值返回IPv4 后续可以扩展IPv6
七、发布日志
- 2023-11-02 08-58-03-添加app-lib-exec依赖
- 2023-10-31 10-25-29-aaaaaa
- 2023-09-11 10-10-18-读取目录的参数
- 2023-08-20 08-08-04-添加注释
- 2023-08-20 10-48-58-复制文件copyFile 修复存在的文件
- 2023-08-18 01-12-32-调整参数文案
- 2023-08-17 11-26-22-调整导出顺序
- 2023-08-17 11-24-43-调整导出顺序
- 2023-08-17 11-08-01-添加文档注释
- 2023-08-17 11-03-36-测试显示文档
- 2023-08-17 10-40-04-测试显示文档
- 2023-08-17 10-02-47-测试显示文档
- 2023-08-07 11-44-22-添加获取本机IP
- 2023-07-19 10-15-56-处理同步复制的访问错误
- 2023-07-17 06-37-03-添加复制文件夹
- 2023-04-25 11-01-37-添加删除文件
- 2023-04-20 10-04-26-修改package文件
- 2023-04-19 10-26-33-优化用户输入函数
- 2023-04-18 08-25-08-内部文档变更
- 2023-04-18 05-18-05-添加告警打印日志
- 2023-04-16 11-26-48-aaaa
- 2023-04-16 10-18-55-提交组件
4 months ago