forked from phodal/growth-ionic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
159 lines (142 loc) · 5.14 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
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
aws: grunt.file.readJSON('aws-credentials.json'),
aws_s3: {
options: {
accessKeyId: '<%= aws.AWSAccessKeyId %>', // Use the variables
secretAccessKey: '<%= aws.AWSSecretKey %>', // You can also use env variables
region: 'ap-southeast-2',
uploadConcurrency: 5,
downloadConcurrency: 5
},
production: {
options: {
bucket: 'www.growth.ren',
params: {
CacheControl: 'max-age=604800'
}
},
files: [
{expand: true, cwd: 'www/assets/', src: ['**'], dest: 'assets/', action: 'upload'},
{expand: true, cwd: 'www/css/', src: ['**'], dest: 'css/', action: 'upload'},
{expand: true, cwd: 'www/img/', src: ['**'], dest: 'img/', action: 'upload'},
{expand: true, cwd: 'www/js/', src: ['**'], dest: 'js/', action: 'upload'},
{expand: true, cwd: 'www/lib/', src: ['**'], dest: 'lib/', action: 'upload'},
{expand: true, cwd: 'www/templates/', src: ['**'], dest: 'templates/', action: 'upload'},
{expand: true, cwd: 'www/', src: ['manifest.json'], dest: './', action: 'upload'},
{
expand: true,
cwd: './www/',
src: ['index.html'],
dest: './',
action: 'upload',
params: {CacheControl: 'max-age=30', ContentType: 'text/html'}
}
]
},
deploy_apk: {
options: {
bucket: 'www.growth.ren',
params: {
CacheControl: 'max-age=604800'
}
},
files: [
{expand: true, cwd: 'www/', src: ['manifest.json'], dest: './', action: 'upload'},
{
expand: true,
cwd: 'www/',
src: ['version.json'],
dest: './',
action: 'upload',
params: {CacheControl: 'max-age=300'}
},
{expand: true, cwd: 'platforms/android/build/outputs/apk', src: ['growth.apk'], dest: './', action: 'upload'}
]
},
clean_production: {
options: {
bucket: 'www.growth.ren',
debug: true // Doesn't actually delete but shows log
},
files: [
{dest: 'assets/', src: ['**'], action: 'delete'},
{dest: 'css/', src: ['**'], action: 'delete'},
{dest: 'img/', src: ['**'], action: 'delete'},
{dest: 'js/', src: ['**'], action: 'delete'},
{dest: 'lib/', src: ['**'], action: 'delete'},
{dest: 'templates/', src: ['**'], action: 'delete'},
{dest: './', src: ['index.html', 'growth.apk', 'version.json'], action: 'delete'}
]
}
}
});
//GRUNT TASK TO BUILD A JSON MANIFEST FILE FOR HOT CODE UPDATES
grunt.registerMultiTask('jsonmanifest', 'Generate JSON Manifest for Hot Updates', function () {
var options = this.options({loadall:true, root: "./", files: {}, load: []});
var done = this.async();
var path = require('path');
this.files.forEach(function (file) {
var files;
//manifest format
var json = {
"files": options.files,
"load": options.load,
"root": options.root
};
//clear load array if loading all found assets
if(options.loadall) {
json.load = [];
}
// check to see if src has been set
if (typeof file.src === "undefined") {
grunt.fatal('Need to specify which files to include in the json manifest.', 2);
}
// if a basePath is set, expand using the original file pattern
if (options.basePath) {
files = grunt.file.expand({cwd: options.basePath}, file.orig.src);
} else {
files = file.src;
}
// Exclude files
if (options.exclude) {
files = files.filter(function (item) {
return options.exclude.indexOf(item) === -1;
});
}
// Set default destination file
if (!file.dest) {
file.dest = ['manifest.json'];
}
// add files
if (files) {
files.forEach(function (item) {
var isDir = grunt.file.isDir(path.join(options.basePath, item));
if (!isDir)
{
var hasher = require('crypto').createHash('sha256');
var filename = encodeURI(item);
var key = filename.split("-").slice(1).join('-');
json.files[key] = {};
json.files[key]['filename'] = filename;
json.files[key]['version'] = hasher.update(grunt.file.read(path.join(options.basePath, item))).digest("hex");
if(options.loadall)
{
json.load.push(filename);
}
}
});
}
//write out the JSON to the manifest files
file.dest.forEach(function(f) {
grunt.file.write(f, JSON.stringify(json, null, 2));
});
done();
});
});
grunt.loadNpmTasks('grunt-aws-s3');
grunt.registerTask('release', ['aws_s3:clean_production', 'aws_s3:production', 'aws_s3:deploy_apk']);
grunt.registerTask('update', ['aws_s3:clean_production', 'aws_s3:production']);
};