关于javascript:编写自定义的CLI工具

繁难demo
  1. 编码 package.json
{
  "name": "daytoy",
  "version": "0.0.1",
  "description": "nodejs cli program",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "daytoy",
  "license": "ISC",
  "bin": {
    "toy": "index.js"
  }
}

bin 属性具备可执行文件,cli 命令要求运行 index.js 文件。

  1. 编写可执行文件
#! node
console.log('DAY DAY TOY !');
/**
在Linux和基于Unix的操作系统(例如Mac)中,#! / usr / bin / env node 不仅仅是一个正文。它应用在 /usr/bin/env 中注册的node命令来运行文件。

然而,在Windows中,这只是一个正文。
**/
  1. 运行 npm i -g 在package.json中装置配置

  1. 执行自定义的命令

问题: 零碎上禁止运行脚本?

解决:
1.关上PowerShell(以管理员身份运行)
2.set-ExecutionPolicy RemoteSigned //设置为关上
3.键入Y或者A,批准
4.执行get-executionpolicy查看是否更改胜利,为RemoteSigned示意胜利

### 利用:创立工程脚手架模板交互(nodejs)

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理