forked from prototypejs/prototype
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGruntfile.js
More file actions
142 lines (118 loc) · 3.23 KB
/
Gruntfile.js
File metadata and controls
142 lines (118 loc) · 3.23 KB
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
function stripcomments(src,filepath)
{
var lines = src.split('\n');
var newlines = [];
var opencomment = false;
for( var t = 0 ; t < lines.length ; t++)
{
if(lines[t].match(/^\s*\/\*\*/))
{
opencomment = true;
}
else if(opencomment && lines[t].match(/\*\//))
{
lines[t] = "";
opencomment = false;
}
if(opencomment)
{
lines[t] = "";
}
if(lines[t].match(/^\/\//))
{
lines[t] = "";
}
if(lines[t].length > 0)
{
newlines.push(lines[t]);
}
}
return newlines.join("\n");
}
module.exports = function(grunt) {
var fs = require('fs');
function replacevars()
{
grunt.task.requires('resolve')
var options = grunt.config.get('replacevars');
var contents = fs.readFileSync(options.file,{encoding:'utf8'});
fs.writeFileSync(options.file,contents.replace(/<%= PROTOTYPE_VERSION %>/g,options.PROTOTYPE_VERSION))
}
function closure_compile()
{
var done = this.async();
var options = grunt.config.get('gcc_rest');
ClosureCompiler.compile(
[options.source],
{
compilation_level: "SIMPLE_OPTIMIZATIONS",
},
function(error, result) {
if (result) {
fs.writeFile(options.dest,result)
} else {
// Display error...
}
done();
}
);
}
function generate_docs()
{
var parseObject = require('./test/docparser.js');
var results = parseObject.parse();
console.log(results);
}
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
PROTOTYPE_VERSION : grunt.file.readYAML('src/constants.yml'),
resolve : {
files : ['src/prototype.js'],
dist : 'dist'
},
replacevars : {
file : 'dist/prototype.js',
PROTOTYPE_VERSION : '<%= PROTOTYPE_VERSION.PROTOTYPE_VERSION %>'
},
gcc_rest : {
source : 'dist/prototype.js',
dest : 'dist/prototype.min.js'
},
concat : {
options : {
process : stripcomments,
banner : "/**\n * @preserve\n * Prototype JavaScript framework, version <%= PROTOTYPE_VERSION.PROTOTYPE_VERSION %>\n * (c) 2005-2010 Sam Stephenson\n *\n * Prototype is freely distributable under the terms of an MIT-style license.\n * For details, see the Prototype web site: http://www.prototypejs.org/\n *\n *--------------------------------------------------------------------------*/\n"
},
dist : {
src : ['dist/prototype.js'],
dest : 'dist/prototype.js'
}
},
mocha_phantomjs : {
all : {
options : {
'urls' : [ 'http://localhost:1337/test/ajaxtests.html',
'http://localhost:1337/test/formtests.html' ]
},
src : ['test/index.html',
'test/domtests.html',
'test/selectortests.html',
'test/layouttests.html']
}
}
});
grunt.loadNpmTasks('grunt-resolve');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
grunt.registerTask('replacevars','Replace Variables in PrototypeJS file',replacevars);
grunt.registerTask('runwebserver',"Run Test Webserver",function(){
var done = this.async();
require('./test/webserver.js').listen(1337, '127.0.0.1',function(){
grunt.log.writeln('Web server Started on port 1337.');
done();
});
})
grunt.registerTask('test', ['runwebserver','mocha_phantomjs']);
grunt.registerTask('dist', ['resolve','replacevars','concat']);
grunt.registerTask('default',['test','dist'])
};