-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gruntfile.js
173 lines (155 loc) · 4.45 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
module.exports = function(grunt) {
// Setup some constants
var IS_PRODUCTION;
// Decide if this is the dev or live server
if ((grunt.cli.tasks.indexOf("live") > -1) ||
(grunt.option('env') === 'production')) {
IS_PRODUCTION = true;
}
// Read basic info from json files
var includes = grunt.file.readJSON("includes.json");
// Initialize the list of CSS files to include
var cssFiles = [];
for (var i = 0; i < includes.css.length; i++) {
cssFiles.push("src/assets/css/" + includes.css[i]);
}
// Initialize the list of JS files to include
var jsFiles = [];
for (var j = 0; j < includes.js.length; j++) {
jsFiles.push("src/assets/js/" + includes.js[j]);
}
// List of target files and respective templates
var files = {
'index.html': ['src/content/home.hbs'],
'wallets/index.html': ['src/content/wallets.hbs'],
'quickstart/index.html': ['src/content/quickstart.hbs'],
'faqs/index.html': ['src/content/faqs.hbs'],
};
// Function to generate assemble target with localization data
function i18nTarget(lang, root) {
let destDir = root ? '.build/' : `.build/${lang}/`;
let i18nData = grunt.file.readYAML(`src/i18n/${lang}.yml`);
let i18nFiles = {};
Object.entries(files).forEach(entry => i18nFiles[destDir + entry[0]] = entry[1]);
return {
options: {
data: i18nData,
base_dir: root ? '/' : `/${lang}/`
},
files: i18nFiles
};
}
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Start with a fresh build folder
clean: ['.build'],
// Concatonate CSS files
concat: {
css: {
src: cssFiles,
dest: '.build/_assets/css/styles.css'
}
},
// Minify concatonated CSS file
cssmin: {
combine: {
files: [{
expand: true,
src: ['.build/_assets/css/styles.css'],
ext: '.min.css'
}]
}
},
// Minify concatonated JS file
uglify: {
options: {
compress: {
unused: true,
drop_debugger: true,
drop_console: true,
dead_code: true
},
mangle: true,
beautify: false
},
build: {
files: {
'.build/_assets/js/scripts.min.js': jsFiles
}
}
},
// Copy the required files to the build directory
copy: {
assets: {
expand: true,
cwd: 'src/assets',
src: '**/**',
dest: '.build/_assets'
},
downloads: {
expand: true,
cwd: 'src/downloads',
src: '**/**',
dest: '.build/downloads'
}
},
// Build the HTML files from our templates
assemble: {
options:{
layoutdir: 'src/layouts',
flatten: true,
layout: 'default.hbs',
partials: 'src/partials/*.hbs',
base_dir: '/',
css_dir: '/_assets/css/',
js_dir: '/_assets/js/',
img_dir: '/_assets/img/',
svg_dir: '/_assets/svg/',
downloads_dir: '/downloads/',
base_url: 'https://cashshuffle.com',
twitter_site: 'cashshuffle',
twitter_creator: 'cashshuffle',
production: IS_PRODUCTION
},
root: i18nTarget('en', true),
ja: i18nTarget('ja'),
fr: i18nTarget('fr'),
pt: i18nTarget('pt')
},
// Watch for changes
watch: {
options: {
spawn: false
},
css: {
files: ['src/assets/css/**'],
tasks: ['concat', 'cssmin', 'copy']
},
js: {
files: ['src/assets/js/**'],
tasks: ['uglify', 'copy']
},
images: {
files: ['src/assets/img/**',
'src/assets/svg/**'],
tasks: ['copy']
},
content: {
files: ['src/data.yml',
'src/content/**',
'src/layouts/**',
'src/partials/**'],
tasks: ['assemble']
}
}
});
grunt.loadNpmTasks('grunt-assemble');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('live', ['clean', 'concat', 'cssmin', 'uglify', 'assemble', 'copy']);
return grunt.registerTask('default', ['concat', 'cssmin', 'uglify', 'assemble', 'copy', 'watch']);
};