npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mb3-speck

v1.5.0

Published

Simple lead comment parser that generates JSON from block comments.

Downloads

6

Readme

Speck

Build Status Code Climate Test Coverage

A simple parser to generate JSON from leading block comments.

See Atom Speck Language for a language package that does syntax highlighting within comments for speck.

Usage

CLI

    Usage: speck [options] -i [dir]

    Options:

      -h, --help             output usage information
      -V, --version          output the version number
      -i, --input [dir]      Input Directory
      -c, --config [config]  The relative path to a directory where a speck.json config file can be found
      -o, --output [dir]     Output directory
      -t, --types [values]   A list of all file types to parse separated by comma[,]
      --validate             Validate speck files
      --php                  Use php parser.

speck.json

You can use speck with a config file like the one below. It can be used to ignore paths by globs and store all other options for a simpler CLI execution. Speck will search the CWD for a speck.json file or you can specify which directory to look in with the -c or --config option.

{
    "ignore": [
        "!**/src{/,*}**",
        "**/*.spec.js"
    ]
}

Generating Jest Test Shells

Input

/* speck
  'name': 'JestSpeckPlugin'
  'extends': 'SpeckPlugin'
  'type': 'Plugin'
  'description': 'Generates a Jest test shell with the given interactions.'
  'interactions': [
    'can parse interactions from a file.',
    'can generate a test shell from a file.',
    'can append to a file cleanly.',
    'can create a new test file cleanly.'
  ]
*/
export class JestSpeckPlugin extends SpeckPlugin {
  // ...
}

Output

import {JestSpeckPlugin} from '../relative/path/to/jest.plugin.js';

describe('JestSpeckPlugin', () => {
  it('should parse interactions from a file.', () => {
    fail('Not Implemented');
  });

  it('should generate a test shell from a file.', () => {
    fail('Not Implemented');
  });

  it('should append to a file cleanly.', () => {
    fail('Not Implemented');
  });

  it('should create a new test file cleanly.', () => {
    fail('Not Implemented');
  });
});

Example

Input:

/* speck
  'class name': 'Comment'
  'description': 'Parses a comment from within a file.'
  'comment structure': 'Block comments should be written in cson'
  'example usage':
     'js': '''let c = new Comment('@title: hello');
       c.parse().toJSON(); // { title: 'hello' }'''
     'markdown': '''# Speck.Comment
       ## Features
       + Multiline
       + Json (nested is also suppoted)
       + Pluggable'''
  'multi line': '''This is a test
   for multiline comments'''
  'list items': [
   0,1,2,3,4
  ]
 */

 export class SomeJSClass {
   // ...
 }

Output:

{
    "class name": "Comment",
    "description": "Parses a comment from within a file.",
    "comment structure": "Block comments should be written in cson",
    "example usage": {
        "js": "let c = new Comment('@title: hello');\nc.parse().toJSON(); // { title: 'hello' }",
        "markdown": "# Speck.Comment\n## Features\n+ Multiline\n+ Json (nested is also suppoted)\n+ Pluggable"
    },
    "multi line": "This is a test\nfor multiline comments",
    "list items": [
        0,
        1,
        2,
        3,
        4
    ]
}

Extending

This repo is a base for the parser, it will take any block comments and generate JSON output. The base class doesn't ship with an implementation and will fail if run as follows:

import Speck from 'speck';

const parser = new Speck(...);

parser
  .gather()
  .parse(); // Throws an error.

However, it does ship with a Speck implemented using the babel parser babylon, this is the default when running the CLI:

import BabelSpeck from 'speck';

const parser = new BabelSpeck(...);

parser
  .gather()
  .parser(); // Generates JSON from ES6 code.

It also ships with a custom php tokenizer to parse leading comments.

To use Speck with other languages to generate JSON from leading block comments you must implement the getComments method.

Example

import Speck from 'speck';

export default BabelSpeck extends Speck {
  getComments(code) {
    // Parse out, and return, leading comments from code.

    return babylon.parse(code, OPTIONS)
      .comments
      .filter(comment => comment.type === 'CommentBlock')
      .map(comment => comment.value);
  }
}

Plugins

Plugins for speck are simple, all you need to do is export a class with a run function that takes three parameters:

  • logger
  • file: the source file path
  • json: the json results from the source file speck comments
export default class ExmplePlugin {
    run(logger, file, json): void {
        // ...
    }
}

If you need to pass options to the plugin at runtime, you can specify the configuration in the speck.json config file as an object that will be passed to the constructor of the plugin.

export default class ExamplePlugin {
    constructor(options = {}) {
        // ...
    }
}

All plugins are run after the base parsing of speck has been complete.

To see an example of how to write a Speck Plugin see MB3-jest-speck-plugin

Development

  • to test yarn test
  • to build yarn run build -> this will also run the tests
  • to run yarn start -- [options] OR ./script/speck.js [options] OR yarn link; speck [options]

Environment Setup

  • make sure you have node version > 6.2.x (n is an easy way to manage your node on MAC only.) run : yarn add -g n; sudo n stable

  • make sure you have php 7 (brew update; brew install homebrew/php/php70)

  • checkout the repo and yarn install; yarn add -g gulp; yarn add -g jasmine