|
| 1 | +var gulp = require('gulp'); |
| 2 | +var markdownpdf = require('gulp-markdown-pdf'); |
| 3 | +var path = require('path'); |
| 4 | +var replace = require('gulp-replace'); |
| 5 | +var package = require('./package.json'); |
| 6 | +var rename = require('gulp-rename'); |
| 7 | +var rimraf = require('gulp-rimraf'); |
| 8 | +var runSequence = require('run-sequence'); |
| 9 | +var glob = require('glob'); |
| 10 | + |
| 11 | +var TITLE = 'AngularJS in Patterns'; |
| 12 | + |
| 13 | +function genericTask(lang){ |
| 14 | + |
| 15 | + gulp.task('generate:pdf:' + lang, function() { |
| 16 | + |
| 17 | + var files = ['./temp/*.md']; |
| 18 | + if (lang === 'eng'){ |
| 19 | + files = './temp/README.md'; |
| 20 | + } |
| 21 | + else if(lang !== 'all'){ |
| 22 | + files = ['./temp/*-'+lang+'.md']; |
| 23 | + } |
| 24 | + |
| 25 | + return gulp.src(files) |
| 26 | + .pipe(markdownpdf({ |
| 27 | + cwd: path.resolve('./temp/'), |
| 28 | + layout: 'github' |
| 29 | + })) |
| 30 | + .on('error', function(err){ |
| 31 | + gutil.log(gutil.colors.red('doc task failed'), err); |
| 32 | + }) |
| 33 | + .pipe(rename(function (path) { |
| 34 | + var lang = 'ENG'; |
| 35 | + if(path.basename.indexOf('-') >= 0){ |
| 36 | + lang = path.basename.replace('README-', '').toUpperCase(); |
| 37 | + } |
| 38 | + path.basename = TITLE + ' ('+lang+')'; |
| 39 | + path.extname = '.pdf' |
| 40 | + })) |
| 41 | + .pipe(gulp.dest('./build/')); |
| 42 | + }); |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | +// build custom tasks for i18n |
| 47 | + |
| 48 | +glob.sync('./temp/README-*.md').map(function(file){ |
| 49 | + |
| 50 | + return file.replace('README-', ''); |
| 51 | + |
| 52 | +}).concat(['all', 'eng']).forEach(function(lang){ |
| 53 | + |
| 54 | + genericTask(lang); |
| 55 | + gulp.task('doc:pdf:'+lang, function(cb){ |
| 56 | + runSequence('clean', ['copy:images', 'copy:md'], 'generate:pdf:'+lang, cb); |
| 57 | + }); |
| 58 | + |
| 59 | +}); |
| 60 | + |
| 61 | +gulp.task('default', function(cb){ |
| 62 | + runSequence('clean', ['copy:images', 'copy:md'], 'doc:pdf:all', cb); |
| 63 | +}); |
| 64 | + |
| 65 | +gulp.task('copy:md', function(){ |
| 66 | + return gulp.src(['README.md', 'i18n/README-*.md']) |
| 67 | + |
| 68 | + // @todo I have no idea where should the TOC go?! |
| 69 | + // for now, let's keep the TOC content and remove these markers |
| 70 | + .pipe(replace('<!--toc-->', '')) |
| 71 | + .pipe(replace('<!--endtoc-->', '')) |
| 72 | + |
| 73 | + // preapre the image paths for the renderer |
| 74 | + .pipe(replace(/https:\/\/rawgit.com\/mgechev\/angularjs-in-patterns\/master\/images/g, '.')) |
| 75 | + .pipe(gulp.dest('./temp/')); |
| 76 | +}); |
| 77 | + |
| 78 | +gulp.task('copy:images', function(){ |
| 79 | + return gulp.src(['images/*.svg','meta.json']).pipe(gulp.dest('./temp')); |
| 80 | +}); |
| 81 | + |
| 82 | +gulp.task('clean', function() { |
| 83 | + return gulp.src('./temp/', { read: false }).pipe(rimraf()); |
| 84 | +}); |
0 commit comments