From 7d930569929f7eb3d31d3e541c7b6967a0e08a8b Mon Sep 17 00:00:00 2001 From: Julia McGeoghan Date: Wed, 23 Jan 2019 19:26:13 -0500 Subject: [PATCH] chore: add script for copying package readme files to docs/en/packages (#1315) --- build/documentation/copy-package-readme.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/build/documentation/copy-package-readme.js b/build/documentation/copy-package-readme.js index ca879e53e10..12924e21461 100644 --- a/build/documentation/copy-package-readme.js +++ b/build/documentation/copy-package-readme.js @@ -8,13 +8,15 @@ const glob = require("glob"); const rootDir = path.resolve(process.cwd()); const srcReadmePaths = "packages/*/README.md"; -const destDir = "docs\\en\\packages"; +const destDir = path.join("docs", "en", "packages"); + var dryRun = false; /** * Determine if a dry run will be executed based off --dry-run argument being present * if an invalid third parameter is entered, the application will exit */ + process.argv.forEach(function (val, index) { var validArg = true; @@ -37,19 +39,19 @@ function copyReadmeFiles() { const resolvedSrcReadmePaths = path.resolve(rootDir, srcReadmePaths); glob(resolvedSrcReadmePaths, {realpath:true}, function(error, files) { - + files.forEach((filePath) => { const destReadmePath = filePath.replace(/(\bpackages\b)(?!.*\1)/, destDir); - const dirPath = destReadmePath.replace(/(\b\\README.md\b)(?!.*\1)/, ''); + const dirPath = path.dirname(destReadmePath); if (!fs.existsSync(dirPath)) { dryRun ? console.log("----> Would create folder " + dirPath) : fs.mkdirSync(dirPath); } - if (!fs.existsSync(destReadmePath)) { - dryRun ? console.log(" --> Would create file README.md in " + dirPath) : fs.copyFileSync(filePath, destReadmePath); - } else { - dryRun ? console.log(" --> Would replace README.md in " + dirPath) : fs.copyFileSync(filePath, destReadmePath); + if (!fs.existsSync(destReadmePath)) { + dryRun ? console.log(" --> Would create file README.md in " + dirPath) : fs.copyFileSync(filePath, destReadmePath); + } else { + dryRun ? console.log(" --> Would replace README.md in " + dirPath) : fs.copyFileSync(filePath, destReadmePath); } - + }); }); @@ -59,4 +61,4 @@ function copyReadmeFiles() { /** * Copy all files */ -copyReadmeFiles(); \ No newline at end of file +copyReadmeFiles();