Skip to content

Commit b1a33cc

Browse files
HackManiacphotonstorm
authored andcommitted
Extended Gruntfile to create phaser-fx.js and phaser-fx.amd.js including declarations
1 parent b5b5a99 commit b1a33cc

1 file changed

Lines changed: 82 additions & 36 deletions

File tree

GruntFile.js

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,102 @@ module.exports = function (grunt) {
33
grunt.loadNpmTasks('grunt-contrib-watch');
44
grunt.loadNpmTasks('grunt-contrib-copy');
55

6+
var wrapPhaserInUmd = function(content, isAddon) {
7+
var replacement = [
8+
'(function (root, factory) {',
9+
' if (typeof exports === \'object\') {',
10+
' module.exports = factory();',
11+
' } else if (typeof define === \'function\' && define.amd) {',
12+
' define(factory);',
13+
' } else {',
14+
' root.Phaser = factory();',
15+
' }',
16+
'}(this, function () {',
17+
content,
18+
'return Phaser;',
19+
'}));'
20+
];
21+
return replacement.join('\n');
22+
};
23+
24+
var wrapAddonInUmd = function(content) {
25+
var replacement = [
26+
'(function (root, factory) {',
27+
' if (typeof exports === \'object\') {',
28+
' module.exports = factory(require(\'phaser\'));',
29+
' } else if (typeof define === \'function\' && define.amd) {',
30+
' define([\'phaser\'], factory);',
31+
' } else {',
32+
' factory(root.Phaser);',
33+
' }',
34+
'}(this, function (Phaser) {',
35+
content,
36+
'return Phaser;',
37+
'}));'
38+
];
39+
return replacement.join('\n');
40+
};
41+
642
grunt.initConfig({
743
pkg: grunt.file.readJSON('package.json'),
844
typescript: {
945
base: {
1046
src: ['Phaser/**/*.ts'],
1147
dest: 'build/phaser.js',
1248
options: {
13-
target: 'ES5'
49+
target: 'ES5',
50+
declaration: true,
51+
comments: true
52+
}
53+
},
54+
fx: {
55+
src: ['SpecialFX/**/*.ts'],
56+
dest: 'build/phaser-fx.js',
57+
options: {
58+
target: 'ES5',
59+
declaration: true,
60+
comments: true
61+
}
62+
}
63+
},
64+
copy: {
65+
main: {
66+
files: [{
67+
src: 'build/phaser.js',
68+
dest: 'Tests/phaser.js'
69+
}]
70+
},
71+
fx: {
72+
files: [{
73+
src: 'build/phaser-fx.js',
74+
dest: 'Tests/phaser-fx.js'
75+
}]
76+
},
77+
mainAmd: {
78+
files: [{
79+
src: 'build/phaser.js',
80+
dest: 'build/phaser.amd.js'
81+
}],
82+
options: {
83+
processContent: wrapPhaserInUmd
84+
}
85+
},
86+
fxAmd: {
87+
files: [{
88+
src: 'build/phaser-fx.js',
89+
dest: 'build/phaser-fx.amd.js'
90+
}],
91+
options: {
92+
processContent: wrapAddonInUmd
1493
}
1594
}
1695
},
17-
copy: {
18-
main: {
19-
files: [{
20-
src: 'build/phaser.js',
21-
dest: 'Tests/phaser.js'
22-
}]
23-
},
24-
amd: {
25-
files: [{
26-
src: 'build/phaser.js',
27-
dest: 'build/phaser.amd.js'
28-
}],
29-
options: {
30-
processContent: function(content) {
31-
var replacement = [
32-
'(function (root, factory) {',
33-
' if (typeof exports === \'object\') {',
34-
' module.exports = factory();',
35-
' } else if (typeof define === \'function\' && define.amd) {',
36-
' define(factory);',
37-
' } else {',
38-
' root.Phaser = factory();',
39-
' }',
40-
'}(this, function () {',
41-
content,
42-
'return Phaser;',
43-
'}));'
44-
];
45-
return replacement.join('\n');
46-
}
47-
}
48-
}
49-
},
50-
watch: {
96+
watch: {
5197
files: '**/*.ts',
5298
tasks: ['typescript', 'copy']
5399
}
54100
});
55101

56-
grunt.registerTask('default', ['watch']);
102+
grunt.registerTask('default', ['typescript', 'copy', 'watch']);
57103

58104
}

0 commit comments

Comments
 (0)