Giter Site home page Giter Site logo

npi's Introduction

npi

Node Project Init.

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 @maboiteaspam/set-verbosity @maboiteaspam/show-help
   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.

explicit && changelog

Worth to note that two utilities are embedded for your convenience

Build your own

Please consider visiting

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

Develop

mkdir npi
cd npi
git clone [email protected]:maboiteaspam/npi.git
git clone [email protected]:maboiteaspam/npi-utils.git
git clone [email protected]:maboiteaspam/npi-regular.git

cd npi
npm i && npm link ../npi-utils
npm i && npm link ../npi-regular

npm test

+/- like this.

npi's People

Contributors

maboiteaspam avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mikesm

npi's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.