From 704edab100de3a9ce86a1ba536fff28b079b1ba6 Mon Sep 17 00:00:00 2001 From: Jiawen Geng Date: Mon, 23 Aug 2021 10:02:34 +0000 Subject: [PATCH] feat: add golang support --- fixers/upgrade-go.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 36 insertions(+) create mode 100644 fixers/upgrade-go.js diff --git a/fixers/upgrade-go.js b/fixers/upgrade-go.js new file mode 100644 index 0000000..363ae16 --- /dev/null +++ b/fixers/upgrade-go.js @@ -0,0 +1,35 @@ +// Copyright © 2020 Jan Keromnes. +// The following code is covered by the MIT license. + +const { getData } = require("crawler-toolbox"); +const { patchDom } = require("crawler-toolbox/build/utils"); + +const getLatestGoVersion = async () => { + const url = "https://golang.org/dl/"; + + let golangVersion = undefined + const result = await getData(url); + patchDom(result.content, ($) => { + // https://regex101.com/r/cJLyi6/1 + const regex = /\/dl\/go(.*?).src.tar.gz/gm; + const links = [... $("a[href]")]; + for (const l of links) { + const version = regex.exec(l.attribs["href"])?.[1]; + if (version != undefined) { + golangVersion = version + break; + } + } + }); + + return golangVersion +}; +exports.register = async (fixers) => { + const golangVersion = await getLatestGoVersion() + console.log(golangVersion) + fixers[0].push({ + id: "upgrade-golang", + cmd: `todo`, + description: "Update pinned Go module versions", + }); +}; diff --git a/package.json b/package.json index e86f4a4..649ada8 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "test": "node tests.js" }, "dependencies": { + "crawler-toolbox": "^1.0.1", "minimist": "1.2.5" }, "devDependencies": {}