Skip to content

Commit

Permalink
Migrate concatenateDocs script to js
Browse files Browse the repository at this point in the history
  • Loading branch information
Monteth committed Apr 19, 2024
1 parent 416d133 commit c67bcb8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build
- name: Create a concentrated doc file
run: ./scripts/concatenateDocs.sh . uniformsConcentratedDocs.md
run: node ./scripts/concatenateDocs.js . uniformsConcentratedDocs.md
- name: Upload the concentrated doc file as an artifact
uses: actions/upload-artifact@v3
with:
Expand Down
34 changes: 34 additions & 0 deletions scripts/concatenateDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs');
const path = require('path');

// Check if the correct number of arguments are passed
if (process.argv.length !== 4) {
console.log(`Usage: node ${path.basename(__filename)} <root_directory> <output_file>`);

Check failure on line 6 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Unexpected console statement

Check failure on line 6 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Replace ``Usage:·node·${path.basename(__filename)}·<root_directory>·<output_file>`` with `⏎····`Usage:·node·${path.basename(__filename)}·<root_directory>·<output_file>`,⏎··`
process.exit(1);
}

const rootDirectory = process.argv[2];
const outputFile = process.argv[3];

// Create or clear the output file
fs.writeFileSync(outputFile, '');

console.log(`Starting concatenation of md files from '${rootDirectory}' directory.`);

Check failure on line 16 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Unexpected console statement

Check failure on line 16 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Replace ``Starting·concatenation·of·md·files·from·'${rootDirectory}'·directory.`` with `⏎··`Starting·concatenation·of·md·files·from·'${rootDirectory}'·directory.`,⏎`

// Find all .md files and concatenate their contents
function processDirectory(directory) {
fs.readdirSync(directory, { withFileTypes: true }).forEach(dirent => {
const fullPath = path.join(directory, dirent.name);
if (dirent.isDirectory() && !['node_modules'].includes(dirent.name)) {
processDirectory(fullPath);
} else if (dirent.isFile() && ['.md', '.mdx'].includes(path.extname(dirent.name))) {

Check failure on line 24 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Replace `dirent.isFile()·&&·['.md',·'.mdx'].includes(path.extname(dirent.name))` with `⏎······dirent.isFile()·&&⏎······['.md',·'.mdx'].includes(path.extname(dirent.name))⏎····`
console.log(`Adding file: ${fullPath}`);

Check failure on line 25 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Unexpected console statement
const data = fs.readFileSync(fullPath, 'utf8');
fs.appendFileSync(outputFile, `File: ${fullPath}\n\n${data}\n`);
}
});
}

processDirectory(rootDirectory);

console.log(`Concatenation complete. Output is in ${outputFile}`);

Check failure on line 34 in scripts/concatenateDocs.js

View workflow job for this annotation

GitHub Actions / CI (14.x)

Unexpected console statement
27 changes: 0 additions & 27 deletions scripts/concatenateDocs.sh

This file was deleted.

0 comments on commit c67bcb8

Please sign in to comment.