forked from gyliu513/dcos-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (82 loc) · 2.73 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
var checker = require('license-checker');
var connect = require('gulp-connect');
var fs = require('fs');
var gulp = require('gulp');
var packageJSON = require('./package.json');
var shrinkwrap = require('./npm-shrinkwrap.json');
gulp.task('ensureConfig', function () {
// Make sure we have a Config.dev so we don't error on Config loading
var configFilePath = './src/js/config/Config.dev.js';
if (!fs.existsSync(configFilePath)) {
var template = fs.readFileSync('./src/js/config/Config.template.js', 'utf8');
fs.writeFileSync(configFilePath, template, 'utf8');
}
});
gulp.task('ensureDevProxy', function () {
// Create a proxy.dev to make getting started easier
var proxyFilePath = './webpack/proxy.dev.js';
if (!fs.existsSync(proxyFilePath)) {
var template = fs.readFileSync('./webpack/proxy.template.js', 'utf8');
fs.writeFileSync(proxyFilePath, template, 'utf8');
}
});
function buildDependenciesArray(dependencies) {
return Object.keys(dependencies).map(function (dependency) {
return dependency + '@' + dependencies[dependency];
});
}
gulp.task('checkDependencies', function () {
var dependencies = buildDependenciesArray(packageJSON.dependencies);
dependencies = dependencies.concat(
buildDependenciesArray(packageJSON.devDependencies)
);
checker.init({
start: './'
}, function(json, error) {
if (error) {
console.log(error);
process.exit(1);
}
var count = 0;
var found = [];
Object.keys(json).forEach(function (dependency) {
if (dependencies.indexOf(dependency) === -1) {
return;
}
count++;
found.push(dependency);
var licenses = json[dependency].licenses;
if (licenses === 'UNKNOWN') {
console.warn(
'Dependency has an unknown license', json[dependency]
);
}
if (licenses.indexOf('LGPL') === -1 && licenses.match(/GPL/gi)) {
console.log('Package has invalid license.', json[dependency]);
process.exit(1);
}
});
// Ensure we found them all
if (count !== dependencies.length) {
console.log('Dependency length doesn\'t match.');
var missing = dependencies.filter(function (dependency) {
return found.indexOf(dependency) === -1;
});
console.log(missing);
process.exit(1);
}
});
});
gulp.task('serve', function () {
connect.server({
port: 4200,
root: './dist'
});
});
// remove 'fsevents' from shrinkwrap, since it causes errors on non-Mac hosts
// see https://github.com/npm/npm/issues/2679
gulp.task('fixShrinkwrap', function (done) {
delete shrinkwrap.dependencies.fsevents;
var shrinkwrapString = JSON.stringify(shrinkwrap, null, ' ') + '\n';
fs.writeFile('./npm-shrinkwrap.json', shrinkwrapString, done);
});