add updatePluginVersion gulp task

This commit is contained in:
Becky Gilbert 2022-05-03 14:18:37 -07:00
parent 262cc1cd89
commit 74cc2ece69
3 changed files with 26 additions and 1 deletions

View File

@ -1 +1 @@
export { createCoreDistArchive, updateUnpkgLinks } from "@jspsych/config/gulp";
export { createCoreDistArchive, updateUnpkgLinks, updatePluginVersion } from "@jspsych/config/gulp";

View File

@ -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",

View File

@ -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"));
};