Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Create npm module and publish to npm

kkeeth
August 23, 2018

Create npm module and publish to npm

kkeeth

August 23, 2018
Tweet

More Decks by kkeeth

Other Decks in Programming

Transcript

  1. About me const my_info = { Name: ‘܂ݪ੟ਔ’, Home: ‘૔ෑ,

    ޿ౡ’, Community: ‘Riot.js, Ionic, Dist’, Podcast: ‘͕͠ͳ͍ϥδΦ sp.30a’, Workplace: ‘Yumemi Inc’, }
  2. 1. Have you ever published a library? 2. Procedure until

    release to npm 3. Create one library with Node.js 4. Publish to npm, install, confirm operation Table of Contents
  3. 1. JavaScript 2. Studying asynchronous processing ✎ 3. Easier than

    I thought 4. There are lots of knowledge Because…
  4. 1. Create account on npm site 2. Develop library 3.

    Write setting items necessary for package.json 4. Login npm on your terminal 5. execute “npm publish” ToDo
  5. Directory Structure ./ ᵓᴷ bin/ ᵓᴷ lib/ ᵓᴷ package.json ᵓᴷ

    package-lock.json ᵋᴷ node_modules/ command files logic files
  6. Initialize $ mkdir lib $ mkdir bin && cd bin

    $ touch check-stats-modules
  7. Edit package.json … “name”: “check-stats-modules”, “main”: “./lib/check-stats-modules”, “bin”: { “check-stats-modules”:

    “./bin/check-stats-modules” }, … Since the module with this name already exists in npm, please change it when publishing.
  8. Edit check-stats-modules #!/usr/bin/env node ‘use strict’ - console.log(‘Hello node command!!’)

    + require(‘../lib/check-stats-modules’)() create and edit this file
  9. Initialize $ cd .. $ mkdir lib && cd lib

    $ touch check-stats-modules.js
  10. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) (continue...)
  11. Edit lib/check-stats-modules.js /** * run function * * @param void

    * @return void */ module.exports = () => { // 'help' is top priority option if (args.h) { show_help() } else if (args.v) { console.log(pkg.version) } } (continue...)
  12. Edit lib/check-stats-modules.js /** * show help * * @param {String}

    help message if specifying a message * @return {String} full help message */ const show_help = (text) => { if (text) console.log(text) yargs.showHelp() }
  13. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) (continue...) create and edit this file
  14. Edit lib/args.js (Omit this time. Please copy all contents of

    this file.) ↓ https://github.com/k-kuwahara/check-stats-modules/blob/master/src/ lib/args.js
  15. Edit lib/args.js (Omit this time. Please copy all contents of

    this file.) ↓ https://github.com/k-kuwahara/check-stats-modules/blob/master/src/ lib/args.js Briefly, we describe the setting of the contents of the “help“ and the processing to handle the arguments and options of the command.
  16. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) + const npm = require('npm-stat-api') + const moment = require('moment') + const chalk = require('chalk')
  17. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) + const npm = require('npm-stat-api') + const moment = require('moment') + const chalk = require('chalk') get module’s stats from Github
  18. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) + const npm = require('npm-stat-api') + const moment = require('moment') + const chalk = require('chalk') makes it easy to handle dates and times
  19. Edit lib/check-stats-modules.js 'use strict’ const args = require(‘./args’) const yargs

    = require(‘yargs’) const pkg = require(‘../package.json’) + const npm = require('npm-stat-api') + const moment = require('moment') + const chalk = require('chalk') for decorating output contents
  20. Edit lib/check-stats-modules.js module.exports = () => { // 'help' is

    top priority option if (args.h) { show_help() } else if (args.v) { console.log(pkg.version) - } + } else if (args._.length === 0) { + show_help(chalk.yellow.bold('Please enter the module names at least one. \n')) + } else { + const rank = show_stats() + } } (continue...)
  21. Edit lib/check-stats-modules.js /** * show stats about modules * *

    @param void * @return void */ const show_stats = () => { // Omit this time. Please copy all contents of this file. // ↓ // https://github.com/k-kuwahara/check-stats-modules/blob/master/ src/lib/check-stats-modules.js }
  22. • Enrich README • Enhance help • Prepare a shortcut

    command • Put some badges on README Tips
  23. Add badges into top of README Plz show this site

    → https://shields.io/ BTW, We can also make our own badge ↓ Badges