-
Notifications
You must be signed in to change notification settings - Fork 94
/
Gruntfile.js
executable file
·103 lines (93 loc) · 3.2 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
/* eslint-disable */
/* OpenSprinkler App
* Copyright (C) 2015 - present, Samer Albahra. All rights reserved.
*
* This file is part of the OpenSprinkler project <http://opensprinkler.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3 as
* published by the Free Software Foundation.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
module.exports = function( grunt ) {
grunt.loadNpmTasks( "grunt-shell" );
grunt.loadNpmTasks( "grunt-contrib-compress" );
grunt.loadNpmTasks( "grunt-contrib-csslint" );
grunt.loadNpmTasks( "grunt-eslint" );
var secrets;
if ( grunt.file.exists( ".secrets.json" ) ) {
secrets = grunt.file.readJSON( ".secrets.json" );
} else {
secrets = {
"getLocalization": {
"username": "",
"password": ""
}
};
}
// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
secrets: secrets,
eslint: {
target: ["www/js/**/*.js"]
},
csslint: {
strict: {
options: {
csslintrc: ".csslintrc"
},
src: [ "www/css/main.css" ]
}
},
compress: {
makeFW: {
options: {
archive: "build/firmware/UI.zip"
},
files: [ {
src: [ "css/**", "js/**", "vendor-js/**", "img/**", "locale/*.js", "*.html", "manifest.json", "sw.js" ],
cwd: "www/",
expand: true
}, {
src: "res/ios-web/**"
} ]
}
},
shell: {
unzipFW: {
command: "cd build/firmware && unzip UI.zip"
},
pushEng: {
command: [
"xgettext --keyword=_ --output=- www/js/main.js www/js/analog.js --omit-header --force-po --from-code=UTF-8 --language='Python' | sed '/^\#/d' > .msgjs",
"sed -E 's/data-translate=\"([^\"]*)\"/_\(\"\\1\"\)/g' www/index.html > temp.html && xgettext --keyword=_ --output=- --language='Python' --omit-header --force-po temp.html | sed '/^#/d' > .msghtml && rm temp.html",
"msgcat .msgjs .msghtml > www/locale/messages_en.po",
"rm .msgjs .msghtml",
"tx push",
"git add www/locale/messages_en.po",
"git diff-index --quiet HEAD || git commit -m 'Localization: Update English strings'",
"git push"
].join( "&&" )
},
updateLang: {
command: [
"tx pull --all",
"find . -type f -maxdepth 1 -iname 'messages_*.po' -print0 | while IFS= read -r -d $'\\0' line; do file=(${line//_/ }); lang=${file[1]}; file=(${lang//-/ }); " +
"lang=${file[0]}; file=(${lang//./ }); lang=${file[0]}; mv \"$line\" messages.po; npx po2json -p -f mf messages.po \"www/locale/$lang.js\"; rm messages.po; " +
"echo '{\"messages\":' | cat - \"www/locale/$lang.js\" | (cat && echo '}') > temp && mv temp \"www/locale/$lang.js\"; done",
"git add www/locale",
"git diff-index --quiet HEAD || git commit -m 'Localization: Update languages from Transifex'",
"git push"
].join( "&&" )
}
}
} );
// Default task(s).
grunt.registerTask( "default", [ "eslint" ] );
grunt.registerTask( "updateLang", [ "shell:updateLang" ] );
grunt.registerTask( "pushEng", [ "shell:pushEng" ] );
grunt.registerTask( "prepareFW", [ "compress:makeFW", "shell:unzipFW" ] );
};