-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
executable file
·92 lines (81 loc) · 3.01 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
/*
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var gulp = require('gulp'),
del = require('del'),
wiredep = require('wiredep').stream,
plugins = require('gulp-load-plugins')({}),
map = require('vinyl-map'),
fs = require('fs'),
path = require('path');
var pkg = require('./package.json'),
taskCreator = require('./build/gulpfile.js');
var pluginBuildTasks = [],
pluginFolders = getFolders('./plugins');
var config = {
main: '.',
ts: function (pluginName){ return ['./plugins/' + pluginName + '/plugins/**/*.ts'];},
templates: function (pluginName){ return ['./plugins/' + pluginName + '/plugins/**/*.html'];},
less: function (pluginName){ return ['./plugins/' + pluginName + '/plugins/**/*.less'];},
templateModule: function(pluginName){ return pkg.name + '-' + pluginName +'-templates'; },
dist: './dist/',
js: function(pluginName){ return pkg.name + '-' + pluginName +'.js'; },
css: function(pluginName){ return pkg.name + '-' + pluginName +'.css'; },
jsMain: pkg.name +'.js',
tsProject: plugins.typescript.createProject({
target: 'ES5',
module: 'commonjs',
declarationFiles: true,
noExternalResolve: false,
removeComments: true
}),
tsLintOptions: {
rulesDirectory: './tslint-rules/'
}
};
// Get the contents of ./plugins directory. Directory names must match actual plugin names.
function getFolders(dir) {
return fs.readdirSync(dir)
.filter(function(file) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}
// Create subtasks for each plugin.
for (var i = 0; i < pluginFolders.length; i++){
var pluginName = pluginFolders[i];
taskCreator(gulp, config, pluginName);
pluginBuildTasks.push('build-' + pluginName);
}
/** Adjust the reference path of any typescript-built plugin this project depends on */
gulp.task('path-adjust', function(done) {
gulp.src('libs/**/includes.d.ts')
.pipe(map(function(buf, filename) {
var textContent = buf.toString();
var newTextContent = textContent.replace(/"\.\.\/libs/gm, '"../../../libs');
return newTextContent;
}))
.pipe(gulp.dest('libs'))
.on('end', function() {done()});
});
gulp.task('reload', function() {
var staticPath = path.resolve(__dirname, '.tmp/gulp-connect-server/');
gulp.src(staticPath)
.pipe(plugins.connect.reload());
});
gulp.task('clean', function() {
del(['.tmp/**']);
});
gulp.task('default', pluginBuildTasks);