This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (97 loc) · 2.81 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
var gulp = require('gulp'),
exit = require('gulp-exit'), // Because https://github.com/gulpjs/gulp/issues/411
bower = require('bower'),
fs = require('fs'),
sassModules = require('config').plugins,
_ = require('lodash'),
bowerDependencies = _.keys(require('./bower.json').dependencies),
bowerInfo = function(pkg, callback) {
bower.commands.info(pkg)
.on('end', function (res) {
callback(res.latest);
});
};
function bowerListAndInstall() {
var extensions = [],
length = _.size(sassModules),
i = 0;
_.each(sassModules, function(extension, key) {
if(! _.contains(bowerDependencies, extension.bower)) {
extensions.push(extension.bower);
}
if(i == length - 1) {
bower.commands.install(extensions, { save: true })
.on('end', function (installed) {
return;
});
}
i++;
});
}
function writeExtensionsJSON() {
var extensions = {},
length = _.size(sassModules),
i = 0;
_.each(sassModules, function(extension, key) {
bowerInfo(extension.bower, function(info) {
extensions[key] = {
version: info.version,
import: extension.imports,
homepage: info.homepage
};
if(i == length - 1) {
fs.writeFileSync('public/extensions.json', JSON.stringify(extensions));
}
i++;
});
});
}
function fixturePreflightCheck() {
_.each(sassModules, function(extension, key) {
var fixture = 'test/fixtures/' + key + '.scss',
exists = fs.existsSync(fixture);
if(! exists) {
fs.writeFileSync(fixture, '');
throw 'Populate this new spec fixture before continuing: ' + fixture;
}
});
}
function setMetadata() {
var nodeSass = require('node-sass'),
version = nodeSass.info.match(/(?:libsass\s+)([\w\d\.-]+)/i)[1],
compiler = {
sass: version,
engine: 'LibSass'
},
redis = require('./lib/redis').redis,
extension_list = require('./public/extensions.json');
var compilers = redis('compilers');
compilers.merge({'lib': compiler});
var extensions = redis('extensions');
_.mapValues(extension_list, function(value, key) {
this[key]=_.omit(value, ['gem', 'bower', 'paths', 'fingerprint']);
}, extension_list);
extensions.merge(extension_list);
return true;
}
gulp.task('setMetadata', function() {
return setMetadata();
});
gulp.task('assets', ['setMetadata'], function() {
setTimeout(function() {
return gulp.src('', {read: false})
.pipe(exit());
}, 150);
});
gulp.task('update', function() {
bowerListAndInstall();
writeExtensionsJSON();
return;
});
gulp.task('default', ['update'], function() {
var mocha = require('gulp-mocha');
fixturePreflightCheck();
return gulp.src('test/*.js', {read: false})
.pipe(mocha())
.pipe(exit());
});