@kgryte/package-json

Creates a package.json file.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kgryte/package-json
302.0.95 years ago6 years agoMinified + gzip package size for @kgryte/package-json in KB

Readme

package.json

NPM version Build Status Coverage Status Dependencies

Creates a package.json file.

Installation

$ npm install @kgryte/package-json

Usage

var cp = require( '@kgryte/package-json' );

cp( dest[, opts ][, clbk ] )

Asynchronously create a package.json file in a specified destination directory.

cp( 'path/to/a/directory', onCreate );

function onCreate( error ) {
    if ( error ) {
        throw error;
    }
    console.log( 'Success!' );
}

The function accepts the following options:

  • template: package.json template name. Default: 'default'.
  • name: package name. Default: ''.
  • desc: package description. Default: ''.
  • author: package author.
  • email: package author email.
  • repo: package Github repository.
  • cmd: package command, if the package should be used as a CLI tool.
  • keywords: package keywords. Default: [].
  • license: package license. Default: 'MIT'.
  • private: boolean indicating whether a package is private. Default: false.

By default, a default template is used. To specify a different package.json template, set the template option.

cp( 'path/to/a/directory', {
    'template': 'default'
});

To specify package.json fields, set the corresponding options.

cp( 'path/to/a/directory', {
    'name': 'beep',
    'author': 'Jane Doe',
    'repo': 'janedoe/beep'
});

cp.sync( dest[, opts] )

Synchronously create a package.json file in a specified destination directory.

cp.sync( 'path/to/a/directory' );

The function accepts the same options as the asynchronous version.

Notes

  • Supported templates may be found in the `./lib` directory and are named according to the directory name.
    
  • The package name is validated using validate-npm-package-name.
  • The package repository is assumed to be a Github repository. Thus, only the owner/organization and repository names are needed; e.g.,
```
kgryte/package-json
```
  • In asynchronous mode, the module checks for NPM package name availability. If an internet connection is not available, the module assumes that the package name is available in order to allow offline use.

Examples

var mkdirp = require( 'mkdirp' ),
    path = require( 'path' ),
    cp = require( '@kgryte/package-json' );

var dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );

mkdirp.sync( dirpath );
cp.sync( dirpath, {
    'template': 'default',
    'name': 'beep',
    'desc': 'Beep boop.',
    'author': 'Jane Doe',
    'email': 'jane@doe.com',
    'repo': 'janedoe/beep',
    'cmd': 'beep',
    'keywords': [
        'beep',
        'boop',
        'bop'
    ],
    'license': 'MIT'
});

To run the example code from the top-level application directory,

$ node ./examples/index.js

CLI

Installation

To use the module as a general utility, install the module globally

$ npm install -g @kgryte/package-json

Usage

Usage: packagejson [options] [destination]

Options:

  -h,    --help               Print this message.
  -V,    --version            Print the package version.
  -tmpl  --template name      Template name. Default: 'default'.
         --name name          Package name. Default: ''.
  -desc  --description desc   Package description. Default: ''.
         --author author      Package author.
         --email email        Package author email.
         --repo repo          Package Github repository. Default: ''.
         --cmd name           Package command, if package is a CLI tool.
         --keywords keywords  Package keywords; e.g., word1,word2,...,wordN.
         --license name       Package license. Default: 'MIT'.
         --private            Specifies whether a package is private.

Examples

$ cd ~/my/project/directory
$ packagejson
# => creates a package.json file in the current working directory

To specify a destination other than the current working directory, provide a destination.

$ packagejson ./../some/other/directory

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2015. Athan Reines.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.