forked from wanadev/PhotonUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntfile.js
142 lines (130 loc) · 4.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var path = require('path');
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dist: {
files: {
'dist/<%= pkg.name %>.js': ['src/photonui.js']
},
options: {
browserifyOptions: {
'standalone': '<%= pkg.name %>'
}
}
}
},
uglify: {
dist: {
files: {
'dist/<%= pkg.name %>.min.js': ['dist/<%= pkg.name %>.js']
}
}
},
yuidoc: {
doc: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
linkNatives: true,
attributesEmit: true,
selleck: true,
paths: ['./src/'],
outdir: './doc/',
tabtospace: 2
}
}
},
concat: {
},
less: {
less_base: {
options: {
paths: ['.'],
plugins: [
new (require('less-plugin-autoprefix'))({browsers: ['last 2 versions']}),
new (require('less-plugin-clean-css'))()
],
},
files: {
'dist/photonui-base.css': 'less/base/photonui-base.less'
}
},
less_themes: {
options: {
paths: ['.'],
plugins: [
new (require('less-plugin-autoprefix'))({browsers: ['last 2 versions']}),
new (require('less-plugin-clean-css'))()
],
},
files: {
'dist/photonui-theme-particle.css': 'less/theme-particle/photonui-theme-particle.less',
'dist/photonui-theme-wave.css': 'less/theme-wave/photonui-theme-wave.less'
}
},
},
copy: {
assets: {
expand: true,
flatten: true,
filter: 'isFile',
cwd: 'src/assets/',
src: '**',
dest: 'dist/assets/'
},
demoResources: {
expand: true,
cwd: 'demo-src/Resources/',
src: '**',
dest: 'demo/'
}
},
clean: {
dist: ['dist'],
docs: ['doc'],
demo: ['demo'],
assets: ['dist/assets']
}
});
// Load the grunt plugins.
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-browserify');
// Register runnable tasks.
grunt.registerTask('gen-js', ['browserify', 'uglify']);
grunt.registerTask('gen-css', ['less:less_base', 'less:less_themes', 'clean:assets', 'copy:assets']);
grunt.registerTask('gen-docs', ['clean:demo', 'clean:docs', 'copy:demoResources', 'gen-demos', 'concat', 'yuidoc']);
grunt.registerTask('default', ['gen-js', 'gen-docs', 'gen-css']);
grunt.registerTask('dist', ['default']);
grunt.registerTask('gen-demos', 'iterates over all module directories and compiles modules js files', function() {
// Process all demo scripts
grunt.file.expand('demo-src/*').forEach(function(file){
// Return if not a js file.
if(path.basename(file).indexOf('.js') == -1) return;
var conf = {
demoName: path.basename(file).split('.js').join('')
};
// Create a new concat task.
var concat = grunt.config.get('concat') || {};
// Combine the script with the header and footer.
concat['demo-'+conf.demoName] = {
// Replace demoName in the templates with the name of the demo.
options: {
banner: '<!-- Auto-generated demo file for <%= pkg.name %> - <%= pkg.version %> -->\n',
process: {data:conf}
},
src: ['demo-src/TEMPLATE_HEADER.html', file, 'demo-src/TEMPLATE_FOOTER.html'],
dest: 'demo/'+conf.demoName+'.html'
};
// Save the new concat configuration.
grunt.config.set('concat', concat);
});
});
};