-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
108 lines (99 loc) · 3.13 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
'use strict';
module.exports = function (grunt) {
// Project configuration.
var pkgJson = require('./package.json')
var widgetName = pkgJson.name;
var widgetNameAllLower = widgetName.toLowerCase();
var widgetNameAllCap = widgetNameAllLower.toUpperCase();
var widgetNameFirstCap = widgetNameAllLower.charAt(0).toUpperCase() + widgetNameAllLower.slice(1);
var replacements = [
{
pattern: new RegExp("animationstuff", "g"),
replacement: widgetNameAllLower
},
{
pattern: new RegExp("Animationstuff", "g"),
replacement: widgetNameFirstCap
},
{
pattern: new RegExp("ANIMATIONSTUFF", "g"),
replacement: widgetNameAllCap
}
];
grunt.initConfig({
copy: {
main: {
files: [
{
expand: true,
cwd: './',
src: ['js/widgetboilerActor.js'],
dest: './',
rename: function(dest, src) {
// use the source directory to create the file
// example with your directory structure
// dest = 'dev/js/'
// src = 'module1/js/main.js'
return widgetName + '.js';
}
},
{
expand: true,
cwd: './',
src: ['css/widgetboilerActor.css'],
dest: './',
rename: function(dest, src) {
// use the source directory to create the file
// example with your directory structure
// dest = 'dev/js/'
// src = 'module1/js/main.js'
return widgetName + '.css';
}
}
]
}
},
clean: ["widgetboilerActor.js,css/widgetboilerActor.css"],
config: {
dist: './'
},
'string-replace': {
inline: {
// files: {
// 'widgetboilerActor.js': 'widgetboilerActor.js'
// },
files: [
{
src: '**/*.*',
dest: './',
filter: function(filepath) {
//return (grunt.file.isDir(filepath) && require('fs').readdirSync(filepath).length === 0);
var filepathHasBannedString = false;
var bannedStrings = ['node_modules','Gruntfile.js','jquery.min.js','require.js','r.js','package.json','.git/'];
for(var i=0,l=bannedStrings.length;i<l;i++){
filepathHasBannedString = filepathHasBannedString || filepath.indexOf(bannedStrings[i]) === 0;
}
if(filepathHasBannedString){
//console.log('----' + filepath)
return false
} else{
console.log(filepath)
return true;
}
}
}
],
options: {
replacements: replacements
}
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
// Default task.
grunt.registerTask('rename', ['string-replace']);
grunt.registerTask('default', ['string-replace','copy','clean']);
};