forked from yoniholmes/grunt-text-replace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
107 lines (91 loc) · 2.66 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
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc',
},
},
replace: {
example: {
src: ['test/text_files/example.txt'],
dest: 'test/modified/',
replacements: [{
from: 'Hello',
to: 'Good bye'
}, {
from: /(f|F)(o{2,100})/g,
to: 'M$2'
}, {
from: /"localhost"/,
to: function (matchedWord, index, fullText, regexMatches) {
return '"www.mysite.com"';
}
}, {
from: '<p>Version:</p>',
to: '<p>Version: <%= grunt.template.date("18 Feb 2013", "yyyy-mm-dd") %></p>'
}, {
from: /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}/g,
to: function() {
return "<%= grunt.template.date('18 Feb 2013', 'dd/mm/yyyy') %>";
}
}]
},
overwrite: {
src: ['test/modified/example.txt'],
overwrite: true,
replacements: [{
from: 'World',
to: 'PLANET'
}]
},
disable_template_processing: {
src: ['test/text_files/template-example.txt'],
dest: 'test/modified/',
options: {
processTemplates: false
},
replacements: [{
from: /url\(.*\)/g,
to: function () {
return "url(<% some unprocessed text %>)";
}
}]
}
},
nodeunit: {
errors: ['test/text-replace-error-tests.js'],
tests: ['test/text-replace-unit-tests.js'],
replace: ['test/text-replace-functional-tests.js'],
},
});
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.registerTask('default', ['jshint', 'test']);
/*
A note on testing (ie. running: grunt test):
There are two kinds of tests:
- Tests that don't result in a warning
- Test that do result in a warning (grunt.warn())
I haven't been able to find a convenient way of testing for grunt.warn()
events without enabling '--force' when running grunt. For this reason I've
set up the 'test' task to just run the main tests, and only if --force is on
to run the error-throwing tests.
*/
grunt.registerTask('test', function () {
var isForceOn = grunt.option('force') || false;
var taskList = ['nodeunit:tests'];
if (isForceOn) {
taskList.push('nodeunit:errors');
}
taskList.push('replace');
taskList.push('nodeunit:replace');
grunt.task.run(taskList);
});
};