From ead2a72fd61d7f09f4c6a00561d6e96a44390d3c Mon Sep 17 00:00:00 2001 From: Tim McMackin Date: Wed, 29 Jan 2025 09:37:29 -0500 Subject: [PATCH 1/4] Filter dependencies by file --- README.md | 5 +++- src/scripts/check_dependencies.mjs | 42 +++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2760fbf5c..23ba50393 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,10 @@ dependencies: The current versions of these tools are set in the file `src/scripts/dependencies.json`. When you run `npm run check-dependencies`, a script checks for files that need to be updated. -You can check specific tools by passing them to the script, as in `npm run check-dependencies smartpy taquito`. + +- 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 in a comma-separated list, as in `npm run check-dependencies -- --filesToCheck=docs/developing/octez-client/accounts.md,docs/tutorials/build-your-first-app.md`. ## Search diff --git a/src/scripts/check_dependencies.mjs b/src/scripts/check_dependencies.mjs index d11006f08..3afc583b8 100644 --- a/src/scripts/check_dependencies.mjs +++ b/src/scripts/check_dependencies.mjs @@ -12,11 +12,15 @@ List the current versions of the tools in the config file at ./dependencies.json Arguments: -You can pass individual tools to check, as in npm run check-dependencies -- smartpy taquito and it will check only those dependencies. +You can pass individual tools to check in a comma-separated list, as in npm run check-dependencies -- --dependencies=smartpy,taquito and it will check only those dependencies. By default, this script checks for differences down to the fixpack level. You can pass --major or --minor to ignore differences up to the specified level. +By default, this script checks all files. +You can pass individual files to check in a comma-separated list with the --filesToCheck parameter, as in +npm run check-dependencies -- --filesToCheck=docs/developing/octez-client/accounts.md,docs/tutorials/build-your-first-app.md + */ import path, { dirname } from 'path'; @@ -36,18 +40,33 @@ const docsFolder = path.resolve(baseFolder, 'docs'); const dependencyConfig = fs.readFileSync(path.resolve(__dirname, 'dependencies.json'), 'utf8'); const { currentVersions } = JSON.parse(dependencyConfig); +// Set up parameters const argv = minimist(process.argv.slice(2), { boolean: ['major', 'minor'], + string: ['filesToCheck', 'dependencies'], + alias: { + f: 'filesToCheck', + d: 'dependencies', + }, unknown: (unknownArg) => { if (currentVersions[unknownArg]) { return true; } - console.error('Error: unknown argument or tool name: ', unknownArg); + console.error('Error: unknown argument', unknownArg); + console.error('Pass dependencies to check in a comma-separated list, as in --dependencies=octez,smartpy,ligo.'); + console.error('Pass the version level to check with --major or --minor, or omit the version level to check down to the fixpack level.'); + console.error('Pass files to check in a comma-separated list, as in --filesToCheck=docs/dApps/wallets.md,docs/developing/octez-client/accounts.md.') process.exit(1); } }); -const params = argv['_']; - +// By default, check all files +const filesToCheckPromise = argv['filesToCheck'] ? + argv['filesToCheck'] + .split(',') + .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); const checkMajor = argv.major; const checkMinor = argv.minor; if (checkMajor && checkMinor) { @@ -79,8 +98,8 @@ const isOldVersion = (v1String, v2String) => { } const printDependencies = async () => { - // Get all MD and MDX files - const files = await glob(docsFolder + '/**/*.{md,mdx}'); + // Get files to check + const files = await filesToCheckPromise; // Get front matter for each file const filesAndFrontMatter = await Promise.all( @@ -95,15 +114,14 @@ const printDependencies = async () => { }) ); - // Filter to files with dependencies + // Filter to dependencies that we care about const filesWithDependencies = filesAndFrontMatter - // Filter to the dependencies passed on the command line .map(({ filePath, frontMatter }) => { - if (params.length > 0 && frontMatter.dependencies) { + if (frontMatter.dependencies) { let newDependencies = {}; - params.forEach((oneParam) => { - if (frontMatter.dependencies[oneParam]) { - newDependencies[oneParam] = frontMatter.dependencies[oneParam]; + dependenciesToCheck.forEach((oneDependency) => { + if (frontMatter.dependencies[oneDependency]) { + newDependencies[oneDependency] = frontMatter.dependencies[oneDependency]; } }); let newFrontMatter = JSON.parse(JSON.stringify(frontMatter)); From 457983e67a18e21ca51f96e0cfd6e876b3fb0956 Mon Sep 17 00:00:00 2001 From: Tim McMackin Date: Wed, 29 Jan 2025 09:43:09 -0500 Subject: [PATCH 2/4] Check for unknown dependencies --- src/scripts/check_dependencies.mjs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/scripts/check_dependencies.mjs b/src/scripts/check_dependencies.mjs index 3afc583b8..169058991 100644 --- a/src/scripts/check_dependencies.mjs +++ b/src/scripts/check_dependencies.mjs @@ -49,9 +49,6 @@ const argv = minimist(process.argv.slice(2), { d: 'dependencies', }, unknown: (unknownArg) => { - if (currentVersions[unknownArg]) { - return true; - } console.error('Error: unknown argument', unknownArg); console.error('Pass dependencies to check in a comma-separated list, as in --dependencies=octez,smartpy,ligo.'); console.error('Pass the version level to check with --major or --minor, or omit the version level to check down to the fixpack level.'); @@ -59,14 +56,24 @@ const argv = minimist(process.argv.slice(2), { process.exit(1); } }); + // By default, check all files const filesToCheckPromise = argv['filesToCheck'] ? argv['filesToCheck'] .split(',') .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) => { + if (!Object.keys(currentVersions).includes(oneDependency)) { + console.error('Unknown dependency:', oneDependency); + process.exit(1); + } +}); + +// By default, check to the fixpack version const checkMajor = argv.major; const checkMinor = argv.minor; if (checkMajor && checkMinor) { From 9286020f813fe8c709c516f61681918bb09bc55a Mon Sep 17 00:00:00 2001 From: Tim McMackin Date: Thu, 30 Jan 2025 09:37:51 -0500 Subject: [PATCH 3/4] Files as anonymous arguments --- README.md | 2 +- src/scripts/check_dependencies.mjs | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 23ba50393..e0f649b92 100644 --- a/README.md +++ b/README.md @@ -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 in a comma-separated list, as in `npm run check-dependencies -- --filesToCheck=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 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`. ## Search diff --git a/src/scripts/check_dependencies.mjs b/src/scripts/check_dependencies.mjs index 169058991..d5130a68e 100644 --- a/src/scripts/check_dependencies.mjs +++ b/src/scripts/check_dependencies.mjs @@ -18,8 +18,8 @@ By default, this script checks for differences down to the fixpack level. You can pass --major or --minor to ignore differences up to the specified level. By default, this script checks all files. -You can pass individual files to check in a comma-separated list with the --filesToCheck parameter, as in -npm run check-dependencies -- --filesToCheck=docs/developing/octez-client/accounts.md,docs/tutorials/build-your-first-app.md +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 */ @@ -43,24 +43,16 @@ const { currentVersions } = JSON.parse(dependencyConfig); // Set up parameters const argv = minimist(process.argv.slice(2), { boolean: ['major', 'minor'], - string: ['filesToCheck', 'dependencies'], + string: ['dependencies'], alias: { - f: 'filesToCheck', d: 'dependencies', }, - unknown: (unknownArg) => { - console.error('Error: unknown argument', unknownArg); - console.error('Pass dependencies to check in a comma-separated list, as in --dependencies=octez,smartpy,ligo.'); - console.error('Pass the version level to check with --major or --minor, or omit the version level to check down to the fixpack level.'); - console.error('Pass files to check in a comma-separated list, as in --filesToCheck=docs/dApps/wallets.md,docs/developing/octez-client/accounts.md.') - process.exit(1); - } }); // By default, check all files -const filesToCheckPromise = argv['filesToCheck'] ? - argv['filesToCheck'] - .split(',') +// 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}'); From 400ed6b4420c7657bf699893773017c6c6cdccbd Mon Sep 17 00:00:00 2001 From: Tim McMackin Date: Thu, 30 Jan 2025 09:38:13 -0500 Subject: [PATCH 4/4] Linting --- src/scripts/check_dependencies.mjs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/scripts/check_dependencies.mjs b/src/scripts/check_dependencies.mjs index d5130a68e..6fc6e8bef 100644 --- a/src/scripts/check_dependencies.mjs +++ b/src/scripts/check_dependencies.mjs @@ -53,7 +53,7 @@ const argv = minimist(process.argv.slice(2), { // 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)) + .map((shortPath) => path.resolve(baseFolder, shortPath)) : glob(docsFolder + '/**/*.{md,mdx}'); // By default, check all dependencies @@ -105,12 +105,13 @@ const printDependencies = async () => { files .sort() .map(async (filePath) => { - const fileContents = await fs.promises.readFile(filePath, 'utf8'); - const frontMatter = matter(fileContents).data; - return { - filePath: path.relative(baseFolder, filePath), - frontMatter }; - }) + const fileContents = await fs.promises.readFile(filePath, 'utf8'); + const frontMatter = matter(fileContents).data; + return { + filePath: path.relative(baseFolder, filePath), + frontMatter + }; + }) ); // Filter to dependencies that we care about