forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (71 loc) · 2.19 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
gulpfile.js - gulp script for building Faker package for browser / stand-alone package
run this file using the gulp command
If this is your first time trying to build faker, you will need to install gulp:
cd faker.js/
[sudo] npm install
[sudo] npm install gulp -g
cd build/
gulp
*/
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var mustache = require('gulp-mustache');
var browserify = require('browserify');
var transform = require('vinyl-transform');
gulp.task('browser-package', function() {
/* task for building browser bundles using browserify
this task will generate the following files:
./build/faker.js
./build/faker.min.js
../examples/browser/js/faker.js
../examples/browser/js/faker.min.js
*/
var browserified = transform(function(filename) {
// use browserify to create UMD stand-alone browser package
var b = browserify(filename, {
standalone: 'faker'
});
return b.bundle();
});
return gulp.src('../index.js')
.pipe(browserified)
.pipe(rename('faker.js'))
.pipe(gulp.dest('build/'))
.pipe(gulp.dest('../examples/browser/js'))
.pipe(rename({ extname: ".min.js" }))
.pipe(uglify())
.pipe(gulp.dest('build/'))
.pipe(gulp.dest('../examples/browser/js'))
.pipe(rename('../examples/browser/js/faker.min.js'));
});
// builds Readme.md file from docs.md and exported faker methods
gulp.task('documentation', function(cb) {
/* task for generating documentation
this task will generate the following file:
../Readme.md
*/
var API = '';
var faker = require('../index');
// generate nice tree of api for docs
API += '<ul>';
for (var module in faker) {
API += '<li>' + module;
API += '<ul>';
for (var method in faker[module]) {
API += '<li>' + method + '</li>';
}
API += '</ul>';
API += '</li>';
}
API += '</ul>';
return gulp.src('./src/docs.md')
.pipe(mustache({
'API': API,
'copyrightYear': new Date().getFullYear()
}))
.pipe(rename("./Readme.md"))
.pipe(gulp.dest('../'))
});
gulp.task('default', ['browser-package', 'documentation']);