-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathGruntfile.js
132 lines (119 loc) · 3.61 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
/**
* Grunt automation.
*
* This is used by the NPM prepublish script in order to update `dist/`,
* which is then published as a separate package (sails.io.js-dist) by the
* postpublish script.
*
* (See `package.json`.)
*
*
* > To test this process without actually publishing anything, use `npm run prepublish`.
*/
module.exports = function(grunt) {
var packageJson = require('./package.json');
var sioClientPackageJson = require('./node_modules/socket.io-client/package.json');
grunt.initConfig({
PATHS: {
eslintEnable: './dependencies/eslint-enable.txt',
eslintDisable: './dependencies/eslint-disable.txt',
amdInstructions: './dependencies/amd_instructions.js',
socketioClient: './dependencies/socket.io.min.js',
header: './.tmp/header.txt',
socketioClientVersion: './dependencies/socket.io-client.version-info.txt',
sailsio: './sails.io.js',
dist: './dist/sails.io.js',
distPackageJson: './dist/package.json',
},
replace: {
main: {
src: '<%= PATHS.sailsio %>',
dest: '<%= PATHS.sailsio %>',
replacements: [{
from: /(var\s+SDK_INFO\s+=\s+{\s*?version:\s+['"])\d+\.\d+\.\d+(['"])/m,
to: '$1' + packageJson.version + '$2'
}]
},
sioClient: {
src: '<%= PATHS.socketioClientVersion %>',
dest: '<%= PATHS.socketioClientVersion %>',
replacements: [{
from: /version .*/,
to: 'version ' + sioClientPackageJson.version
}]
},
distPackageJson: {
src: '<%= PATHS.distPackageJson %>',
dest: '<%= PATHS.distPackageJson %>',
replacements: [{
from: /"version":\s+"\d+\.\d+\.\d+"/m,
to: '"version": "' + packageJson.version + '"'
}]
},
dist: {
src: '<%= PATHS.dist %>',
dest: '<%= PATHS.dist %>',
// Add sails.io.js version string in the fireworks
// at the top of the sails.io.js distributable:
replacements: [{
from: /(\/\*\*\s*\n\s*\*\s*sails\.io\.js)/m,
to: '$1\n \* v' + packageJson.version
}]
}
},
concat: {
header: {
src: [
'<%= PATHS.eslintDisable %>',
'<%= PATHS.amdInstructions %>',
'<%= PATHS.socketioClientVersion %>',
'<%= PATHS.socketioClient %>',
],
dest: '<%= PATHS.header %>'
},
main: {
options: {
separator: ';\n\n',
},
src: [
'<%= PATHS.header %>',
'<%= PATHS.sailsio %>',
'<%= PATHS.eslintEnable %>',
],
dest: '<%= PATHS.dist %>'
}
},
clean: {
main: ['<%= PATHS.header %>', '<%= PATHS.socketioClient %>']
},
uglify: {
main: {
src: ['./node_modules/socket.io-client/dist/socket.io.js'],
dest: '<%= PATHS.socketioClient %>'
}
},
watch: {
files: ['<%= PATHS.sailsio %>', './package.json'],
tasks: ['publish']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['publish']);
// Publish task for copying version numbers and creating dist/sails.io.js
grunt.registerTask('publish', [
'replace:main',
'replace:sioClient',
'uglify',
'concat:header',
'concat:main',
'replace:distPackageJson',
'replace:dist',
'clean'
]);
// Dev task for watching files during development
grunt.registerTask('dev', ['publish', 'watch']);
};