-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.js
199 lines (172 loc) · 7.4 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
'use strict';
var shell = require('shelljs');
var exec = require('child_process').exec;
var fs = require('fs-extra');
var path = require('path');
var debug = require('debug')('yeoman:generator-grunt-symfony');
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: [
'Gruntfile.js',
'app/index.js',
'test/**/*.js',
'!test/fixtures/**/*.js',
'!test/temp/**/*.js'
],
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
}
},
clean: {
test: [
'test/fixtures/node_modules',
'test/fixtures/bower_components',
'test/fixtures/jspm_packages',
'test/fixtures/composer.phar',
'test/fixtures/app/bootstrap.php.cache',
'test/fixtures/app/check.php',
'test/fixtures/app/SymfonyRequirements.php',
'test/fixtures/vendor'
]
},
simplemocha: {
all: ['test/*.js'],
options: {
reporter: 'spec',
timeout: 600000,
ui: 'bdd'
}
}
});
grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function () {
var done = this.async();
var packageJson = fs.readFileSync(path.resolve('app/templates/_package.json'), 'utf8');
var bowerJson = fs.readFileSync(path.resolve('app/templates/_bower.json'), 'utf8');
var jspmConfig = fs.readFileSync(path.resolve('app/templates/scripts/jspm/config.js'), 'utf8');
// remove all ejs conditionals
packageJson = packageJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
packageJson = packageJson.replace(/<%(.*)%>/g, '');
bowerJson = bowerJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
bowerJson = bowerJson.replace(/<%(.*)%>/g, '');
jspmConfig = jspmConfig.replace(/<%(.*)%>/g, '');
// save files
fs.outputFile(path.resolve(__dirname + '/test/fixtures/package.json'), packageJson, function () {
fs.outputFile(path.resolve(__dirname + '/test/fixtures/bower.json'), bowerJson, function () {
fs.outputFile(path.resolve(__dirname + '/test/fixtures/app/Resources/public/scripts/config.js'), jspmConfig, function () {
done();
});
});
});
});
grunt.registerTask('installNpmFixtures', 'install npm packages', function () {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('installing npm dependencies for generated app');
exec('npm install', {cwd: '../fixtures'}, function () {
grunt.log.ok('installing npm dependencies for generated app (2nd run)');
exec('npm install', {cwd: '../fixtures'}, function () {
shell.cd('../../');
done();
}).stdout.on('data', function(data) {
console.log(data);
});
}).stdout.on('data', function(data) {
console.log(data);
});
});
grunt.registerTask('installBowerFixtures', 'install bower packages', function () {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('installing bower dependencies for generated app');
exec('bower install', {cwd: '../fixtures'}, function () {
shell.cd('../../');
done();
}).stdout.on('data', function(data) {
console.log(data);
});
});
grunt.registerTask('installJspmFixtures', 'install jspm packages', function () {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('installing jspm dependencies for generated app');
exec('npm install --save jspm', {cwd: '../fixtures'}, function () {
exec('node_modules/.bin/jspm install', {cwd: '../fixtures'}, function () {
shell.cd('../../');
done();
}).stdout.on('data', function(data) {
console.log(data);
});
}).stdout.on('data', function(data) {
console.log(data);
});
});
grunt.registerTask('installComposerFixtures', 'install Composer fixtures', function () {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('fetching local composer');
exec('php -r "readfile(\'https://getcomposer.org/installer\');" | php', function() {
grunt.log.ok('installing composer dependencies for generated app');
exec('php composer.phar update --prefer-source --no-interaction --dev ', {cwd: '../fixtures'}, function (error, stdout, stderr) {
debug('stdout: composer.phar update -> ', stdout);
debug('stderr: composer.phar update -> ', stderr);
if (error) {
debug('stderr: composer.phar update -> ', stderr);
}
exec('php composer.phar run-script post-update-cmd --no-interaction ', {cwd: '../fixtures'}, function (error, stdout, stderr) {
debug('stdout: composer.phar run-script -> ', stdout);
debug('stderr: composer.phar run-script -> ', stderr);
if (error) {
debug('stderr: composer.phar run-script -> ', stderr);
}
shell.cd('../../');
done();
}).stdout.on('data', function(data) {
console.log(data);
});
}).stdout.on('data', function(data) {
console.log(data);
});
}).stdout.on('data', function(data) {
console.log(data);
});
});
grunt.registerTask('installFixtures', 'install package and bower fixtures', function () {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('installing jspm dependencies for generated app');
exec('jspm install', {cwd: '../fixtures'}, function (err) {
if (err) {
grunt.log.error(err.message || err);
}
grunt.log.ok('installing bower dependencies for generated app');
exec('bower install', {cwd: '../fixtures'}, function () {
grunt.log.ok('installing npm dependencies for generated app');
exec('npm install', {cwd: '../fixtures'}, function () {
grunt.log.ok('installing comnposer dependencies for generated app');
exec('composer install --no-interaction', {cwd: '../fixtures'}, function () {
grunt.log.ok('installing npm dependencies for generated app (2nd run)');
exec('npm install', {cwd: '../fixtures'}, function () {
shell.cd('../../');
done();
});
});
});
});
});
});
grunt.registerTask('test', [
'clean:test',
'jshint',
'updateFixtures',
'installJspmFixtures',
'installNpmFixtures',
'installBowerFixtures',
'installComposerFixtures',
'simplemocha'
]);
};