当前位置: 首页> 文旅> 酒店 > 微信云开发平台_网站建设推广唯心磁遁8_百度一下你就知道手机版官网_怎么查百度收录

微信云开发平台_网站建设推广唯心磁遁8_百度一下你就知道手机版官网_怎么查百度收录

时间:2025/7/10 2:54:17来源:https://blog.csdn.net/qq_34568700/article/details/146531502 浏览次数:1次
微信云开发平台_网站建设推广唯心磁遁8_百度一下你就知道手机版官网_怎么查百度收录

新建文件夹 template-cli
template-cli下运行

npm init

在这里插入图片描述

生成package.json

新建bin文件夹和index.js文件
编写index.js

#! /usr/bin/env node
console.log('hello cli')

在这里插入图片描述

package.json增加 bin 字段注册命令template-cli
template-cli命令对应执行的内容文件 bin/index.js
在这里插入图片描述
运行 npm link,就可以把template-cli注册到命令行

npm link

在这里插入图片描述

测试一下,运行自己的命令template-cli,输出了index.js中编写的内容 hello cli
在这里插入图片描述

继续编写更多内容使用 commander
我们来安装下

npm install commander --save

在这里插入图片描述
考虑使用 ESModule模块编写,所以在package.json文件中配置 "type": "module"
在这里插入图片描述
使用commander编写index.js

import { Command } from 'commander'
const program = new Command()
program.name('create template').description('Use template-cli to create').version('0.0.1')
program.parse()

现在我们可以使用 --help--version 来获取我们的描述信息和版本信息
在这里插入图片描述
下面我们要编写一些真正的执行事项

program.command('create <name>').description('create a new project').action(async (name) => {console.log(name)})
program.parse()

运行create命令得到的输出
在这里插入图片描述
目前为止,index.js中的全部内容如下

#! /usr/bin/env node
console.log('hello cli')
import { Command } from 'commander'
const program = new Command()
program.name('create template').description('Use template-cli to create').version('0.0.1')
program.command('create <name>').description('create a new project').action(async (name) => {console.log(name)})
program.parse()

运行不带任务的命令结果如下
在这里插入图片描述

关键字:微信云开发平台_网站建设推广唯心磁遁8_百度一下你就知道手机版官网_怎么查百度收录

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: