如何写自己的一款脚手架工具 creeate-react-app @vue/cli源码解读

原理:快速搭建一个项目的完整结构
常见的脚手架工具:yeoman ,express-genereator, vue-cli

npm link
npm unlink

node 不支持es6的方式
https://javascript.ruanyifeng.com/nodejs/module.html

git clone ${gitUrl} ${folderName}
从远程仓库克隆到自定义目录

一 、入口文件

/bin

二、 使用的类库

co库

generator函数的用法

类似于async /await

co-prompt库

返回nodejs的用户终端输入

chalk

美化输出

execa

execa是可以调用shell和本地外部程序的javascript封装。会启动子进程执行。支持多操作系统,包括windows。如果父进程退出,则生成的全部子进程都被杀死。

dns

域名解析

commander

完整的 node.js 命令行解决方案

envinfo

semver

语义版本号

validate-npm-package-name

校验是否是有效的npm包名

fs-extra

fs.ensureDirSync(name); //创建文件夹

leven

比较字符串间的差异

slash

window反斜杠路径转换

minimist

命令行参数解析

inquirer

命令行交互工具

ini

lru-cache

一个高速缓存对象,用于删除最近最少使用的项目

strip-ansi

从字符串中去除ANIS转义码

ejs

js模板引擎

deepmerge

深度合并对象

三、 node

child_process

child_process.spawn(command[, args][, options])
执行command命令

subprocess.stderr
子进程可读流

stdio 流
data事件
close事件

stream

writable.write(chunk) 时,数据会被缓冲在可写流中。

process

process.cwd()
返回当前进程目录

process.stderr属性返回一个双工流

resolve

isbinaryfile

检测是否为二进制文件

四、 linux命令

ls
ls -lh 可以在列出文件的同时查看文件的大小
ls -lh /usr 查看uer目录

五、js

str.match(/[.*] (\d+)/(\d+)/)
匹配版本号

类的私有方法


class cjrApi{
    
    
  constructor(cjr){
    
    
    this.cjr=cjr
  }
  init(){
    
    
    this.cjr.cjrArray=[1,3]
  }
}
class cjr{
    
    
  constructor(){
    
    
    // super()
    this.cjrArray=[]
  }
  init(){
    
    
    let api=new cjrApi(this)
    console.log(api,this.cjrArray)
  }
}

猜你喜欢

转载自blog.csdn.net/cs18335818140/article/details/111479277