1.0.4 • Published 6 months ago

chamick7say v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Basic Node Package 101

install Node.js

  1. install nvm for node.js version management
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.6/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  1. install node.js for specific version
nvm install lts/iron
  1. check node version
node -v

create node package

  1. create project folder
mkdir <name>say
cd <name>say
  1. init node package (package.json will be generated)
npm init -y
  1. create file .npmrc to config npm registry to default (incase default registry is other)
registry=https://registry.npmjs.org
  1. install yargs lib for cli
npm install yargs
  1. create bin folder and file for cli execution
mkdir bin & touch bin/say.js
  1. edit file bin/say.js
#! /usr/bin/env node

const fs = require("fs");
const yargs = require("yargs");

function readCharacter() {
  return fs.readFileSync(`${__dirname}/../character/bear.ascii`, "utf-8"); //read character text file
}

function say(word) {
  const character = readCharacter();
  const output = character
    .replace("$text", word) //replace $text with provided word
    .replaceAll("$bubble", "-".repeat(word.length * 1.2)); // replace $bubble with - to create bubble
  console.log(output); // print output to console
}

const command = yargs.argv.$0; // read command that use in command line
const args = yargs.argv._.join(" "); // join arguments in command

if (!args) {
  return console.log(`Usage: ${command} text`);
}

say(args);
  1. find ascii art that you like
  1. create character in text file ex. bear.ascii in folder character
   ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄      $bubble
   █▒▒░░░░░░░░░▒▒█     < $text
    █░░█░░░░░█░░█    /  $bubble
 ▄▄  █░░░▀█▀░░░█  ▄▄
█░░█ ▀▄░░░░░░░▄▀ █░░█
  1. config add field bin and files in package.json
//package.json

"bin": {
    "<project-name>": "bin/say.js"
  },
"files": [
    "bin/",
    "character/"
  ],
  1. login to npm registry type in terminal
npm login
  1. publish node package to npm registry
npm publish
  1. try your node package by typing in terminal
npx <your-project-name> hello
1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago