-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
291 lines (260 loc) · 7.91 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
module.exports = function (grunt) {
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// URL to JSON is located here "https://fonts.google.com/metadata/icons"
var MDOfficial = grunt.file.readJSON("_data/MDOfficial.json");
var FPACIconsList = grunt.file.readJSON("_data/fpac-material-icons-list.json");
var MDIcons = MDOfficial.icons;
// start building icons JSON string
var iconsList = '{"icons":[';
var iconsStr = "";
var hasRun = false;
var cats = [];
var count = 0;
grunt.file.recurse('img/material-design-icons', createFileList);
function createFileList(abspath, rootdir, subdir, fileName){
var cat = '';
var pop = '1';
// strip fileName of extra details
var fn = fileName.split("_24px")[0].split("ic_")[1];
// search thru official Material Design Icons data for object
var newObj = MDIcons.find(obj => obj.name == fn);
var iconName, iconTags;
var svg = grunt.file.read(String( abspath ));
// Clearn svg string of characters that cause JSON parsing errors
svg = svg.replace(/[\n\r]+/g,'');
svg = svg.replace(/\s\s+/g, ' ');
svg = svg.replace(/"/g, "'");
// Assign truthy value if icon is FPAC Design System default
var showDS = FPACIconsList.icons.some( item => item.fileName === fileName );
if(newObj != undefined){
// create the display name for the icon
iconName = newObj.name.split("_").join(" ");
// ensure the keywords list is populated
iconTags = String(newObj.tags) == "" ? iconName.split("_").join(",") : newObj.tags;
cat = newObj.categories.toString();
cats.push( cat );
pop = parseInt( newObj.popularity ) > 0 ? newObj.popularity : '1';
} else {
// create the display name for the icon
iconName = fn.split("_").join(" ");
// ensure the keywords list is populated
iconTags = iconName.split("_").join(",");
};
// Used only for Development/Testing
count++;
//continue building icons JSON string
iconsStr += '{"name":"'+String(iconName)+'",';
iconsStr += '"fileName":"'+String(fileName)+'",';
iconsStr += '"category":"'+String(cat)+'",';
iconsStr += '"popularity":"'+String(pop)+'",';
iconsStr += '"keywords":"'+String(iconTags)+'",'
iconsStr += '"svg":"'+String(svg)+'",';
iconsStr += '"showDS":"'+showDS+'"},';
};
if(!hasRun) {
hasRun = true;
// Used only for Development/Testing
console.log("ICON COUNT", count);
// finalize building icons JSON string
iconsList += iconsStr.slice(0,-1) +'],';
// Add Categories List to JSON file and finalize string
var catsArray = [...new Set(cats)];
var catsString = '"';
catsArray.forEach(item => { catsString += String(item + '","') });
catsString = catsString.slice(0,-2);
iconsList += '"categories":['+ catsString +']}';
// ensure string is in JSON format
iconsJson = JSON.parse(JSON.stringify(iconsList));
}
// Listing Tasks
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// shell commands for use in Grunt tasks
shell: {
jekyllBuild: {
command: "bundle exec jekyll build"
},
jekyllServe: {
command: "bundle exec jekyll serve"
}
},
'string-replace': {
dist: {
files: { 'data/icons.json': '_data/icons-blank.json'},
options: {
replacements: [{
pattern: '{}',
replacement: iconsJson
}]
}
}
},
// Copies templates and assets from dependencies and/or src
copy: {
fsaStyleSass: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/stylesheets',
dest: '_sass/lib/fsa-style'
},
fsaStyleImg: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/img',
dest: 'img'
},
fsaStyleFonts: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/fonts',
dest: 'fonts'
},
fsaStyleJavascriptComponents: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/js/components',
dest: 'js/components'
},
fsaStyleJavascriptUtilities: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/js/utilities',
dest: 'js/utilities'
},
fsaStyleJavascriptVendor: {
expand: true,
src: '**',
cwd: 'node_modules/fsa-style/src/js/vendor',
dest: 'js/vendor'
}
},
// Lint scss files
scsslint: {
allFiles: [
'_sass/*.scss',
'_sass/*/*.scss',
],
options: {
bundleExec: false,
colorizeOutput: true,
config: '.scss-lint.yml',
force: true,
reporterOutput: null
},
},
// Sass all the style things
sass: {
default: {
files: {
'css/<%= pkg.name %>.css': '_sass/<%= pkg.name %>.scss',
//'css/file.css': '_sass/file.scss'
},
options: {
sourceMap: true,
outputStyle: 'expanded'
},
},
minify: {
files: {
'css/<%= pkg.name %>.min.css': '_sass/<%= pkg.name %>.scss',
//'css/file.min.css': '_sass/file.scss'
},
options: {
sourceMap: true,
outputStyle: 'compressed'
},
},
},
// Watches files for changes and run relevant tasks
watch: {
sass: {
files: [
'_sass/*.scss',
'_sass/**/*.scss'
],
tasks: ['sass', 'scsslint', 'postcss'],
options: { nospawn: true }
},
// css: {
// files: [
// 'css/*.css'
// ],
// tasks: ['postcss'],
// options: { nospawn: true }
// },
js: {
files: [
'js/*.js',
'js/**/*.js',
],
tasks: ['browserify', 'uglify']
},
},
// PostCSS, primarily to autoprefix
postcss: {
options: {
map: {
inline: false, // save all sourcemaps as separate files...
annotation: '_site/css' // ...to the specified directory
},
processors: [
require('pixrem')(), // add fallbacks for rem units
require('autoprefixer')({ browsers: 'last 3 versions' }), // add vendor prefixes
// require('cssnano')() // minify the result
]
},
dist: {
src: 'css/*.css'
}
},
// Uglify (minimize) JS
uglify: {
options: {
banner: '/*! FPAC Design System - Docs | http://usda-fsa.github.io/fsa-design-system/ */\n\n'
},
build: {
src: 'js/<%= pkg.name %>.js',
dest: 'js/<%= pkg.name %>.min.js'
}
},
// Browserify them JSs
browserify: {
main: {
files: {
'js/<%= pkg.name %>.js': [
'js/main.js'
],
}
}
},
// run tasks in parallel --- "start": "grunt concurrent:serve"
concurrent: {
serve: [
'shell:jekyllServe',
'watch'
],
options: {
logConcurrentOutput: true
}
}
});
grunt.loadNpmTasks('grunt-string-replace');
// Register Tasks
grunt.registerTask('default', ['build', 'string-replace']);
grunt.registerTask('build', [
'copy',
'sass',
'postcss',
'browserify',
'uglify',
'string-replace',
'shell:jekyllServe',
'watch'
]);
grunt.registerTask('server', ['shell:jekyllServe']);
grunt.registerTask('lint', 'scsslint');
grunt.registerTask('test', 'default', function () { grunt.log.writeln('Test that the app runs');});
};