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
5 changed files with 225 additions and 125 deletions

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);