This repository has been archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
165 lines (141 loc) · 4.28 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
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
// Generated on 2014-06-19 using generator-angular 0.9.0-1
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
var modRewrite = require('connect-modrewrite');
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
var authConfig =
grunt.option('auth-client') ||
process.env.GRUNT_AUTH_CLIENT ||
'authconf.json';
grunt.log.writeln("Using %s", authConfig);
var authConfigData = grunt.file.readJSON(authConfig);
// Define the configuration for all the tasks
// note this will overwrite previous grunt.config properties
// with the object literal passed into the function
grunt.initConfig({
// Project settings
yeoman: appConfig,
auth_config: authConfig,
auth_config_data: authConfigData,
// Watches files for changes and runs tasks based on the changed files
watch: {
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'<%= yeoman.app %>/{,*/}*.js',
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
],
tasks: ['newer:copy']
}
},
// The actual grunt server settings
connect: {
options: {
port: "<%= auth_config_data.APP_PORT %>", // may need to convert to number?
// Change this to '0.0.0.0' to access the server from outside.
hostname: '<%= auth_config_data.APP_HOST %>',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'dist/app'
],
middleware: function (connect, options) {
var middlewares = [];
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']));
middlewares.push(connect().use(
'/bower_components',
connect.static('./bower_components')
));
options.base.forEach(function (base) {
return middlewares.push(connect['static'](base));
});
return middlewares;
}
}
},
},
// Empties folders to start fresh
clean: {
server: {
files: [{
src: ['.tmp', 'dist']
}]
}
},
// Copies remaining files to places other tasks can use
copy: {
styles: {
expand: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
},
dist: {
expand: true,
dest: 'dist',
src: [
'register_with_anvil_connect.sh',
'<%= yeoman.app %>/**'],
options: {
process: function( content, srcpath) {
return grunt.template.process(
content,
{data: authConfigData});
},
},
},
},
// Run some tasks in parallel to speed up the build process
concurrent: {
server: [
'copy:styles',
'copy:dist',
]
},
});
grunt.registerTask('chmodScript', 'Makes script executable', function(target) {
var fs = require('fs');
fs.chmodSync('dist/register_with_anvil_connect.sh', '755');
});
grunt.registerTask('build', function (target) {
grunt.log.writeln('Build app in dist folder, matching auth server configuration in %s', grunt.config('auth_config'));
grunt.log.writeln('If not yet done register client using dist/register_with_anvil_connect.sh. See README.md');
grunt.task.run([
'clean',
'copy:dist',
'chmodScript',
]);
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'connect:livereload',
'watch'
]);
});
};