forked from idno/known
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.js
196 lines (180 loc) · 4.92 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* Gruntfile for Known project.
*
* This is a grunt task for building various aspects of Known. You'll only need to
* use this if you're a developer working on the core.
*
* Installation
*
* - npm i
*
* Useful tasks:
*
* - grunt - builds everything
* - grunt build-lang - recompiles gettext corpus (make sure you composer install before hand to get the build scripts!)
* - grunt build-css - Compile the SASS
* - grunt build-js - minify javascript and pass it through babel
* - grunt test - lint your js and css
* - grunt watch - look for changes and recompile as needed (useful for development)
*/
/*jshint ignore:start*/
const sass = require('node-sass'); // Use Node SASS (wrapper around libsass)
/*jshint ignore:end*/
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
sourcemap: 'none',
implementation: sass,
noCache: true
},
dev: {
files: {
'css/known.css': 'css/scss/known.scss',
'css/known-simple.css': 'css/scss/known-simple.scss'
},
},
dist: {
files: {
'css/known.min.css': 'css/scss/known.scss',
'css/known-simple.min.css': 'css/scss/known-simple.scss'
},
options: {
outputStyle: 'compressed'
}
}
},
concat: {
options: {
},
js: {
files: {
'js/known.es6': [
'js/src/classes/Security.js',
'js/src/classes/Logger.js',
'js/src/classes/Notifications.js',
'js/src/lib/Known.js',
'js/src/classes/Unfurl.js',
'js/src/classes/Image.js',
'js/src/lib/Image.js',
'js/src/classes/Template.js',
'js/src/lib/Template.js',
],
'js/service-worker.es6': [
'js/src/ServiceWorker.js'
]
}
}
},
babel: {
options: {
sourceType: "module"
},
dist: {
files: [
{
expand: true,
cwd: 'js/',
src: ['*.es6'],
dest: 'js/',
ext: '.js',
extDot: 'last'
}]
},
},
terser: {
options: {
},
dist: {
files: [{
expand: true,
cwd: "js/",
src: ["*.js", "!*.min.js"],
dest: "js",
ext: ".min.js",
extDot: 'last'
}]
},
},
csslint: {
options: {
quiet: true,
ids: false
},
src: ['css/*.css', '!*.min.css']
},
jshint: {
// define the files to lint
files: [
'Gruntfile.js',
'js/src/**/*.js'
],
// configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// more options here if you want to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true,
"$": false,
known: false,
wwwroot: true,
base64ToArrayBuffer: true,
EXIF: true,
self: true,
Security: true,
Template: true,
ImageTools: true,
},
node: true,
browser: true,
esversion: 6
}
},
watch: {
options: {
dateFormat: function(time) {
grunt.log.writeln('The watch finished in ' + time + 'ms at ' + (new Date()).toString());
grunt.log.writeln('Waiting for more changes...');
},
},
sass: {
files: 'css/scss/**/*.scss',
tasks: ['build-css', 'csslint']
},
js: {
files: ['js/src/**/*.js', 'Gruntfile.js'],
tasks: ['build-js', 'jshint']
}
}
});
// Load the plugins
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-terser');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-csslint');
// Tests
grunt.registerTask('test', ['csslint', 'jshint']);
// Build language pack
grunt.registerTask('build-lang', '', function () {
/*jshint ignore:start*/
const {execSync} = require('child_process');
/*jshint ignore:end*/
var pot = grunt.config.get('pkg.name').toLowerCase() + '.pot';
console.log("Building language file as ./languages/" + pot);
execSync('touch ./languages/source/' + pot); // Make sure it exists, if we're going to remove (for broken builds)
execSync('rm ./languages/source/' + pot); // Remove existing
execSync('find ./Idno ./templates -type f -regex ".*\.php" | sort | php vendor/mapkyca/known-language-tools/buildpot.php >> ./languages/source/' + pot); // Build from idno core
execSync('echo ./known.php | php vendor/mapkyca/known-language-tools/buildpot.php >> ./languages/source/' + pot); // Build from console
});
// Default task(s).
grunt.registerTask('build-js', ['concat', 'babel', 'terser']);
grunt.registerTask('build-css', ['sass']);
grunt.registerTask('default', ['build-js', 'build-css', 'build-lang', 'test']);
};