@@ -5,6 +5,8 @@ module.exports = function(grunt) {
5
5
6
6
var exec = require ( 'child_process' ) . exec ;
7
7
var banner = createBanner ( ) ;
8
+ var distPath = 'dist/Autolinker.js' ;
9
+ var minDistPath = 'dist/Autolinker.min.js' ;
8
10
9
11
// Project configuration.
10
12
grunt . initConfig ( {
@@ -29,25 +31,19 @@ module.exports = function(grunt) {
29
31
jasmine : {
30
32
dist : {
31
33
options : {
32
- specs : 'tests/*Spec.js' ,
34
+ specs : 'tests/*Spec.js'
33
35
} ,
34
- src : 'dist/Autolinker.min.js'
36
+ src : minDistPath
35
37
}
36
38
} ,
37
39
38
40
concat : {
39
41
development : {
40
42
options : {
41
- banner : banner + createDistFileHeader ( ) ,
42
- footer : createDistFileFooter ( ) ,
43
- nonull : true ,
44
-
45
- process : function ( src , filepath ) {
46
- return '\t' + src . replace ( / \n / g, '\n\t' ) ; // indent each source file, which is placed inside the UMD block
47
- }
43
+ banner : banner ,
44
+ nonull : true
48
45
} ,
49
46
src : [
50
- 'src/umdBegin.js' ,
51
47
'src/Autolinker.js' ,
52
48
'src/Util.js' ,
53
49
'src/HtmlParser.js' ,
@@ -57,19 +53,18 @@ module.exports = function(grunt) {
57
53
'src/match/Email.js' ,
58
54
'src/match/Twitter.js' ,
59
55
'src/match/Url.js' ,
60
- 'src/umdEnd.js'
61
56
] ,
62
- dest : 'dist/Autolinker.js' ,
63
- } ,
57
+ dest : distPath
58
+ }
64
59
} ,
65
60
66
61
uglify : {
67
62
production : {
68
63
options : {
69
64
banner : banner
70
65
} ,
71
- src : [ 'dist/Autolinker.js' ] ,
72
- dest : 'dist/Autolinker.min.js' ,
66
+ src : [ distPath ] ,
67
+ dest : minDistPath
73
68
}
74
69
} ,
75
70
@@ -88,6 +83,15 @@ module.exports = function(grunt) {
88
83
'title' : 'Autolinker API Docs'
89
84
}
90
85
}
86
+ } ,
87
+
88
+ umd : {
89
+ main : {
90
+ src : distPath ,
91
+ globalAlias : 'Autolinker' , // Changes the name of the global variable
92
+ objectToExport : 'Autolinker' ,
93
+ indent : '\t'
94
+ }
91
95
}
92
96
} ) ;
93
97
@@ -98,16 +102,15 @@ module.exports = function(grunt) {
98
102
grunt . loadNpmTasks ( 'grunt-contrib-uglify' ) ;
99
103
grunt . loadNpmTasks ( 'grunt-contrib-jshint' ) ;
100
104
grunt . loadNpmTasks ( 'grunt-jsduck' ) ;
105
+ grunt . loadNpmTasks ( 'grunt-umd' ) ;
101
106
102
107
// Tasks
103
108
grunt . registerTask ( 'default' , [ 'jshint' , 'build' , 'jasmine' ] ) ;
104
- grunt . registerTask ( 'build' , [ 'concat:development' , 'uglify:production' ] ) ;
109
+ grunt . registerTask ( 'build' , [ 'concat:development' , 'umd' , ' uglify:production' ] ) ;
105
110
grunt . registerTask ( 'test' , [ 'build' , 'jasmine' ] ) ;
106
111
grunt . registerTask ( 'doc' , "Builds the documentation." , [ 'jshint' , 'jsduck' ] ) ;
107
112
grunt . registerTask ( 'serve' , [ 'connect:server:keepalive' ] ) ;
108
113
109
-
110
-
111
114
/**
112
115
* Creates the banner comment with license header that is placed over the concatenated/minified files.
113
116
*
@@ -127,49 +130,4 @@ module.exports = function(grunt) {
127
130
' */\n'
128
131
] . join ( "\n" ) ;
129
132
}
130
-
131
-
132
- /**
133
- * Creates the UMD (Universal Module Definition) header, which defines Autolinker as one of the following when loaded:
134
- *
135
- * 1. An AMD module, if an AMD loader is available (such as RequireJS)
136
- * 2. A CommonJS module, if a CommonJS module environment is available (such as Node.js), or
137
- * 3. A global variable if the others are unavailable.
138
- *
139
- * This UMD header is combined with the UMD footer to create the distribution JavaScript file.
140
- *
141
- * @private
142
- * @return {String }
143
- */
144
- function createDistFileHeader ( ) {
145
- return [
146
- "/*global define, module */" ,
147
- "( function( root, factory ) {" ,
148
- "\tif( typeof define === 'function' && define.amd ) {" ,
149
- "\t\tdefine( factory ); // Define as AMD module if an AMD loader is present (ex: RequireJS)." ,
150
- "\t} else if( typeof exports !== 'undefined' ) {" ,
151
- "\t\tmodule.exports = factory(); // Define as CommonJS module for Node.js, if available." ,
152
- "\t} else {" ,
153
- "\t\troot.Autolinker = factory(); // Finally, define as a browser global if no module loader." ,
154
- "\t}" ,
155
- "}( this, function() {\n\n"
156
- ] . join ( "\n" ) ;
157
- }
158
-
159
-
160
- /**
161
- * Creates the UMD (Universal Module Definition) footer. See {@link #createDistFileHeader} for details.
162
- *
163
- * @private
164
- * @return {String }
165
- */
166
- function createDistFileFooter ( ) {
167
- var umdEnd = [
168
- '\n\n\treturn Autolinker;\n' ,
169
- '} ) );'
170
- ] ;
171
-
172
- return umdEnd . join ( "\n" ) ;
173
- }
174
-
175
133
} ;
0 commit comments