-
Notifications
You must be signed in to change notification settings - Fork 23
/
Gruntfile.js
109 lines (86 loc) · 2.76 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
/*
* @TODO add task for updating container
*/
var fs = require('fs');
var jsBeautify = require('js-beautify').js_beautify;
module.exports = function(grunt) {
var footer = ['/*',
' * v<%= pkg.version %>',
' * Created by the Google Analytics consultants at http://www.lunametrics.com/',
' * Written by @notdanwilkerson',
' * Documentation: https://github.com/lunametrics/gascroll/',
' * Licensed under the MIT License',
' */'
].join('\r\n');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
ignore_warning: {
options: {
'-W030': true,
'-W058': true
},
src: ['./src/*.js']
}
},
uglify: {
options: {
footer: '\r\n' + footer
},
build: {
src: './src/scroll-tracker.js',
dest: './scroll-tracker.min.js'
}
},
appendFooter: {
options: {
build: {
src: './src/scroll-tracker.js',
dest: './scroll-tracker.js'
},
footer: footer
}
},
updateContainer: {
options: {
build: {
src: './scroll-tracker.js',
dest: './luna-gtm-scroll-tracker.json'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('appendFooter', ['append credits to footer'], function() {
var options = this.options();
var data = fs.readFileSync(options.build.src, 'utf-8');
fs.writeFileSync(options.build.dest, data + options.footer);
console.log('appended footer to unminifed script');
});
/*grunt.registerTask('updateContainer', ['Updating container import file'], function() {
var options = this.options();
var oldContainer = require(options.build.dest);
var newScript = fs.readFileSync(options.build.src, 'utf-8');
var oldTag,
oldParameter,
i;
for (i = 0; i < oldContainer.containerVersion.tag.length; i++) {
if (oldContainer.containerVersion.tag[i].name === 'CU - Scroll Tracking - LunaMetrics Plugin') {
oldTag = i;
break;
}
}
for (i = 0; i < oldContainer.containerVersion.tag[oldTag].parameter.length; i++) {
if (oldContainer.containerVersion.tag[oldTag].parameter[i].key === 'html') {
oldParameter = i;
break;
}
}
oldContainer.containerVersion.tag[oldTag].parameter[oldParameter].value = '<script type="text/javascript" id="gtm-scroll-tracking">\n' +
newScript +
'\n</script>';
fs.writeFileSync(options.build.dest, jsBeautify(JSON.stringify(oldContainer)));
});*/
grunt.registerTask('default', ['jshint', 'appendFooter', 'uglify', /*'updateContainer'*/]);
};