This repository has been archived by the owner on Mar 1, 2020. It is now read-only.
forked from soniaxu7/uskin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
executable file
·113 lines (99 loc) · 2.97 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
/*!
* USkin's Gruntfile
* Author: Lee Yao <[email protected]>
* Licensed under MIT
*/
var fs = require('fs');
var webpackConfig = require('./webpack.config.js');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var lessVarParse = require('less-var-parse');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * USkin v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license %> (https://github.com/unitedstack/uskin/blob/master/LICENSE)\n' +
' */\n',
// Task configuration.
clean: {
dist: ['dist'],
legacy: ['dist/js/fonts', 'dist/js/css.js', 'dist/js/css.js.map', 'dist/js/*.css.min.js']
},
webpack: {
options: webpackConfig,
dev: {
output: {
filename: '[name].js'
},
plugins: [
new ExtractTextPlugin({
filename: '../css/uskin.css'
})
],
devtool: 'source-map'
},
build: {
plugins: [
new ExtractTextPlugin({
filename: '../css/[hash:6].uskin.min.css'
}),
new webpack.optimize.UglifyJsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
}
},
copy: {
fonts: {
expand: true,
cwd: './dist/js',
src: 'fonts/*',
dest: './dist/css'
},
img: {
expand: true,
cwd: './dist/js',
src: 'img/*',
dest: './dist/css'
}
},
usebanner: {
options: {
position: 'top',
banner: '<%= banner %>'
},
files: {
src: ['dist/css/*.css', 'dist/js/*.js']
}
}
});
// These plugins provide necessary tasks.
require('load-grunt-tasks')(grunt, {
scope: 'devDependencies'
});
require('time-grunt')(grunt);
// Build JS
grunt.registerTask('js', ['webpack:dev', 'webpack:build']);
// Default task.
grunt.registerTask('build', ['clean:dist', 'js', 'copy', 'clean:legacy', 'usebanner', 'palette']);
// Release with hash.
grunt.registerTask('release', ['clean:dist', 'webpack:build', 'copy', 'clean:legacy', 'usebanner']);
// Generate palette preview
grunt.registerTask('palette', function(buildTheme) {
const done = this.async();
const theme = process.env.npm_config_theme || buildTheme || 'default';
fs.readFile(`css/themes/${theme}/index.less`, 'utf8', (e, data) => {
const template = fs.readFileSync('css/template/preview.tpl', 'utf8');
const vars = JSON.stringify(lessVarParse(data));
const content = template.replace('@palette', vars).replace('@theme_name', theme);
fs.writeFile(`css/themes/${theme}/index.html`, content, done);
});
});
};