From 3acf27193dfe77241615d283f3c05974ea5ffb53 Mon Sep 17 00:00:00 2001 From: Han Li Date: Wed, 24 Jan 2024 10:01:33 +0800 Subject: [PATCH] support flutter cn (#5) --- dart/dart.lua | 2 +- deno/deno.lua | 2 +- flutter/flutter-cn.lua | 135 +++++++++++++++++++++++++++++++++++++++++ flutter/flutter.lua | 3 +- golang/golang.lua | 2 +- maven/maven.lua | 2 +- nodejs/nodejs.lua | 2 +- 7 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 flutter/flutter-cn.lua diff --git a/dart/dart.lua b/dart/dart.lua index eb3d29a..614318c 100644 --- a/dart/dart.lua +++ b/dart/dart.lua @@ -27,7 +27,7 @@ PLUGIN = { --- Plugin name name = "dart", --- Plugin author - author = "aooohan", + author = "Aooohan", --- Plugin version version = "0.0.1", description = "dart plugin, support for getting stable, dev, beta version", diff --git a/deno/deno.lua b/deno/deno.lua index fd0cb07..f090051 100644 --- a/deno/deno.lua +++ b/deno/deno.lua @@ -25,7 +25,7 @@ DownloadURL = "https://github.com/denoland/deno/releases/download/v%s/%s" PLUGIN = { name = "deno", - author = "aooohan", + author = "Aooohan", version = "0.0.1", description = "Deno plugin, https://deno.com/", updateUrl = "https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/deno/deno.lua", diff --git a/flutter/flutter-cn.lua b/flutter/flutter-cn.lua new file mode 100644 index 0000000..c2cf1aa --- /dev/null +++ b/flutter/flutter-cn.lua @@ -0,0 +1,135 @@ +--- Copyright 2024 [lihan aooohan@gmail.com] +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +local http = require("http") +local json = require("json") + +OS_TYPE = "" +ARCH_TYPE = "" + +BASE_URL = "https://storage.flutter-io.cn/flutter_infra_release/releases/releases_%s.json" + +PLUGIN = { + --- Plugin name + name = "flutter", + --- Plugin author + author = "Aooohan", + --- Plugin version + version = "0.0.1", + description = "flutter plugin for China, support for getting stable, dev, beta version", + -- Update URL + updateUrl = "https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/flutter/flutter-cn.lua", +} + +function PLUGIN:PreInstall(ctx) + local arg = ctx.version + if arg == "beta" or arg == "dev" or arg == "stable" then + local type = getOsTypeAndArch() + local resp, err = http.get({ + url = BASE_URL:format(type.osType) + }) + if err ~= nil or resp.status_code ~= 200 then + error("get version failed" .. err) + end + local body = json.decode(resp.body) + local cr = body.current_release + local key = cr[arg] + local releases = self:Available({}) + for _, info in ipairs(releases) do + if info.key == key then + return { + version = info.version, + url = info.url, + sha256 = info.sha256 + } + end + end + end + local releases = self:Available({}) + for _, info in ipairs(releases) do + if info.version == arg then + return { + version = info.version, + url = info.url, + sha256 = info.sha256 + } + end + end + return nil +end + +function PLUGIN:PostInstall(ctx) +end + +function PLUGIN:Available(ctx) + local type = getOsTypeAndArch() + local resp, err = http.get({ + url = BASE_URL:format(type.osType) + }) + if err ~= nil or resp.status_code ~= 200 then + error("get version failed" .. err) + end + local body = json.decode(resp.body) + local result = {} + for _, info in ipairs(body.releases) do + local version = info.version + local oldVersion = string.sub(version, 1, 1) == "v" + if oldVersion then + break + end + table.insert(result, { + version = info.version, + url = body.base_url .. "/" .. info.archive, + sha256 = info.sha256, + key = info.hash, + note = info.channel, + addition = { + { + name = "dart", + version = info.dart_sdk_version + } + } + }) + end + return result +end + + +function getOsTypeAndArch() + local osType = OS_TYPE + local archType = ARCH_TYPE + if OS_TYPE == "darwin" then + osType = "macos" + end + if ARCH_TYPE == "amd64" then + archType = "x64" + elseif ARCH_TYPE == "arm64" then + archType = "arm64" + else + error("flutter does not support" .. ARCH_TYPE .. "architecture") + end + return { + osType = osType, archType = archType + } +end + +function PLUGIN:EnvKeys(ctx) + local mainPath = ctx.path + return { + { + key = "PATH", + value = mainPath .. "/bin" + } + } +end \ No newline at end of file diff --git a/flutter/flutter.lua b/flutter/flutter.lua index a2f66f5..86e7745 100644 --- a/flutter/flutter.lua +++ b/flutter/flutter.lua @@ -20,12 +20,11 @@ ARCH_TYPE = "" BASE_URL = "https://storage.googleapis.com/flutter_infra_release/releases/releases_%s.json" ---- https://go.dev/dl/go1.21.5.darwin-arm64.tar.gz PLUGIN = { --- Plugin name name = "flutter", --- Plugin author - author = "Han Li", + author = "Aooohan", --- Plugin version version = "0.0.2", description = "flutter plugin, support for getting stable, dev, beta version", diff --git a/golang/golang.lua b/golang/golang.lua index 1a4bf77..3b79b67 100644 --- a/golang/golang.lua +++ b/golang/golang.lua @@ -25,7 +25,7 @@ PLUGIN = { --- Plugin name name = "golang", --- Plugin author - author = "Han Li", + author = "Aooohan", --- Plugin version version = "0.0.2", -- Update URL diff --git a/maven/maven.lua b/maven/maven.lua index e58b3f8..dd98bea 100644 --- a/maven/maven.lua +++ b/maven/maven.lua @@ -26,7 +26,7 @@ PLUGIN = { --- Plugin name name = "maven", --- Plugin author - author = "Han Li", + author = "Aooohan", --- Plugin version version = "0.0.1", -- Update URL diff --git a/nodejs/nodejs.lua b/nodejs/nodejs.lua index fca2ced..5800934 100644 --- a/nodejs/nodejs.lua +++ b/nodejs/nodejs.lua @@ -15,7 +15,7 @@ VersionSourceUrl = "https://nodejs.org/dist/index.json" PLUGIN = { name = "nodejs", - author = "aooohan", + author = "Aooohan", version = "0.0.2", description = "Node.js", updateUrl = "https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/node/node.lua",