UNPKG

2.24 kBJavaScriptView Raw
1module.exports = function (grunt) {
2 "use strict";
3
4 grunt.initConfig({
5 nodeunit: {
6 main: ['test/test-text-replace.js'],
7 errors: ['test/test-text-replace-errors.js']
8 },
9 lint: {
10 files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js']
11 },
12 jshint: {
13 options: {
14 curly: true,
15 eqeqeq: true,
16 immed: true,
17 latedef: true,
18 newcap: true,
19 noarg: true,
20 sub: true,
21 undef: true,
22 boss: true,
23 eqnull: true,
24 node: true,
25 es5: true
26 },
27 globals: {}
28 },
29 replace: {
30 example: {
31 src: ['test/text_files/example.txt'],
32 dest: 'test/modified/',
33 replacements: [
34 {
35 from: 'Hello',
36 to: 'Good bye'
37 },
38 {
39 from: /(f|F)(o{2,100})/g,
40 to: 'M$2'
41 },
42 {
43 from: /"localhost"/,
44 to: function (matchedWord, index, fullText, regexMatches) {
45 return '"www.mysite.com"';
46 }
47 },
48 {
49 from: '<p>Version:</p>',
50 to: '<p>Version: <%= grunt.template.today("yyyy-mm-dd") %></p>'
51 },
52 {
53 from: /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}/g,
54 to: "<%= grunt.template.today('dd/mm/yyyy') %>"
55 }
56 ]
57 }
58 }
59 });
60
61/*
62 A note on testing:
63
64 There are two kinds of tests:
65
66 - Tests that don't result in an error
67 - Test that do result in an error (ie. grunt.warn())
68
69 I haven't been able to find a convenient way of testing for grunt.warn()
70 events without enabling '--force' when running grunt. For this reason I've
71 set up the 'test' task to just run the main tests, and only if --force is on
72 to run the error-throwing tests.
73
74*/
75
76 grunt.loadTasks('tasks');
77
78 grunt.renameTask('test', 'nodeunit');
79
80 grunt.registerTask('test', function () {
81 var isForceOn = grunt.option('force') || false;
82 var taskList = ['lint', 'nodeunit:main'];
83 if (isForceOn) {
84 taskList.push('nodeunit:errors');
85 }
86 grunt.task.run(taskList);
87 });
88
89 grunt.registerTask('default', 'test');
90
91 grunt.registerTask('example', 'replace');
92};
\No newline at end of file