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

gulp-todo

v7.1.1

Published

Generate a TODO.md file from comments of files in stream

Downloads

7,685

Readme

gulp-todo

Parse and output TODOs and FIXMEs from comments in your file in a stream

NPM Version NPM Downloads Build Status

Parse your files in a gulp-stream, extracting todos/fixmes from comments and reporting them in a reporter to your choosing using leasot.

Issues with the output should be reported on the leasot issue tracker

Supports latest leasot version 7.0.0.

Please upgrade carefully to version 7.0.0, there were breaking changes in the gulp-todo API

Install

Install with npm

$ npm install --save-dev gulp-todo

Usage

const gulp = require('gulp');
const todo = require('gulp-todo');

// generate a todo.md from your javascript files
gulp.task('todo', function() {
    gulp.src('js/**/*.js')
        .pipe(todo())
        .pipe(gulp.dest('./'));
        // -> Will output a TODO.md with your todos
});

// generate todo from your jade files
gulp.task('todo-jade', function() {
    gulp.src('partials/**/*.jade')
        .pipe(todo({ fileName: 'jade-todo.md' }))
        .pipe(gulp.dest('./'));
        // -> Will output a jade-todo.md with your todos
});

// get filenames relative to project root (where your gulpfile is)
gulp.task('todo-absolute', function() {
    gulp.src('js/**/*.js')
        .pipe(todo({
            absolute: true
        }))
        .pipe(gulp.dest('./'));
});

// get relative path filenames
gulp.task('todo-absolute', function() {
    gulp.src('js/**/*.js', { base: '/' })
        .pipe(todo())
        .pipe(gulp.dest('./'));
});

// create a json output of the comments (useful for CI such as jenkins)
gulp.task('todo-json', function () {
    gulp.src('./**/*.js', {
        base: './'
    })
        .pipe(todo({
            fileName: 'todo.json',
            reporter: 'json'
        }))
        .pipe(gulp.dest('./'));
});

// output once in markdown and then output a json file as well
gulp.task('todo-reporters', function() {
    gulp.src('js/**/*.js')
        .pipe(todo())
        .pipe(gulp.dest('./')) //output todo.md as markdown
        .pipe(todo.reporter('json', {fileName: 'todo.json'}))
        .pipe(gulp.dest('./')) //output todo.json as json
});


// Delete the todo.md file if no todos were found
const gulpIf = require('gulp-if');
const del = require('del');
const vinylPaths = require('vinyl-paths');

gulp.task('todo-delete', function() {
    gulp.src('js/**/*.js')
        .pipe(todo())
        .pipe(gulpIf(function (file) {
            return file.todos && Boolean(file.todos.length);
        }, gulp.dest('./'), vinylPaths(del)));
});

Injecting the todo generated file into another template

If you want to inject the generated todo stream into another file (say a readme.md.template) you can do the following:

  • Create readme.md.template file that contains the following marker, marking where you want to inject the generated todo file:
### some previous content
<%= marker %>
  • Use the following code to inject into that markdown, creating a markdown file with the generated todo:
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const todo = require('gulp-todo');
const template = require('lodash.template');
const through = require('through2');

gulp.task('default', function () {
    gulp.src('./js/**/*.js')
        .pipe(todo())
        .pipe(through.obj(function (file, enc, cb) {
            //read and interpolate template
            const tmpl = fs.readFileSync('./readme.md.template', 'utf8');
            const compiledTpl = template(tmpl);
            const newContents = compiledTpl({
                'marker': file.contents.toString()
            });
            //change file name
            file.path = path.join(file.base, 'readme-new.md');
            //replace old contents
            file.contents = Buffer.from(newContents);
            //push new file
            this.push(file);
            cb();
        }))
       .pipe(gulp.dest('./'));
});

Supported Filetypes

See https://github.com/pgilad/leasot#supported-languages

API

todo(options)

options is an optional configuration object, see https://github.com/pgilad/gulp-todo/blob/master/index.js#L22-L32

todo.reporter(reporter, options)

options is an optional configuration object, see https://github.com/pgilad/gulp-todo/blob/master/lib/reporter.js#L10-L16

Use another reporter in stream, will replace the contents of the output file. Must be used after todo(), since it uses the file.todos that are passed along.

See the example in the usage

License

MIT © Gilad Peleg