This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGruntfile.js
112 lines (100 loc) · 3.18 KB
/
Gruntfile.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
var API_KEY_FILENAME = 'tmp.apikeys.js';
/* custom tasks */
module.exports = function(grunt) {
var fs = require('fs');
var wflDir = 'bower_components/webfontloader/';
var libsDistDir = 'dist/libs/';
var helpers = {
setUpApiKeyFile: function() {
var googleApiKey = {}, hasKeys = false;
if (process.env.JD_FONTSELECT_GOOGLE_FONTS_API_KEY) {
googleApiKey = process.env.JD_FONTSELECT_GOOGLE_FONTS_API_KEY;
hasKeys = true;
}
if (hasKeys) {
fs.writeFileSync(
API_KEY_FILENAME,
'window._jdFontselectGoogleApiKey = \'' + googleApiKey + '\';'
);
}
},
ensureApiKeyFileExists: function() {
var exists = grunt.file.exists(API_KEY_FILENAME);
if (!exists) {
grunt.fail.fatal('We need an API key for the Google web fonts, please get one here:' +
'https://developers.google.com/fonts/docs/developer_api#Auth'
);
}
}
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
angularToolbox: {
moduleName: 'jdFontselect',
files: {
src: {
js: [
'src/js/helper.module.js',
'src/js/helper.defaults.js',
'src/js/helper.google-font-categories.js',
'src/js/helper.functions.js',
'src/js/!(helper)*.js'
]
},
test: {
unit: [
'test/default-websafe-fonts.js',
'test/unit/**/*.+(js|coffee)'
],
e2e: [
'test/e2e/SpecHelper.js',
'test/e2e/test.*.js'
]
},
},
},
shell: {
buildWFL: {
options: {
failOnError: true,
stderr: true
},
command: [
'BASEDIR=`pwd`',
'cd ' + wflDir,
'bundle install --path=vendor/bundle',
'bundle exec rake compile',
'cd $BASEDIR',
'mkdir -p ' + libsDistDir,
'echo ' + libsDistDir + 'webfontloader.js',
'mv ' + wflDir + 'target/webfont.js ' + libsDistDir + 'webfontloader.js'
].join(';')
}
}
});
grunt.loadNpmTasks('grunt-angular-toolbox');
/* Ensure jquery, angular and angular mocks are loaded correctly */
var unitSuite = grunt.config('angularToolbox.files.test.unitSuite');
function indexFor(lib) {
var index = -1;
unitSuite.forEach(function(entry, i) {
if (entry.indexOf(lib) !== -1) {
index = i;
}
});
return index;
}
var jQuery = unitSuite.splice(indexFor('bower_components/jquery/'), 1)[0];
var angular = unitSuite.splice(indexFor('bower_components/angular/'), 1)[0];
var angularMocks = unitSuite.splice(indexFor('bower_components/angular-mocks/'), 1)[0];
unitSuite = [jQuery, angular, angularMocks].concat(unitSuite);
grunt.config('angularToolbox.files.test.unitSuite', unitSuite);
grunt.registerTask('_buildapikeys', function() {
helpers.setUpApiKeyFile();
helpers.ensureApiKeyFileExists();
});
grunt.registerTask('demo:before', ['_buildapikeys']);
grunt.registerTask('test:before', ['_buildapikeys']);
grunt.registerTask('build:before', ['_buildapikeys', 'shell:buildWFL']);
grunt.registerTask('default', ['test']);
};