-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGruntfile.js
219 lines (203 loc) · 6.55 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
module.exports = function (grunt) {
var fs = require('fs'),
pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')),
serverPort = pkg.localserver.port,
localhostUrl = pkg.localserver.url + serverPort;
const sass = require('node-sass');
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
umd: {
all: {
options: {
src: 'dist/spid-button-mix.js',
dest: 'dist/spid-button-umd.js',
objectToExport: 'SPID',
globalAlias: 'SPID',
}
}
},
watch: {
build: {
files: ['src/scss/*', 'src/js/*', 'src/data/*'],
tasks: ['build:dev']
},
test: {
files: ['src/scss/*', 'src/js/*'],
tasks: ['build:dev', 'jasmine']
}
},
// Controllo di sicurezza, rileva vulnerabilità note nel codice e nelle dipendenze
retire: {
js: ['src/js/*'],
node: ['.'],
options: {
outputFile: 'reports/retire.json'
}
},
// SCSS code style linting
stylelint: {
src: [
'src/scss/*'
],
options: {
outputFile: 'reports/stylelint.log'
}
},
// JS code style linting
eslint: {
target: ['src/js/*', 'test/*.js', '!src/js/*-tpl.js'],
options: {
outputFile: 'reports/eslint.log'
}
},
// Stylesheets minify
sass: {
// imports and dependecies defined in the SCSS file
dev: {
options: {
implementation: sass,
style: 'expanded'
},
files: {
'dist/spid-button.min.css': 'src/scss/spid-button-dev.scss'
}
},
prod: {
options: {
implementation: sass,
style: 'compressed',
sourcemap: 'none'
},
files: {
'dist/spid-button.min.css': 'src/scss/spid-button-prod.scss'
}
}
},
// Processa i CSS prodotti da sass e aggiunge vendor prefix sulle proprietà per browser obsoleti
postcss: {
options: {
failOnError: true,
processors: [
require('autoprefixer')()
]
},
dev: {
options: {
map: true
},
src: 'dist/spid-button.min.css',
dest: 'dist/spid-button.min.css'
},
prod: {
options: {
map: false
},
src: 'dist/spid-button.min.css',
dest: 'dist/spid-button.min.css'
}
},
// JavaScript minify
uglify: {
mix_dev: {
options: {
mangle: false,
beautify: true,
compress: false
},
files: {
'dist/spid-button-mix.js': [
'src/js/spid-button.js',
'src/js/i18n.js',
'src/js/providers.js',
'src/js/config-dev.js'
]
}
},
mix_prod: {
options: {
mangle: false,
beautify: true,
compress: false
},
files: {
'dist/spid-button-mix.js': [
'src/js/spid-button.js',
'src/js/i18n.js',
'src/js/providers.js',
'src/js/config.js'
]
}
},
dev: {
options: {
mangle: false,
beautify: true,
compress: false
},
files: {
'dist/spid-button.min.js': [
'dist/spid-button-umd.js',
]
}
},
prod: {
options: {
mangle: true,
beautify: false,
compress: {
drop_console: false
}
},
files: {
'dist/spid-button.min.js': [
'dist/spid-button-umd.js',
]
}
}
},
copy: {
prod: {
files: [
// includes files within path
{ expand: true, src: ['img/**'], dest: 'dist/', filter: 'isFile' }
],
},
},
// Unit tests
jasmine: {
unitTest: {
src: [
'node_modules/axe-core/axe.js', // A11y accessibility testing library
'dist/spid-button.min.js' // Modulo minifizzato da testare
],
options: {
specs: ['src/test/spid-button-*.js'],
outfile: '_SpecRunner.html',
keepRunner: true,
host: localhostUrl
}
}
},
// Localhost server per sviluppo e unit test
serve: {
options: {
port: serverPort
}
}
});
grunt.loadNpmTasks('grunt-umd');
grunt.registerTask('log-jasmine', function () {
grunt.log.writeln('La pagina specrunner di jasmine si trova in:');
grunt.log.writeln(localhostUrl + '/_SpecRunner.html');
});
grunt.registerTask('log-coverage', function () {
grunt.log.writeln('Il report della code coverage si trova in:');
grunt.log.writeln(localhostUrl + '/reports/coverage/distv/spid-button.min.js.html');
});
grunt.registerTask('default', ['watch']);
grunt.registerTask('lint', ['stylelint', 'eslint']);
grunt.registerTask('build:prod', ['sass:prod', 'postcss:prod', 'copy:prod', 'uglify:mix_prod', 'umd:all', 'uglify:prod']);
grunt.registerTask('build:dev', ['sass:dev', 'postcss:dev', 'uglify:mix_dev', 'umd:all', 'uglify:dev']);
grunt.registerTask('test', ['jasmine', 'log-jasmine']);
};