• [Custom CLI] Develop and Publish a Node.js CLI from Scratch


    Before you use any frameworks, you should know the fundamentals of what makes Node CLI's tick. Here we explain everything you need to know to write a complete Node.js CLI from scratch, parse arguments, publish it to NPM for users, and set up yarn symlinks for optimal developer experience.

    Create a mycli.js file, in the very first line, we will add this code

    #!/usr/bin/env node

    It tells the running env. The benenfits for that is in order to run mycli.s file:

    // Before
    node ./mycli.js
    
    // After
    ./mycli.js

    Pass the argv:

    We also want to pass some information into file, in order to do some operations.

    ./mycli.js myapp --name=Answer1215

    They way to get the information is using:

    process.argv

    If we log the value:

    [ '/usr/local/bin/node',
      '/Users/zhentianwan/Documents/programming/cus-cli/mycli.js',
      'myapp',
      '--name=good' ]

    The first two is always there, the other information you pass into the cli, it will be push to the array.

    In order for easy testing cli, we can publish to npm, or just using:

    yarn link --global
  • 相关阅读:
    翻译一下libtiff的手册
    LIBTIFF读写黑白TIFF
    LIBTIFF存储代码,存图、拼图
    几点TIFF的说明
    TIFF Tag TileWidth
    TIFF Tag Orientation
    OpenCV 加速图像处理
    Qt QString 、String、char* 三者之间相互转换
    PackBits解压缩算法
    关于LZW算法的压缩与解压缩
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12387775.html
Copyright © 2020-2023  润新知