Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ When you run `npm run check-dependencies`, a script checks for files that need t

- You can check specific tools by passing them to the script, as in `npm run check-dependencies -- --dependencies=smartpy,taquito`.
- By default, the script checks for differences down to the fixpack level, but you can pass `--major` or `--minor` to check for differences at those levels.
- By default, it checks all files, but you can pass individual files to check after the other arguments, as in `npm run check-dependencies -- --major -d=smartpy,taquito docs/developing/octez-client/accounts.md docs/tutorials/build-your-first-app.md`.
- By default, it checks all files, but you can pass individual files or folders to check after the other arguments, as in `npm run check-dependencies -- --major -d=smartpy,taquito docs/developing/octez-client/accounts.md docs/tutorials/build-your-first-app.md` or `npm run check-dependencies -- --major -d=smartpy,taquito docs/tutorials`.

## Search

Expand Down
40 changes: 32 additions & 8 deletions src/scripts/check_dependencies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ By default, this script checks all files.
You can pass individual files to check as anonymous arguments after the other parameters, as in
npm run check-dependencies -- --major -d=smartpy,taquito docs/developing/octez-client/accounts.md docs/tutorials/build-your-first-app.md

You can also pass folders to check, as in
npm run check-dependencies -- --major -d=smartpy,taquito docs/tutorials
*/

import path, { dirname } from 'path';
Expand All @@ -41,6 +43,7 @@ const dependencyConfig = fs.readFileSync(path.resolve(__dirname, 'dependencies.j
const { currentVersions } = JSON.parse(dependencyConfig);

// Set up parameters
// Anonymous params are in argv['_']
const argv = minimist(process.argv.slice(2), {
boolean: ['major', 'minor'],
string: ['dependencies'],
Expand All @@ -49,13 +52,6 @@ const argv = minimist(process.argv.slice(2), {
},
});

// By default, check all files
// But if file names are passed as anonymous params, check only those files
const filesToCheckPromise = argv['_'].length > 0 ?
argv['_']
.map((shortPath) => path.resolve(baseFolder, shortPath))
: glob(docsFolder + '/**/*.{md,mdx}');

// By default, check all dependencies
const dependenciesToCheck = argv['dependencies'] ? argv['dependencies'].split(',') : Object.keys(currentVersions);
dependenciesToCheck.forEach((oneDependency) => {
Expand All @@ -73,6 +69,34 @@ if (checkMajor && checkMinor) {
process.exit(1);
}

const getFilesToCheck = async () => {
// By default, check all files
if (argv['_'].length === 0) {
return glob(docsFolder + '/**/*.{md,mdx}');
}
// But if file names or paths are passed as anonymous params, check only those files
return argv['_'].reduce(async (allFilesPromise, oneShortPath) => {
const fullPath = path.resolve(baseFolder, oneShortPath);
const allFiles = await allFilesPromise;
// Is this a path or a file name?
return fs.promises.lstat(fullPath)
.then(async (lstatResult) => {
if (lstatResult.isFile()) {
return allFiles.concat([fullPath]);
} else if (lstatResult.isDirectory()) {
return allFiles.concat(await glob(path.resolve(fullPath, '**/*.{md,mdx}')));
} else {
throw 'Path does not appear to be either a file or a directory.';
}
})
.catch((err) => {
console.error('Error: Could not resolve this file or path:', oneShortPath);
console.error(err);
process.exit(1);
});
}, Promise.resolve([]));
}

// Function to compare versions based on whether we care about major, minor, or patch versions
// diff(v1, v2): Returns the difference between two versions by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if the versions are the same.
const isOldVersion = (v1String, v2String) => {
Expand All @@ -98,7 +122,7 @@ const isOldVersion = (v1String, v2String) => {

const printDependencies = async () => {
// Get files to check
const files = await filesToCheckPromise;
const files = await getFilesToCheck();

// Get front matter for each file
const filesAndFrontMatter = await Promise.all(
Expand Down
Loading