forked from enketo/enketo-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
183 lines (174 loc) · 6.58 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* When using enketo-core in your own app, you'd want to replace
* this build file with one of your own in your project root.
*/
/*jshint node:true*/
"use strict";
module.exports = function( grunt ) {
var js;
// show elapsed time at the end
require( 'time-grunt' )( grunt );
// load all grunt tasks
require( 'load-grunt-tasks' )( grunt );
// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
concurrent: {
develop: {
tasks: [ 'connect:server:keepalive', 'watch' ],
options: {
logConcurrentOutput: true
}
}
},
connect: {
server: {
options: {
port: 8080
}
},
test: {
options: {
port: 8000
}
}
},
jsbeautifier: {
test: {
src: [ "*.js", "src/js/*.js", "src/widget/*/*.js" ],
options: {
config: "./.jsbeautifyrc",
mode: "VERIFY_ONLY"
}
},
fix: {
src: [ "*.js", "src/js/*.js", "src/widget/*/*.js" ],
options: {
config: "./.jsbeautifyrc"
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [ '*.js', 'src/js/**/*.js', '!src/js/extern.js' ]
},
watch: {
sass: {
files: [ 'config.json', 'grid/sass/**/*.scss', 'src/sass/**/*.scss', 'src/widget/**/*.scss' ],
tasks: [ 'style' ],
options: {
spawn: true,
livereload: true,
}
},
js: {
files: [ '*.js', 'src/**/*.js' ],
tasks: [ 'modernizr' ],
options: {
spawn: false,
livereload: true
}
}
},
karma: {
options: {
singleRun: true,
reporters: [ 'dots' ]
},
headless: {
configFile: 'test/karma.conf.js',
browsers: [ 'PhantomJS' ]
},
browsers: {
configFile: 'test/karma.conf.js',
browsers: [ 'Chrome', 'ChromeCanary', /*'Firefox'*/ /*, 'Opera',*/ 'Safari' ]
}
},
prepWidgetSass: {
writePath: 'src/sass/core/_widgets.scss',
widgetConfigPath: 'config.json'
},
sass: {
compile: {
cwd: 'src/sass',
dest: 'build/css',
expand: true,
outputStyle: 'expanded',
src: '**/*.scss',
ext: '.css',
flatten: true,
extDot: 'last'
}
},
// this compiles all javascript to a single minified file
requirejs: {
compile: {
options: {
name: '../app',
baseUrl: './lib',
mainConfigFile: 'require-config.js',
findNestedDependencies: true,
include: ( function() {
//add widgets js and widget config.json files
var widgets = grunt.file.readJSON( 'config.json' ).widgets;
widgets.forEach( function( widget, index, arr ) {
arr.push( 'text!' + widget.substr( 0, widget.lastIndexOf( '/' ) + 1 ) + 'config.json' );
} );
return [ './bower-components/requirejs/require.js' ].concat( widgets );
} )(),
out: "build/js/enketo.min.js",
optimize: "none"
}
}
},
modernizr: {
dist: {
"devFile": "remote",
"outputFile": "lib/Modernizr.js",
"extra": {
"shiv": false,
"printshiv": true,
"load": false,
"mq": false,
"cssclasses": true
},
"uglify": false,
"parseFiles": true
}
}
} );
//maybe this can be turned into a npm module?
grunt.registerTask( 'prepWidgetSass', 'Preparing _widgets.scss dynamically', function() {
var widgetConfig, widgetFolderPath, widgetSassPath, widgetConfigPath,
config = grunt.config( 'prepWidgetSass' ),
widgets = grunt.file.readJSON( config.widgetConfigPath ).widgets,
content = '// Dynamically created list of widget stylesheets to import based on the content\r\n' +
'// based on the content of config.json\r\n\r\n';
widgets.forEach( function( widget ) {
if ( widget.indexOf( 'enketo-widget/' ) === 0 ) {
//strip require.js module name
widgetFolderPath = widget.substr( 0, widget.lastIndexOf( '/' ) + 1 );
//replace widget require.js path shortcut with proper path relative to src/js
widgetSassPath = widgetFolderPath.replace( /^enketo-widget\//, '../../widget/' );
//create path to widget config file
widgetConfigPath = widgetFolderPath.replace( /^enketo-widget\//, 'src/widget/' ) + 'config.json';
grunt.log.writeln( 'widget config path: ' + widgetConfigPath );
//create path to widget stylesheet file
widgetSassPath += grunt.file.readJSON( widgetConfigPath ).stylesheet;
} else {
grunt.log.error( [ 'Expected widget path "' + widget + '" in config.json to be preceded by "widget/".' ] );
}
//replace this by a function that parses config.json in each widget folder to get the 'stylesheet' variable
content += '@import "' + widgetSassPath + '";\r\n';
} );
grunt.file.write( config.writePath, content );
} );
grunt.registerTask( 'compile', [ 'requirejs:compile' ] );
grunt.registerTask( 'test', [ 'modernizr', 'jsbeautifier:test', 'jshint', 'compile', 'karma:headless' ] );
grunt.registerTask( 'style', [ 'prepWidgetSass', 'sass' ] );
grunt.registerTask( 'server', [ 'connect:server:keepalive' ] );
grunt.registerTask( 'develop', [ 'concurrent:develop' ] );
grunt.registerTask( 'default', [ 'prepWidgetSass', 'sass', 'compile' ] );
};