This repository was archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGruntfile.js
More file actions
178 lines (141 loc) · 3.8 KB
/
Copy pathGruntfile.js
File metadata and controls
178 lines (141 loc) · 3.8 KB
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
/*jshint node:true*/
'use strict';
var path = require('path');
require('js-yaml');
var CLEAN_DIRS = [
'components',
'dist',
'build'
];
var BROWSERS = require('./node_modules/browsers-yaml/browsers');
var ASSET_HOST = process.env.ASSET_HOST;
module.exports = function(grunt) {
var DIST_OUTPUT_PATH = path.join(__dirname, 'dist');
var COMPONENT_BIN_PATH = path.join(__dirname,
'node_modules/component/bin/component');
var UGLIFY_BIN_PATH = path.join(__dirname,
'node_modules/uglify-js/bin/uglifyjs');
function getSemver() {
return require('./component').version;
}
function getName() {
return require('./component').name;
}
function getSemverURLPath() {
return ASSET_HOST + '/widgets/user-list/v' + getSemver();
}
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.initConfig({
clean: CLEAN_DIRS,
connect: {
server: {
options: {
base: "",
port: 9999
}
}
},
'saucelabs-mocha': {
all: {
options: {
urls: ["http://localhost:9999/test/index.html"],
tunnelTimeout: 5,
build: process.env.TRAVIS_JOB_ID,
concurrency: 8,
browsers: BROWSERS,
testname: "mocha tests",
tags: ["master"]
}
}
},
});
grunt.registerTask('test', ['build', 'connect', 'saucelabs-mocha']);
// Jshint default task
grunt.registerTask('build', [
'clean',
'component:install',
'component:build:dev'
]);
grunt.registerTask('build:prod', [
'clean',
'component:install',
'component:build:prod',
'minify'
]);
grunt.registerTask('component:install', function() {
var done = this.async();
var install = {
cmd: COMPONENT_BIN_PATH,
args: [ 'install', '-d' ]
};
// Build the component.
grunt.log.writeln('component install - start');
grunt.util.spawn(install, function(err) {
if (err) {
return done(err);
}
grunt.log.writeln('component install - done');
done();
});
});
grunt.registerTask('component:build:dev', function() {
var done = this.async();
var args = ['build', '-c', '-d'];
var build = {
cmd: COMPONENT_BIN_PATH,
args: args
};
// Build the component.
grunt.util.spawn(build, function(err) {
if (err) {
return done(err);
}
done();
});
});
grunt.registerTask('component:build:prod', function() {
var done = this.async();
// To prevent having to write a custom build.js file, we take advantage
// of their lack of escaping in order to build up the widgets namespace.
// Yeah, this is hacky.
// In the following code string's context, `this` is the window object.
var exportName = '"];' +
'this.goinstant = this.goinstant || {};' +
'this.goinstant.widgets = this.goinstant.widgets || {};' +
'this.goinstant.widgets["UserList';
var args = [
'build', '-c',
'-n', getName(),
'-s', exportName,
'-o', DIST_OUTPUT_PATH
];
var build = {
cmd: COMPONENT_BIN_PATH,
args: args
};
// Build the component.
grunt.util.spawn(build, function(err) {
if (err) {
return done(err);
}
done();
});
});
grunt.registerTask('minify', function() {
var done = this.async();
var componentDir = DIST_OUTPUT_PATH;
var jsFilePath = path.join(componentDir, getName() + '.js');
var minJsFilePath = path.join(componentDir, getName() + '.min.js');
var uglify = {
cmd: UGLIFY_BIN_PATH,
args: [
'-o',
minJsFilePath,
jsFilePath
]
};
grunt.util.spawn(uglify, done);
});
};