-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gruntfile.js
144 lines (131 loc) · 4.6 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
module.exports = function (grunt) {
var fs = require('fs');
var path = require('path');
var pkg = grunt.file.readJSON('package.json');
var currentPath = path.dirname(fs.realpathSync(__filename));
grunt.initConfig({
pkg: pkg,
mkdir: {
tmp: {
options: {
mode: 0755,
create: [
'build/tmp',
]
},
}
},
clean: {
start: ['build/installer-*'],
final: [
'build/tmp',
'build/installer-' + pkg.version + '/' + pkg.name + '-' + pkg.version
]
},
copy: {
options: {
mode: true,
},
files: {
expand: true,
dot: true,
src: [
'commands/**',
'installation-modes/**',
'system-configuration/**',
'LICENSE'
],
dest: 'build/tmp/<%= pkg.name %>-<%= pkg.version %>/',
},
script: {
expand: true,
dot: true,
src: [
'install.sh'
],
dest: 'build/tmp/',
},
final: {
expand: true,
dot: true,
src: '**',
cwd: 'build/tmp',
dest: 'build/installer-<%= pkg.version %>/',
},
},
replace: {
version: {
options: {
patterns: [
{
match: /archive\/refs\/heads\/master/g,
replacement: 'releases/download/<%= pkg.version %>/<%= pkg.name %>-<%= pkg.version %>'
},
{
match: /installer MASTER/g,
replacement: 'installer v<%= pkg.version %>'
},
{
match: /VERSION: MASTER/g,
replacement: 'VERSION: <%= pkg.version %>'
},
{
match: /espocrm-installer-master/g,
replacement: 'espocrm-installer-<%= pkg.version %>'
},
{
match: /2014-20[0-9][0-9] Yu/g,
replacement: '2014-<%= grunt.template.today("yyyy") %> Yu'
}
]
},
files: [
{
src: 'build/tmp/install.sh',
dest: 'build/tmp/install.sh'
},
{
src: 'build/tmp/<%= pkg.name %>-<%= pkg.version %>/commands/command.sh',
dest: 'build/tmp/<%= pkg.name %>-<%= pkg.version %>/commands/command.sh'
},
{
src: 'build/tmp/<%= pkg.name %>-<%= pkg.version %>/installation-modes/**/nginx/docker-compose.yml',
dest: './'
}
]
}
},
});
grunt.registerTask("zip", function() {
var resolve = this.async();
var folder = pkg.name + '-' + pkg.version;
var zipPath = 'build/installer-' + pkg.version + '/' + folder +'.zip';
if (fs.existsSync(zipPath)) fs.unlinkSync(zipPath);
var archiver = require('archiver');
var archive = archiver('zip');
archive.on('error', function (err) {
grunt.fail.warn(err);
});
var zipOutput = fs.createWriteStream(zipPath);
zipOutput.on('close', function () {
console.log("Package has been built.");
resolve();
});
archive.directory(currentPath + '/build/installer-' + pkg.version + '/' + folder, folder).pipe(zipOutput);
archive.finalize();
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-replace');
grunt.registerTask('default', [
'clean:start',
'mkdir:tmp',
'copy:files',
'copy:script',
'replace',
'copy:final',
'zip',
'clean:final',
]);
};