Skip to content

引入

ts
import {
  replaceContent,
  execCommandInTarget,
  replaceEachContent,
  log
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  replaceContent,
  execCommandInTarget,
  replaceEachContent,
  log
} from 't-comm/lib/sync-repo/index';

// 只支持 ESM 的项目
import {
  replaceContent,
  execCommandInTarget,
  replaceEachContent,
  log
} from 't-comm/es/sync-repo/index';

replaceContent(replaceList, targetProject)

描述:替换文件内容 批量替换目标项目中指定文件的内容

参数

参数名描述
replaceList替换配置列表
targetProject目标项目路径

示例

ts
replaceContent({
  replaceList: [
    {
      dirList: ['src/*.ts'],
      from: 'old-text',
      to: 'new-text'
    }
  ],
  targetProject: '/path/to/project'
});

execCommandInTarget(command, targetProject)

描述:在目标项目中执行命令

参数

参数名描述
command要执行的命令
targetProject目标项目路径

示例

ts
execCommandInTarget('npm install', '/path/to/project');

replaceEachContent(dirList, to, from, targetProject)

描述:替换单个内容 在指定目录列表中替换文件内容

参数

参数名描述
dirList目录列表
to替换为的内容
from要被替换的内容
targetProject目标项目路径

示例

ts
replaceEachContent({
  dirList: ['src', 'lib'],
  from: '@old/package',
  to: '@new/package',
  targetProject: '/path/to/project'
});

log(content, args)

描述:输出日志信息 带有信息图标的日志输出

参数

参数名描述
content日志内容
args额外参数

示例

ts
log('正在处理...', 'file.ts');