makeDep增加了强制模式处理
This commit is contained in:
parent
02784275d6
commit
c6faab7de0
|
|
@ -749,7 +749,7 @@ function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|||
* @param fromDir 依赖项目的目录
|
||||
* @param toDir 当前项目的目录
|
||||
*/
|
||||
function tryCopyFilesRecursively(fromDir, toDir) {
|
||||
function tryCopyFilesRecursively(fromDir, toDir, rebuild) {
|
||||
const files = (0, fs_1.readdirSync)(fromDir);
|
||||
files.forEach((file) => {
|
||||
const fromFile = join(fromDir, file);
|
||||
|
|
@ -757,7 +757,12 @@ function tryCopyFilesRecursively(fromDir, toDir) {
|
|||
const stat = (0, fs_1.statSync)(fromFile);
|
||||
if (stat.isFile()) {
|
||||
if ((0, fs_1.existsSync)(join(toDir, file))) {
|
||||
console.log(`覆盖文件${toFile}`);
|
||||
if (rebuild) {
|
||||
console.log(`覆盖文件${toFile}`);
|
||||
}
|
||||
else {
|
||||
console.log(`忽略文件${toFile}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(`拷贝文件${toFile}`);
|
||||
|
|
@ -771,7 +776,7 @@ function tryCopyFilesRecursively(fromDir, toDir) {
|
|||
console.log(`创建文件夹${toFile}`);
|
||||
(0, fs_extra_1.mkdirSync)(toFile);
|
||||
}
|
||||
tryCopyFilesRecursively(fromFile, toFile);
|
||||
tryCopyFilesRecursively(fromFile, toFile, rebuild);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -781,7 +786,7 @@ function tryCopyFilesRecursively(fromDir, toDir) {
|
|||
* @param dependencies
|
||||
* @param briefNames
|
||||
*/
|
||||
function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer) {
|
||||
function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebuild) {
|
||||
const injectDataIndexFileDependencies = [];
|
||||
const injectDataIndexFileBriefNames = [];
|
||||
dependencies.forEach((dep, idx) => {
|
||||
|
|
@ -792,7 +797,7 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer) {
|
|||
const dataFile = join(moduleTemplateDir, 'data.ts');
|
||||
if ((0, fs_1.existsSync)(dataFile)) {
|
||||
const prjDataFile = join(cwd, 'src', 'data', `${briefNames[idx]}Data.ts`);
|
||||
if (!(0, fs_1.existsSync)(prjDataFile)) {
|
||||
if (!(0, fs_1.existsSync)(prjDataFile) || rebuild) {
|
||||
console.log(`拷贝${dataFile}到${prjDataFile}中`);
|
||||
(0, fs_extra_1.copySync)(dataFile, prjDataFile);
|
||||
injectDataIndexFileDependencies.push(dep);
|
||||
|
|
@ -802,7 +807,7 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer) {
|
|||
// src下面的文件是可以拷贝到项目中的
|
||||
const srcDir = join(moduleTemplateDir, 'src');
|
||||
if ((0, fs_1.existsSync)(srcDir)) {
|
||||
tryCopyFilesRecursively(srcDir, join(cwd, 'src'));
|
||||
tryCopyFilesRecursively(srcDir, join(cwd, 'src'), rebuild);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1020,7 +1025,7 @@ function buildDependency(rebuild) {
|
|||
}
|
||||
// 把各个依赖项目的一些初始化的文件拷贝过去
|
||||
if (!isModule) {
|
||||
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer);
|
||||
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebuild);
|
||||
}
|
||||
}
|
||||
exports.default = buildDependency;
|
||||
|
|
|
|||
|
|
@ -1453,7 +1453,7 @@ function injectDataIndexFile(
|
|||
* @param fromDir 依赖项目的目录
|
||||
* @param toDir 当前项目的目录
|
||||
*/
|
||||
function tryCopyFilesRecursively(fromDir: string, toDir: string) {
|
||||
function tryCopyFilesRecursively(fromDir: string, toDir: string, rebuild?: boolean) {
|
||||
const files = readdirSync(fromDir);
|
||||
|
||||
files.forEach(
|
||||
|
|
@ -1463,7 +1463,12 @@ function tryCopyFilesRecursively(fromDir: string, toDir: string) {
|
|||
const stat = statSync(fromFile);
|
||||
if (stat.isFile()) {
|
||||
if (existsSync(join(toDir, file))) {
|
||||
console.log(`覆盖文件${toFile}`);
|
||||
if (rebuild) {
|
||||
console.log(`覆盖文件${toFile}`);
|
||||
}
|
||||
else {
|
||||
console.log(`忽略文件${toFile}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(`拷贝文件${toFile}`);
|
||||
|
|
@ -1477,7 +1482,7 @@ function tryCopyFilesRecursively(fromDir: string, toDir: string) {
|
|||
console.log(`创建文件夹${toFile}`);
|
||||
mkdirSync(toFile);
|
||||
}
|
||||
tryCopyFilesRecursively(fromFile, toFile);
|
||||
tryCopyFilesRecursively(fromFile, toFile, rebuild);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -1493,7 +1498,8 @@ function tryCopyModuleTemplateFiles(
|
|||
cwd: string,
|
||||
dependencies: string[],
|
||||
briefNames: string[],
|
||||
printer: ts.Printer
|
||||
printer: ts.Printer,
|
||||
rebuild?: boolean
|
||||
) {
|
||||
const injectDataIndexFileDependencies: string[] = [];
|
||||
const injectDataIndexFileBriefNames: string[] = [];
|
||||
|
|
@ -1507,7 +1513,7 @@ function tryCopyModuleTemplateFiles(
|
|||
const dataFile = join(moduleTemplateDir, 'data.ts');
|
||||
if (existsSync(dataFile)) {
|
||||
const prjDataFile = join(cwd, 'src', 'data', `${briefNames[idx]}Data.ts`);
|
||||
if (!existsSync(prjDataFile)) {
|
||||
if (!existsSync(prjDataFile) || rebuild) {
|
||||
console.log(`拷贝${dataFile}到${prjDataFile}中`);
|
||||
copySync(dataFile, prjDataFile);
|
||||
injectDataIndexFileDependencies.push(dep);
|
||||
|
|
@ -1518,7 +1524,7 @@ function tryCopyModuleTemplateFiles(
|
|||
// src下面的文件是可以拷贝到项目中的
|
||||
const srcDir = join(moduleTemplateDir, 'src');
|
||||
if (existsSync(srcDir)) {
|
||||
tryCopyFilesRecursively(srcDir, join(cwd, 'src'));
|
||||
tryCopyFilesRecursively(srcDir, join(cwd, 'src'), rebuild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1851,6 +1857,6 @@ export default function buildDependency(rebuild?: boolean) {
|
|||
|
||||
// 把各个依赖项目的一些初始化的文件拷贝过去
|
||||
if (!isModule) {
|
||||
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer);
|
||||
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebuild);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue