-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
121 lines (102 loc) · 4.19 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
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
theme: grunt.file.readJSON('themes.json'),
shell: {
compress: {},
xgettext: {}
},
replace: {
}
});
var themeObj = grunt.config.get('theme');
var packageObj = grunt.file.readJSON('package.json');
for ( var key in themeObj ) {
var theme = themeObj[key];
var version = packageObj.version_modern;
if(theme.slug!="modern") {
version = packageObj.version_modern_maps;
// copy specific main.php for map themes
grunt.config( 'copy.main_theme_'+ theme.slug , {
files: [
{
expand: true,
cwd: 'data/map_main/',
src: '**',
dest: 'tmp/'+ theme.slug +'/'
}
]
});
}
grunt.config( 'copy.theme_'+ theme.slug , {
files: [
{
expand: true,
cwd: 'theme_map/',
src: '**',
dest: 'tmp/'+ theme.slug +'/'
},
{
expand: true,
cwd: 'data/'+theme.slug,
src: '**',
dest: 'tmp/'+theme.slug+'/'
}
]
});
// zip destination
var archive = '../packages/theme_'+ theme.slug + '_'+(version || '1.0.0')+'.zip';
// shell gettext + compress
grunt.config( 'shell.compress_'+ theme.slug , {
command : 'cd tmp/; zip -r ' + archive + ' ' + theme.slug + '; rm -rf ' + theme.slug ,
options: {
stdout: false
}
});
var varaux = theme.slug;
varaux = varaux.toUpperCase() + '_THEME_VERSION';
// replace theme strings
grunt.config( 'replace.theme_name_'+ theme.slug , {
src: ['tmp/'+theme.slug+'/*.php', 'tmp/'+theme.slug+'/admin/*.php'],
overwrite: true, // overwrite matched source files
replacements: [{
from: '_theme_maps_n_regions_group',
to: theme.n_regions_group
},{
from: '_theme_maps_n_regions',
to: theme.n_regions
},{
from: 'theme_map',
to: theme.slug
},{
from: 'theme_country_title',
to: theme.slug
},{
from: '_theme_version_const',
to: varaux
},{
from: '_theme_version_number',
to: version
}]
});
// generate po files & mo files
grunt.config( 'shell.gettext_' + theme.slug, {
command : 'xgettext --from-code=UTF-8 -k_n:1,2 -k_e -k__ --package-name="'+theme.slug+' - theme map" --msgid-bugs-address="[email protected]" --package-version="'+version+'" -o temp.po $(find tmp/'+theme.slug+'/. -name "*.php") && sed \'s/CHARSET/UTF-8/\' temp.po > default.po ;msginit --no-translator --locale=en_US.UTF-8 -o theme.po -i default.po ;msgfmt -o theme.mo theme.po; cp -f theme.po theme.mo tmp/'+theme.slug+'/languages/en_US; rm -f theme.po theme.mo temp.po default.po',
options: {
stdout: true,
stderr: true
}
});
if(theme.slug=="modern") {
// if modern theme, minor changes on building
grunt.registerTask('build:'+theme.slug , ['copy:theme_'+theme.slug, 'replace:theme_name_'+theme.slug, 'shell:gettext_'+theme.slug, 'shell:compress_'+theme.slug]);
} else {
grunt.registerTask('build:'+theme.slug , ['copy:theme_'+theme.slug, 'copy:main_theme_'+theme.slug, 'replace:theme_name_'+theme.slug, 'shell:gettext_'+theme.slug, 'shell:compress_'+theme.slug]);
}
}
grunt.registerTask('build', ['build:modern', 'build:spain', 'build:italia', 'build:brasil', 'build:india', 'build:usa']);
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-gettext');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
};