pidgin/nest
Clone
Summary
Browse
Changes
Graph
Fix a couple typos in the design guidelines.
2019-02-03, John Bailey
ba5f60fccca8
Fix a couple typos in the design guidelines.
const
{
html
:
beautify_html
}
=
require
(
'js-beautify'
)
const
fs
=
require
(
'fs'
)
const
path
=
require
(
'path'
)
const
SVGO
=
require
(
'svgo'
)
const
target
=
path
.
join
(
__dirname
,
'../public/'
)
const
svgo
=
new
SVGO
()
const
xmlRegex
=
/\.(html|xml)$/
const
jsonRegex
=
/\.json$/
const
svgRegex
=
/\.svg$/
getFilePaths
(
target
,
tidyPath
)
function
getFilePaths
(
input
,
cb
)
{
let
items
=
readDir
(
input
)
while
(
items
.
length
)
{
const
item
=
items
.
pop
()
const
stat
=
fs
.
statSync
(
item
)
if
(
stat
.
isDirectory
())
{
const
nueveau
=
readDir
(
item
)
items
.
push
(...
nueveau
)
}
else
if
(
stat
.
isFile
())
{
cb
(
item
)
}
}
}
function
readDir
(
item
)
{
return
fs
.
readdirSync
(
item
).
map
(
i
=>
path
.
join
(
item
,
i
))
}
function
tidyPath
(
path
)
{
if
(
path
.
match
(
xmlRegex
))
{
const
data
=
fs
.
readFileSync
(
path
,
'utf8'
)
fs
.
writeFile
(
path
,
beautify_html
(
data
,
{
max_preserve_newlines
:
0
,
}),
err
=>
{
if
(
err
)
{
console
.
log
(
`Error Tidiyng
${
path
}
`
,
err
)
}
console
.
log
(
`Tidied path:
${
path
.
replace
(
target
,
''
)
}
`
)
}
)
}
else
if
(
path
.
match
(
jsonRegex
))
{
const
data
=
fs
.
readFileSync
(
path
,
'utf8'
)
fs
.
writeFile
(
path
,
JSON
.
stringify
(
JSON
.
parse
(
data
)),
err
=>
{
if
(
err
)
{
console
.
log
(
`Error minifying
${
path
}
`
,
err
)
}
console
.
log
(
`Minified path:
${
path
.
replace
(
target
,
''
)
}
`
)
})
}
else
if
(
path
.
match
(
svgRegex
))
{
const
data
=
fs
.
readFileSync
(
path
,
'utf8'
)
svgo
.
optimize
(
data
)
.
then
(
d
=>
{
fs
.
writeFileSync
(
path
,
d
.
data
)
console
.
log
(
`Optimised:
${
path
.
replace
(
target
,
''
)
}
`
)
})
.
catch
(
err
=>
console
.
log
(
`Error Optimising SVG
${
path
}
`
,
err
))
}
}