LoginSignup
22

More than 5 years have passed since last update.

JSのコメントからmarkdownファイルを生成するgulpプラグイン作った

Last updated at Posted at 2015-04-17

コメントからドキュメント生成するのは結構あるけど、単純にそのままmarkdownとして出力するものは探したけどなかったので作った。(あるぞという場合は教えてくださいm(_ _)m すごくありそうな気がする...)

インストール

$ npm i --save-dev gulp gulp-comment2md

使い方

/*md
 * Title
 * =====
 * 
 * - one
 * - two
 * - three
 */
function hello () {
  console.log('hello!!');
}

↑のように/*mdもしくは/*markdownで始まるブロックコメントを書く。

var gulp = require('gulp');
var comment2md = require('gulp-comment2md');

gulp.task('markdown', function () {
  return gulp.src('src/**/*.js')
    .pipe(comment2md())
    .pipe(gulp.dest('doc/'));
});

このようなtaskを書いて実行すると、src/hello.jsの場合、doc/hello.mdという感じで出力する。
出力ファイル名を変えたい場合は、引数に文字列か、関数を渡すことで変更できる。

comment2md('new-name.md') // new-name.mdで出力

// `file`はvinyl
// https://github.com/wearefractal/vinyl
comment2md(function (file) {
  return 'new-name.md'; // new-name.mdで出力
})

開発・テスト

バグや要望があれば、issueにくださいなー

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22