-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |