Split nodejs out

This commit is contained in:
Aoran Zeng 2024-08-09 02:33:10 +08:00
parent bf1fb434ae
commit fceb0363de
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 120 additions and 107 deletions

View File

@ -108,15 +108,10 @@ MirrorSite
// 开源社区 // 开源社区
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}, NugetOrg = {"nuget.org", "NuGet Org", "Nuget Organization", "https://www.nuget.org/", NULL},
EmacsChina = {"emacschina", "EmacsChina", "Emacs China 社区", "https://elpamirror.emacs-china.org/", NULL}; EmacsChina = {"emacschina", "EmacsChina", "Emacs China 社区", "https://elpamirror.emacs-china.org/", NULL};
MirrorSite MirrorSite
Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL}; Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL};
MirrorSite MirrorSite
@ -132,22 +127,7 @@ typedef struct {
/** static SourceInfo
* 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"}
},
/** /**
* 2024-05-24 * 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) #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_perl); def_sources_n(pl_php);
def_sources_n(pl_rust); def_sources_n(pl_rust);
def_sources_n(pl_java); def_sources_n(pl_clojure); def_sources_n(pl_java); def_sources_n(pl_clojure);

View File

@ -24,90 +24,7 @@
#include "recipe/lang/ruby.c" #include "recipe/lang/ruby.c"
#include "recipe/lang/python.c" #include "recipe/lang/python.c"
#include "recipe/lang/nodejs.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);
}
void void
@ -2066,7 +1983,7 @@ wr_anaconda_setsrc (char *option)
/************************************** Begin Target Matrix ****************************************/ /************************************** 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_rust); def_target(pl_java); def_target(pl_dart); def_target(pl_ocaml);
def_target(pl_r); def_target(pl_julia); def_target(pl_r); def_target(pl_julia);
def_target_noget (pl_clojure); def_target_noget (pl_clojure);

116
src/recipe/lang/nodejs.c Normal file
View File

@ -0,0 +1,116 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* Contributors : Aoran Zeng <ccmywish@qq.com>
* 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);