-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
146 lines (136 loc) · 4.39 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
'use strict';
var MergeBuildPropertiesClass = require('./build/MergeBuildProperties');
var propertyMerger = new MergeBuildPropertiesClass('buildDefaultProperties.json', 'buildProperties.json');
// LOAD AND MERGE BUILD PROPERTIES
var buildProperties = propertyMerger.merge();
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);
grunt.initConfig({
// package info
pkg: grunt.file.readJSON('package.json'),
// build properties("buildDefaultProperties.json" merged with "buildProperties.json")
buildProperties: buildProperties,
watch: {
src: {
files: ['<%= buildProperties.src %>/**/*'],
tasks: ['deploy']
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= buildProperties.dist %>'
]
}]
},
deploy: {
files: [{
dot: true,
src: [
'<%= buildProperties.deploydir %>/**/*',
'!<%= buildProperties.deploydir %>/vendor/**'
]
}]
},
tmp: '.tmp'
},
// Put files not handled in other tasks here
copy: {
src: {
files: [{
expand: true,
dot: true,
cwd: '<%= buildProperties.src %>',
dest: '<%= buildProperties.dist %>',
src: '**/*'
}]
},
package: {
files: [{
expand: true,
dot: true,
dest: '<%= buildProperties.dist %>',
src: 'package.json'
}]
},
app: {
files: [{
expand: true,
dot: true,
cwd: '<%= buildProperties.app %>',
dest: '<%= buildProperties.dist %>',
src: '**/*'
}]
},
deploy: {
files: [{
expand: true,
dot: true,
cwd: '<%= buildProperties.dist %>',
dest: '<%= buildProperties.deploydir %>',
src: '**/*'
}]
}
},
curl: {
// downloads the app
app: {
src: '<%= buildProperties.appDistUrl %>',
dest: '.tmp/appdist.zip'
}
},
unzip: {
// unzips downloaded app dist package into dist
appdist: {
src: '.tmp/appdist.zip',
dest: '<%= buildProperties.dist %>',
router: function (filepath) {
// remove directory
return filepath.replace(buildProperties.appDistDir + '/', '');
}
}
}
});
/**
* Copy the app from set directory, if not found loads last build from github
*/
grunt.registerTask('requireApp', function(target) {
var fs = require('fs');
if (fs.existsSync(buildProperties.app)) {
console.log('Got app from ' + buildProperties.app);
grunt.task.run('copy:app');
}else{
console.info('App not found under: ' + buildProperties.app);
console.info('You should specify the path to the app dist');
console.info('Create a build/buildProperties.json and define the app dir.');
console.info('Look into the buildDefaultProperties.json for help.');
console.log('Fallback: Load app from ' + buildProperties.appDistUrl);
grunt.task.run(['curl:app', 'unzip:appdist', 'clean:tmp']);
}
});
grunt.registerTask('server', function (target) {
grunt.task.run([
'deploy',
'watch'
]);
});
grunt.registerTask('build', [
'clean:dist',
'copy:src',
'copy:package',
'requireApp'
]);
grunt.registerTask('deploy', [
'build',
'clean:deploy',
'copy:deploy'
]);
grunt.registerTask('default', [
'build'
]);
};