Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995269
index.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
index.ts
View Options
import
yargs
,
{
array
}
from
"yargs"
;
import
fs
from
"fs"
;
import
{
exec
}
from
"child_process"
;
const
args
:
any
=
yargs
.
parserConfiguration
({
"unknown-options-as-args"
:
true
,
})
.
option
(
"array-arg"
,
{
type
:
"array"
}).
argv
;
const
options
:
Array
<
Array
<
string
>>
=
args
[
"_"
].
map
((
arg
:
string
)
=>
{
return
arg
.
replace
(
"--"
,
""
).
split
(
"="
);
});
let
input
:
string
|
undefined
=
""
;
let
inputFound
:
boolean
=
false
;
options
.
map
((
opt
:
Array
<
string
>
)
=>
{
if
(
opt
[
0
]
==
"input"
)
{
if
(
inputFound
)
{
console
.
error
(
"E: You have stated multiple input paths! Please choose only one!"
);
return
;
}
input
=
opt
[
1
];
inputFound
=
true
;
}
});
if
(
!
inputFound
)
{
console
.
error
(
"E: No input file's path! Please state one!"
);
}
else
{
let
svg
:
string
=
fs
.
readFileSync
(
`
${
input
}
`
,
"utf8"
);
let
regex
:
RegExp
=
new
RegExp
(
``
,
"g"
);
options
.
map
((
opt
:
Array
<
string
>
)
=>
{
if
(
opt
[
0
]
!=
"input"
)
{
regex
=
new
RegExp
(
`{{
${
opt
[
0
]
}
}}`
,
"g"
);
svg
=
svg
.
replace
(
regex
,
`
${
opt
[
1
]
}
`
);
}
});
fs
.
writeFileSync
(
`copy_
${
input
}
`
,
svg
);
regex
=
new
RegExp
(
`"export_(.*?)"`
,
"g"
);
let
exportIds
:
Array
<
string
>
|
null
=
svg
.
match
(
regex
);
if
(
exportIds
)
{
exportIds
.
map
((
id
)
=>
{
id
=
id
.
replace
(
`"export_`
,
""
).
replace
(
`"`
,
""
);
exec
(
`if [[ -d output ]]; then rm -rf output/*; else mkdir output; fi`
,
()
=>
{
exec
(
`inkscape --export-filename="output/
${
id
}
" --export-id=export_
${
id
}
--export-type=png copy_
${
input
}
`
,
()
=>
{
exec
(
`rm copy_
${
input
}
`
);
}
);
}
);
});
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 00:57 (3 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556748
Default Alt Text
index.ts (1 KB)
Attached To
Mode
rSTART Module Starter
Attached
Detach File
Event Timeline
Log In to Comment