forked from meteoric/meteor-ionic
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
202 lines (174 loc) · 6.26 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var path = require('path'),
gulp = require('gulp'),
del = require('del'),
es = require('event-stream'),
_ = require('underscore'),
template = require('gulp-template'),
argv = require('yargs').argv,
semver = require('semver');
var runSequence = require('run-sequence');
var Dgeni = require('dgeni');
var exec = require('child_process').exec;
var insert = require('gulp-insert-lines');
var rename = require("gulp-rename");
var paths = {
js: [
'./src/components/**/*.js',
'./src/lib/controller/*.js',
'./src/lib/service/*.js',
'./src/lib/utils/*.js'
],
templates: [
'./src/components/**/*.html',
'./config/**/*.html'
],
docStyles: ['./config/styles/**/*.scss']
};
var arg = {
version: function () {
var version = argv.version;
if (_.isUndefined(version)) {
console.error("Error: Version is not given. 'gulp setup-meteor-doc-project --version=<version>'");
process.exit(1);
} else if (!semver.valid(version)) {
// Check if version is valid.
console.error("Error: Invalid semver format for --version argument.");
process.exit(1);
}
return version;
}
};
gulp.task('dgeni-clean', function(cb) {
exec('rm -rf doc/client/partials', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('dgeni', ['dgeni-clean'], function(done) {
var dgeni = new Dgeni([ require('./config/dgeni-meteoric')({
include: paths.js,
exclude: [
'./src/lib/service/modal.js',
'./src/lib/service/popover.js',
'./src/lib/service/popup.js',
'./src/lib/service/actionSheet.js',
'./src/lib/service/backdrop.js',
'./src/lib/service/loading.js'
],
dest: './doc/client',
version: arg.version() // todo: not used atm, but I'm sure will be used in the future.
})]);
dgeni.generate().then(function() { done(); });
});
gulp.task('doc-styles', function() {
return gulp.src('config/templates/meteor/styles/main.scss')
.pipe(gulp.dest('doc/client/styles'));
});
gulp.task('create-meteor-doc-project', function(cb) {
exec('meteor create meteoric-doc', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
console.log('Renaming meteoric-doc to doc ...');
exec('rm -rf doc', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
exec('mv meteoric-doc doc', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
console.log('done.');
cb(err);
});
});
});
});
gulp.task('setup-meteor-doc-project-packages', function() {
gulp.src('config/templates/meteor/packages.template')
.pipe(rename('packages'))
.pipe(gulp.dest('doc/.meteor'));
});
gulp.task('_setup-meteor-doc-project-templates', function() {
return gulp.src([
'config/templates/meteor/client/**/*',
'!./config/templates/meteor/client/**/*.template.*'
]).pipe(gulp.dest('doc/client'));
});
gulp.task('setup-meteor-doc-project-templates', function(cb) {
return runSequence('_setup-meteor-doc-project-templates', 'dgeni', cb);
});
gulp.task('clean-up-meteor-doc-project', function(cb) {
exec([ 'rm',
'-rf',
'doc/server',
'doc/client',
'doc/lib' +
'doc/.meteor/packages' +
'doc/public' ].join(' '),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('create-router-meteor-doc-project', function() {
var docPath = 'doc/client/partials/api/meteoric';
var modules = [];
return new Promise(function(resolve) {
gulp.src([
docPath + '/{directive,object,service,utility,page,provider}/**/*.{md,html,markdown}'
]).pipe(es.map(function(file, callback) {
// Grab relative path from ionic-site root
var relpath = file.path.replace(RegExp('^.*?' + docPath + '/'), '');
modules.push(relpath);
callback();
})).on('end', function() {
modules = modules.map(function(m) {
var routeName = m.split('.html')[0].split('/');
routeName = routeName[routeName.length - 1];
var routePath = 'api/' + m.split('.html')[0];
// get rid of .html,
var new_m = {
routePath: routePath,
routeName: routeName
};
return new_m;
});
gulp.src('config/templates/meteor/router.template.js')
.pipe(template({modules: modules}))
.pipe(rename('router.js'))
.pipe(gulp.dest('doc/lib'))
.on('end', function() {
gulp.src('config/templates/meteor/helpers.template.js')
.pipe(template({version: arg.version()}))
.pipe(rename('helpers.js'))
.pipe(gulp.dest('doc/client/lib'))
.on('end', function() {
resolve();
});
});
});
});
});
gulp.task('copy-meteor-doc-public-files', function() {
return gulp.src('config/templates/meteor/public/**/*')
.pipe(gulp.dest('doc/public'));
});
gulp.task('setup-meteor-doc-project', function(cb) {
runSequence(
'clean-up-meteor-doc-project',
'copy-meteor-doc-public-files',
'setup-meteor-doc-project-templates',
'setup-meteor-doc-project-packages',
'create-router-meteor-doc-project',
'doc-styles', cb);
});
gulp.task('doc', function(cb) {
runSequence('create-meteor-doc-project', 'setup-meteor-doc-project', cb);
});
// Watcher section.
gulp.task('watchers', function () {
gulp.watch(paths.js, ['setup-meteor-doc-project']);
gulp.watch(paths.templates, ['setup-meteor-doc-project']);
gulp.watch(paths.docStyles, ['setup-meteor-doc-project']);
});
gulp.task('default', ['setup-meteor-doc-project', 'watchers']);