This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Gruntfile.js
118 lines (100 loc) · 3.44 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
'use strict';
module.exports = function (grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.name %> <%= pkg.version %> - <%= pkg.license %> | <%= pkg.repository.url %> */\n',
export: {
src: "src/main.js",
dst: "dist/popupS.js"
},
watch: {
scripts: {
files: ['src/**/*.*', 'css/popupS.css'],
tasks: ['default'],
options: { interrupt: true }
}
},
uglify: {
options: {
banner: '<%= banner %>'
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['dist/popupS.js']
}
}
},
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: {
'css/<%= pkg.name %>.min.css': ['css/popupS.css']
}
}
},
usebanner: {
taskName: {
options: {
position: 'top',
banner: '<%= banner %>',
linebreak: false
},
files: {
src: [
'css/popupS.min.css'
]
}
}
},
clean: [
'css/popupS.min.css'
]
});
grunt.registerTask('export', 'Export js', function () {
function file(rel, name) {
return rel.split('/').slice(0, -1).concat(name).join('/') + '.js';
}
function parse(src, pad) {
grunt.log.writeln((pad || '') + 'Parse file:', src);
if(src == 'src/main.js'){
return grunt.file.read(src)
.replace(/require\('(.*?)'\);?/g, function (_, name) {
return parse(file(src, name), ' ');
})
.replace(/\/+\s+&import\s+"(.*?)".*?\n/g, function (_, name) {
return parse(file(src, name), ' ');
})
.trim()
;
} else {
return grunt.file.read(src)
.replace(/module\.exports\s*=\s*([\s\S]+);/, '$1')
.replace(/require\('(.*?)'\);?/g, function (_, name) {
return parse(file(src, name), ' ');
})
.replace(/\/+\s+&import\s+"(.*?)".*?\n/g, function (_, name) {
return parse(file(src, name), ' ');
})
.trim()
;
}
}
var config = grunt.config(this.name);
var content = parse(config.src).replace(/;;;[^\n]+/g, '');
grunt.log.writeln(new Array(50).join('-'));
grunt.log.oklns('Write file:', config.dst);
grunt.file.write(config.dst, content);
});
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-usebanner');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('js', ['export']);
grunt.registerTask('min', ['uglify']);
grunt.registerTask('css', ['clean', 'cssmin', 'usebanner']);
grunt.registerTask('default', ['js', 'min', 'css']);
};