Skip to content

Commit

Permalink
chore: add script for copying package readme files to docs/en/packages (
Browse files Browse the repository at this point in the history
  • Loading branch information
jkmdev authored and awentzel committed Jan 24, 2019
1 parent 9c02fc3 commit 7d93056
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions build/documentation/copy-package-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

});

});
Expand All @@ -59,4 +61,4 @@ function copyReadmeFiles() {
/**
* Copy all files
*/
copyReadmeFiles();
copyReadmeFiles();

0 comments on commit 7d93056

Please sign in to comment.