管理端adm-tpl-part模版

# 简介

# 克隆依赖项目

const gitClone = opts => {
  const { remoteRepoOpts, branchMap, repoUser, tempPath, callback, noMove, remoteRepos = [], loopNum = 0 } = opts;

  const { name, repoUrl, branch, pages } = remoteRepoOpts;
  const url = userCredentials(repoUrl, repoUser);
  const repoTempPath = join(tempPath, name);

  const pagesPath = join(process.cwd(), '/src/pages');
  const to = join(pagesPath, name);
  // 先删除pages
  removeSync(to);

  const configBranch = branchMap[name] || '';
  if (configBranch === '' || configBranch === 'null' || configBranch === '0') {
    return;
  }

  // git命令,远程拉取项目并自定义项目名
  const cmdStr = `git clone -b ${configBranch} ${url} ${repoTempPath}`;
  console.log(`开始克隆: ${repoUrl} checkout分支 ${configBranch}`);
  exec(cmdStr, (error, stdout, stderr) => {
    if (error) {
      console.error('发生错误:');
      safeConsole(error, repoUser);

      // 只要有一个出错就不能进行下去了
      process.exit();
    }
    console.success(`${name}克隆成功!`);
    if (name === 'portal') {
      moveToRoot(name, branchMap);
    } else if (name === 'env') {
      moveToConfig(name);
    } else if (!noMove) {
      moveToPages(name, pages);
    }
    const tempPath = join(process.cwd(), GITTEMP);
    const { dependencies } = require(`${tempPath}/${name}/package.json`);
    depsObj = Object.assign(dependencies, depsObj)
    if (loopNum === remoteRepos.length - 1) {
      delete depsObj.bdpcloud // 移除子系统中bdpcloud相关依赖
      const pkg = require(`${tempPath}/portal/package.json`);
      pkg.dependencies = depsObj
      writeFileSync(join(process.cwd(), '../package.json'), JSON.stringify(pkg))
      console.success("package.json组合生成成功")
    }
    if (typeof callback === 'function') {
      callback();
    }
  });
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# 依赖合并

const tempPath = join(process.cwd(), GITTEMP);
const { dependencies } = require(`${tempPath}/${name}/package.json`);
depsObj = Object.assign(dependencies, depsObj)
if (loopNum === remoteRepos.length - 1) {
  delete depsObj.bdpcloud // 移除子系统中bdpcloud相关依赖
  const pkg = require(`${tempPath}/portal/package.json`);
  pkg.dependencies = depsObj
  writeFileSync(join(process.cwd(), '../package.json'), JSON.stringify(pkg))
  console.success("package.json组合生成成功")
}
if (typeof callback === 'function') {
  callback();
}

// 创建配置文件
const createConfigFile = (jsonObj) => {
  const str = `module.exports = ${JSON.stringify(jsonObj, null, 2)}`;
  fs.writeFileSync(configPath, str);
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
上次更新: 2022/04/15, 05:41:29
×