Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update to create packages folder when it doesn't already exist #1395

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions build/documentation/copy-package-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ process.argv.forEach(function (val, index) {
*/
function copyReadmeFiles() {

if (dryRun) console.log("In docs/en/packages/, this script would...");

const resolvedSrcReadmePaths = path.resolve(rootDir, srcReadmePaths);

if (dryRun) console.log(`For ${destDir}, this script would...`);

createDirectory(destDir);
glob(resolvedSrcReadmePaths, {realpath:true}, function(error, srcFiles) {

srcFiles.forEach((srcReadmePath) => {
Expand Down Expand Up @@ -91,18 +93,14 @@ function createDestReadme(srcReadmePath) {
`sidebar_label: ${title}\n` +
`---\n\n`;

if (!fs.existsSync(destDirPath)) {
dryRun ? console.log(`...CREATE folder '${folderName}'`) : fs.mkdirSync(destDirPath);
}
createDirectory(destDirPath);

if (dryRun) {

if (fs.existsSync(destReadmePath)) {
console.log(`...REPLACE readme.md in the '${folderName}' folder`);
} else {
console.log(`...ADD readme.md into the '${folderName}' folder`);
}

} else {
try {
fs.writeFileSync(destReadmePath, docusaurusHeader);
Expand Down Expand Up @@ -140,6 +138,16 @@ function updateSidebar() {

}

/**
* Utility function that creates new folders
* based off dir argument
*/
function createDirectory(dir) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat of a naming nit, but I think it may be helpful - perhaps we should consider renaming this function to something more along the lines of ensureDirectoryExists. This is really a function that checks to ensure a directory exists and if it doesn't, it creates it. I think naming it to better align with that will help clarify it's purpose when reading through the copy and create functions above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Yes that's a much clearer name, I'll make that change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkmdev Looks like this was merged prior to you being able to push the change here - would you mind pushing a new PR to address the name change here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's named appropriately. The assurance is included in the conditional creation.

if (!fs.existsSync(dir)) {
dryRun ? console.log(`...CREATE the '${dir}' folder.`) : fs.mkdirSync(dir);
}
}

/**
* Run script
* Based off presence of --dry-run parameter
Expand Down