Skip to content

Commit

Permalink
Deps updater
Browse files Browse the repository at this point in the history
  • Loading branch information
j3lte committed Nov 24, 2023
1 parent 0f4dcf3 commit 8bacbe4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 11 deletions.
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

"test:watch": "deno test --watch",
"update:version": "deno run --allow-read --allow-write ./scripts/update-version.ts",
"update:deno_deps": "deno run -A https://deno.land/x/udd/main.ts dev_deps.ts ./src/lib/Pastebin.ts ./src/lib/Scraper.ts",
"update:deno_deps": "deno run -A https://deno.land/x/udd/main.ts dev_deps.ts ./scripts/build-npm.ts ./src/lib/Pastebin.ts ./src/lib/Scraper.ts",
"update:node_deps": "deno run --allow-read --allow-write --allow-net ./scripts/update-node-deps.ts",
"update:deps": "deno task update:deno_deps && deno task update:node_deps",
"localTest": "deno run --allow-read --allow-write --allow-run ./scripts/watch-test.ts",
"clean": "rm -r ./coverage",
"npm": "deno run -A ./scripts/build-npm.ts"
Expand Down
7 changes: 1 addition & 6 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dev_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export {
assertEquals,
assertRejects,
assertThrows,
} from "https://deno.land/std@0.207.0/assert/mod.ts";
export { emptyDir } from "https://deno.land/std@0.207.0/fs/mod.ts";
} from "https://deno.land/std@0.208.0/assert/mod.ts";
export { emptyDir } from "https://deno.land/std@0.208.0/fs/mod.ts";
export { MockFetch } from "https://deno.land/x/[email protected]/mod.ts";
export { resolvesNext, stub } from "https://deno.land/std@0.207.0/testing/mock.ts";
export { walk } from "https://deno.land/std@0.207.0/fs/walk.ts";
export { resolvesNext, stub } from "https://deno.land/std@0.208.0/testing/mock.ts";
export { walk } from "https://deno.land/std@0.208.0/fs/walk.ts";
69 changes: 69 additions & 0 deletions scripts/update-node-deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2023 J.W. Lagendijk. All rights reserved. MIT license.

const getDirPath = (): string => {
const filePath = new URL(import.meta.url).pathname;
const dirPath = filePath.split("/").slice(0, -1).join("/");
return dirPath;
};

async function update_npm_build_script(): Promise<void> {
const path = `${getDirPath()}/build-npm.ts`;
const file = await Deno.readTextFile(path);

// Find the version number in for "[email protected]"
const evtVersion = (file.match(/evt@v(\d+\.\d+\.\d+)/) as string[])[1];
// Replace the version number in the build script
const updatedFile = file.replace(
/version: ".*",/,
`version: "${evtVersion}",`,
);

// check if the updated file changed
if (file === updatedFile) {
console.log("No changes to npm build script needed.");
return;
}

await Deno.writeTextFile(path, updatedFile);
}

async function update_npm_packages(): Promise<void> {
const pastebinPath = `${getDirPath()}/../src/node/Pastebin.ts`;

const pastebinFile = await Deno.readTextFile(pastebinPath);

try {
// Find the version number in "npm:[email protected]"
const pastebinVersion = (
pastebinFile.match(/npm:node-fetch@(\d+\.\d+\.\d+)/) as string[]
)[1];

const npmJSON = await fetch("https://registry.npmjs.org/node-fetch").then((r) => r.json());
const latest = npmJSON["dist-tags"].latest;

if (pastebinVersion === latest) {
console.log("No changes to node/Pastebin.ts package needed.");
return;
} else {
console.log(`Updating npm packages from ${pastebinVersion} to ${latest}`);

// Replace the version number in Pastebin.ts
const updatedFile = pastebinFile.replace(
/npm:node-fetch@\d+\.\d+\.\d+/,
`npm:node-fetch@${latest}`,
);

await Deno.writeTextFile(pastebinPath, updatedFile);
}
} catch (error) {
console.error("Error updating version in Pastebin.ts");
console.error(error);
}
}

async function update(_args: string[]): Promise<void> {
await update_npm_build_script();
await update_npm_packages();
}

update(Deno.args);

0 comments on commit 8bacbe4

Please sign in to comment.