Skip to content

Commit 79b51d5

Browse files
geddskiIgorMinar
authored andcommittedMar 6, 2013
chore(Grunt): switch from Rake to Grunt
Migrates the Angular project from Rake to Grunt. Benefits: - Drops Ruby dependency - Lowers barrier to entry for contributions from JavaScript ninjas - Simplifies the Angular project setup and build process - Adopts industry-standard tools specific to JavaScript projects - Support building angular.js on Windows platform (really?!? why?!?) BREAKING CHANGE: Rake is completely replaced by Grunt. Below are the deprecated Rake tasks and their Grunt equivalents: rake --> grunt rake package --> grunt package rake init --> N/A rake clean --> grunt clean rake concat_scenario --> grunt build:scenario rake concat --> grunt build rake concat_scenario --> grunt build:scenario rake minify --> grunt minify rake version --> grunt write:version rake docs --> grunt docs rake webserver --> grunt webserver rake test --> grunt test rake test:unit --> grunt test:unit rake test:<jqlite|jquery|modules|e2e> --> grunt test:<jqlite|jquery|modules|end2end|e2e> rake test[Firefox+Safari] --> grunt test --browsers Firefox,Safari rake test[Safari] --> grunt test --browsers Safari rake autotest --> grunt autotest NOTES: * For convenience grunt test:e2e starts a webserver for you, while grunt test:end2end doesn't. Use grunt test:end2end if you already have the webserver running. * Removes duplicate entry for Describe.js in the angularScenario section of angularFiles.js * Updates docs/src/gen-docs.js to use #done intead of the deprecated #end * Uses grunt-contrib-connect instead of lib/nodeserver (removed) * Removes nodeserver.sh, travis now uses grunt webserver * Built and minified files are identical to Rake's output, with the exception of one less character for git revisions (using --short) and a couple minor whitespace differences Closes angular#199
1 parent fe8d893 commit 79b51d5

18 files changed

+468
-682
lines changed
 

‎.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ node_js:
55
before_script:
66
- export DISPLAY=:99.0
77
- sh -e /etc/init.d/xvfb start
8-
- npm install -g testacular@canary
9-
- rake package
10-
- ./nodeserver.sh > /dev/null &
8+
- npm install -g grunt-cli
9+
- grunt package
10+
- grunt webserver > /dev/null &
1111

1212
script:
13-
- rake test[Firefox,"--reporters=dots"]
13+
- grunt test --browsers Firefox --reporters=dots

‎Gruntfile.js

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
var files = require('./angularFiles').files;
2+
var util = require('./lib/grunt/utils.js');
3+
4+
module.exports = function(grunt) {
5+
//grunt plugins
6+
grunt.loadNpmTasks('grunt-contrib-clean');
7+
grunt.loadNpmTasks('grunt-contrib-copy');
8+
grunt.loadNpmTasks('grunt-contrib-connect');
9+
grunt.loadNpmTasks('grunt-contrib-compress');
10+
grunt.loadTasks('lib/grunt');
11+
12+
var NG_VERSION = util.getVersion();
13+
14+
15+
//global beforeEach
16+
util.init();
17+
18+
19+
//config
20+
grunt.initConfig({
21+
NG_VERSION: NG_VERSION,
22+
23+
connect: {
24+
devserver: {
25+
options: {
26+
port: 8000,
27+
hostname: 'localhost',
28+
base: '.',
29+
keepalive: true,
30+
middleware: function(connect, options){
31+
return [
32+
//uncomment to enable CSP
33+
// util.csp(),
34+
util.rewrite(),
35+
connect.favicon('images/favicon.ico'),
36+
connect.static(options.base),
37+
connect.directory(options.base)
38+
];
39+
}
40+
}
41+
},
42+
testserver: {}
43+
},
44+
45+
46+
test: {
47+
jqlite: 'testacular-jqlite.conf.js',
48+
jquery: 'testacular-jquery.conf.js',
49+
modules: 'testacular-modules.conf.js',
50+
//NOTE run grunt test:e2e instead and it will start a webserver for you
51+
end2end: 'testacular-e2e.conf.js'
52+
},
53+
54+
55+
autotest: {
56+
jqlite: 'testacular-jqlite.conf.js',
57+
jquery: 'testacular-jquery.conf.js'
58+
},
59+
60+
61+
clean: {build: ['build']},
62+
63+
64+
build: {
65+
scenario: {
66+
dest: 'build/angular-scenario.js',
67+
src: [
68+
'lib/jquery/jquery.js',
69+
util.wrap([files['angularSrc'], files['angularScenario']], 'ngScenario/angular')
70+
],
71+
styles: {
72+
css: ['css/angular.css', 'css/angular-scenario.css']
73+
}
74+
},
75+
angular: {
76+
dest: 'build/angular.js',
77+
src: util.wrap([files['angularSrc']], 'angular'),
78+
styles: {
79+
css: ['css/angular.css'],
80+
minify: true
81+
}
82+
},
83+
loader: {
84+
dest: 'build/angular-loader.js',
85+
src: util.wrap(['src/loader.js'], 'loader')
86+
},
87+
mocks: {
88+
dest: 'build/angular-mocks.js',
89+
src: ['src/ngMock/angular-mocks.js'],
90+
strict: false
91+
},
92+
sanitize: {
93+
dest: 'build/angular-sanitize.js',
94+
src: util.wrap([
95+
'src/ngSanitize/sanitize.js',
96+
'src/ngSanitize/directive/ngBindHtml.js',
97+
'src/ngSanitize/filter/linky.js',
98+
], 'module')
99+
},
100+
resource: {
101+
dest: 'build/angular-resource.js',
102+
src: util.wrap(['src/ngResource/resource.js'], 'module')
103+
},
104+
cookies: {
105+
dest: 'build/angular-cookies.js',
106+
src: util.wrap(['src/ngCookies/cookies.js'], 'module')
107+
},
108+
bootstrap: {
109+
dest: 'build/angular-bootstrap.js',
110+
src: util.wrap(['src/bootstrap/bootstrap.js'], 'module')
111+
},
112+
bootstrapPrettify: {
113+
dest: 'build/angular-bootstrap-prettify.js',
114+
src: util.wrap(['src/bootstrap/bootstrap-prettify.js', 'src/bootstrap/google-prettify/prettify.js'], 'module'),
115+
styles: {
116+
css: ['src/bootstrap/google-prettify/prettify.css'],
117+
minify: true
118+
}
119+
}
120+
},
121+
122+
123+
min: {
124+
angular: 'build/angular.js',
125+
cookies: 'build/angular-cookies.js',
126+
loader: 'build/angular-loader.js',
127+
resource: 'build/angular-resource.js',
128+
sanitize: 'build/angular-sanitize.js',
129+
bootstrap: 'build/angular-bootstrap.js',
130+
bootstrapPrettify: 'build/angular-bootstrap-prettify.js',
131+
},
132+
133+
134+
docs: {
135+
process: ['build/docs/*.html', 'build/docs/.htaccess']
136+
},
137+
138+
139+
copy: {
140+
i18n: {
141+
files: [
142+
{ src: 'src/ngLocale/**', dest: 'build/i18n/', expand: true, flatten: true }
143+
]
144+
}
145+
},
146+
147+
148+
compress: {
149+
build: {
150+
options: {archive: 'build/angular-'+ NG_VERSION.full +'.zip'},
151+
src: ['**'], cwd: 'build', expand: true
152+
}
153+
},
154+
155+
156+
write: {
157+
versionTXT: {file: 'build/version.txt', val: NG_VERSION.full},
158+
versionJSON: {file: 'build/version.json', val: JSON.stringify(NG_VERSION)}
159+
}
160+
});
161+
162+
163+
//alias tasks
164+
grunt.registerTask('test:unit', ['test:jqlite', 'test:jquery', 'test:modules']);
165+
grunt.registerTask('minify', ['clean', 'build', 'minall']);
166+
grunt.registerTask('test:e2e', ['connect:testserver', 'test:end2end']);
167+
grunt.registerTask('webserver', ['connect:devserver']);
168+
grunt.registerTask('package', ['clean', 'buildall', 'minall', 'docs', 'copy', 'write', 'compress']);
169+
grunt.registerTask('default', ['package']);
170+
};

‎README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,19 @@ Building AngularJS
2121
---------
2222
[Once you have your environment setup](http://docs.angularjs.org/misc/contribute) just run:
2323

24-
rake package
24+
grunt package
2525

2626

2727
Running Tests
2828
-------------
2929
To execute all unit tests, use:
3030

31-
rake test:unit
31+
grunt test:unit
3232

3333
To execute end-to-end (e2e) tests, use:
3434

35-
rake package
36-
rake webserver &
37-
rake test:e2e
35+
grunt package
36+
grunt test:e2e
3837

39-
To learn more about the rake tasks, run `rake -T` and also read our
40-
[contribution guidelines](http://docs.angularjs.org/misc/contribute) and instructions in this
41-
[commit message](https://github.com/angular/angular.js/commit/9d168f058f9c6d7eeae0daa7cb72ea4e02a0003a).
38+
To learn more about the grunt tasks, run `grunt --help` and also read our
39+
[contribution guidelines](http://docs.angularjs.org/misc/contribute).

‎Rakefile

Lines changed: 0 additions & 355 deletions
This file was deleted.

‎check-size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
rake minify
3+
grunt minify
44
gzip -c < build/angular.min.js > build/angular.min.js.gzip
55
ls -l build/angular.min.*

‎docs/content/misc/contribute.ngdoc

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,11 @@ Several steps are needed to check out and build AngularJS:
8181
Before you can build AngularJS, you must install or configure the following dependencies on your
8282
machine:
8383

84-
* {@link http://rake.rubyforge.org Rake}: We use Rake as our build system, which is pre-installed
85-
on most Macintosh and Linux machines. If that is not true in your case, you can grab it from the
86-
Rake website.
87-
8884
* Git: The {@link http://help.github.com/mac-git-installation Github Guide to Installing Git} is
8985
quite a good source for information on Git.
9086

91-
* {@link http://nodejs.org Node.js}: We use Node to generate the documentation and to run a
92-
development web server. Depending on your system, you can install Node either from source or as a
87+
* {@link http://nodejs.org Node.js}: We use Node to generate the documentation, run a
88+
development web server, run tests, and generate a build. Depending on your system, you can install Node either from source or as a
9389
pre-packaged bundle.
9490

9591
Once installed, you'll also need several npms (node packages), which you can install once you checked out a local copy
@@ -98,6 +94,10 @@ pre-packaged bundle.
9894
* `cd angular.js`
9995
* `npm install`
10096

97+
* {@link http://gruntjs.com Grunt}: We use Grunt as our build system. Install the grunt command-line tool globally with:
98+
99+
* `sudo npm install -g grunt-cli`
100+
101101

102102
## Creating a Github Account and Forking Angular
103103

@@ -108,7 +108,7 @@ https://github.com/angular/angular.js main angular repository}.
108108

109109
## Building AngularJS
110110

111-
To build AngularJS, you check out the source code and use Rake to generate the non-minified and
111+
To build AngularJS, you check out the source code and use Grunt to generate the non-minified and
112112
minified AngularJS files:
113113

114114
1. To clone your Github repository, run:
@@ -129,7 +129,7 @@ minified AngularJS files:
129129

130130
5. To build AngularJS, run:
131131

132-
rake package
132+
grunt package
133133

134134
The build output can be located under the `build` directory. It consists of the following files and
135135
directories:
@@ -158,7 +158,7 @@ made available a local web server based on Node.js.
158158

159159
1. To start the web server, run:
160160

161-
rake webserver
161+
grunt webserver
162162

163163
2. To access the local server, go to this website:
164164

@@ -173,18 +173,20 @@ made available a local web server based on Node.js.
173173
Our unit and integration tests are written with Jasmine and executed with Testacular. To run all of the
174174
tests once on Chrome run:
175175

176-
rake test:unit
176+
grunt test:unit
177177

178178
To run the tests on other browsers (Chrome, ChromeCanary, Firefox, Opera and Safari are pre-configured) use:
179179

180-
rake test:unit[Opera+Firefox]
180+
grunt test:unit --browsers Opera,Firefox
181+
182+
Note there should be _no spaces between browsers_. `Opera, Firefox` is INVALID.
181183

182184
During development it's however more productive to continuously run unit tests every time the source or test files
183185
change. To execute tests in this mode run:
184186

185187
1. To start the Testacular server, capture Chrome browser and run unit tests, run:
186188

187-
rake autotest:jqlite
189+
grunt autotest:jqlite
188190

189191
2. To capture more browsers, open this url in the desired browser (url might be different if you have multiple instance
190192
of Testacular running, read Testacular's console output for the correct url):
@@ -194,9 +196,9 @@ change. To execute tests in this mode run:
194196
3. To re-run tests just change any source or test file.
195197

196198

197-
To learn more about all of the preconfigured Rake tasks run:
199+
To learn more about all of the preconfigured Grunt tasks run:
198200

199-
rake -T
201+
grunt --help
200202

201203

202204
## Running the end-to-end Test Suite
@@ -205,15 +207,21 @@ To run the E2E test suite:
205207

206208
1. Start the local web server if it's not running already.
207209

208-
rake webserver
210+
grunt webserver
209211

210212
2. In a browser, go to:
211213

212214
http://localhost:8000/build/docs/docs-scenario.html
213215

214216
or in terminal run:
215217

216-
rake test:e2e
218+
grunt test:end2end
219+
220+
For convenience you can also simply run:
221+
222+
grunt test:e2e
223+
224+
This will start the webserver for you and run the tests.
217225

218226

219227

‎docs/src/gen-docs.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ var reader = require('./reader.js'),
55
appCache = require('./appCache.js').appCache,
66
Q = require('qq');
77

8-
process.on('uncaughtException', function(err) {
9-
console.error(err.stack || err);
10-
});
11-
128
var start = now();
139
var docs;
1410

@@ -42,10 +38,10 @@ writer.makeDir('build/docs/', true).then(function() {
4238
function writeTheRest(writesFuture) {
4339
var metadata = ngdoc.metadata(docs);
4440

45-
writesFuture.push(writer.symlinkTemplate('css'));
46-
writesFuture.push(writer.symlinkTemplate('font'));
47-
writesFuture.push(writer.symlink('../../docs/img', 'build/docs/img'));
48-
writesFuture.push(writer.symlinkTemplate('js'));
41+
writesFuture.push(writer.symlinkTemplate('css', 'dir'));
42+
writesFuture.push(writer.symlinkTemplate('font', 'dir'));
43+
writesFuture.push(writer.symlink('../../docs/img', 'build/docs/img', 'dir'));
44+
writesFuture.push(writer.symlinkTemplate('js', 'dir'));
4945

5046
var manifest = 'manifest="/build/docs/appcache.manifest"';
5147

‎docs/src/ngdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Doc.prototype = {
203203
flush();
204204
this.shortName = this.name.split(/[\.:#]/).pop().trim();
205205
this.id = this.id || // if we have an id just use it
206-
(((this.file||'').match(/.*\/([^\/]*)\.ngdoc/)||{})[1]) || // try to extract it from file name
206+
(((this.file||'').match(/.*(\/|\\)([^(\/|\\)]*)\.ngdoc/)||{})[2]) || // try to extract it from file name
207207
this.name; // default to name
208208
this.description = this.markdown(this.description);
209209
this.example = this.markdown(this.example);

‎docs/src/reader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ exports.collect = collect;
77

88
var ngdoc = require('./ngdoc.js'),
99
Q = require('qq'),
10-
qfs = require('q-fs');
10+
qfs = require('q-fs'),
11+
PATH = require('path');
1112

1213
var NEW_LINE = /\n\r?/;
1314

@@ -43,7 +44,7 @@ function collect() {
4344
var work2;
4445
if (file.match(/\.ngdoc$/)) {
4546
work2 = Q.when(qfs.read(file, 'b'), function(content){
46-
var section = '@section ' + file.split('/')[2] + '\n';
47+
var section = '@section ' + file.split(PATH.sep)[2] + '\n';
4748
allDocs.push(new ngdoc.Doc(section + content.toString(),file, 1).parse());
4849
});
4950
}

‎docs/src/templates/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# current angular version. If this rule matches the appcache-offline.manifest will be served for
55
# requests to appcache.manifest
66
#
7-
# This file must be processed by Rake in order to replace %ANGULAR_VERSION% with the actual version.
7+
# This file must be processed by Grunt in order to replace %ANGULAR_VERSION% with the actual version.
88

99
Options -Indexes
1010
RewriteEngine on

‎docs/src/writer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,21 @@ exports.copy = function(from, to, transform) {
6161

6262

6363
exports.symlink = symlink;
64-
function symlink(from, to) {
64+
function symlink(from, to, type) {
6565
return qfs.exists(to).then(function(exists) {
6666
if (!exists) {
67-
return qfs.symbolicLink(to, from);
67+
return qfs.symbolicLink(to, from, type);
6868
}
6969
});
7070
}
7171

7272

7373
exports.symlinkTemplate = symlinkTemplate;
74-
function symlinkTemplate(filename) {
74+
function symlinkTemplate(filename, type) {
7575
var dest = OUTPUT_DIR + filename,
7676
dirDepth = dest.split('/').length,
7777
src = Array(dirDepth).join('../') + 'docs/src/templates/' + filename;
78-
79-
return symlink(src, dest);
78+
return symlink(src, dest, type);
8079
}
8180

8281

File renamed without changes.

‎lib/grunt/plugins.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var util = require('./utils.js');
2+
var spawn = require('child_process').spawn;
3+
4+
module.exports = function(grunt) {
5+
6+
grunt.registerMultiTask('min', 'minify JS files', function(){
7+
util.min.call(util, this.data, this.async());
8+
});
9+
10+
11+
grunt.registerTask('minall', 'minify all the JS files in parallel', function(){
12+
var files = grunt.config('min');
13+
files = Object.keys(files).map(function(key){ return files[key]; });
14+
grunt.util.async.forEach(files, util.min.bind(util), this.async());
15+
});
16+
17+
18+
grunt.registerMultiTask('build', 'build JS files', function(){
19+
util.build.call(util, this.data, this.async());
20+
});
21+
22+
23+
grunt.registerTask('buildall', 'build all the JS files in parallel', function(){
24+
var builds = grunt.config('build');
25+
builds = Object.keys(builds).map(function(key){ return builds[key]; });
26+
grunt.util.async.forEach(builds, util.build.bind(util), this.async());
27+
});
28+
29+
30+
grunt.registerMultiTask('write', 'write content to a file', function(){
31+
grunt.file.write(this.data.file, this.data.val);
32+
grunt.log.ok('wrote to ' + this.data.file);
33+
});
34+
35+
36+
grunt.registerMultiTask('docs', 'create angular docs', function(){
37+
var done = this.async();
38+
var files = this.data;
39+
var docs = spawn('node', ['docs/src/gen-docs.js']);
40+
docs.stdout.pipe(process.stdout);
41+
docs.stderr.pipe(process.stderr);
42+
docs.on('exit', function(code){
43+
if(code !== 0) grunt.fail.warn('Error creating docs');
44+
grunt.file.expand(files).forEach(function(file){
45+
grunt.file.write(file, util.process(grunt.file.read(file), grunt.config('NG_VERSION'), false));
46+
});
47+
grunt.log.ok('docs created');
48+
done();
49+
});
50+
});
51+
52+
53+
grunt.registerMultiTask('test', 'Run the unit tests with testacular', function(){
54+
util.startTestacular.call(util, this.data, true, this.async());
55+
});
56+
57+
58+
grunt.registerMultiTask('autotest', 'Run and watch the unit tests with testacular', function(){
59+
util.startTestacular.call(util, this.data, false, this.async());
60+
});
61+
};

‎lib/grunt/utils.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
var fs = require('fs');
2+
var shell = require('shelljs');
3+
var yaml = require('yaml-js');
4+
var grunt = require('grunt');
5+
var spawn = require('child_process').spawn;
6+
7+
module.exports = {
8+
9+
init: function() {
10+
shell.exec('npm install');
11+
},
12+
13+
14+
getVersion: function(){
15+
var versionYaml = yaml.load(fs.readFileSync('version.yaml', 'UTF-8'));
16+
var match = versionYaml.version.match(/^([^\-]*)(-snapshot)?$/);
17+
var semver = match[1].split('.');
18+
var hash = shell.exec('git rev-parse --short HEAD', {silent: true}).output.replace('\n', '');
19+
20+
var version = {
21+
full: (match[1] + (match[2] ? '-' + hash : '')),
22+
major: semver[0],
23+
minor: semver[1],
24+
dot: semver[2],
25+
codename: versionYaml.codename,
26+
stable: versionYaml.stable
27+
};
28+
29+
return version;
30+
},
31+
32+
33+
startTestacular: function(config, singleRun, done){
34+
var browsers = grunt.option('browsers');
35+
var reporters = grunt.option('reporters');
36+
var noColor = grunt.option('no-colors');
37+
var p = spawn('node', ['node_modules/testacular/bin/testacular', 'start', config,
38+
singleRun ? '--single-run=true' : '',
39+
reporters ? '--reporters=' + reporters : '',
40+
browsers ? '--browsers=' + browsers : '',
41+
noColor ? '--no-colors' : ''
42+
]);
43+
p.stdout.pipe(process.stdout);
44+
p.stderr.pipe(process.stderr);
45+
p.on('exit', function(code){
46+
if(code !== 0) grunt.fail.warn("Test(s) failed");
47+
done();
48+
});
49+
},
50+
51+
52+
wrap: function(src, name){
53+
src.unshift('src/' + name + '.prefix');
54+
src.push('src/' + name + '.suffix');
55+
return src;
56+
},
57+
58+
59+
addStyle: function(src, styles, minify){
60+
styles = styles.map(processCSS.bind(this)).join('\n');
61+
src += styles;
62+
return src;
63+
64+
function processCSS(file){
65+
var css = fs.readFileSync(file).toString();
66+
if(minify){
67+
css = css
68+
.replace(/\n/g, '')
69+
.replace(/\/\*.*?\*\//g, '')
70+
.replace(/:\s+/g, ':')
71+
.replace(/\s*\{\s*/g, '{')
72+
.replace(/\s*\}\s*/g, '}')
73+
.replace(/\s*\,\s*/g, ',')
74+
.replace(/\s*\;\s*/g, ';');
75+
}
76+
//espace for js
77+
css = css
78+
.replace(/\\/g, '\\\\')
79+
.replace(/'/g, "\\'")
80+
.replace(/\n/g, '\\n');
81+
return "angular.element(document).find('head').append('<style type=\"text/css\">" + css + "</style>');";
82+
}
83+
},
84+
85+
86+
process: function(src, NG_VERSION, strict){
87+
var processed = src
88+
.replace(/"NG_VERSION_FULL"/g, NG_VERSION.full)
89+
.replace(/"NG_VERSION_MAJOR"/, NG_VERSION.major)
90+
.replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor)
91+
.replace(/"NG_VERSION_DOT"/, NG_VERSION.dot)
92+
.replace(/"NG_VERSION_STABLE"/, NG_VERSION.stable)
93+
.replace(/"NG_VERSION_CODENAME"/, NG_VERSION.codename);
94+
if (strict !== false) processed = this.singleStrict(processed, '\n\n', true);
95+
return processed;
96+
},
97+
98+
99+
build: function(config, fn){
100+
var files = grunt.file.expand(config.src);
101+
var styles = config.styles;
102+
//concat
103+
var src = files.map(function(filepath){
104+
return grunt.file.read(filepath);
105+
}).join(grunt.util.normalizelf('\n'));
106+
//process
107+
var processed = this.process(src, grunt.config('NG_VERSION'), config.strict);
108+
if (styles) processed = this.addStyle(processed, styles.css, styles.minify);
109+
//write
110+
grunt.file.write(config.dest, processed);
111+
grunt.log.ok('File ' + config.dest + ' created.');
112+
fn();
113+
},
114+
115+
116+
singleStrict: function(src, insert, newline){
117+
var useStrict = newline ? "$1\n'use strict';" : "$1'use strict';";
118+
return src
119+
.replace(/\s*("|')use strict("|');\s*/g, insert) // remove all file-specific strict mode flags
120+
.replace(/(\(function\([^)]*\)\s*\{)/, useStrict); // add single strict mode flag
121+
},
122+
123+
124+
min: function(file, done) {
125+
var minFile = file.replace(/\.js$/, '.min.js');
126+
shell.exec(
127+
'java ' +
128+
this.java32flags() + ' ' +
129+
'-jar lib/closure-compiler/compiler.jar ' +
130+
'--compilation_level SIMPLE_OPTIMIZATIONS ' +
131+
'--language_in ECMASCRIPT5_STRICT ' +
132+
'--js ' + file + ' ' +
133+
'--js_output_file ' + minFile,
134+
function(code) {
135+
if (code !== 0) grunt.fail.warn('Error minifying ' + file);
136+
grunt.file.write(minFile, this.singleStrict(grunt.file.read(minFile), '\n'));
137+
grunt.log.ok(file + ' minified into ' + minFile);
138+
done();
139+
}.bind(this));
140+
},
141+
142+
143+
//returns the 32-bit mode force flags for java compiler if supported, this makes the build much faster
144+
java32flags: function(){
145+
if (process.platform === "win32") return '';
146+
if (shell.exec('java -version -d32 2>&1', {silent: true}).code !== 0) return '';
147+
return ' -d32 -client';
148+
},
149+
150+
151+
//csp connect middleware
152+
csp: function(){
153+
return function(req, res, next){
154+
res.setHeader("X-WebKit-CSP", "default-src 'self';");
155+
res.setHeader("X-Content-Security-Policy", "default-src 'self'");
156+
next();
157+
};
158+
},
159+
160+
161+
//rewrite connect middleware
162+
rewrite: function(){
163+
return function(req, res, next){
164+
var REWRITE = /\/(guide|api|cookbook|misc|tutorial).*$/,
165+
IGNORED = /(\.(css|js|png|jpg)$|partials\/.*\.html$)/,
166+
match;
167+
168+
if (!IGNORED.test(req.url) && (match = req.url.match(REWRITE))) {
169+
console.log('rewriting', req.url);
170+
req.url = req.url.replace(match[0], '/index.html');
171+
}
172+
next();
173+
};
174+
}
175+
};

‎lib/nodeserver/server.js

Lines changed: 0 additions & 273 deletions
This file was deleted.

‎nodeserver.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"name": "AngularJS",
33
"version": "0.0.0",
4-
"dependencies" : {
5-
"testacular" : "0.5.9",
6-
"jasmine-node" : "1.2.3",
7-
"q-fs" : "0.1.36",
8-
"qq" : "0.3.5"
4+
"dependencies": {
5+
"testacular": "0.5.9",
6+
"jasmine-node": "1.2.3",
7+
"q-fs": "0.1.36",
8+
"qq": "0.3.5",
9+
"grunt": "0.4.0",
10+
"grunt-contrib-clean": "0.4.0",
11+
"grunt-contrib-copy": "0.4.0",
12+
"grunt-contrib-connect": "0.1.2",
13+
"grunt-contrib-compress": "0.4.1",
14+
"shelljs": "0.1.2",
15+
"yaml-js": "0.0.5"
916
}
1017
}

‎src/AngularPublic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat".
1515
*/
1616
var version = {
17-
full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by rake's
18-
major: "NG_VERSION_MAJOR", // compile task
17+
full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by grunt's
18+
major: "NG_VERSION_MAJOR", // package task
1919
minor: "NG_VERSION_MINOR",
2020
dot: "NG_VERSION_DOT",
2121
codeName: '"NG_VERSION_CODENAME"'

0 commit comments

Comments
 (0)
Please sign in to comment.