tonic-example

Tonic example generator


Keywords
tonic, example
License
MIT
Install
npm install tonic-example@0.2.0

Documentation

tonic-example

Tonic example generator

NPM version Build status for master Test coverage for master

Installation

npm install tonic-example --save-dev

Usage

Create an example file in your module that requires the main file of your module and demonstrates how it works.

Lets suppose you have a sum module with this structure.

+-- sum
  +-- index.js
  +-- example.js
  +-- package.json
  `-- README.md

Your example.js can look like this:

const sum = require('.')
sum(1 + 2)

This example file can be easily tried out in the console by running node example.js. However, a tonic example needs the module required by name. Here comes tonic-example! Run tonic-example example.js from the root directory of your package and you'll get a tonic-example.js file generated with this content:

const sum = require('sum')
sum(1 + 2)

Now you can just add the tonicExampleFilename property to your package.json.

"tonicExampleFilename": "tonic-example.js"

After you publish your package next time, you'll have a working example at tonicdev.com/npm/sum.

Generate the example before publish

In order to always have the latest example code on tonicdev, add the example generation code to a prepublish npm script.

{
  "scripts": {
    "prepublish": "tonic-example"
  }
}

Add tonic-example.js to .gitignore

It is recommended to add tonic-example.js to .gitignore. It is a generated file and there is no benefit from having it in git.

Add tonic-example.js to your files array

If you use the files property in your package.json then don't forget to add tonic-example.js to it. Otherwise it won't be published with your module.

License

MIT © Zoltan Kochan


Dependencies Dependency status for master

Dev Dependencies devDependency status for master

  • babel-cli: Babel command line.
  • babel-plugin-add-module-exports: Fix babel/babel#2212
  • babel-plugin-transform-runtime: Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals
  • babel-preset-es2015: Babel preset for all es2015 plugins.
  • babel-register: babel require hook
  • chai: BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
  • cz-conventional-changelog: Commitizen adapter following the conventional-changelog format.
  • eslint: An AST-based pattern checker for JavaScript.
  • eslint-config-standard: JavaScript Standard Style - ESLint Shareable Config
  • eslint-plugin-promise: Enforce best practices for JavaScript promises
  • eslint-plugin-standard: ESlint Plugin for the Standard Linter
  • ghooks: Simple git hooks
  • istanbul: Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests
  • mocha: simple, flexible, fun test framework
  • mos: A pluggable module that injects content into your markdown files via hidden JavaScript snippets
  • semantic-release: automated semver compliant package publishing
  • validate-commit-msg: Script to validate a commit message follows the conventional changelog standard