diff --git a/common/config/rush/command-line.json b/common/config/rush/command-line.json index a49ed2c85..1ab15b41d 100644 --- a/common/config/rush/command-line.json +++ b/common/config/rush/command-line.json @@ -32,14 +32,23 @@ }, { "commandKind": "bulk", - "summary": "Run all build for all packages", + "summary": "Run all build targets for all packages", "name": "build", + "enableParallelism": true, "allowWarningsInSuccessfulBuild": true }, { "commandKind": "bulk", - "summary": "Run all build for all packages", + "summary": "Run all build targets for all packages", "name": "rebuild", + "enableParallelism": true, + "allowWarningsInSuccessfulBuild": true + }, + { + "commandKind": "bulk", + "summary": "Run all compile targets for all packages", + "name": "compile", + "enableParallelism": true, "allowWarningsInSuccessfulBuild": true } ] diff --git a/sandbox-tools/merge-repos/src/config.ts b/sandbox-tools/merge-repos/src/config.ts index 09caa70d5..45d22a461 100644 --- a/sandbox-tools/merge-repos/src/config.ts +++ b/sandbox-tools/merge-repos/src/config.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { IRushCommandLine } from "./rush/rush"; import { IMergeDetail, IMergePackageDetail, IRepoSyncDetails } from "./support/types"; export const LICENSE_HEADER = "/*!\n" + @@ -161,7 +162,7 @@ export const foldersToMerge: IMergePackageDetail[] = [ */ export const filesToMerge: IMergeDetail[] = [ { srcPath: "auto-merge/js/.markdownlint.json", destPath: ".markdownlint.json" }, - { srcPath: "auto-merge/js/eslint.config.js", destPath: "eslint.config.js" }, + { srcPath: "auto-merge/js/eslint.base.js", destPath: "eslint.base.js", optional: true }, { srcPath: "auto-merge/js/karma.base.js", destPath: "karma.base.js" }, { srcPath: "auto-merge/js/karma.webpack.js", destPath: "karma.webpack.js" }, { srcPath: "auto-merge/js/karma.worker.js", destPath: "karma.worker.js" }, @@ -177,6 +178,28 @@ export const filesToMerge: IMergeDetail[] = [ { srcPath: "auto-merge/js/prettier.config.js", destPath: "prettier.config.js" } ]; +/** + * Files to remove from staging + */ +export const filesToCleanup: IMergeDetail[] = [ + { destPath: "eslint.config.js" }, +]; + + +/** + * Files to remove after merging + */ +export const mergeFilesToCleanup: IMergeDetail[] = [ + { destPath: "eslint.config.js" }, +]; + +/** + * Repo root files to check for bad merging + */ +export const fixBadMergeRootFiles: string[] = [ + ".gitmodules" +]; + /** * Enforce these versions when specified (required, dev or peer) */ @@ -186,9 +209,10 @@ export let dependencyVersions = { "@types/sinon": "^10.0.13", "@types/webpack-env": "1.16.3", "@types/jquery": "^3.5.14", - "@typescript-eslint/eslint-plugin": "5.3.1", - "@typescript-eslint/parser": "5.3.1", + "@typescript-eslint/eslint-plugin": "5.59.11", + "@typescript-eslint/parser": "5.59.11", "zone.js": "^0.11.4", + "prettier": "2.8.8", "typescript": "^4.9.5" }; @@ -202,11 +226,14 @@ export let addMissingDevDeps = { "@types/webpack-env": "1.16.3", "@types/jquery": "^3.5.14", "karma-mocha-webworker": "1.3.0", - "@typescript-eslint/eslint-plugin": "5.3.1", - "@typescript-eslint/parser": "5.3.1", - "eslint": "7.32.0", + "@typescript-eslint/eslint-plugin": "5.59.11", + "@typescript-eslint/parser": "5.59.11", + "babel-loader": "8.3.0", + "babel-plugin-istanbul": "6.1.1", + "eslint": "8.46.0", "eslint-plugin-header": "3.1.1", "eslint-plugin-node": "11.1.0", + "prettier": "2.8.8", "typedoc": "^0.23.26", "typedoc-plugin-missing-exports": "^1.0.0", "typedoc-plugin-resolve-crossmodule-references": "^0.3.3" @@ -224,9 +251,9 @@ export let dropDependencies = { * Add these scripts to the root package.json */ export let initScripts = { - "build": "rush rebuild --verbose", - "rebuild": "npm run build", - "compile": "npm run build", + "build": "rush build --verbose", // This will compile and package (bundle) + "rebuild": "rush rebuild --verbose", // clean, compile and package + "compile": "rush compile --verbose", // Run compile target for all projects -- auto lints and compiles "postinstall": "rush update", "test": "rush test --verbose", "lint": "rush lint --verbose", @@ -266,9 +293,9 @@ export let initDevDependencyVersions = { * Add these dev dependencies to ALL processed package.json files */ export let commonDevDependencyVersions = { - "@typescript-eslint/eslint-plugin": "5.3.1", - "@typescript-eslint/parser": "5.3.1", - "eslint": "7.32.0", + "@typescript-eslint/eslint-plugin": "5.59.11", + "@typescript-eslint/parser": "5.59.11", + "eslint": "8.46.0", "eslint-plugin-header": "3.1.1", "eslint-plugin-import": "2.25.3", "eslint-plugin-node": "11.1.0", @@ -284,6 +311,7 @@ export let commonDevDependencyVersions = { "karma-typescript": "^5.5.3", "mocha": "10.0.0", "chromium": "^3.0.3", + "prettier": "2.8.8", "puppeteer": "^14.2.1", "sinon": "^14.0.0", "nyc": "^15.1.0", @@ -294,6 +322,64 @@ export let commonDevDependencyVersions = { "pako": "^2.0.3" }; +export let rootDevDependencies = { + "@typescript-eslint/eslint-plugin": "5.59.11", + "@typescript-eslint/parser": "5.59.11", + "eslint": "8.46.0", + "eslint-plugin-header": "3.1.1", + "eslint-plugin-import": "2.25.3", + "eslint-plugin-node": "11.1.0", + "eslint-config-prettier": "8.5.0", + "eslint-plugin-prettier": "4.2.1" +}; + +export const mergeRushCommandLine: { [name: string]: IRushCommandLine } = { + build: { + commandKind: "bulk", + summary: "Run all build targets for all packages", + enableParallelism: true, + allowWarningsInSuccessfulBuild: true + }, + rebuild: { + commandKind: "bulk", + summary: "Run all build targets for all packages", + enableParallelism: true, + allowWarningsInSuccessfulBuild: true + }, + compile: { + commandKind: "bulk", + summary: "Run all compile targets for all packages", + enableParallelism: true, + allowWarningsInSuccessfulBuild: true + }, + lint: { + commandKind: "bulk", + summary: "Run all tslint for all packages", + description: "Runs tslint for all projects", + safeForSimultaneousRushProcesses: false, + enableParallelism: true, + ignoreMissingScript: false + }, + "lint:fix": { + commandKind: "bulk", + summary: "Run all tslint for all packages", + description: "Runs tslint for all projects", + safeForSimultaneousRushProcesses: false, + enableParallelism: true, + ignoreMissingScript: false, + allowWarningsInSuccessfulBuild: true + }, + test : { + commandKind: "bulk", + summary: "Run all tests for all packages", + description: "Runs tests for all projects", + safeForSimultaneousRushProcesses: false, + enableParallelism: false, + ignoreMissingScript: false, + allowWarningsInSuccessfulBuild: true + } +}; + /** * Apply any expected defaults to the provided configuration, this is a helper * to ensure that the expected values (for the script) are always present diff --git a/sandbox-tools/merge-repos/src/git/resolveConflictsToTheirs.ts b/sandbox-tools/merge-repos/src/git/resolveConflictsToTheirs.ts index 46554d551..7f12d399d 100644 --- a/sandbox-tools/merge-repos/src/git/resolveConflictsToTheirs.ts +++ b/sandbox-tools/merge-repos/src/git/resolveConflictsToTheirs.ts @@ -167,10 +167,19 @@ function getFileStatus(status: StatusResult, name: string): FileStatusResult { conflicted ]); - await git.raw([ - "add", - "-f", - conflicted]); + try { + await git.raw([ + "add", + "-f", + conflicted]); + } catch (e) { + if (!conflicted.endsWith("/protos")) { + throw e; + } else { + log(` - !! Ignoring git add for known submodule folder - ${conflicted}`); + await git.rm(conflicted); + } + } } else if (fileStatus.working_dir === "M") { commitMessage = logAppendMessage(gitRoot, commitMessage, fileStatus, "Added in theirs, modified in ours => checkout theirs"); await git.checkout([ diff --git a/sandbox-tools/merge-repos/src/mergeStagingToMain.ts b/sandbox-tools/merge-repos/src/mergeStagingToMain.ts index f3c49952a..39b0935d5 100644 --- a/sandbox-tools/merge-repos/src/mergeStagingToMain.ts +++ b/sandbox-tools/merge-repos/src/mergeStagingToMain.ts @@ -19,7 +19,7 @@ import * as path from "path"; import { CleanOptions, SimpleGit } from "simple-git"; import { MERGE_CLONE_LOCATION, MERGE_DEST_BASE_FOLDER, MERGE_ORIGIN_MERGE_MAIN_BRANCH, MERGE_ORIGIN_REPO, MERGE_ORIGIN_STAGING_BRANCH, SANDBOX_PROJECT_NAME, - addMissingDevDeps, dependencyVersions, dropDependencies, foldersToMerge, initDevDependencyVersions, initScripts, cleanupScripts, filesToMerge, commonDevDependencyVersions + addMissingDevDeps, dependencyVersions, dropDependencies, foldersToMerge, initDevDependencyVersions, initScripts, cleanupScripts, filesToMerge, commonDevDependencyVersions, filesToCleanup, mergeFilesToCleanup, fixBadMergeRootFiles, mergeRushCommandLine, rootDevDependencies } from "./config"; import { commitChanges, ICommitDetails } from "./git/commit"; import { createGit } from "./git/createGit"; @@ -32,7 +32,7 @@ import { checkPrExists } from "./github/checkPrExists"; import { createPullRequest, gitHubCreateForkRepo } from "./github/github"; import { createPackageKarmaConfig } from "./tests/karma"; import { createPackageRollupConfig } from "./rollup/rollup"; -import { rushUpdateShrinkwrap } from "./rush/rush"; +import { rushUpdateCommandLine, rushUpdateShrinkwrap } from "./rush/rush"; import { abort, fail, terminate } from "./support/abort"; import { addCleanupCallback, doCleanup } from "./support/clean"; import { isIgnoreFolder } from "./support/isIgnoreFolder"; @@ -42,7 +42,7 @@ import { IMergeDetail, IMergePackageDetail, IPackageJson, IPackages, IRepoDetail import { dumpObj, findCurrentRepoRoot, formatIndentLines, log, logError, logWarn, removeTrailingComma, transformContent, transformPackages } from "./support/utils"; import { createPackageWebpackTestConfig } from "./tests/webpack"; import { initPackageJson } from "./package/package"; -import { checkFixBadMerges } from "./support/mergeFixup"; +import { checkFixBadMerges, validateFile } from "./support/mergeFixup"; interface IStagingRepoDetails { git: SimpleGit, @@ -120,7 +120,7 @@ let _packages: IPackages = { /** * An array of submodules paths created that should be ignored from validation */ -let _subModules: string[] = []; +let _subModules: { url: string, path: string }[] = []; /** * Show the Help for this tool @@ -392,7 +392,10 @@ async function getStagingRepo(git: SimpleGit, repoName: string, details: IRepoDe let modulePath = path.join(packageDetails.destPath, moduleDef.path).replace(/\\/g, "/"); log ("adding submodule " + modulePath + " => " + moduleDef.url); await stagingGit.submoduleAdd(moduleDef.url, modulePath); - _subModules.push(modulePath); + _subModules.push({ + url: moduleDef.url, + path: modulePath + }); } } @@ -400,6 +403,21 @@ async function getStagingRepo(git: SimpleGit, repoName: string, details: IRepoDe await updateFilePackageReferences(stagingDetails, forkDestOrg, packageDetails.destPath); }); + log ("Cleaning up Files"); + await processMergeDetail(filesToCleanup, async (fileDetails) => { + let dest = path.join(_mergeGitRoot, fileDetails.destPath).replace(/\\/g, "/"); + + if (fs.existsSync(dest)) { + log(` - (Removing) ${fileDetails.destPath}`); + try { + await stagingGit.rm(fileDetails.destPath); + } catch (e) { + log(` - (Git rm failed Removing) ${fileDetails.destPath} - ${e}`); + fs.rmSync(dest); + } + } + }); + await commitChanges(stagingGit, stagingDetails.commitDetails); return stagingDetails; @@ -433,7 +451,7 @@ async function updateRushJson(git: SimpleGit, thePath: string) { projectFolderMaxDepth: 8, projects: [] }; - let rushJsonPath = path.join(thePath, "rush.json"); + let rushJsonPath = path.join(thePath, "rush.json").replace(/\\/g, "/"); log(`Loading package ${rushJsonPath}`); if (fs.existsSync(rushJsonPath)) { // Reading file vs using require(packagePath) as some package.json have a trailing "," which doesn't load via require() @@ -594,6 +612,12 @@ function updateDependencies(srcPackage: IPackageJson, destPackage: IPackageJson, return changed; } +function updateRootPackage(packageJson: IPackageJson) { + Object.keys(rootDevDependencies).forEach((key) => { + packageJson.devDependencies[key] = rootDevDependencies[key]; + }); +} + function sortPackageJson(packageJson: IPackageJson) { ["scripts", "dependencies", "devDependencies", "peerDependencies"].forEach((subKey) => { let sortTarget = packageJson[subKey]; @@ -666,9 +690,9 @@ function updatePackageJsonScripts(basePath: string, dest: string, newPackage: IP let hasKarmaWorkerCfg = fs.existsSync(path.join(basePath, path.join(packageDetails.destPath, "./karma.worker.conf.js")).replace(/\\/g, "/")); let newPackageScripts = { - "build": "npm run lint:fix-quiet && npm run version && tsc --build " + tsConfigJson.trim() + " && npm run package", - "rebuild": "npm run build", - "compile": "npm run build", + "build": "npm run compile && npm run package", + "rebuild": "npm run clean && npm run build", + "compile": "npm run lint:fix-quiet && npm run version && tsc --build " + tsConfigJson.trim(), "clean": "tsc --build --clean " + tsConfigJson.trim() + "", "package": "npx rollup -c ./rollup.config.js --bundleConfigAsCjs", "test": "npm run test:node && npm run test:browser && npm run test:webworker", @@ -677,8 +701,8 @@ function updatePackageJsonScripts(basePath: string, dest: string, newPackage: IP "test:webworker": "nyc karma start karma.worker.js --single-run", "test:debug": "nyc karma start ./karma.debug.conf.js --wait", "lint": "eslint . --ext .ts", - "lint:fix": "npm run lint -- --fix", - "lint:fix-quiet": "npm run lint -- --fix --quiet", + "lint:fix": "eslint . --ext .ts --fix", + "lint:fix-quiet": "eslint . --ext .ts --fix --quiet", "version": `node ${versionUpdate}`, "watch": "npm run version && tsc --build --watch " + tsConfigJson.trim() + "" }; @@ -702,7 +726,7 @@ function updatePackageJsonScripts(basePath: string, dest: string, newPackage: IP }); newPackageScripts["pre-build"] = preBuild; - newPackageScripts["build"] = newPackageScripts["build"].replace("&& tsc --build ", "&& npm run pre-build && tsc --build "); + newPackageScripts["compile"] = newPackageScripts["compile"].replace("&& tsc --build ", "&& npm run pre-build && tsc --build "); } if (packageDetails.compileScripts.post) { @@ -715,7 +739,7 @@ function updatePackageJsonScripts(basePath: string, dest: string, newPackage: IP }); newPackageScripts["post-build"] = postBuild; - newPackageScripts["build"] = newPackageScripts["build"].replace("&& npm run package", "&& npm run post-build && npm run package"); + newPackageScripts["compile"] = (newPackageScripts["compile"] + " && npm run post-build"); } } @@ -807,7 +831,7 @@ async function updateConfigFileRelativePaths(stagingDetails: IStagingRepoDetails let dest = path.join(basePath, destPath).replace(/\\/g, "/"); let relativePath = path.relative(dest, path.join(basePath, "$$$temp$$$")).replace(/\\/g, "/").replace("/$$$temp$$$", "/"); - const baseEsLintConfig = path.relative(dest, path.join(basePath, "eslint.config.js")).replace(/\\/g, "/"); + const baseEsLintConfig = path.relative(dest, path.join(basePath, "eslint.base.js")).replace(/\\/g, "/"); const files = fs.readdirSync(dest); log(`Updating relative paths: ${files.length} file(s) in ${dest}`); @@ -858,12 +882,17 @@ async function updateConfigFileRelativePaths(stagingDetails: IStagingRepoDetails } } else if (name === ".eslintrc.js") { - // update paths to base eslint.config.js + // update paths to base eslint.config.js to eslint.base.js (contrib) content = fs.readFileSync(theFilename, "utf-8"); newContent = content.replace(/require\(['"](.*eslint\.config\.js)['"]\)/gm, function(match, group) { log(` -- replacing ${group} => ${baseEsLintConfig}`); return match.replace(group, baseEsLintConfig); }); + // update paths to base eslint.base.js + newContent = newContent.replace(/require\(['"](.*eslint\.base\.js)['"]\)/gm, function(match, group) { + log(` -- replacing ${group} => ${baseEsLintConfig}`); + return match.replace(group, baseEsLintConfig); + }); } else if (name.startsWith("karma")) { // update paths to base karma configs content = fs.readFileSync(theFilename, "utf-8"); @@ -884,6 +913,22 @@ async function updateConfigFileRelativePaths(stagingDetails: IStagingRepoDetails } } +async function cleanupMergeFiles(mergeGit: SimpleGit) { + await processMergeDetail(mergeFilesToCleanup, async (fileDetails) => { + let dest = path.join(_mergeGitRoot, fileDetails.destPath).replace(/\\/g, "/"); + + if (fs.existsSync(dest)) { + log(` - (Removing) ${fileDetails.destPath}`); + try { + await mergeGit.rm(fileDetails.destPath); + } catch (e) { + log(` - (Git rm failed Removing) ${fileDetails.destPath} - ${e}`); + fs.rmSync(dest); + } + } + }); +} + async function mergeStagingToMaster(mergeGit: SimpleGit, stagingDetails: IStagingRepoDetails) { let mergeCommitMessage: ICommitDetails = { committed: false, @@ -899,6 +944,8 @@ async function mergeStagingToMaster(mergeGit: SimpleGit, stagingDetails: IStagin "--no-ff", "--no-edit", "staging/" + stagingDetails.branch]).catch(async (reason) => { + log (`Remove cleanup merge files in ${_mergeGitRoot} first`); + await cleanupMergeFiles(mergeGit); commitPerformed = await resolveConflictsToTheirs(mergeGit, _mergeGitRoot, mergeCommitMessage, false); }); @@ -916,7 +963,7 @@ async function mergeStagingToMaster(mergeGit: SimpleGit, stagingDetails: IStagin let destPath = path.join(destFolder, source).replace(/\\/g, "/"); let isSubmodule = false; _subModules.forEach((subPath) => { - if (destPath.indexOf(subPath) !== -1) { + if (destPath.indexOf(subPath.path) !== -1) { log(` - Submodule ignore: ${subPath}`); isSubmodule = true; } @@ -931,13 +978,35 @@ async function mergeStagingToMaster(mergeGit: SimpleGit, stagingDetails: IStagin // Validate and fixup any bad merges that may have occurred -- make sure the source and new merged repo contain the same files await checkFixBadMerges(mergeGit, _mergeGitRoot, _isVerifyIgnore, stagingDetails.branch, stagingDetails.path + "/pkgs", _mergeGitRoot + "/pkgs", mergeCommitMessage, 0); - + + for (let lp = 0; lp < fixBadMergeRootFiles.length; lp++) { + let mergeFileChk = fixBadMergeRootFiles[lp]; + + if (validateFile(_mergeGitRoot, stagingDetails.path + "/" + mergeFileChk, _mergeGitRoot + "/" + mergeFileChk, mergeCommitMessage)) { + + await mergeGit.raw([ + "add", + "-f", + _mergeGitRoot + "/" + mergeFileChk]); + } + } + + log ("Resetting up submodules"); + for (let lp = 0; lp < _subModules.length; lp++) { + log ("adding submodule " + _subModules[lp].path + " => " + _subModules[lp].url); + await mergeGit.submoduleAdd(_subModules[lp].url, _subModules[lp].path); + } + // Update the root package json if (!checkPackageName(_mergeGitRoot, SANDBOX_PROJECT_NAME, _mergeGitRoot, true)) { fail(mergeGit, "Current repo folder does not appear to be the sandbox"); } + log (`Cleaning up merge files in ${_mergeGitRoot}`); + await cleanupMergeFiles(mergeGit); + let rootPackage = _packages.dest[SANDBOX_PROJECT_NAME]; + updateRootPackage(rootPackage.pkg); sortPackageJson(rootPackage.pkg); let newRushText = JSON.stringify(rootPackage.pkg, null, 2); @@ -955,6 +1024,11 @@ async function mergeStagingToMaster(mergeGit: SimpleGit, stagingDetails: IStagin await mergeGit.add(shrinkWrapFile); } + let commandLineJson = rushUpdateCommandLine(_mergeGitRoot, mergeRushCommandLine); + if (commandLineJson) { + await mergeGit.add(commandLineJson); + } + mergeCommitMessage.committed = await commitChanges(mergeGit, mergeCommitMessage) || commitPerformed; return mergeCommitMessage; diff --git a/sandbox-tools/merge-repos/src/rush/rush.ts b/sandbox-tools/merge-repos/src/rush/rush.ts index 7a8f3c819..cce8644a3 100644 --- a/sandbox-tools/merge-repos/src/rush/rush.ts +++ b/sandbox-tools/merge-repos/src/rush/rush.ts @@ -19,9 +19,20 @@ import * as child_process from "child_process"; import * as util from "util"; import { log, removeTrailingComma } from "../support/utils"; import path = require("path"); +import { SimpleGit } from "simple-git"; const execFile = util.promisify(child_process.execFile); +export interface IRushCommandLine { + commandKind: string, + summary: string, + description?: string , + safeForSimultaneousRushProcesses?: boolean, + enableParallelism: boolean, + ignoreMissingScript?: boolean, + allowWarningsInSuccessfulBuild?: boolean +}; + /** * Get a list of fork repositories, using the provided `gitRoot` as the current path * when executing the github `gh` CLI. @@ -68,3 +79,68 @@ export async function rushUpdateShrinkwrap(gitRoot: string): Promise { return result; } +export function rushUpdateCommandLine(gitRoot: string, rushCommands: { [name: string]: IRushCommandLine}): string { + let result: string = null; + + process.chdir(path.resolve(gitRoot)); + + log(`Updating command-line.json in ${path.resolve(gitRoot)}`); + + let commandLineLocation = "common/config/rush/command-line.json"; + let orgContent = ""; + let commandLinePath = path.resolve(gitRoot, commandLineLocation); + if (fs.existsSync(commandLinePath)) { + // Reading file vs using require(packagePath) as some package.json have a trailing "," which doesn't load via require() + orgContent = removeTrailingComma(fs.readFileSync(commandLinePath, "utf-8")); + } + + let commandLineJson = JSON.parse(orgContent); + let theCommands = {}; + + // Read the current commands + commandLineJson.commands.forEach((theCommand) => { + let props = {}; + let name: string; + Object.keys(theCommand).forEach((key) => { + if (key !== "name") { + props[key] = theCommand[key]; + } else { + name = theCommand[key]; + } + }); + if (name) { + theCommands[name] = props; + } + }); + + // Merge in the new commands + Object.keys(rushCommands).forEach((key) => { + let rushCommand = rushCommands[key]; + let command = theCommands[key] = (theCommands[key] || {}); + Object.keys(rushCommand).forEach((cmdName) => { + command[cmdName] = rushCommand[cmdName]; + }); + }); + + commandLineJson.commands = []; + Object.keys(theCommands).forEach((cmdName) => { + let newCommand = { + name: cmdName + }; + Object.keys(theCommands[cmdName]).forEach((propName) => { + newCommand[propName] = theCommands[cmdName][propName]; + }); + + commandLineJson.commands.push(newCommand); + }); + + let newContent = JSON.stringify(commandLineJson, null, 4); + + if (orgContent !== newContent) { + log(` -- ${commandLinePath} changed -- rewriting...`); + fs.writeFileSync(commandLinePath, newContent); + result = commandLineLocation; + } + + return result; +} \ No newline at end of file diff --git a/sandbox-tools/merge-repos/src/support/isIgnoreFolder.ts b/sandbox-tools/merge-repos/src/support/isIgnoreFolder.ts index e3647ed81..584fa5c2f 100644 --- a/sandbox-tools/merge-repos/src/support/isIgnoreFolder.ts +++ b/sandbox-tools/merge-repos/src/support/isIgnoreFolder.ts @@ -26,7 +26,7 @@ import { IRepoSyncDetails } from "./types"; * @returns */ export function isIgnoreFolder(theRepos: IRepoSyncDetails, source: string, isRoot: boolean) { - if (source === "." || source === ".." || source === ".git" || source === ".vs") { + if (source === "." || source === ".." || source === ".git" || source === ".vs" || source === "protos") { return true; } diff --git a/sandbox-tools/merge-repos/src/support/mergeFixup.ts b/sandbox-tools/merge-repos/src/support/mergeFixup.ts index 1b14ed60e..6501f0191 100644 --- a/sandbox-tools/merge-repos/src/support/mergeFixup.ts +++ b/sandbox-tools/merge-repos/src/support/mergeFixup.ts @@ -19,6 +19,59 @@ import { SimpleGit } from "simple-git"; import { ICommitDetails } from "../git/commit"; import { log, logAppendMessage } from "./utils"; +export async function validateFile( + mergeGitRoot: string, + masterFile: string, + destFile: string, + commitDetails: ICommitDetails) { + + let changed = false; + if (fs.existsSync(destFile)) { + // Compare contents + let destStats = fs.statSync(destFile); + let masterStats = fs.statSync(masterFile); + if (destStats.size !== masterStats.size) { + // File size is different so was not moved / merged correctly + commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "S", path: destFile } , `Re-Copying master file as size mismatch ${destStats.size} !== ${masterStats.size}`); + fs.copyFileSync(masterFile, destFile); + changed = true; + } else { + // Same file size, so compare contents + let masterContent = fs.readFileSync(masterFile); + let destContent = fs.readFileSync(destFile); + if (masterContent.length !== destContent.length) { + // File content is different so was not moved / merged correctly + commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "C", path: destFile } , "Re-Copying master file as content mismatch"); + fs.copyFileSync(masterFile, destFile); + changed = true; + } else { + let isSame = true; + let lp = 0; + while (isSame && lp < masterContent.length) { + if (masterContent[lp] !== destContent[lp]) { + isSame = false; + } + lp++; + } + + if (!isSame) { + // File content is different so was not moved / merged correctly + commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "C", path: destFile } , "Re-Copying master file as content is different"); + fs.copyFileSync(masterFile, destFile); + changed = true; + } + } + } + } else { + // Missing dest so was not moved / merged correctly + commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "M", path: destFile } , "Re-Copying master file"); + fs.copyFileSync(masterFile, destFile); + changed = true; + } + + return changed; +} + export async function checkFixBadMerges( git: SimpleGit, mergeGitRoot: string, @@ -33,54 +86,6 @@ export async function checkFixBadMerges( const masterFiles = fs.readdirSync(baseFolder); const destFiles = fs.readdirSync(destFolder); - async function validateFile(masterFile: string, destFile: string) { - let changed = false; - if (fs.existsSync(destFile)) { - // Compare contents - let destStats = fs.statSync(destFile); - let masterStats = fs.statSync(masterFile); - if (destStats.size !== masterStats.size) { - // File size is different so was not moved / merged correctly - commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "S", path: destFile } , `Re-Copying master file as size mismatch ${destStats.size} !== ${masterStats.size}`); - fs.copyFileSync(masterFile, destFile); - changed = true; - } else { - // Same file size, so compare contents - let masterContent = fs.readFileSync(masterFile); - let destContent = fs.readFileSync(destFile); - if (masterContent.length !== destContent.length) { - // File content is different so was not moved / merged correctly - commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "C", path: destFile } , "Re-Copying master file as content mismatch"); - fs.copyFileSync(masterFile, destFile); - changed = true; - } else { - let isSame = true; - let lp = 0; - while (isSame && lp < masterContent.length) { - if (masterContent[lp] !== destContent[lp]) { - isSame = false; - } - lp++; - } - - if (!isSame) { - // File content is different so was not moved / merged correctly - commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "C", path: destFile } , "Re-Copying master file as content is different"); - fs.copyFileSync(masterFile, destFile); - changed = true; - } - } - } - } else { - // Missing dest so was not moved / merged correctly - commitDetails.message = logAppendMessage(mergeGitRoot, commitDetails.message, { index: "x", working_dir: "M", path: destFile } , "Re-Copying master file"); - fs.copyFileSync(masterFile, destFile); - changed = true; - } - - return changed; - } - log(` - (Verifying) ${baseFolder} <=> ${destFolder}`); for (let mLp = 0; mLp < masterFiles.length; mLp++) { let theFile = masterFiles[mLp]; @@ -107,7 +112,7 @@ export async function checkFixBadMerges( } } else { // Assume file - if (validateFile(baseFolder + "/" + theFile, destFolder + "/" + theFile)) { + if (validateFile(mergeGitRoot, baseFolder + "/" + theFile, destFolder + "/" + theFile, commitDetails)) { await git.raw([ "add", diff --git a/sandbox-tools/merge-repos/src/support/types.ts b/sandbox-tools/merge-repos/src/support/types.ts index c0dc7faa4..f9a829afb 100644 --- a/sandbox-tools/merge-repos/src/support/types.ts +++ b/sandbox-tools/merge-repos/src/support/types.ts @@ -79,7 +79,7 @@ export interface IMergeDetail { /** * Identifies the location in the staging repo */ - srcPath: string; + srcPath?: string; /** * Identifies the location in the main repo where to merge this package diff --git a/sandbox-tools/merge-repos/src/syncReposToStaging.ts b/sandbox-tools/merge-repos/src/syncReposToStaging.ts index 1ce55acc9..937ffb9c9 100644 --- a/sandbox-tools/merge-repos/src/syncReposToStaging.ts +++ b/sandbox-tools/merge-repos/src/syncReposToStaging.ts @@ -427,7 +427,7 @@ localGit.checkIsRepo().then(async (isRepo) => { const originBranch = _theArgs.switches.originBranch; let createPr = !_theArgs.switches.noPr; if (_theArgs.switches.test ) { - createPr = false; + //createPr = false; _theArgs.switches.cloneTo = "../" + _theArgs.switches.cloneTo; }