This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
129 lines (122 loc) · 5.15 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
/**
* This build file is for development only. You probably want to ignore it when using this repo as a library.
*/
/*jshint node:true*/
"use strict";
module.exports = function( grunt ) {
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
connect: {
server: {
options: {
port: 8080,
base: ''
}
}
},
jsbeautifier: {
test: {
src: [ "*.js", "src/js/*.js" ],
options: {
config: "./.jsbeautifyrc",
mode: "VERIFY_ONLY"
}
},
fix: {
src: [ "*.js", "src/js/*.js" ],
options: {
config: "./.jsbeautifyrc"
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [ '*.js', 'src/js/**/*.js' ]
},
watch: {
sass: {
files: [ 'src/**/*.scss', 'lib/enketo-core/src/**/*.scss' ],
tasks: [ 'style' ],
options: {
spawn: false
}
}
},
prepWidgetSass: {
writePath: 'src/sass/_widgets.scss',
widgetConfigPath: 'config.json'
},
sass: {
dist: {
options: {
style: 'compact'
},
files: {
'build/css/dristhi.css': 'src/sass/dristhi.scss'
}
}
},
// this compiles all javascript to a single minified file
requirejs: {
compile: {
options: {
name: '../../main',
baseUrl: 'src/js',
mainConfigFile: "main.js",
findNestedDependencies: true,
exclude: [ 'mockForms' ],
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 [ '../../lib/enketo-core/lib/require.js', 'enketo-js/Widget' ].concat( widgets );
} )(),
out: "build/js/enketo-dristhi-combined.min.js",
optimize: "uglify2"
}
}
}
} );
grunt.loadNpmTasks( 'grunt-contrib-connect' );
grunt.loadNpmTasks( 'grunt-jsbeautifier' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-contrib-requirejs' );
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/sass
widgetSassPath = widgetFolderPath.replace( /^enketo-widget\//, '../../lib/enketo-core/src/widget/' );
//create path to widget config file
widgetConfigPath = widgetFolderPath.replace( /^enketo-widget\//, 'lib/enketo-core/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( 'test', [ 'jasmine' ] );
grunt.registerTask( 'default', [ 'uglify', 'sass', 'test' ] );
grunt.registerTask( 'style', [ 'prepWidgetSass', 'sass' ] );
grunt.registerTask( 'compile', [ 'requirejs:compile' ] );
grunt.registerTask( 'server', [ 'connect:server:keepalive' ] );
grunt.registerTask( 'test', [ 'jsbeautifier:test', 'jshint', 'compile' ] );
grunt.registerTask( 'default', [ 'jsbeautifier:test', 'jshint', 'style', 'compile' ] );
};