環境:
ファントムJSとおそらくチェリオを使用してWebサイトをクロールし、ソース(画像とフォントファイルなど)を取得してフォルダーに入れるgulpプラグインを作成しようとしています。プラグインはStylify-Meに基づいています。
gulpjs.com の「ドキュメント」を読みましたが、基本的な gulp オプションを作成して console.log に記録する方法がまだわかりません。
プラグインは次のようになります。
.pipe(plugin({
url: 'http://stylifyme.com/',
sitemap: true,
content: all,
out: md,
output: './dist/'
}))
私が今求めているのは、オプション (url: 'google.com' など) を取得する方法と、Web サイトの URL を console.log に記録する方法だけです。
私は yeoman ジェネレーターを使用してプラグインを作成し ています。プラグイン用のコードは次のとおりです。
var gutil = require('gulp-util');
var through = require('through2');
var cheerio = require('cheerio'),
var phantom = require('phantom');
var plugin = require('./lib');
module.exports = function (opts) {
opts = opts || {};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-stylify', 'Streaming not supported'));
return;
}
try {
file.contents = new Buffer(someModule(file.contents.toString(), opts));
this.push(file);
} catch (err) {
this.emit('error', new gutil.PluginError('gulp-stylify', err));
}
cb();
});
};