xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Node.js cli tools auto install npm packages All In One

Node.js cli tools auto install npm packages All In One

cli auto install dependencies / cli 自动安装依赖

原理分析

  1. 读取本地或远程的 template files, 复制模版文件到新建的项目中;
  2. 通过交互式的命令行工具 yargs 获取参数;
  3. 自动执行预定义的 shell 安装脚本文件;
if (platform === "linux") {
  template_path = `https://github.com/xgqfrms/hui-templates.git`;
  shell.exec(`git clone ${template_path} ${app_path}`);
  const spinner = ora();
  spinner.start("start downloading ...");
  setTimeout(() => {
    spinner.color = "green";
    spinner.text = "🎉 finished downlaod!";
  }, 1000);
}

https://github.com/xgqfrms/hui-cli/blob/master/hui#LL103-L113C10

if (install) {
    log(`start auto installing...`.green);
    shell.exec(`cd hui-app & npm i`);
    log(`finished install`.green);
}

https://github.com/xgqfrms/hui-cli/blob/master/hui#LL188-L193C2

demos

next.js

# global cli
$ npm i -g @nestjs/cli

$ nest new web-app

image

cra

# 💩 global cli
$ npm uninstall -g create-react-app
$ yarn global remove create-react-app

# npx
$ npx  create-react-app  react-app

$ npx create-react-app typescript-react-app --template typescript

Running any of these commands will create a directory called my-app inside the current folder.
Inside that directory, it will generate the initial project structure and install the transitive dependencies:

运行这些命令中的任何一个都会在当前文件夹中创建一个名为 my-app 的目录
在该目录中,它将生成初始项目结构安装传递依赖项

https://create-react-app.dev/docs/getting-started#quick-start

https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

refs

yargs

https://github.com/xgqfrms-GitHub/Node-CLI-Tools/blob/master/libs/readme.md#yargs

npm

https://www.npmjs.com/package/hui-cli

https://github.com/xgqfrms/hui-cli
https://github.com/xgqfrms/hui-templates

https://www.npmjs.com/package/app-node-env

https://socket.dev/npm/package/@xgqfrms/wcui



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(31)  评论(3编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
历史上的今天:
2022-03-16 js map string trim bug All In One
2022-03-16 LeetCode String to Integer (atoi) js solution All In One
2022-03-16 vscode auto run task on save code & automatic debug All In One
2022-03-16 Apple MacBook Pro 扬声器突然没声音了 bug All In One
2022-03-16 document.execCommand API & Clipboard API All In One
2022-03-16 社交媒体分享代码截图美化工具 All in One
2022-03-16 js one object equal to another object checker All In One
点击右上角即可分享
微信分享提示