mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-24 03:58:39 +08:00
Split nodejs out
This commit is contained in:
parent
bf1fb434ae
commit
fceb0363de
@ -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);
|
||||||
|
87
src/chsrc.c
87
src/chsrc.c
@ -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
116
src/recipe/lang/nodejs.c
Normal 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);
|
Loading…
x
Reference in New Issue
Block a user