diff --git a/include/source.h b/include/source.h index 0556cbf..6906b86 100644 --- a/include/source.h +++ b/include/source.h @@ -108,15 +108,10 @@ MirrorSite // 开源社区 MirrorSite - NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/", - // 注意,这个是跳转后的地址,不确定未来会不会改变 - "https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"}, // 29MB - NugetOrg = {"nuget.org", "NuGet Org", "Nuget Organization", "https://www.nuget.org/", NULL}, EmacsChina = {"emacschina", "EmacsChina", "Emacs China 社区", "https://elpamirror.emacs-china.org/", NULL}; - MirrorSite Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL}; MirrorSite @@ -132,22 +127,7 @@ typedef struct { -/** - * 2024-04-18 更新 - * - * Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有 - * - * @note 腾讯软件源虽然有npm的名,但名存实亡 - */ -SourceInfo -pl_nodejs_sources[] = { - {&Upstream, NULL}, - {&NpmMirror, "https://registry.npmmirror.com"}, - {&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"}, - {&Zju, "https://mirrors.zju.edu.cn/npm"} -}, - - +static SourceInfo /** * 2024-05-24 更新 * @@ -841,7 +821,7 @@ wr_tex_sources[] = { #define def_sources_n(t) const size_t t##_sources_n = xy_arylen(t##_sources) -def_sources_n(pl_nodejs); + def_sources_n(pl_perl); def_sources_n(pl_php); def_sources_n(pl_rust); def_sources_n(pl_java); def_sources_n(pl_clojure); diff --git a/src/chsrc.c b/src/chsrc.c index a2d4888..727b3fa 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -24,90 +24,7 @@ #include "recipe/lang/ruby.c" #include "recipe/lang/python.c" - -void -pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist) -{ - char *check_cmd = xy_str_to_quietcmd ("npm -v"); - *npm_exist = query_program_exist (check_cmd, "npm"); - - check_cmd = xy_str_to_quietcmd ("yarn -v"); - *yarn_exist = query_program_exist (check_cmd, "yarn"); - - check_cmd = xy_str_to_quietcmd ("pnpm -v"); - *pnpm_exist = query_program_exist (check_cmd, "pnpm"); - - if (!*npm_exist && !*yarn_exist && !*pnpm_exist) - { - chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"); - exit (Exit_UserCause); - } -} - - -void -pl_nodejs_getsrc (char *option) -{ - bool npm_exist, yarn_exist, pnpm_exist; - pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); - - if (npm_exist) - { - chsrc_run ("npm config get registry", RunOpt_Default); - } - if (yarn_exist) - { - chsrc_run ("yarn config get registry", RunOpt_Default); - } - if (pnpm_exist) - { - chsrc_run ("pnpm config get registry", RunOpt_Default); - } -} - -/** - * NodeJS换源,参考:https://npmmirror.com/ - */ -void -pl_nodejs_setsrc (char *option) -{ - bool npm_exist, yarn_exist, pnpm_exist; - pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); - - SourceInfo source; - chsrc_yield_source (pl_nodejs); - chsrc_confirm_source (&source); - - char *cmd = NULL; - - char *where = " "; - if (CliOpt_Locally==true) - { - where = " --location project "; - } - - if (npm_exist) - { - cmd = xy_strjoin (4, "npm config", where, "set registry ", source.url); - chsrc_run (cmd, RunOpt_Default); - } - - if (yarn_exist) - { - // 不再阻止换源命令输出到终端,即不再调用 xy_str_to_quietcmd() - cmd = xy_2strjoin ("yarn config set registry ", source.url); - chsrc_run (cmd, RunOpt_Default); - } - - if (pnpm_exist) - { - cmd = xy_2strjoin ("pnpm config set registry ", source.url); - chsrc_run (cmd, RunOpt_Default); - } - - chsrc_say_lastly (&source, ChsrcTypeAuto); -} - +#include "recipe/lang/nodejs.c" void @@ -2066,7 +1983,7 @@ wr_anaconda_setsrc (char *option) /************************************** Begin Target Matrix ****************************************/ -def_target(pl_nodejs); def_target(pl_perl); def_target(pl_php); +def_target(pl_perl); def_target(pl_php); def_target(pl_rust); def_target(pl_java); def_target(pl_dart); def_target(pl_ocaml); def_target(pl_r); def_target(pl_julia); def_target_noget (pl_clojure); diff --git a/src/recipe/lang/nodejs.c b/src/recipe/lang/nodejs.c new file mode 100644 index 0000000..f95ad3f --- /dev/null +++ b/src/recipe/lang/nodejs.c @@ -0,0 +1,116 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * Contributors : Aoran Zeng + * Created on : <2023-09-01> + * Last modified : <2024-08-09> + * ------------------------------------------------------------*/ + +static MirrorSite +NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/", + // 注意,这个是跳转后的地址,不确定未来会不会改变 + "https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.10.0/tfjs-4.10.0.tgz"}; // 29MB + + +/** + * @time 2024-04-18 更新 + * @note { + * Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有 + * 腾讯软件源的npm源一直未证实是否可用 + * } + */ +static SourceInfo +pl_nodejs_sources[] = { + {&Upstream, NULL}, + {&NpmMirror, "https://registry.npmmirror.com"}, + {&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"}, + {&Zju, "https://mirrors.zju.edu.cn/npm"} +}; +def_sources_n(pl_nodejs); + + +void +pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist) +{ + char *check_cmd = xy_str_to_quietcmd ("npm -v"); + *npm_exist = query_program_exist (check_cmd, "npm"); + + check_cmd = xy_str_to_quietcmd ("yarn -v"); + *yarn_exist = query_program_exist (check_cmd, "yarn"); + + check_cmd = xy_str_to_quietcmd ("pnpm -v"); + *pnpm_exist = query_program_exist (check_cmd, "pnpm"); + + if (!*npm_exist && !*yarn_exist && !*pnpm_exist) + { + chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"); + exit (Exit_UserCause); + } +} + + +void +pl_nodejs_getsrc (char *option) +{ + bool npm_exist, yarn_exist, pnpm_exist; + pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); + + if (npm_exist) + { + chsrc_run ("npm config get registry", RunOpt_Default); + } + if (yarn_exist) + { + chsrc_run ("yarn config get registry", RunOpt_Default); + } + if (pnpm_exist) + { + chsrc_run ("pnpm config get registry", RunOpt_Default); + } +} + +/** + * NodeJS换源,参考:https://npmmirror.com/ + */ +void +pl_nodejs_setsrc (char *option) +{ + bool npm_exist, yarn_exist, pnpm_exist; + pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); + + SourceInfo source; + chsrc_yield_source (pl_nodejs); + chsrc_confirm_source (&source); + + char *cmd = NULL; + + char *where = " "; + if (CliOpt_Locally==true) + { + where = " --location project "; + } + + if (npm_exist) + { + cmd = xy_strjoin (4, "npm config", where, "set registry ", source.url); + chsrc_run (cmd, RunOpt_Default); + } + + if (yarn_exist) + { + // 不再阻止换源命令输出到终端,即不再调用 xy_str_to_quietcmd() + cmd = xy_2strjoin ("yarn config set registry ", source.url); + chsrc_run (cmd, RunOpt_Default); + } + + if (pnpm_exist) + { + cmd = xy_2strjoin ("pnpm config set registry ", source.url); + chsrc_run (cmd, RunOpt_Default); + } + + chsrc_say_lastly (&source, ChsrcTypeAuto); +} + + +def_target(pl_nodejs);