Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
support flutter cn (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
aooohan authored Jan 24, 2024
1 parent 1289bec commit 3acf271
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dart/dart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion deno/deno.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
135 changes: 135 additions & 0 deletions flutter/flutter-cn.lua
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions flutter/flutter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion golang/golang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PLUGIN = {
--- Plugin name
name = "golang",
--- Plugin author
author = "Han Li",
author = "Aooohan",
--- Plugin version
version = "0.0.2",
-- Update URL
Expand Down
2 changes: 1 addition & 1 deletion maven/maven.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PLUGIN = {
--- Plugin name
name = "maven",
--- Plugin author
author = "Han Li",
author = "Aooohan",
--- Plugin version
version = "0.0.1",
-- Update URL
Expand Down
2 changes: 1 addition & 1 deletion nodejs/nodejs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3acf271

Please sign in to comment.