LoginSignup
0
0

More than 3 years have passed since last update.

vivliostyle-cli の gulp プラグイン書いた

Last updated at Posted at 2021-01-04

Gulpプラグインを書く演習で、
vivliostyle-cli をgulpで実行するプラグインを書きました。

Gulp4以降で動きます。
vivliostyle build だけです。 vivliostyle preview は使えません。

kanemu/gulp-vivliostyle-build: vivliostyle-cli plugin for Gulp.

インストール

npmには上げてないので、リポジトリ直指定でインストールしてください。

npm install git+ssh://git@github.com:kanemu/gulp-vivliostyle-build.git --save-dev

基本的な使い方

./gulpfile.js に以下の感じで書いて、 gulp build で実行してください。
デフォルトの書き出し先は、htmlと同じパスの .pdf になります。

'use strict';

const gulp = require('gulp'),
    vivliostyleBuild = require('gulp-vivliostyle-build');

gulp.task('build', (done) => {
    return gulp.src('./src/index.html')
        .pipe(vivliostyleBuild())
        .on('end', () => {
            done();
        });
});

オプションについて

vivliostyle-cli/cli-build.ts で設定しているオプションの他に、 outputDir オプションで書き出し先を指定できます。

gulp.src('./src/index.html')
    .pipe(vivliostyleBuild());
// -> output ./src/index.pdf

gulp.src('./src/index.html')
    .pipe(vivliostyleBuild({outputPath:'dist/out.pdf'}));
// -> output ./dist/out.pdf

gulp.src('./src/index.html')
    .pipe(vivliostyleBuild({outputDir:'build'}));
// -> output ./build/index.pdf

gulp.src('./src/index.html')
    .pipe(vivliostyleBuild({outputPath:'dist/out.pdf',outputDir:'build'}));
// -> output ./build/dist/out.pdf

ライセンスについて

vivliostyle-cli に合わせて
AGPL Version 3 にしてあります。

作ってみた感想

gulpプラグインが Vinyl のストリームだというのがよく理解できました。

あと、vivliostyle-cli が vivliostyle-cli/build.ts 内で process.exit(0); してプロセスが終了してしまうので、
child_process.fork を使って別プロセスで実行してます(結構大変だった)。

参考URL

0
0
1

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
0
0