mirror of
https://github.com/RubyMetric/chsrc.git
synced 2024-11-22 13:49:18 +08:00
parent
5fdea2a3c6
commit
2d0fb8ce56
11
src/chsrc.c
11
src/chsrc.c
|
@ -13,13 +13,13 @@
|
|||
* | Terrasse <terrasse@qq.com>
|
||||
* |
|
||||
* Created On : <2023-08-28>
|
||||
* Last Modified : <2024-09-04>
|
||||
* Last Modified : <2024-09-10>
|
||||
*
|
||||
* chsrc: Change Source —— 全平台通用命令行换源工具
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
#define Chsrc_Version "0.1.8.1dev2"
|
||||
#define Chsrc_Release_Date "2024/09/04"
|
||||
#define Chsrc_Version "0.1.8.1dev3"
|
||||
#define Chsrc_Release_Date "2024/09/10"
|
||||
#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"
|
||||
|
@ -28,7 +28,10 @@
|
|||
|
||||
#include "recipe/lang/Ruby.c"
|
||||
#include "recipe/lang/Python.c"
|
||||
#include "recipe/lang/Node.js.c"
|
||||
#include "recipe/lang/Node.js/Node.js.c"
|
||||
#include "recipe/lang/Node.js/npm.c"
|
||||
#include "recipe/lang/Node.js/pnpm.c"
|
||||
#include "recipe/lang/Node.js/Yarn.c"
|
||||
#include "recipe/lang/Perl.c"
|
||||
#include "recipe/lang/PHP.c"
|
||||
#include "recipe/lang/Lua.c"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
/** ------------------------------------------------------------
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* -------------------------------------------------------------
|
||||
* File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
* Contributors : Mr. Will <mr.will.com@outlook.com>
|
||||
* Created On : <2023-08-30>
|
||||
* Last Modified : <2024-08-28>
|
||||
* File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
* Contributors : Mr. Will <mr.will.com@outlook.com>
|
||||
* Created On : <2023-08-30>
|
||||
* Major Revision : 2
|
||||
* Last Modified : <2024-09-10>
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
static MirrorSite
|
||||
|
@ -22,7 +23,7 @@ NpmMirror = {"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "
|
|||
*/
|
||||
static SourceInfo
|
||||
pl_nodejs_sources[] = {
|
||||
{&Upstream, NULL},
|
||||
{&Upstream, "https://registry.npmjs.org/"},
|
||||
{&NpmMirror, "https://registry.npmmirror.com"},
|
||||
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
|
||||
{&Zju, "https://mirrors.zju.edu.cn/npm"}
|
||||
|
@ -35,7 +36,7 @@ pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist)
|
|||
{
|
||||
*npm_exist = chsrc_check_program ("npm");
|
||||
*yarn_exist = chsrc_check_program ("yarn");
|
||||
*pnpm_exist = chsrc_check_program ("yarn");
|
||||
*pnpm_exist = chsrc_check_program ("pnpm");
|
||||
|
||||
if (!*npm_exist && !*yarn_exist && !*pnpm_exist)
|
||||
{
|
||||
|
@ -45,14 +46,6 @@ pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist)
|
|||
}
|
||||
|
||||
|
||||
double
|
||||
get_yarn_version ()
|
||||
{
|
||||
char *ver = xy_run ("yarn --version", 0, NULL);
|
||||
double version = atof (ver);
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pl_nodejs_getsrc (char *option)
|
||||
|
@ -62,26 +55,20 @@ pl_nodejs_getsrc (char *option)
|
|||
|
||||
if (npm_exist)
|
||||
{
|
||||
chsrc_run ("npm config get registry", RunOpt_Default);
|
||||
// TODO
|
||||
}
|
||||
if (yarn_exist)
|
||||
{
|
||||
// 最后一个版本应该是 v1.22.22
|
||||
if (get_yarn_version () >= 2)
|
||||
// https://github.com/RubyMetric/chsrc/issues/53
|
||||
// 从 Yarn V2 开始,使用新的配置名
|
||||
chsrc_run ("yarn config get npmRegistryServer", RunOpt_Default);
|
||||
else
|
||||
chsrc_run ("yarn config get registry", RunOpt_Default);
|
||||
// TODO
|
||||
}
|
||||
if (pnpm_exist)
|
||||
{
|
||||
chsrc_run ("pnpm config get registry", RunOpt_Default);
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NodeJS换源,参考:https://npmmirror.com/
|
||||
* chsrc set nodejs
|
||||
*/
|
||||
void
|
||||
pl_nodejs_setsrc (char *option)
|
||||
|
@ -91,44 +78,19 @@ pl_nodejs_setsrc (char *option)
|
|||
|
||||
chsrc_yield_source_and_confirm (pl_nodejs);
|
||||
|
||||
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);
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (yarn_exist)
|
||||
{
|
||||
// 从 Yarn V2 开始,使用新的配置名
|
||||
if (get_yarn_version () >= 2)
|
||||
{
|
||||
if (CliOpt_Locally==true) // 默认基于本项目换源
|
||||
cmd = xy_2strjoin ("yarn config set npmRegistryServer ", source.url);
|
||||
else
|
||||
cmd = xy_2strjoin ("yarn config set npmRegistryServer --home ", source.url);
|
||||
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 不再阻止换源命令输出到终端,即不再调用 xy_str_to_quietcmd()
|
||||
cmd = xy_2strjoin ("yarn config set registry ", source.url);
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
}
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (pnpm_exist)
|
||||
{
|
||||
cmd = xy_2strjoin ("pnpm config set registry ", source.url);
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
// TODO
|
||||
}
|
||||
|
||||
chsrc_conclude (&source, ChsrcTypeAuto);
|
||||
|
@ -141,10 +103,10 @@ pl_nodejs_feat (char *option)
|
|||
FeatInfo fi = {0};
|
||||
|
||||
fi.can_get = true;
|
||||
fi.can_reset = false;
|
||||
fi.can_reset = true;
|
||||
|
||||
fi.stcan_locally = CanSemi;
|
||||
fi.locally = "支持 npm (From v0.1.7); 支持 yarn v2 (From v0.1.8.1); pnpm 未知";
|
||||
fi.stcan_locally = CanFully;
|
||||
fi.locally = "支持 npm (From v0.1.7); 支持 yarn v2 (chsrc v0.1.8.1); 支持 pnpm (chsrc v0.1.8.2)";
|
||||
fi.can_english = false;
|
||||
fi.can_user_define = true;
|
||||
|
87
src/recipe/lang/Node.js/npm.c
Normal file
87
src/recipe/lang/Node.js/npm.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/** ------------------------------------------------------------
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* -------------------------------------------------------------
|
||||
* File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
* Contributors : Mr. Will <mr.will.com@outlook.com>
|
||||
* Created On : <2023-08-30>
|
||||
* Major Revision : 2
|
||||
* Last Modified : <2024-09-10>
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @update 2024-04-08
|
||||
*/
|
||||
static SourceInfo
|
||||
pl_nodejs_npm_sources[] = {
|
||||
{&Upstream, "https://registry.npmjs.org/"}, // @note 根据 pnpm 官网,有最后的斜线
|
||||
{&NpmMirror, "https://registry.npmmirror.com"},
|
||||
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/"},
|
||||
{&Zju, "https://mirrors.zju.edu.cn/npm"}
|
||||
};
|
||||
def_sources_n(pl_nodejs_npm);
|
||||
|
||||
|
||||
/**
|
||||
* chsrc get npm
|
||||
*/
|
||||
void
|
||||
pl_nodejs_npm_getsrc (char *option)
|
||||
{
|
||||
chsrc_run ("npm config get registry", RunOpt_Default);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @consult https://npmmirror.com/
|
||||
*
|
||||
* chsrc set npm
|
||||
*/
|
||||
void
|
||||
pl_nodejs_npm_setsrc (char *option)
|
||||
{
|
||||
chsrc_yield_source_and_confirm (pl_nodejs_npm);
|
||||
|
||||
char *cmd = NULL;
|
||||
|
||||
if (CliOpt_Locally==true)
|
||||
cmd = xy_2strjoin ("npm config --location project set registry ", source.url);
|
||||
else
|
||||
cmd = xy_2strjoin ("npm config set registry ", source.url);
|
||||
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
|
||||
chsrc_conclude (&source, ChsrcTypeAuto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* chsrc reset npm
|
||||
*/
|
||||
void
|
||||
pl_nodejs_npm_resetsrc (char *option)
|
||||
{
|
||||
pl_nodejs_npm_setsrc (ChsrcTypeReset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* chsrc ls npm
|
||||
*/
|
||||
FeatInfo
|
||||
pl_nodejs_npm_feat (char *option)
|
||||
{
|
||||
FeatInfo fi = {0};
|
||||
|
||||
fi.can_get = true;
|
||||
fi.can_reset = true;
|
||||
|
||||
fi.stcan_locally = CanFully;
|
||||
fi.locally = NULL;
|
||||
fi.can_english = true;
|
||||
fi.can_user_define = true;
|
||||
|
||||
fi.note = NULL;
|
||||
return fi;
|
||||
}
|
||||
|
||||
def_target_gsrf(pl_nodejs_npm);
|
|
@ -13,9 +13,12 @@
|
|||
static const char
|
||||
*pl_ruby [] = {"gem", "ruby", "rubygem", "rb", "rubygems", "bundler", NULL, t(&pl_ruby_target)},
|
||||
*pl_python[] = {"pip", "python", "pypi", "py", "poetry", "pdm", NULL, t(&pl_python_target)},
|
||||
*pl_nodejs[] = {"npm", "node", "nodejs", "js", NULL, t(&pl_nodejs_target)},
|
||||
*pl_nodejs_yarn[] = {"yarn", NULL, t(&pl_nodejs_yarn_target)},
|
||||
*pl_nodejs_pnpm[] = {"pnpm", NULL, t(&pl_nodejs_pnpm_target)},
|
||||
|
||||
*pl_nodejs[] = {"node", "nodejs", NULL, t(&pl_nodejs_target)},
|
||||
*pl_nodejs_npm[] = {"npm", NULL, t(&pl_nodejs_npm_target)},
|
||||
*pl_nodejs_yarn[] = {"yarn", NULL, t(&pl_nodejs_yarn_target)},
|
||||
*pl_nodejs_pnpm[] = {"pnpm", NULL, t(&pl_nodejs_pnpm_target)},
|
||||
|
||||
*pl_perl [] = {"perl", "cpan", NULL, t(&pl_perl_target)},
|
||||
*pl_php [] = {"php", "composer", NULL, t(&pl_php_target)},
|
||||
*pl_lua [] = {"lua", "luarocks", NULL, t(&pl_lua_target)},
|
||||
|
@ -32,7 +35,7 @@ static const char
|
|||
**pl_packagers[] =
|
||||
{
|
||||
pl_ruby, pl_python,
|
||||
pl_nodejs, pl_nodejs_pnpm, pl_nodejs_yarn,
|
||||
pl_nodejs, pl_nodejs_npm, pl_nodejs_pnpm, pl_nodejs_yarn,
|
||||
pl_perl, pl_php, pl_lua,
|
||||
pl_rust, pl_go, /*pl_nuget,*/ pl_java, pl_clojure, pl_dart,
|
||||
pl_haskell, pl_ocaml,
|
||||
|
|
Loading…
Reference in New Issue
Block a user