Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Last active July 28, 2016 18:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/8d8efc9c8005e11801b87b2a787f3b64 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/8d8efc9c8005e11801b87b2a787f3b64 to your computer and use it in GitHub Desktop.
Simple script to display usage information about your project

Simple script to display usage information about your project

Usage

Implement a help field on your project's package.json listing all the scripts you want to display information about. Just make sure to use the same keys.

$ npm run help -s

> project-sample@1.0.0 help /Users/gordon-freeman/dev/project-sample
> node tools/help.js

Available scripts for "project-sample"
 
   start                 Start local development server at http://localhost:3000
   deps                  Inherit dependencies from main application and persist to manifest
   help                  Display project usage information

Note: the -s will suppress npm output noise, you can still use without it if you want

import { resolve } from 'path';
// Current application manifest
const APP_BASE_PATH = resolve(`${__dirname}/../`);
const APP_MANIFEST = require(`${APP_BASE_PATH}/package.json`);
// Manifest information
const { help, name } = APP_MANIFEST;
// Simple function to Format the output message
const formatter = (script, help) => `\n ${script} \t\t ${help[script]}`;
// Compose output message
const output = Object.keys(help)
.map(script => formatter(script, help))
.join('');
console.log(`Available scripts for "${name}"\n ${output}`);
{
"scripts": {
"start": "webpack-dev-server --progress --colors --port 3000",
"help": "node tools/help.js",
"deps": "node tools/inherit-dependencies.js",
"lint": "eslint app/src"
},
"help": {
"start": "Start local development server at http://localhost:3000",
"deps": "Inherit dependencies from main application and persist to manifest",
"help": "Display project usage information"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment