🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@maboiteaspam/npi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maboiteaspam/npi

Node Project Init

latest
Source
npmnpm
Version
2.0.3
Version published
Maintainers
1
Created
Source

npi

Node Project Init. Way more than npm init -y.

Install

npm i @maboiteaspam/npi -g

Usage

npi

 Init a node project.

 Usage
   npi [module1 module2]
   npi [opts] -- [module1 module2]

   npi --explicit           Run explicit-deps
   npi --config             Show config
   npi --add [module]       Add workflow
   npi --default [module]   Set default workflow

 Options
   -v                       verbose
   -h                       show help
   -w                       Workflow to use
   --explicit               Invoke rvagg/node-explicit --yes.
   --add                    Add new init workflow.
   --default                Set the default workflow

 Examples
   npi debug minimist multiline
   npi -v -- debug minimist multiline
   npi -w @maboiteaspam/npi-regular -- debug minimist multiline

   npi --explicit
   npi -h

Workflow

Workflow is the stream that implement the initialization of the package.

Currently see npi-regular workflow.

Workflow are expected to create a minimal environment to get on work, cooked just for the user.

 - node_modules/
 - .gitignore
 - index.js
 - playground.js
 - package.json
 - README.md

Workflow must perform any action as automated as possible, otherwise query for user input at runtime.

Workflow describes your habits, preferences, environments requirements, when its about a node package setup.

Build your own

Please consider visiting

  • https://github.com/maboiteaspam/npi-regular
  • https://github.com/maboiteaspam/npi-utils

tips

Use -v to check the workflow errors while using npi.

npi -v -- mod1...

workflow signature

workflow are node module which exports a function(pkg, argv, conf), which must return a stream bubbler (one of stream-messenger, stream-router, bubbler, bubbled).

A simple workflow would be

    var messageRouter = require('stream-message-router')
    var npi = messageRouter('npi');

It is then possible to enhance the workflow in such way,

    var trimT         = require('@maboiteaspam/npi-utils/trim.js')
    var spawn         = require('@maboiteaspam/npi-utils/spawn')
    var bubble        = require('@maboiteaspam/npi-utils/bubble')

    npi
    .pipe(trimT(templateVars, ['author']))
    .pipe(spawn('npm', function (){
        return ['init', '--scope='+templateVars.author, '--yes']
    }))
    .pipe(bubble('message', {message: 'file', 'body':'package.json'}))

the latter, the workflow is connected to npi main stream, and invoked when necessary.

About the code

TLDR: It use a workflow stream npi on which transforms are piped to.

They execute in sequence, time management is totally left to the underlying pipe system.

To communicate with the user along the commands, npi will bubble events to the source stream.

msgListener a dedicated stream is setup to listen npi stream message events.

It then route chunks to specific transforms which are responsible to display an output given the type of message.

The type of events you may encounter are

When a file is created : {message: 'file', body:'path'}

When a process spawns : {message: 'spawn', body:child_process}

When a process has spawned (child_process.close event) : {message: 'spawned', body:child_process}

May this drawing you to jump in the code,

       process
-â–¶-stdin-â–¶|                       (1)
          | var npi = stream()    /
          |    .pipe() â–Ľ         /
          |       route 'npi' -----â–Ľ
          |                        |
          |      (3)               |
          |      /                 |
          |  npi emit()â—€--|        |
          |   â–Ľ           |        |
          |  down         |        |
          |   â–Ľ           â–˛        |
          |   |    bubble()◀◀|     |-▶fnT1 (spawn npm)
          |   |              |           â–Ľ push()      (2)
          |   |              â–˛           â–Ľ            /
          |   |       bubble()◀◀|     fnT2 start bubble() ▶-|
          |   |                 |        â–Ľ                  |
          |   |                 |        â–Ľ  {type: 'file'   |
          |   |                 |------------body: 'index'}-|
          |   |                          â–Ľ push()
          |   |                       fnT3 (inquire)
          |   |                          â–Ľ push()
          |   |                       fnT4 (git commit)
          |   |                          â–Ľ push()
          |   |          (4)          (end of npi)
          |   |            \
          |   â–¶-â–¶ var msgListener = eventStream('message', npi);
          |         .pipe() â–Ľ
          |            route 'file' -â–Ľ
          |                          |-â–¶fnT1 (extract body)  (5)
          |                                 â–Ľ push()        /
          |                             fnT2 (log to console)
          |                                 â–Ľ push()
          |                             (end of msgListener)
          |     msgListener
          |         .pipe() â–Ľ                            (5 bis)
          |            route 'spawn' -â–Ľ                 /
          |                           |-â–¶fnT1 (pipe to process)
          |                                 â–Ľ push()
          |                              (end of msgListener)
â—€-stdout-â—€|
   (end of process)

Read more

Keywords

node

FAQs

Package last updated on 21 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts