FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-pull-request-github/scripts/preprocess-svg.js at main · abh80/vscode-pull-request-github · GitHub
abh80
/
vscode-pull-request-github
Public
forked from
microsoft/vscode-pull-request-github
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-pull-request-github
/
scripts
/
preprocess-svg.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (60 loc) · 2.09 KB
Breadcrumbs
vscode-pull-request-github
/
scripts
/
preprocess-svg.js
Copy path
File metadata and controls
73 lines (60 loc) · 2.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
util
=
require
(
'util'
)
;
const
fs
=
require
(
'fs'
)
;
const
path
=
require
(
'path'
)
;
const
minimist
=
require
(
'minimist'
)
;
const
svgLoader
=
require
(
'svg-inline-loader'
)
;
const
globCb
=
require
(
'glob'
)
;
const
mkdirpCb
=
require
(
'mkdirp'
)
;
function
printUsage
(
consoleFn
,
exitCode
)
{
consoleFn
(
`Usage: bin/preprocess-svg --in [filename] --out [filename]
Preprocess a directory containing *.svg files into *.js modules consistently
with the way that Webpack will transpile them at build time.
Options:
--help, -h Display this message.
--in, -i [dirname] Discover and convert SVG files beneath [dirname].
--out, -o [dirname] Emit JavaScript source to files beneath [dirname].
`
)
;
process
.
exit
(
exitCode
)
;
}
const
argv
=
minimist
(
process
.
argv
.
slice
(
2
)
,
{
string
:
[
'in'
,
'out'
]
,
boolean
:
[
'help'
]
,
alias
:
{
h
:
'help'
,
i
:
'in'
,
o
:
'out'
}
,
unknown
:
param
=>
{
console
.
error
(
`Unrecognized command-line argument:
${
param
}
\n`
)
;
printUsage
(
console
.
error
,
1
)
;
}
,
}
)
;
if
(
argv
.
help
)
{
printUsage
(
console
.
log
,
0
)
;
}
const
inRoot
=
argv
.
in
;
const
outRoot
=
argv
.
out
;
if
(
!
inRoot
||
!
outRoot
)
{
console
.
error
(
'Both --in and --out parameters are required.\n'
)
;
printUsage
(
console
.
error
,
1
)
;
}
const
readFile
=
util
.
promisify
(
fs
.
readFile
)
;
const
writeFile
=
util
.
promisify
(
fs
.
writeFile
)
;
async
function
processFile
(
inFilename
,
outFilename
)
{
const
originalSource
=
await
readFile
(
inFilename
,
{
encoding
:
'utf8'
}
)
;
const
moduleSource
=
svgLoader
(
originalSource
)
;
await
writeFile
(
outFilename
,
moduleSource
,
{
encoding
:
'utf8'
}
)
;
}
const
glob
=
util
.
promisify
(
globCb
)
;
const
mkdirp
=
util
.
promisify
(
mkdirpCb
)
;
async
function
processDirectory
(
inDirectory
,
outDirectory
)
{
const
files
=
await
glob
(
'**/*.svg'
,
{
cwd
:
inDirectory
}
)
;
return
Promise
.
all
(
files
.
map
(
async
subPath
=>
{
const
inFilename
=
path
.
join
(
__dirname
,
inDirectory
,
subPath
)
;
const
outFilename
=
path
.
join
(
__dirname
,
outDirectory
,
subPath
)
;
await
mkdirp
(
path
.
dirname
(
outFilename
)
)
;
await
processFile
(
inFilename
,
outFilename
)
;
}
)
,
)
;
}
processDirectory
(
inRoot
,
outRoot
)
.
catch
(
error
=>
{
console
.
error
(
error
.
stack
)
;
process
.
exit
(
1
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL