1+ // Gruntfile for building layer including src.js and the jquery modules it references
2+ module . exports = function ( grunt ) {
3+ "use strict" ;
4+
5+ grunt . loadNpmTasks ( "grunt-contrib-clean" ) ;
6+ grunt . loadNpmTasks ( "grunt-contrib-copy" ) ;
7+ grunt . loadNpmTasks ( "grunt-contrib-concat" ) ;
8+ grunt . loadNpmTasks ( "grunt-amd-build" ) ;
9+
10+ var outprop = "amdoutput" ;
11+ var outdir = "./build/" ;
12+ var tmpdir = "./tmp/" ;
13+
14+ grunt . initConfig ( {
15+ amdloader : {
16+ baseUrl : "." ,
17+
18+ paths : {
19+ jquery : "bower_components/jquery" ,
20+ lie : "bower_components/lie" ,
21+ "requirejs-dplugins" : "../../.."
22+ } ,
23+
24+ // Unfortunately this is needed for the jquery plugin.
25+ // It's automatically handled by the plugin itself at runtime, but not during builds.
26+ map : {
27+ "*" : {
28+ "jquery/src/selector" : "jquery/src/selector-native"
29+ }
30+ }
31+ } ,
32+
33+ amdbuild : {
34+ dir : tmpdir ,
35+
36+ // List of layers to build.
37+ layers : [
38+ // Test build for jquery plugin. Should contain main test js file and a few jquery modules.
39+ {
40+ name : "app" ,
41+ include : [
42+ // Modules and layers listed here, and their dependencies, will be added to the layer.
43+ "src"
44+ ]
45+ }
46+ ]
47+ } ,
48+
49+ // Config to allow to concatenate files to generate the layer.
50+ concat : {
51+ options : {
52+ banner : "<%= " + outprop + ".header%>" ,
53+ sourceMap : true
54+ } ,
55+ dist : {
56+ src : "<%= " + outprop + ".modules.abs %>" ,
57+ dest : outdir + "<%= " + outprop + ".layerPath %>"
58+ }
59+ } ,
60+
61+ copy : {
62+ plugins : {
63+ expand : true ,
64+ cwd : tmpdir ,
65+ src : "<%= " + outprop + ".plugins.rel %>" ,
66+ dest : outdir
67+ }
68+ } ,
69+
70+ clean : {
71+ out : [ outdir ] ,
72+ temp : [ tmpdir ]
73+ }
74+ } ) ;
75+
76+ grunt . registerTask ( "amdbuild" , function ( amdloader ) {
77+ var name = this . name , layers = grunt . config ( name ) . layers ;
78+ layers . forEach ( function ( layer ) {
79+ grunt . task . run ( "amddepsscan:" + layer . name + ":" + name + ":" + amdloader ) ;
80+ grunt . task . run ( "amdserialize:" + layer . name + ":" + name + ":" + outprop ) ;
81+ grunt . task . run ( "concat" ) ;
82+ grunt . task . run ( "copy:plugins" ) ;
83+ } ) ;
84+ } ) ;
85+ grunt . registerTask ( "build" , [
86+ "clean:out" ,
87+ "clean:temp" ,
88+ "amdbuild:amdloader"
89+ ] ) ;
90+ } ;
0 commit comments