From fc6131283c0281db3bd495548cb1cb6a5b3ddeae Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Tue, 10 Sep 2024 18:59:13 +0800 Subject: [PATCH] Make target `nodejs` aggregate [GitHub #53 #66] --- src/chsrc.c | 5 ++- src/recipe/lang/Node.js/Node.js.c | 66 ++++++++++++++++--------------- src/recipe/lang/Node.js/common.h | 14 +++++++ src/recipe/lang/Node.js/pnpm.c | 5 +-- 4 files changed, 54 insertions(+), 36 deletions(-) create mode 100644 src/recipe/lang/Node.js/common.h diff --git a/src/chsrc.c b/src/chsrc.c index ca20c0e..1a8292f 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -28,10 +28,13 @@ #include "recipe/lang/Ruby.c" #include "recipe/lang/Python.c" -#include "recipe/lang/Node.js/Node.js.c" + +#include "recipe/lang/Node.js/common.h" #include "recipe/lang/Node.js/npm.c" #include "recipe/lang/Node.js/pnpm.c" #include "recipe/lang/Node.js/Yarn.c" +#include "recipe/lang/Node.js/Node.js.c" + #include "recipe/lang/Perl.c" #include "recipe/lang/PHP.c" #include "recipe/lang/Lua.c" diff --git a/src/recipe/lang/Node.js/Node.js.c b/src/recipe/lang/Node.js/Node.js.c index 8128c40..b095bfd 100644 --- a/src/recipe/lang/Node.js/Node.js.c +++ b/src/recipe/lang/Node.js/Node.js.c @@ -8,12 +8,6 @@ * Last Modified : <2024-09-10> * ------------------------------------------------------------*/ -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 { @@ -40,13 +34,17 @@ pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist) if (!*npm_exist && !*yarn_exist && !*pnpm_exist) { - chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"); + char *msg = CliOpt_InEnglish ? "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_nodejs_getsrc (char *option) { @@ -54,19 +52,16 @@ pl_nodejs_getsrc (char *option) pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); if (npm_exist) - { - // TODO - } + pl_nodejs_npm_getsrc (option); + if (yarn_exist) - { - // TODO - } + pl_nodejs_yarn_getsrc (option); + if (pnpm_exist) - { - // TODO - } + pl_nodejs_pnpm_getsrc (option); } + /** * chsrc set nodejs */ @@ -76,27 +71,34 @@ pl_nodejs_setsrc (char *option) bool npm_exist, yarn_exist, pnpm_exist; pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); - chsrc_yield_source_and_confirm (pl_nodejs); + // chsrc_yield_source_and_confirm (pl_nodejs); if (npm_exist) - { - // TODO - } + pl_nodejs_npm_setsrc (option); if (yarn_exist) - { - // TODO - } + pl_nodejs_yarn_setsrc (option); if (pnpm_exist) - { - // TODO - } + pl_nodejs_pnpm_setsrc (option); - chsrc_conclude (&source, ChsrcTypeAuto); + // chsrc_conclude (&source, ChsrcTypeAuto); } +/** + * chsrc reset nodejs + */ +void +pl_nodejs_resetsrc (char *option) +{ + pl_nodejs_setsrc (ChsrcTypeReset); +} + + +/** + * chsrc ls nodejs + */ FeatInfo pl_nodejs_feat (char *option) { @@ -105,12 +107,12 @@ pl_nodejs_feat (char *option) fi.can_get = true; fi.can_reset = true; - 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.stcan_locally = CanSemi; + fi.locally = "Support npm (chsrc v0.1.7)\nSupport yarn v2 (chsrc v0.1.8.1)\nSupport pnpm (chsrc v0.1.8.2)"; + fi.can_english = true; fi.can_user_define = true; return fi; } -def_target_gsf (pl_nodejs); +def_target_gsrf (pl_nodejs); diff --git a/src/recipe/lang/Node.js/common.h b/src/recipe/lang/Node.js/common.h new file mode 100644 index 0000000..1dee9f0 --- /dev/null +++ b/src/recipe/lang/Node.js/common.h @@ -0,0 +1,14 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nul None + * Created On : <2023-09-09> + * Major Revision : 1 + * Last Modified : <2024-09-10> + * ------------------------------------------------------------*/ + +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 diff --git a/src/recipe/lang/Node.js/pnpm.c b/src/recipe/lang/Node.js/pnpm.c index c89cbdb..f2506ce 100644 --- a/src/recipe/lang/Node.js/pnpm.c +++ b/src/recipe/lang/Node.js/pnpm.c @@ -3,8 +3,8 @@ * ------------------------------------------------------------- * File Authors : Aoran Zeng * Contributors : Nul None - * Created On : <2024-09-10> - * Major Revision : 1 + * Created On : <2024-04-18> + * Major Revision : 2 * Last Modified : <2024-09-10> * ------------------------------------------------------------*/ @@ -86,5 +86,4 @@ pl_nodejs_pnpm_feat (char *option) } -// 下列情形多选1 def_target_gsrf(pl_nodejs_pnpm);