Get Flutter URL correct

[GitHub #80]
This commit is contained in:
Aoran Zeng 2024-09-14 03:29:36 +08:00
parent e66cff3686
commit 001b477936
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
5 changed files with 225 additions and 125 deletions

View File

@ -13,13 +13,13 @@
* | Terrasse <terrasse@qq.com>
* |
* Created On : <2023-08-28>
* Last Modified : <2024-09-13>
* Last Modified : <2024-09-14>
*
* chsrc: Change Source
* ------------------------------------------------------------*/
#define Chsrc_Version "0.1.8.2.dev1"
#define Chsrc_Release_Date "2024/09/13"
#define Chsrc_Version "0.1.8.2.dev2"
#define Chsrc_Release_Date "2024/09/14"
#define Chsrc_Banner_Version "v" Chsrc_Version "-" Chsrc_Release_Date
#define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc"
#define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc"
@ -46,7 +46,10 @@
#include "recipe/lang/Go.c"
#include "recipe/lang/Java.c"
#include "recipe/lang/Rust.c"
#include "recipe/lang/Dart.c"
#include "recipe/lang/Dart/Pub.c"
#include "recipe/lang/Dart/Flutter.c"
#include "recipe/lang/Haskell.c"
#include "recipe/lang/OCaml.c"
#include "recipe/lang/R.c"

View File

@ -1,119 +0,0 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-10>
* Major Revision : 2
* Last Modified : <2024-09-14>
* ------------------------------------------------------------*/
/**
* @update 2024-09-14
* @note {
* Flutter
* setsrc函数中生成
* 1. https://mirrors.tuna.tsinghua.edu.cn/dart-pub
* 2. https://mirrors.tuna.tsinghua.edu.cn/flutter
* }
*/
static SourceInfo
pl_dart_sources[] = {
{&Upstream, NULL},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/"}, // 不确定SJTUG的flutter镜像给的对不对
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"},
{&Tencent, "https://mirrors.cloud.tencent.com/"},
// {&Tencent_Intra, "https://mirrors.cloud.tencentyun.com/"},
{&Nju, "https://mirror.nju.edu.cn/"}
};
def_sources_n(pl_dart);
void
pl_dart_getsrc (char *option)
{
char *cmd = NULL;
if (xy_on_windows)
{
cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL";
chsrc_run (cmd, RunOpt_Default);
}
else
{
cmd = "echo $PUB_HOSTED_URL; echo $FLUTTER_STORAGE_BASE_URL";
chsrc_run (cmd, RunOpt_Default);
}
}
/**
* Dart pub https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/
*/
void
pl_dart_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_dart);
char *towrite1, *towrite2 = NULL;
char *pub = xy_2strjoin (source.url, "dart-pub");
char *flutter = xy_2strjoin (source.url, "flutter");
if (xy_on_windows)
{
towrite1 = xy_strjoin (3, "$env:PUB_HOSTED_URL = \"", pub, "\"");
towrite2 = xy_strjoin (3, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
if (xy_file_exist (xy_win_powershell_profile))
{
chsrc_append_to_file (towrite1, xy_win_powershell_profile);
chsrc_append_to_file (towrite2, xy_win_powershell_profile);
}
if (xy_file_exist (xy_win_powershellv5_profile))
{
chsrc_append_to_file (towrite1, xy_win_powershellv5_profile);
chsrc_append_to_file (towrite2, xy_win_powershellv5_profile);
}
}
else
{
char *zshrc = "~/.zshrc";
char *bashrc = "~/.bashrc";
chsrc_backup (zshrc);
towrite1 = xy_strjoin (3, "export PUB_HOSTED_URL=\"", pub, "\"");
towrite2 = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", flutter, "\"");
chsrc_append_to_file (towrite1, zshrc);
chsrc_append_to_file (towrite2, zshrc);
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (towrite1, bashrc);
chsrc_append_to_file (towrite2, bashrc);
}
}
chsrc_conclude (&source, ChsrcTypeAuto);
}
FeatInfo
pl_dart_feat (char *option)
{
FeatInfo fi = {0};
fi.can_get = true;
fi.can_reset = false;
fi.stcan_locally = CanNot;
fi.locally = NULL;
fi.can_english = true;
/* 该换源方案中URL存在拼凑因此不能让用户手动使用某URL来换源 */
fi.can_user_define = false;
fi.note = "该换源通过写入环境变量实现若多次换源请手动清理profile文件";
return fi;
}
def_target_gsf(pl_dart);

View File

@ -0,0 +1,110 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-10>
* Major Revision : 2
* Last Modified : <2024-09-14>
*
* 2024-09-14: Dart和Flutter拆分为两个Target
* 3 Dart Flutter URL模式都不一样
* ------------------------------------------------------------*/
/**
* @update 2024-09-14
*/
static SourceInfo
pl_dart_flutter_sources[] = {
{&Upstream, NULL},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn"}, // 没有后缀,怀疑是否存在问题
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/git/flutter"}, // URL 带 git
{&Nju, "https://mirror.nju.edu.cn/flutter"}
};
def_sources_n(pl_dart_flutter);
/**
* chsrc get flutter
*/
void
pl_dart_flutter_getsrc (char *option)
{
char *cmd = NULL;
if (xy_on_windows)
{
// cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL";
cmd = "set FLUTTER_STORAGE_BASE_URL";
chsrc_run (cmd, RunOpt_No_Last_New_Line);
}
else
{
cmd = "echo $FLUTTER_STORAGE_BASE_URL";
chsrc_run (cmd, RunOpt_No_Last_New_Line);
}
}
/**
* @consult https://mirrors.tuna.tsinghua.edu.cn/flutter
* @consult https://mirror.sjtu.edu.cn/docs/flutter_infra
* @consult https://mirror.nju.edu.cn/mirrorz-help/flutter/?mirror=NJU
*/
void
pl_dart_flutter_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_dart_flutter);
char *towrite = NULL;
if (xy_on_windows)
{
towrite = xy_strjoin (3, "$env:FLUTTER_STORAGE_BASE_URL = \"", source.url, "\"");
if (xy_file_exist (xy_win_powershell_profile))
chsrc_append_to_file (towrite, xy_win_powershell_profile);
if (xy_file_exist (xy_win_powershellv5_profile))
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
}
else
{
char *zshrc = "~/.zshrc";
char *bashrc = "~/.bashrc";
chsrc_backup (zshrc);
towrite = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", source.url, "\"");
chsrc_append_to_file (towrite, zshrc);
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (towrite, bashrc);
}
}
chsrc_conclude (&source, ChsrcTypeAuto);
}
/**
* chsrc ls flutter
*/
FeatInfo
pl_dart_flutter_feat (char *option)
{
FeatInfo fi = {0};
fi.can_get = true;
fi.can_reset = false;
fi.stcan_locally = CanNot;
fi.locally = NULL;
fi.can_english = true;
fi.can_user_define = true;
fi.note = "该换源通过写入环境变量实现若多次换源请手动清理profile文件";
return fi;
}
def_target_gsf(pl_dart_flutter);

103
src/recipe/lang/Dart/Pub.c Normal file
View File

@ -0,0 +1,103 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-10>
* Major Revision : 3
* Last Modified : <2024-09-14>
*
* Dart Pub
* ------------------------------------------------------------*/
/**
* @update 2024-09-14
*/
static SourceInfo
pl_dart_sources[] = {
{&Upstream, NULL},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/dart-pub"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"},
{&Nju, "https://mirror.nju.edu.cn/dart-pub"}
};
def_sources_n(pl_dart);
void
pl_dart_getsrc (char *option)
{
char *cmd = NULL;
if (xy_on_windows)
{
// cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL";
cmd = "set PUB_HOSTED_URL";
chsrc_run (cmd, RunOpt_Default);
}
else
{
cmd = "echo $PUB_HOSTED_URL";
chsrc_run (cmd, RunOpt_Default);
}
}
/**
* @consult https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/
* @consult https://mirror.sjtu.edu.cn/docs/dart-pub
* @consult https://mirror.nju.edu.cn/mirrorz-help/dart-pub/?mirror=NJU
*/
void
pl_dart_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_dart);
char *towrite = NULL;
if (xy_on_windows)
{
towrite = xy_strjoin (3, "$env:PUB_HOSTED_URL = \"", source.url, "\"");
if (xy_file_exist (xy_win_powershell_profile))
chsrc_append_to_file (towrite, xy_win_powershell_profile);
if (xy_file_exist (xy_win_powershellv5_profile))
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
}
else
{
char *zshrc = "~/.zshrc";
char *bashrc = "~/.bashrc";
chsrc_backup (zshrc);
towrite = xy_strjoin (3, "export PUB_HOSTED_URL=\"", source.url, "\"");
chsrc_append_to_file (towrite, zshrc);
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (towrite, bashrc);
}
}
chsrc_conclude (&source, ChsrcTypeAuto);
}
FeatInfo
pl_dart_feat (char *option)
{
FeatInfo fi = {0};
fi.can_get = true;
fi.can_reset = false;
fi.stcan_locally = CanNot;
fi.locally = NULL;
fi.can_english = true;
fi.can_user_define = true;
fi.note = "该换源通过写入环境变量实现若多次换源请手动清理profile文件";
return fi;
}
def_target_gsf(pl_dart);

View File

@ -29,7 +29,10 @@ static const char
*pl_rust [] = {"rust", "cargo", "crate", "crates", NULL, t(&pl_rust_target)},
*pl_java [] = {"java", "maven", "mvn", "gradle", NULL, t(&pl_java_target)},
*pl_clojure[]= {"clojure","clojars","cloj", "lein", "leiningen", NULL, t(&pl_clojure_target)},
*pl_dart [] = {"dart", "pub", "flutter", NULL, t(&pl_dart_target)},
*pl_dart [] = {"dart", "pub", NULL, t(&pl_dart_target)},
*pl_dart_flutter [] = {"flutter",NULL, t(&pl_dart_flutter_target)},
*pl_nuget[] = {"nuget", "net", ".net", "dotnet", NULL, t(&pl_nuget_target)},
*pl_haskell[]= {"haskell", "cabal", "stack", "hackage", NULL, t(&pl_haskell_target)},
*pl_ocaml[] = {"ocaml", "opam", NULL, t(&pl_ocaml_target)},
@ -45,7 +48,7 @@ static const char
pl_rust, pl_go,
/*pl_nuget,*/
pl_java, pl_clojure,
pl_dart,
pl_dart, pl_dart_flutter,
pl_ocaml,
pl_r, pl_julia,
pl_haskell,