Rename to JavaScript

This commit is contained in:
Aoran Zeng
2025-08-10 13:36:10 +08:00
parent a936136d14
commit c531b8b56e
10 changed files with 85 additions and 85 deletions

View File

@@ -0,0 +1,84 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Lontten <lontten@163.com>
* Created On : <2024-09-29>
* Last Modified : <2025-07-22>
* ------------------------------------------------------------*/
/**
* chsrc get bun
*/
void
pl_js_bun_getsrc (char *option)
{
chsrc_view_file ("~/.bunfig.toml");
}
/**
* @consult https://bun.sh/docs/runtime/bunfig#global-vs-local
* @consult https://github.com/RubyMetric/chsrc/issues/83
* @consult https://github.com/RubyMetric/chsrc/pull/90
*
* chsrc set bun
*/
void
pl_js_bun_setsrc (char *option)
{
// 用的是 npm Registry 的源
chsrc_yield_source (pl_js_group);
char *content = RAWSTR_pl_js_bun_config;
content = xy_str_gsub (content, "@url@", source.url);
if (chsrc_in_local_mode())
{
chsrc_note2 ("请手动写入以下内容到本项目根目录的 bunfig.toml 文件中");
}
else
{
chsrc_note2 (xy_strjoin (3, "请手动写入以下内容到 ", xy_normalize_path ("~/.bunfig.toml"), " 文件中"));
}
println (content);
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
/**
* chsrc reset bun
*/
void
pl_js_bun_resetsrc (char *option)
{
pl_js_bun_setsrc (option);
}
/**
* chsrc ls bun
*/
Feature_t
pl_js_bun_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
f.cap_locally = FullyCan;
f.cap_locally_explain = NULL;
f.can_english = true;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_js_bun);
Target_t pl_js_bun_target = {def_target_inner_gsrf(pl_js_bun),def_target_sourcesn(pl_js_group)};

View File

@@ -0,0 +1,131 @@
/** ------------------------------------------------------------
* 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 : <2025-07-11>
* ------------------------------------------------------------*/
void
pl_js_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 ("pnpm");
if (!*npm_exist && !*yarn_exist && !*pnpm_exist)
{
char *msg = ENGLISH ? "No npm, yarn or pnpm command found, check if at least one is present"
: "未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一";
chsrc_error (msg);
exit (Exit_UserCause);
}
}
/**
* chsrc get nodejs
*/
void
pl_js_group_getsrc (char *option)
{
bool npm_exist, yarn_exist, pnpm_exist;
pl_js_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
hr();
if (npm_exist)
{
pl_js_npm_getsrc (option);
br();
}
if (yarn_exist)
{
pl_js_yarn_getsrc (option);
br();
}
if (pnpm_exist)
{
pl_js_pnpm_getsrc (option);
br();
}
}
/**
* chsrc set nodejs
*/
void
pl_js_group_setsrc (char *option)
{
{
char *msg = ENGLISH ? "Three package managers will be replaced for you at the same time: "
"npm, pnpm, yarn. If you need to change the source independently, "
"please run independently `chsrc set <pkg-manager>`"
: "将同时更换3个包管理器 npm, pnpm, Yarn 的源,若需要独立换源,请独立运行 chsrc set <pkg-manager>";
chsrc_alert2 (msg);
}
bool npm_exist, yarn_exist, pnpm_exist;
pl_js_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
chsrc_set_target_group_mode ();
chsrc_yield_source_and_confirm (pl_js_group);
if (npm_exist)
{
pl_js_npm_setsrc (option);
br();
}
if (yarn_exist)
{
pl_js_yarn_setsrc (option);
br();
}
if (pnpm_exist)
{
pl_js_pnpm_setsrc (option);
}
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
/**
* chsrc reset nodejs
*/
void
pl_js_group_resetsrc (char *option)
{
pl_js_group_setsrc (option);
}
/**
* chsrc ls nodejs
*/
Feature_t
pl_js_group_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
f.cap_locally = FullyCan;
f.cap_locally_explain = "Support `npm` & `yarn v2` & `pnpm`. No support for `yarn v1`";
f.can_english = true;
f.can_user_define = true;
return f;
}
def_target_gsrf (pl_js_group);

View File

@@ -0,0 +1,112 @@
/** ------------------------------------------------------------
* 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-09-09>
* Major Reviison : 3
* Last Modified : <2025-07-11>
* ------------------------------------------------------------*/
static double
pl_js_yarn_get_yarn_version ()
{
char *ver = xy_run ("yarn --version", 0);
double version = atof (ver);
return version;
}
/**
* chsrc get yarn
*/
void
pl_js_yarn_getsrc (char *option)
{
// 最后一个版本应该是 v1.22.22
if (pl_js_yarn_get_yarn_version () >= 2)
// https://github.com/RubyMetric/chsrc/issues/53
// 从 Yarn V2 开始,使用新的配置名
chsrc_run ("yarn config get npmRegistryServer", RunOpt_No_Last_New_Line);
else
chsrc_run ("yarn config get registry", RunOpt_No_Last_New_Line);
}
/**
* @consult https://github.com/RubyMetric/chsrc/issues/53
* @consult https://yarnpkg.com/cli/config/set
*/
void
pl_js_yarn_setsrc (char *option)
{
chsrc_yield_source (pl_js_group);
if (chsrc_in_standalone_mode())
chsrc_confirm_source();
char *cmd = NULL;
// 从 Yarn V2 开始,使用新的配置名
if (pl_js_yarn_get_yarn_version () >= 2)
{
if (chsrc_in_local_mode()) // Yarn 默认情况下就是基于本项目换源
cmd = xy_2strjoin ("yarn config set npmRegistryServer ", source.url);
else
cmd = xy_2strjoin ("yarn config set npmRegistryServer --home ", source.url);
chsrc_run (cmd, RunOpt_No_Last_New_Line);
}
else
{
if (chsrc_in_local_mode())
{
char *msg = ENGLISH ? "Yarn v1 doesn't support `-local`. SKIP changing source!" : "Yarn v1 不支持 -local跳过换源";
chsrc_error (msg);
// 不能直接退出,因为 Leader target 不能就此结束
return;
}
// 不再阻止换源命令输出到终端,即不再调用 xy_str_to_quietcmd()
cmd = xy_2strjoin ("yarn config set registry ", source.url);
chsrc_run (cmd, RunOpt_No_Last_New_Line);
}
if (chsrc_in_standalone_mode())
{
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}
/**
* chsrc reset yarn
*/
void
pl_js_yarn_resetsrc (char *option)
{
pl_js_yarn_setsrc (option);
}
/**
* chsrc ls yarn
*/
Feature_t
pl_js_yarn_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
f.cap_locally = FullyCan;
f.cap_locally_explain = NULL;
f.can_english = true;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_js_yarn);
Target_t pl_js_yarn_target = {def_target_inner_gsrf(pl_js_yarn),def_target_sourcesn(pl_js_group)};

View File

@@ -0,0 +1,86 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nul None <nul@none.org>
* |
* Created On : <2023-09-09>
* Major Revision : 1
* Last Modified : <2025-07-11>
* ------------------------------------------------------------*/
#define PL_JS_Group_Speed_URL_Postfix "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz"
static SourceProvider_t pl_js_npm_upstream =
{
def_upstream, "https://www.npmjs.com/",
{NotSkip, NA, NA, "https://registry.npmjs.org/@tensorflow/tfjs/-/tfjs-4.22.0.tgz", ACCURATE}
};
static MirrorSite_t NpmMirror =
{
IS_DedicatedMirrorSite,
"npmmirror", "npmmirror", "npmmirror (阿里云赞助)", "https://npmmirror.com/",
// 注意,下面这个是跳转后的地址,不确定未来会不会改变
{NotSkip, NA, NA, "https://cdn.npmmirror.com/packages/%40tensorflow/tfjs/4.22.0/tfjs-4.22.0.tgz", ACCURATE} // 29MB
};
/**
* @update 2025-07-11
* @sync https://github.com/RubyMetric/chsrc/wiki/Node.js-MirrorSite
* @sync https://github.com/RubyMetric/chsrc/discussions/85
*
* @note
* Sjtug, Tuna, Lzuoss, Jlu, Bfsu, 网易,搜狐 都没有
*/
static Source_t pl_js_group_sources[] =
{
{&pl_js_npm_upstream, "https://registry.npmjs.org/", DelegateToUpstream}, /* @note 根据 pnpm 官网,有最后的斜线 */
{&NpmMirror, "https://registry.npmmirror.com", DelegateToMirror},
{&Huawei, "https://mirrors.huaweicloud.com/repository/npm/",
"https://mirrors.huaweicloud.com/repository/npm/" PL_JS_Group_Speed_URL_Postfix},
{&Tencent, "https://mirrors.cloud.tencent.com/npm/",
"https://mirrors.cloud.tencent.com/npm/" PL_JS_Group_Speed_URL_Postfix},
};
def_sources_n(pl_js_group);
#define PL_Nodejs_Binary_Speed_URL_Postfix "/v23.4.0/node-v23.4.0-linux-x64.tar.xz"
static SourceProvider_t pl_js_binary_release_upstream =
{
def_upstream, "https://nodejs.org/",
{NotSkip, NA, NA, "https://nodejs.org/dist/v23.4.0/node-v23.4.0.tar.gz", ACCURATE} // 100MB
};
/**
* @update 2025-07-11
* @sync https://github.com/RubyMetric/chsrc/wiki/Node.js-BinaryRelease-MirrorSite
* @sync https://github.com/RubyMetric/chsrc/discussions/85
*
*/
static Source_t pl_js_binary_release_sources[] =
{
{&pl_js_binary_release_upstream, "https://nodejs.org/dist/", DelegateToUpstream},
{&NpmMirror, "https://npmmirror.com/mirrors",
"https://registry.npmmirror.com/-/binary/node/v23.4.0/node-v23.4.0.tar.gz"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/",
"https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/" PL_Nodejs_Binary_Speed_URL_Postfix},
{&Bfsu, "https://mirrors.bfsu.edu.cn/nodejs-release/",
"https://mirrors.bfsu.edu.cn/nodejs-release/" PL_Nodejs_Binary_Speed_URL_Postfix},
{&Ustc, "https://mirrors.ustc.edu.cn/node/",
"https://mirrors.ustc.edu.cn/node/" PL_Nodejs_Binary_Speed_URL_Postfix},
{&Huawei, "https://mirrors.huaweicloud.com/nodejs/",
"https://mirrors.huaweicloud.com/nodejs/" PL_Nodejs_Binary_Speed_URL_Postfix},
{&Tencent, "https://mirrors.cloud.tencent.com/nodejs-release/",
"https://mirrors.cloud.tencent.com/nodejs-release/" PL_Nodejs_Binary_Speed_URL_Postfix}
};
def_sources_n(pl_js_binary_release);

View File

@@ -0,0 +1,81 @@
/** ------------------------------------------------------------
* 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 : <2025-07-11>
* ------------------------------------------------------------*/
/**
* chsrc get npm
*/
void
pl_js_npm_getsrc (char *option)
{
chsrc_run ("npm config get registry", RunOpt_No_Last_New_Line);
}
/**
* @consult https://npmmirror.com/
*
* chsrc set npm
*/
void
pl_js_npm_setsrc (char *option)
{
chsrc_yield_source (pl_js_group);
if (chsrc_in_standalone_mode())
chsrc_confirm_source();
char *cmd = NULL;
if (chsrc_in_local_mode())
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_No_Last_New_Line);
if (chsrc_in_standalone_mode())
{
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}
/**
* chsrc reset npm
*/
void
pl_js_npm_resetsrc (char *option)
{
pl_js_npm_setsrc (option);
}
/**
* chsrc ls npm
*/
Feature_t
pl_js_npm_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
f.cap_locally = FullyCan;
f.cap_locally_explain = NULL;
f.can_english = true;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_js_npm);
Target_t pl_js_npm_target = {def_target_inner_gsrf(pl_js_npm),def_target_sourcesn(pl_js_group)};

View File

@@ -0,0 +1,83 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nul None <nul@none.org>
* |
* Created On : <2024-09-23>
* Last Modified : <2025-06-19>
* ------------------------------------------------------------*/
/**
* chsrc get nvm
*/
void
pl_js_nvm_getsrc (char *option)
{
chsrc_view_env ("NVM_NODEJS_ORG_MIRROR", NULL);
}
/**
* @consult https://github.com/nvm-sh/nvm?tab=readme-ov-file#use-a-mirror-of-node-binaries
* @consult https://mirrors.tuna.tsinghua.edu.cn/help/nodejs-release/
* @issue https://github.com/RubyMetric/chsrc/issues/81
*
* chsrc set nvm
*
* @note nvm does not support Fish
*/
void
pl_js_nvm_setsrc (char *option)
{
chsrc_yield_source_and_confirm (pl_js_binary_release);
char *w = xy_strjoin (3, "export NVM_NODEJS_ORG_MIRROR=", source.url, "\n");
char *zshrc = xy_zshrc;
char *bashrc = xy_bashrc;
chsrc_append_to_file (w, bashrc);
if (xy_file_exist (zshrc))
chsrc_append_to_file (w, zshrc);
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
/**
* chsrc reset nvm
*/
void
pl_js_nvm_resetsrc (char *option)
{
// pl_js_nvm_setsrc (ChgType_Reset);
chsrc_error ("暂不支持对 nvm 重置");
exit (Exit_Unsupported);
}
/**
* chsrc ls nvm
*/
Feature_t
pl_js_nvm_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = false;
f.cap_locally = CanNot;
f.cap_locally_explain = "";
f.can_english = false;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_js_nvm);
Target_t pl_js_nvm_target = {def_target_inner_gsrf(pl_js_nvm),def_target_sourcesn(pl_js_binary_release)};

View File

@@ -0,0 +1,83 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nul None <nul@none.org>
* Created On : <2024-04-18>
* Major Revision : 2
* Last Modified : <2025-07-11>
* ------------------------------------------------------------*/
/**
* chsrc get pnpm
*/
void
pl_js_pnpm_getsrc (char *option)
{
chsrc_run ("pnpm config get registry", RunOpt_No_Last_New_Line);
}
/**
* @consult https://pnpm.io/feature-comparison
* @consult https://pnpm.io/cli/config
*
* chsrc set pnpm
*/
void
pl_js_pnpm_setsrc (char *option)
{
chsrc_yield_source (pl_js_group);
if (chsrc_in_standalone_mode())
chsrc_confirm_source();
char *cmd = NULL;
if (chsrc_in_local_mode())
cmd = xy_2strjoin ("pnpm config --location project set registry ", source.url);
else
cmd = xy_2strjoin ("pnpm config -g set registry ", source.url);
chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (chsrc_in_standalone_mode())
{
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}
/**
* chsrc reset pnpm
*/
void
pl_js_pnpm_resetsrc (char *option)
{
pl_js_pnpm_setsrc (option);
}
/**
* chsrc ls pnpm
*/
Feature_t
pl_js_pnpm_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
f.cap_locally = FullyCan;
f.cap_locally_explain = NULL;
f.can_english = true;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_js_pnpm);
Target_t pl_js_pnpm_target = {def_target_inner_gsrf(pl_js_pnpm),def_target_sourcesn(pl_js_group)};