From 74cc2ece694e68977d9cbb36f0a66ad5ee0d8e3b Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Tue, 3 May 2022 14:18:37 -0700 Subject: [PATCH] add updatePluginVersion gulp task --- gulpfile.js | 2 +- package.json | 1 + packages/config/gulp.js | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index ec2bccf8..88a18bbb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1 +1 @@ -export { createCoreDistArchive, updateUnpkgLinks } from "@jspsych/config/gulp"; +export { createCoreDistArchive, updateUnpkgLinks, updatePluginVersion } from "@jspsych/config/gulp"; diff --git a/package.json b/package.json index 1f9064dc..7960210c 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "build": "turbo run build", "build:archive": "gulp createCoreDistArchive", "update-unpkg-links": "gulp updateUnpkgLinks", + "update-plugin-version": "gulp updatePluginVersion", "prepare": "node -e 'process.exit(!process.env.CI)' || (husky install && npm run build)", "tsc": "turbo tsc", "changeset": "changeset", diff --git a/packages/config/gulp.js b/packages/config/gulp.js index 4329fddd..5829f1c1 100644 --- a/packages/config/gulp.js +++ b/packages/config/gulp.js @@ -1,5 +1,6 @@ import { readFileSync } from "fs"; import { sep as pathSeparator } from "path"; +import { StringDecoder } from "string_decoder"; import glob from "glob"; import gulp from "gulp"; @@ -127,3 +128,26 @@ export const updateUnpkgLinks = () => { ) .pipe(dest("./")); }; + +/** + * Substitutes the string "current-plugin-version" or version number that follows the text "Current version: " + * in the plugin docs pages with the package's current version, as defined in the package's `package.json`. + * Only considers `.md` files in `docs/plugins` folder. + * Gets the package name from the docs page title (i.e. following "# "), ignoring the string " plugin" in the title. + */ +export const updatePluginVersion = () => { + const packageVersions = new Map(getAllPackages().map(({ name, version }) => [name, version])); + + return src(["././docs/plugins/*.md"]) + .pipe( + replace( + /\# (.+?)(?: plugin)?[\s]*?[\n]*Current version: (\d+.\d+.\d+|current-plugin-version)\./gi, + (match_str, packageName, currentVersionText) => { + const fullPackageName = "@jspsych/plugin-" + packageName; + const latestVersion = packageVersions.get(fullPackageName) ?? currentVersionText; + return `# ${packageName}\n\nCurrent version: ${latestVersion}.`; + } + ) + ) + .pipe(dest("./docs/plugins")); +};