-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgen-flags.js
More file actions
39 lines (35 loc) · 973 Bytes
/
gen-flags.js
File metadata and controls
39 lines (35 loc) · 973 Bytes
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
/* global require, __dirname */
/* eslint no-console: off */
const fs = require('fs')
const path = require('path')
const Mustache = require('mustache')
const SVGCountryFlagsDir = path.join(
__dirname,
'..',
'node_modules',
'flag-icon-css',
'flags',
'1x1'
)
const main = () => {
fs.readdir(SVGCountryFlagsDir, (err, files) => {
fs.readFile('scripts/templates/FlagCC.js.tmpl', 'utf8', (err, tmpl) => {
files.forEach((file) => {
const alpha2 = file.split('.svg')[0]
if (alpha2.length !== 2) {
return
}
const alpha2Upper = alpha2.toUpperCase()
const jsContent = Mustache.render(tmpl, {alpha2, alpha2Upper})
const dstPath = path.join(__dirname, '..', 'components', 'flags', `${alpha2}.js`)
fs.writeFile(dstPath, jsContent, (err) => {
if (err) {
console.log('Failed to write ' + dstPath, err)
}
return
})
})
})
})
}
main()