mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Add updateUnpkgLinks Gulp task
This commit is contained in:
parent
fd239ebb93
commit
87f332f925
5
.changeset/sweet-cheetahs-grin.md
Normal file
5
.changeset/sweet-cheetahs-grin.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jspsych/config": minor
|
||||
---
|
||||
|
||||
Implement an `updateUnpkgLinks` Gulp task to update each unpkg link with a precise version number to the corresponding package's current version as defined in the package's `package.json`.
|
@ -1 +1 @@
|
||||
export { createCoreDistArchive } from "@jspsych/config/gulp";
|
||||
export { createCoreDistArchive, updateUnpkgLinks } from "@jspsych/config/gulp";
|
||||
|
@ -9,6 +9,7 @@
|
||||
"test:watch": "npm test -- --watch",
|
||||
"build": "npm run build -w jspsych && npm run build -ws",
|
||||
"build:archive": "gulp createCoreDistArchive",
|
||||
"update-unpkg-links": "gulp updateUnpkgLinks",
|
||||
"prepare": "husky install && npm run build",
|
||||
"tsc": "npm run tsc -ws",
|
||||
"changeset": "changeset",
|
||||
|
@ -13,6 +13,20 @@ const { dest, src } = gulp;
|
||||
|
||||
const readJsonFile = (filename) => JSON.parse(readFileSync(filename, "utf8"));
|
||||
|
||||
const getAllPackages = () =>
|
||||
glob
|
||||
// Get an array of all package.json filenames
|
||||
.sync("packages/*/package.json")
|
||||
|
||||
// Map file names to package details
|
||||
.map((filename) => {
|
||||
const packageJson = readJsonFile(filename);
|
||||
return {
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
};
|
||||
});
|
||||
|
||||
const getVersionFileContents = () =>
|
||||
[
|
||||
"Included in this release:\n",
|
||||
@ -25,19 +39,7 @@ const getVersionFileContents = () =>
|
||||
"/";
|
||||
|
||||
return (
|
||||
glob
|
||||
// Get an array of all package.json filenames
|
||||
.sync("packages/*/package.json")
|
||||
|
||||
// Map file names to package details
|
||||
.map((filename) => {
|
||||
const packageJson = readJsonFile(filename);
|
||||
return {
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
};
|
||||
})
|
||||
|
||||
getAllPackages()
|
||||
// Filter packages that should not be listed
|
||||
.filter(({ name }) => !["@jspsych/config", "@jspsych/test-utils"].includes(name))
|
||||
|
||||
@ -105,3 +107,23 @@ export const createCoreDistArchive = () =>
|
||||
)
|
||||
.pipe(zip("dist.zip"))
|
||||
.pipe(dest("."));
|
||||
|
||||
/**
|
||||
* Updates each unpkg link with a precise version number to the corresponding package's current
|
||||
* version as defined in the package's `package.json`. Only considers `.md` and `.html` files.
|
||||
*/
|
||||
export const updateUnpkgLinks = () => {
|
||||
const packageVersions = new Map(getAllPackages().map(({ name, version }) => [name, version]));
|
||||
|
||||
return src(["./**/*.{md,html}"])
|
||||
.pipe(
|
||||
replace(
|
||||
/"https:\/\/unpkg\.com\/(@?.*)@(\d+.\d+.\d+)(\/[^"]*)?"/g,
|
||||
(url, packageName, currentVersion, path) => {
|
||||
const latestVersion = packageVersions.get(packageName) ?? currentVersion;
|
||||
return `"https://unpkg.com/${packageName}@${latestVersion}${path ?? ""}"`;
|
||||
}
|
||||
)
|
||||
)
|
||||
.pipe(dest("./"));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user