Nodefony Library

Use Nodefony as a Library

Initialize a new node.js Project

$ mkdir project

$ cd project/

$ npm init
...

$ ls
-rw-r--r--  1 cci staff  203  3 avr 20:12 package.json

$ npm install nodefony

⸨░░░░░░░░░░░░░░░░░░⸩ ⠋ ...

$ touch index.js

$ ls
-rw-r--r--     1 cci  staff       0  3 avr 20:18 index.js
drwxr-xr-x  1220 cci  staff   39040  3 avr 20:18 node_modules/
-rw-r--r--     1 cci  staff  714132  3 avr 20:18 package-lock.json
-rw-r--r--     1 cci  staff     253  3 avr 20:18 package.json

Add start commnand

$ vim package.json

  {
    "name": "project",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      

"start":"node index.js"

}, "author": "", "license": "ISC", "dependencies": { "nodefony": "^4.3.1" } }

Add Dependency nodedony in index.js

$ vim index.js

const nodefony = require("nodefony");
console.log(nodefony.version);

Run Script

$ npm start

  > project@1.0.0 start /Users/cci/repository/project
  > node index.js

4.3.1
  

If you prefer have an executable File

$ chmod +x index.js

// add hashbang #!/usr/bin/env node

$ vim index.js

#!/usr/bin/env node

const nodefony = require("nodefony");
  

Now you can use nodefony as Library !

$ vim index.js

  const nodefony = require("nodefony");

  const project = new nodefony.cli("project", {
    version: nodefony.version,
    onStart: (cli) => {
      cli.showBanner();
      cli.log("start");
    }
  });
$ npm start
                                         _                 _
                _ __    _ __    ___     (_)   ___    ___  | |_
               | '_ \  | '__|  / _ \    | |  / _ \  / __| | __|
               | |_) | | |    | (_) |   | | |  __/ | (__  | |_
               | .__/  |_|     \___/   _/ |  \___|  \___|  \__|
               |_|                    |__/

            Version : 4.3.1 Platform : darwin Process : project PID : 40258


   Wed Apr 03 2019 21:43:11 INFO project : start
$