Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f1d505

Browse files
committed
Merge pull request #28 from cmtt/master
Refactoring Gulpfile using dependency injection
2 parents c264dd7 + 5581243 commit 3f1d505

File tree

8 files changed

+110
-88
lines changed

8 files changed

+110
-88
lines changed

‎gulp/modules/generic-task.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = function (gulp, markdownpdf, path, log, chalk, rename, TITLE) {
2+
3+
function genericTask(lang){
4+
5+
gulp.task('generate:pdf:' + lang, function() {
6+
7+
var files = ['./temp/*.md'];
8+
if (lang === 'eng'){
9+
files = './temp/README.md';
10+
}
11+
else if(lang !== 'all'){
12+
files = ['./temp/*-'+lang+'.md'];
13+
}
14+
15+
return gulp.src(files)
16+
.pipe(markdownpdf({
17+
cwd: path.resolve('./temp/'),
18+
layout: 'github'
19+
}))
20+
.on('error', function(err){
21+
log(chalk.red('doc task failed'), err);
22+
})
23+
.pipe(rename(function (path) {
24+
var lang = 'ENG';
25+
if(path.basename.indexOf('-') >= 0){
26+
lang = path.basename.replace('README-', '').toUpperCase();
27+
}
28+
path.basename = TITLE + ' ('+lang+')';
29+
path.extname = '.pdf';
30+
}))
31+
.pipe(gulp.dest('./build/'));
32+
});
33+
34+
}
35+
36+
return genericTask;
37+
38+
};

‎gulp/tasks/clean.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (gulp, rimraf) {
2+
3+
gulp.task('clean', function() {
4+
return gulp.src('./temp/', { read: false }).pipe(rimraf());
5+
});
6+
7+
};

‎gulp/tasks/copy-images.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function (gulp) {
2+
3+
gulp.task('copy:images', function(){
4+
return gulp.src(['images/*.svg','meta.json']).pipe(gulp.dest('./temp'));
5+
});
6+
7+
};

‎gulp/tasks/copy-md.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function (gulp, replace) {
2+
3+
gulp.task('copy:md', function(){
4+
return gulp.src(['README.md', 'i18n/README-*.md'])
5+
// @todo I have no idea where should the TOC go?!
6+
// for now, let's keep the TOC content and remove these markers
7+
.pipe(replace('<!--toc-->', ''))
8+
.pipe(replace('<!--endtoc-->', ''))
9+
10+
// preapre the image paths for the renderer
11+
.pipe(replace(/https:\/\/rawgit.com\/mgechev\/angularjs-in-patterns\/master\/images/g, '.'))
12+
.pipe(gulp.dest('./temp/'));
13+
});
14+
15+
};

‎gulp/tasks/default.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = function (gulp, runSequence) {
2+
gulp.task('default', function(cb){
3+
runSequence('clean', ['copy:images', 'copy:md'], 'doc:pdf:all', cb);
4+
});
5+
};

‎gulp/tasks/i18n.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = function (gulp, glob, genericTask, runSequence) {
2+
3+
// build custom tasks for i18n
4+
5+
glob.sync('./temp/README-*.md').map(function(file){
6+
return file.replace(/.*README\-|\.md$/g, '');
7+
}).concat(['all', 'eng']).forEach(function(lang){
8+
genericTask(lang);
9+
gulp.task('doc:pdf:'+lang, function(cb){
10+
runSequence('clean', ['copy:images', 'copy:md'], 'generate:pdf:'+lang, cb);
11+
});
12+
});
13+
};

‎gulpfile.js‎

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,15 @@
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-
// @todo I have no idea where should the TOC go?!
68-
// for now, let's keep the TOC content and remove these markers
69-
.pipe(replace('<!--toc-->', ''))
70-
.pipe(replace('<!--endtoc-->', ''))
71-
72-
// preapre the image paths for the renderer
73-
.pipe(replace(/https:\/\/rawgit.com\/mgechev\/angularjs-in-patterns\/master\/images/g, '.'))
74-
.pipe(gulp.dest('./temp/'));
75-
});
76-
77-
gulp.task('copy:images', function(){
78-
return gulp.src(['images/*.svg','meta.json']).pipe(gulp.dest('./temp'));
79-
});
80-
81-
gulp.task('clean', function() {
82-
return gulp.src('./temp/', { read: false }).pipe(rimraf());
83-
});
1+
var GulpDI = require('gulp-di');
2+
var gulp = require('gulp');
3+
var di = GulpDI(require('gulp'), {
4+
pattern : ['gulp-*', 'gulp.*', 'run-sequence', 'glob'],
5+
rename : {
6+
'gulp-markdown-pdf' : 'markdownpdf'
7+
}
8+
})
9+
.provide({
10+
TITLE : 'AngularJS in Patterns',
11+
path : require('path')
12+
})
13+
.modules('./gulp/modules')
14+
.tasks('./gulp/tasks')
15+
.resolve();

‎package.json‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
"url": "git://github.com/mgechev/angularjs-patterns.git"
1212
},
1313
"author": "mgechev",
14-
"contributors": [{
15-
"name" : "Wassim Chegham",
16-
"email" : "maneki.nekko@gmail.com",
17-
"url" : "https://github.com/manekinekko/"
18-
}],
14+
"contributors": [
15+
{
16+
"name": "Wassim Chegham",
17+
"email": "maneki.nekko@gmail.com",
18+
"url": "https://github.com/manekinekko/"
19+
}
20+
],
1921
"license": "MIT",
2022
"gitHead": "2009434a6dfdbe5f06f81253fb853840af753b36",
2123
"readmeFilename": "README.md",
@@ -28,5 +30,8 @@
2830
"gulp-rimraf": "^0.1.1",
2931
"markdown-styles": "https://github.com/mgechev/markdown-styles/tarball/master",
3032
"run-sequence": "^1.1.1"
33+
},
34+
"dependencies": {
35+
"gulp-di": "0.0.1"
3136
}
3237
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /