GithubHelp home page GithubHelp logo

pgilad / gulp-todo Goto Github PK

View Code? Open in Web Editor NEW
90.0 7.0 23.0 232 KB

Generate a TODO.md from todos & fixmes in your code using Gulp stream

License: MIT License

JavaScript 100.00%
stream gulp-stream javascript comments todo fixme plugin gulp

gulp-todo's Introduction

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

gulp-todo's People

Contributors

bartveneman avatar davidtsuji avatar eighteyes avatar elgervb avatar ericzon avatar jakschu avatar moeriki avatar pgilad avatar r3fuze avatar thedancingcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-todo's Issues

Where to add `--ignore` options

Trying to get this running but it always includes the node_modules directory. When I use from CLI, I use the --ignore option to ignore node_modules, how can I do the same using this plugin.

TypeError: Uncaught, unspecified "error" event

TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at DestroyableTransform.emit (events.js:74:15)
    at onerror (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:558:12)
    at DestroyableTransform.emit (events.js:95:17)
    at module.exports (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-todo/lib/parsers/jsParser.js:25:14)
    at through.obj.gutil.File.cwd (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-todo/index.js:54:50)
    at Transform._read (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-todo/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Transform._write (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-todo/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/gulp-todo/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)

my gulp task is very simple

gulp.task('todo', function() {
    var todo = require('gulp-todo')

    gulp.src(['src/**/*.js', 'src/**/*.jade', 'src/**/*.styl'])
        .pipe(todo({
            fileName: 'TODO.md'
        }))
        .pipe(gulp.dest('./'))
})

Allow HTML files

events.js:141
      throw er; // Unhandled 'error' event
            ^
Error: File: /.../videomail-client/examples/bad_browser.html - Extension .html is not supported

You know, you can write inline JS in HTML files and in my case, there are some TODO remarks. So I think, HTML files should be allowed.

Provide Support for the Jenkins's TODOs Plugin format (XML)

Problem

Monitor the TODOs on CI Environments such as Jenkins. This request is to support the XML format required by the following Jenkins Plugin:

https://wiki.jenkins-ci.org/display/JENKINS/TODOs+Plugin

Although this is NOT an official Jenkins Plugin, I thought this is a good start to provide users directions in regards to the TODOs list.

Example

The following is the result of the integration...

screen shot 2014-12-01 at 6 03 11 pm

API Change Request

The API must accept a different reporter type "xml" expected by the TODOs App http://todos.sourceforge.net/.

I can provide the library that converts the JSON report to XML.

todo.md is still present when all code TODOs are removed

windows/gulp-todo v0.9.0

Hi there,
It seems that the file todo.md is not removed and still present in my project structure with the last snapshot of TODO comments the next time I run my gulp todo task even though I removed every TODO comment from my codebase.

My todo task:

gulp.task('todo', function() {
  return gulp.src(SRC + 'js/**/*.js')
    .pipe(todo())
    .pipe(gulp.dest(SRC))
    .on('error', gutil.log);
});

I wonder if it is by design? It is kinda annoying since you can find todo.md file in a pull request even though a developer cleaned/fixed all of them in the code.

Todos being generated in random order

Hello, I have an issue with working on multiple machines. I have my office workstation and my home workstation where I work on the same code. The todo generator seems to read in the files in different orders on both machines. The issue with this is that the TODO.md gets generated with todos in different orders on both machines and my source code manager is picking that up as a change in the file and wants to commit it. This is becoming a problem because I don't want list a lot of commits in my git repo and I don't want to always manually ignore the file every commit until there is a real change.

Both of my machines are macbook pros running os x 10.10.

Allow to use leasot customTags option

Leasot allow to add array with additional tags (comment types) to search for (alongside todo & fixme).
It would be great to this feature in gulp-toto πŸ˜‰

SCSS/SASS support isn't working

Hi there!

"gulp-todo" version 1.3.0 (just updated) ignores the .sass/.scss files while it's processing the .js files successfully.

gulp.task('todo', function() {
    return gulp.src([
        'src/assets/js/*.js',
        'src/assets/scss/**/*.s{c,a}css'
    ])
    .pipe(todo({
        verbose: true,
        newLine: '\n'
    }))
    .pipe(gulp.dest('./'))
});

Support es files

This for files going through Babel to ES6/7

Because I am getting this error

Error: File: /home/michael-heuberger/Development/xxx/gulp/load/modules.es - Extension .es is not supported

Can't get ref's to work.

Leasot supports front and back ref's, i.e. TODO(ref):Issue or TODO:Issue\Ref. I've been unable to get this to work with Gulp-todo. Is it supported?

Feature: Have an option to generate a json file so that we can integrate this to Jenkins

This component is awesome! I love it! But in order to hook this to Jenkins and other plugins, we need a metadata value of this. I want to create a webpageΒ that lists the objects from the JSON.

In addition, I'm thinking about integrating this to the following Jenkins plugin: https://wiki.jenkins-ci.org/display/JENKINS/TODOs+Plugin

Although it accepts an XML file, I can transform the JSON file for it...

thanks!

How to print TODOs to the console?

Hello, I used grunt-todo to print TODOs to the screen:

unbenannt

How can I do that using "gulp-todo"? Because for me it creates a TODO.md file but it doesn't print the output to the screen when running gulp todo.

This is my configuration:

gulp.task('todo', function() {
  gulp.src('src/main/ts/**/*.ts')
    .pipe(todo())
    .pipe(gulp.dest('./'));
});

Inject list into README.md directly without the need for a template

I do not want to clutter the root directory of my repos with too many folders or files, i.E. with a readme.md.template.

Would be great to have a new option where I can define a certain marker, i.E.

insertAfter: '## TODOs'

and this will put the whole TODO list into README.md after the header ## TODOs on a new line.

Using with PHP files causes a nasty execption error

Here is the basic contents of error from console

FWIW, this throwing an exception as PHP files start with

Error: gulp-todo: Line 1: Unexpected token < at throwError (/Users/mikee/Documents/Projects/rangladex/node_modules/gulp-todo/node_modules/esprima/esprima.js:1831:21) at throwUnexpected (/Users/mikee/Documents/Projects/rangladex/node_modules/gulp-todo/node_modules/esprima/esprima.js:1889:9) at parsePrimaryExpression (/Users/mikee/Documents/Projects/rangladex/node_modules/gulp-todo/node_modules/esprima/esprima.js:2198:13) at parseLeftHandSideExpressionAllowCall (/Users/mikee/Documents/Projects/rangladex/node_modules/gulp-todo/node_modules/esprima/esprima.

Amend to existing README.md

I love this module, very useful - many thanks!

Do you think another option to amend the TODO to an existing README.md would be possible?

(or can I embed the TODO.md into the README.md somehow?)

--ignore support

Also, it seems this does not support --ignore property as well?

    .pipe(todo({
      'ignore': ['./node_modules/**/*','./public/vendor/**/*'],
    }))

Working on a legacy project which uses <script> tags and all vendor files in ./public/vendor directory so trying to skip those as well :-)

Have a groovy evening!

Using this project ... :-)

Hey bud

Using this project for some legacy work and would like to output to console (in table format) ala the CLI and webpack-todo-plugin Tried to set the reporter property but doesn't seem to use it?

.pipe(todo({reporter: 'table'))

Available in another approach? If not, I might just fork it and add it (or continue to use my CLI script)

    "todo": "./node_modules/.bin/leasot \"./**/*.js\" --ignore \"./node_modules/**/*\",\"./public/vendor/**/*\" --tags error,info || true"

Webpack Plugin

Any chance you have created a webpack version of this plugin? I can surely do it, just curious if you have done it (or thought about doing it)

Support for .php files

Is there any way to make gulp-todo parse php files and create the resulting markdowns?

I'm working with Drupal, and I'm creating a Gulpfile that, as it matures, turns out to be an excelent asset in theme development. However, we have a lot of php files and during development we often add TODOs.

Thanks in advance

ps: awesome utility :)

Feature Request: Multiple tasks appending to the same file

It would be great to write all TODOS, FIXMES to one file from multiple tasks.

e.g. Single task.

gulp.task('default', function () {
    gulp.src(['test.scss', 'test.js'])
        .pipe(todo())
        .pipe(gulp.dest('./'));
});

This will generate a TODO.md from .scss and .js files. However, if there are two tasks, I only see TODOS and FIXMES from styles task:

e.g. Multiple tasks.

gulp.task('scripts', [function () {
    gulp.src(['test.js'])
        .pipe(todo())
        .pipe(gulp.dest('./'));
});

gulp.task('styles', [function () {
    gulp.src(['test.scss'])
        .pipe(todo())
        .pipe(gulp.dest('./'));
});

gulp.task('default', ['scripts', 'styles'],  function () {
});

Thanks.

Support for .twig files

Is it possible to add .twig file support?
In .twig file comments looks like this:

<!-- TODO: Hey, I'm a todo! -->

or

{# TODO: Hey, I'm a todo! #}

Thanks ! :)

Adding support for todo assignee

Gulp-todo, nice idea!
How about adding support for separate outputs based on todo assignee. It's common to have todos like: TODO(alireza): ...

TODO.md vs todo.md

I know it is a minor suggestion - but it would be great to generate todo files with a name "TODO.md" instead of default value of "todo.md". Even in the repo you have all capitals, but if you apply gulp task to any other project it will generate a small capital name.
It is a good idea to have README and TODO to be all capitals to stand out in front of all other files for a developer. Maybe it is just subjective but wanted to suggest this.

Delete TODO.md example not working

In the README.md there are some examples on how to use gulp-todo. One of these examples is how to remove the TODO.md file where there are not TODO's in code.

This example does not work, as it uses gulp-if in a wrong way. Please find my solution here:

gulp-if API; gulp-if(condition, ifTrue, ifFalse);

The ifTrue and ifFalse was switched around, the right way is:
gulp-if(condition, gulp.dest('./'), vinylPaths(del));

// Delete the todo.md file if no todos were found 
var gulpIf = require('gulp-if');
var del = require('del');
var 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);
        }, vinylPaths(del), gulp.dest('./'));
});

should be:

// Delete the todo.md file if no todos were found 
var gulpIf = require('gulp-if');
var del = require('del');
var 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));
});

Thanks for fixing ;-)

Support for .hbs files

Would it be possible to have todo's in a .hbs file?
We use Assemble.io for templates. Wonder if there's a way to do it?

Coffeescript support

Esprima doesn't parse coffee, but still, are you going to add coffee support? :)

TODO.md is not being written

After running my gulp build with the following setup

...
.pipe($.todo({
    verbose: true,
    fileName: 'TODO.md',
    absolute: true
}))
...

I noticed that even though the todo's are shown in my cli, they are not being written to a TODO.md file anywhere.

Is there some preliminary setup that i need to do ?

Awesome

I just wanted to take the time to tell you that this is awesome! Great work! I extended it to include .yaml easily. And we've been having fun extending it to report on other comment types too. Have a great weekend. Stay awesome!

200-1

BugFix: Display the full path of the files instead of relative.

Problem

The current version outputs the file names only from the output of "file.relative". When multiple files live in different directories and they happen to have the same name, the values collide and you don't know which file is being referenced. For instance, I have the following structure:

β”œβ”€β”€ src
β”‚Β Β  └── index.js
└── test
    └── index.js

The output of the todos is as follows:

[
    {
        "file": "index.js",
        "text": "This is needs to be done.",
        "kind": "TODO",
        "line": 30
    },
    {
        "file": "index.js",
        "text": "Find a workaround to install https://github.com/badges/shields locally as a module",
        "kind": "FIXME",
        "line": 139
    }

The problem comes from different files, one from the test cases, and the other from the source.

Solution

  • Full Path: That is easier to for automation tools to properly find the file and link;
  • Relative Path: That gives the flexility to just show src/index.js or test/index.js;

wrong output location

this below gist should output to the root of my repo right near my gulpfile but instead outputs to app/scripts

gulp.task('todo', function () {
    return gulp.src(['app/scripts/**/*.js', '!app/scripts/{vendor,vendor/**}'])
        .pipe(p.todo({
            fileName        : 'TODO.md',
            transformHeader : function (kind) {
                return ['### ' + kind + 's',
                    '| File | Msg',
                    '|--------|------'
                ];
            },
            transformComment: function (file, line, text) {
                return ['| ' + file + ':' + line + ' | ' + text];
            }
        }))
        .pipe(gulp.dest('./'));
});

Support cjsx files

These are React files writte in Coffee, ending like test.cjsx ... thanks for supporting these file types too!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.