网站首页 > 技术文章 正文
脚手架本地link标准流程
链接本地脚手架
cd your-cli-dir
npm link
链接本地库文件
cd your-lib-dir
npm link
cd your-cli-dir
npm link your-lib
取消本地链接脚手架
cd your-lib-dir
npm unlink
cd your-cli-dir
# link存在
npm unlink your-lib
# link不存在
rm -rf node_modules
npm install -S your-lib
理解npm link:
1.npm link your-lib :将当前项目中 node_modules 下指定的库文件链接到 node 全局 node_modules 下的库文件
2.npm link :将当前项目链接到 node 全局 node_modules 中作为一个库文件,并解析 bin 配置创建可执行文件
理解 npm unlink:
1.npm unlink:将当前项目从 node 全局 node_modules 移除
2.npm unlink your-lib :将当前项目中的库文件依赖移除
脚手架命令注册和参数解析
实现注册一个命令:curry-cli-test init
1.首先在 cli-test-lib 项目下 定义一个 init 方法
module.exports = {
init(){
console.log('执行init流程')
}
}
2.在 cli-test 中 注册 init 命令
#!/usr/bin/env node
const lib = require('cli-test-lib');
// 注册一个命令 curry-cli-test init
const argv = require('process').argv;
const command = argv[2];
console.log(command)
if(command){
if(lib[command]){
lib[command]();
}else{
console.log('无效的命令')
}
}else{
console.log('请输入命令')
}
现在在终端输入 curry-cli-test init
在终端输入 curry-cli-test publish
在终端输入 curry-cli-test
实现带参数的命令:curry-cli-test --name vue-test
1.在 cli-test 中 注册
#!/usr/bin/env node
const lib = require('cli-test-lib');
// console.log(lib.sum(1,2))
// 注册一个命令 curry-cli-test init
const argv = require('process').argv;
const command = argv[2];
// 获取 --name vue-test
const options = argv.slice(3);
let [option, param ] =options;
option = option.replace('--','')
console.log(command)
if(command){
if(lib[command]){
// 给 init 方法传入 参数
lib[command]({ option, param });
}else{
console.log('无效的命令')
}
}else{
console.log('请输入命令')
}
2.在cli-test-lib中 init 方法 引入参数
init({ option, param }){
console.log('执行init流程', option, param)
}
此时在终端执行 curry-cli-test init --name vue-test。就可以拿到传入的参数了。
实现 --version
// 实现参数解析 --version
if(command.startsWith('--') || command.startsWith('-')){
const globalOption = command.replace(/--|-/g,'')
if(globalOption === 'version' || globalOption === 'V'){
console.log('1.0.0')
}
}
效果如下:
- 上一篇: 前端脚手架的实现原理
- 下一篇: 构建自己的前端脚手架下载器笔记
猜你喜欢
- 2025-05-26 Wee – 为现代 Web 开发打造的 CSS 脚手架
- 2025-05-26 中建工地高颜值的“秘诀”:盘扣式外架+定型化网片
- 2025-05-26 你没见过的新型花篮外架技术更快捷更方便,值得推广
- 2025-05-26 图解:盘扣式脚手架搭建步骤
- 2025-05-26 收藏!2022最新工字钢悬挑脚手架做法和规范,萌新必看
- 2025-05-26 「架构师必备」基于SpringCloud的SaaS型微服务脚手架
- 2025-05-26 使用 Vue 脚手架,为什么要学 webpack?(一)
- 2025-05-26 新型梁侧预埋式外脚手架连墙件施工工艺和流程
- 2025-05-26 SpringBoot+LayUI后台管理系统开发脚手架
- 2025-05-26 推荐一款超棒的SpringCloud 脚手架项目
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端react (48)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (49)
- 前端路由 (55)
- 前端数组 (65)
- 前端定时器 (47)
- Oracle RAC (73)
- oracle恢复 (76)
- oracle 删除表 (48)
- oracle 用户名 (74)
- oracle 工具 (55)
- oracle 内存 (50)
- oracle 导出表 (57)
- oracle 中文 (51)
- oracle链接 (47)
- oracle的函数 (57)
- mac oracle (47)
- 前端调试 (52)
- 前端登录页面 (48)
本文暂时没有评论,来添加一个吧(●'◡'●)