The tool for npm-module maniacs.
- the module is under development
- This command line tool helps to fulfill the daily jobs you have to do when working with npm modules.
- This module with give you a structure for your npm modules that is the same in every of your nmp modules. that enables reusability and eases collaborative work on a npm module
- Documention in progress.
- i really apreciate if you give me feedback.
- i am always open to improve my workflow.
- so open issues for errors or new features/tasks here dm-npm issues
- note: i am relativly new to npm module development, so forgive me flaws and comment or open issues for improvements
- i will definetly use this tool for while, because i want to write a lot of npm modules, so stay tuned and watch out for updates
- look at the todos to see what will be done
dmn
dm-npm
- tested on ubuntu 14.04 with node 0.11.11 and 0.12.0
npm install dm-npm -g
- for publishing a module you have to create accounts on:
A short use case.
- online
- create github repository
- local
# install dm-npm
npm install dm-npm -g
# clone the repository
git clone git@github.com:your_user_name/fooBar.git
# cd into the repository
cd fooBar
# initialize the module
dmn init
# publish the module directly
dmn publish
Now you have a new running module with a task example, which you can run programmatically via:
var fooBarExample = require("fooBar").example;
fooBarExample();
or globally in the command line via
fooBar example
For testing the task you can run
fooBar test example
There are synchronous and asynchronous tests. explanation later
The created module will have the following structure:
.
|--bin/
|--dm-fooBar
|--gdm-fooBar
|--node_modules/
|--co/
|--colors/
|--dm-npm/
|--shelljs/
|--tasks/
|--example/
|--test/
|--test.js
|--index.js
|--global.js
|--ideas.md
|--index.js
|--package.json
|--README.md
|--todo.md
- in global.js the task-hooks for the command line usage are collected
- in index.js the task-hooks for programmatically usage are collected
- run
fooBar taskAdd
- this command will prompt you for
- the task name (give it the name baz for test purpose)
- the task aliases (give it the alias bz for test purpose)
- the task description
- then the command will
- create a task in the directory tasks with your given task name (tasks/baz/index.js). here you can find
- the yieldable function startAsync which has to be called with yield
- the normal function start which is used to wire up the task in the global.js
- create a entry in the README.md under the point tasks
- create a hook for the task in the global.js
- create a hook for the task in the index.js
- create a test suite (tasks/baz/test/test.js) which you can run via
fooBar test baz
- open the task with your $EDITOR home environment variable (i am coding with vim and it will work for me)
- create a task in the directory tasks with your given task name (tasks/baz/index.js). here you can find
- this command will prompt you for
- globally usage: presuming you named your task baz and gave it the alias bz you are now able to run
fooBar bz
orfooBar baz
and should see the outcoming- the output should look like
start baz
- programmatically usage:
- after publishing your module you can use your method in other modules
var fooBarBaz = require("fooBar").baz;
fooBarBaz();
- README.md: if you look into the README.md of the project you will see a added documentation section for the task baz
- global.js: if you look into the global.js you see a added swith for your task bar, which makes it globally accessable
- index.js: if you look into the index.js you see a added switch for your task bar, which makes it programmatically accessable
After inititalizing the project you get some basic tasks a npm developer needs for a project out of the box. these tasks are:
# opens help. if you have installed markdown and lynx you can browse it with terminal ;-)
fooBar
# add a task to your module
fooBar taskAdd
# open a prompt for your module where you can start the tasks existent in your module, open the markdown files of your project or edit the config file of your project
fooBar prompt
# opens the todo.md of fooBar and lets you write something in there
fooBar todo
# add a idea to the ideas.md via command line (creates the ideas.md if not exitent)
fooBar idea
# todo: bumps the version of the project (including git commit)
fooBar bumpVersion
# publishes fooBar (includes bumpVersion etc)
fooBar publish
# todo: add a config file for fooBar
fooBar configFileAdd
# todo: install fooBar globally
fooBar installGlobal
# todo: links your global fooBar installation locally to your development directory: this is very nifty, because you dont have to reinstall the tool globally on every change
fooBar linkLocal
# todo: reinitializes the project. keeps .git, README.md, todo.md, ideas.md
fooBar reinit
The tasks marked with todo are currently available when you cd into your module and run dmn bumpVersion
or dmn publish
etc. they will all get some improvements and some new features.
Most of the tasks here use the yield style and assume the code is contained within a generator function. For example you can use co for that. This style requires ES6 generators and has to be enabled in node 0.11.x or greater via the --harmony flag.
- bumpVersion todo
- configFileAdd todo
- idea
- init
- installGlobal todo
- linkConfigFiles
- linkLocal todo
- linkNodeModules todo
- prompt
- publish
- publishFolder
- reinit todo
- reinstall todo
- taskAdd todo
- todo
- Returns json from the config file
dmn [configGet|cg]
var configGet = require("dm-npm").configGet;
var configGetResult = configGet.start();
{
"configGet": {
}
}
- Opens the config file for editing
dmn [configEdit|ce]
var configEdit = require("dm-npm").configEdit;
var configEditResult = configEdit.start();
{
"configEdit": {
}
}
- provides the README.md of the module (if markdown and lynx are installed with terminal browsing ;-))
dmn [help|-help|h|-h]
var help = require("dm-npm").help;
var helpResult = help.start();
{
"help": {
}
}
- provides the dm-npm tasks that can be used by every dm-npm module
dmn [getCommonTasks|gct]
var getCommonTasks = require("dm-npm").getCommonTasks;
var getCommonTasksResult = getCommonTasks.start();
{
"getCommonTasks": {
}
}
- initiate a new npm module with the dm-npm flavor
dmn [init|-init|i|-i]
- User Input:
- module name: for example fooBar
- module Shortcut: for example fb
- this file is the entrypoint for programatically usage
- add global.js from template
- this file is the entrypoint for usage from the command line
- the binary file for global usage
- this one is important. adds the following alias, you can use from command line
fooBar # runs your module
fb # alias for fooBar
gfb # cd into your module
fbg # cd into your module
- add tasks directory with test task
- run
npm install
- install the dependencies
- run task create local link
After running that command your module is globally installed and you have the following features enabled for your module.
fb # opens cat's the readme.md
fb prompt # opens a prompt with all added tasks
fb todo # opens the todo.md file with vim
fb idea # asks for a idea you have for your project and adds it to the end of ideas.md. creates ideas.md if not existent
[gfb|fbg] # cd into the module directory (no need to create aliases)
gfb && dmn task add // adds a tasks in dir tasks and makes it programmatically and globally available
dmn [publish|-publish]
- get/create root path (.git-repository with package.json for npm)
- get git status
- switch git status
- a) if git status (2) says nothing to commit, abort task (path clean)
- b) if git status (2) says there is something to commit (go on)
- commit current changes
- bump version in package.json (see task bump version)
- commit the bump Version change
- push commits
- tag new version
- push tags
- npm publish
- publishes all npm modules in a given folder
dmn [publishFolder|pubFol|pf|-pf]
- searches for publishFolder.path in ~/dm-npm.json for usage as default value
- asks for the directory including the npm-modules destined to publish
- dirctories starting with _ (underscore) will be ignored
- then, a loop will run the task publish for every directory included in the prompted path
- links files from given directory into home directory
dmn [linkConfigFiles|lc]
- search for ~/.dm-npm.json and get linkConfigFiles.path as default value
- for example ~/dotfiles/npm-modules-config
- prompt user for directory where the npm module files are placed
- links the src to the home directory
- adds a . to the beginning of the filename and soft links it in the home directory
- ie: ln -s ~/dotfiles/npm-modules-config/fb.json ~/.fb.json
- add ideas to the npm-module via shell (ideas will be added to ideas.md)
- examples
dmn idea //
- prompts for execution of the existent tasks of npm module
- examples
dmn prompt //
- opens the todo.md file of the npm module
- examples
dmn todo //
- you can place a .dm-npm.json file in your home directory (~/.dm-npm.json)
- the following things are allowed at the moment
{
"publishFolder": {
"path": "~/code/dm"
}
}
-
i am not really done here ;-)
npm test