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

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

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-2021

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

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


posted @ 2023-03-16 13:22  xgqfrms  阅读(26)  评论(3编辑  收藏  举报