зеркало из https://github.com/microsoft/fast.git
chore: add script for copying package readme files to docs/en/packages (#1315)
This commit is contained in:
Родитель
9c02fc32d0
Коммит
7d93056992
|
@ -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();
|
||||
copyReadmeFiles();
|
||||
|
|
Загрузка…
Ссылка в новой задаче