Skip to content

引入

ts
import {
  parseCommentJson,
  readCommentJson,
  innerCopyDir,
  copyDir,
  deleteFolder,
  rmEmptyDir,
  copyFile,
  traverseFolder,
  execCommand,
  execCommandAll
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  parseCommentJson,
  readCommentJson,
  innerCopyDir,
  copyDir,
  deleteFolder,
  rmEmptyDir,
  copyFile,
  traverseFolder,
  execCommand,
  execCommandAll
} from 't-comm/lib/node/index';

// 只支持 ESM 的项目
import {
  parseCommentJson,
  readCommentJson,
  innerCopyDir,
  copyDir,
  deleteFolder,
  rmEmptyDir,
  copyFile,
  traverseFolder,
  execCommand,
  execCommandAll
} from 't-comm/es/node/index';

parseCommentJson(content)

描述

解析带注释的 json 文件

参数

参数名描述
content

原始文件内容

返回:

json数据

readCommentJson(file)

描述

获取带注释的 json 文件内容

参数

参数名描述
file

文件路径

返回:

json数据

innerCopyDir(src, dist)

描述

复制目录、子目录,及其中的文件

参数

参数名类型描述
srcString

要复制的目录

distString

复制到目标目录

copyDir(src, dist, callback)

描述

拷贝目录以及子文件

参数

参数名类型
srcObject
distObject
callbackObject

deleteFolder(path)

描述

删除目录

参数

参数名类型
pathObject

rmEmptyDir(path, level)

描述

递归删除空目录

参数

参数名描述
path

路径

level

层级

copyFile(from, to)

描述

拷贝文件

参数

参数名类型描述
fromObject

文件来自那里

toObject

拷贝到那里

traverseFolder(cb, path)

描述

递归遍历文件夹,并执行某操作

参数

参数名类型描述
cbfunction

回调参数

pathString

文件夹或文件路径

execCommand(command, root, stdio)

描述

nodejs 中调用 child_process.execSync 执行命令, 这个方法会对输出结果截断,只返回第一行内容

参数

参数名类型描述
commandstring

命令

rootstring

执行命令的目录

stdiostring | object

结果输出,默认为 pipe

返回: string

命令执行结果

execCommandAll(command, root, stdio)

描述

nodejs中调用 child_process.execSync 执行命令

参数

参数名类型描述
commandstring

命令

rootstring

执行命令的目录

stdiostring

结果输出,默认为 pipe

返回: string

命令执行结果