Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010219
build.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
build.ts
View Options
import
{
promises
as
fs
}
from
"fs"
;
import
*
as
chokidar
from
"chokidar"
;
import
{
make_notifier
}
from
"./notifier.js"
;
import
getPort
from
"get-port"
;
import
_locreq
from
"locreq"
;
import
{
BackendTSBuilder
,
CSSBuilder
,
FontsBuilder
,
FrontendTSBuilder
,
}
from
"./builder.js"
;
const
target_locreq
=
_locreq
(
process
.
cwd
());
async
function
get_notifier_port
()
{
return
getPort
({
port
:
4000
});
}
async
function
write_notifier_config
(
watch
:
boolean
,
port
?:
number
)
{
const
config
=
{
watch
}
as
Record
<
string
,
boolean
|
number
>
;
if
(
port
)
{
config
.
port
=
port
;
}
await
fs
.
writeFile
(
target_locreq
.
resolve
(
"public/dist/notifier.json"
),
JSON
.
stringify
(
config
)
);
}
async
function
build
(
watch
:
boolean
)
:
Promise
<
void
>
{
const
fonts_builder
=
new
FontsBuilder
();
const
backend_ts_builder
=
new
BackendTSBuilder
();
const
frontend_ts_builder
=
new
FrontendTSBuilder
();
const
css_builder
=
new
CSSBuilder
();
const
builders
=
[
fonts_builder
,
backend_ts_builder
,
css_builder
,
frontend_ts_builder
,
];
await
Promise
.
all
(
builders
.
map
((
b
)
=>
b
.
build
()));
if
(
watch
)
{
const
watcher
=
chokidar
.
watch
(
"src"
,
{
ignoreInitial
:
true
});
const
port
=
await
get_notifier_port
();
const
notifier
=
make_notifier
(
port
);
await
write_notifier_config
(
watch
,
port
);
watcher
.
on
(
"all"
,
(
_
,
file_path
)
=>
{
console
.
log
(
"Detected a change!"
,
file_path
);
builders
.
forEach
((
builder
)
=>
{
const
owns_a_file
=
builder
.
ownsFile
(
file_path
);
if
(
owns_a_file
)
{
void
builder
.
build
(
notifier
);
}
});
});
}
else
{
await
write_notifier_config
(
watch
);
builders
.
forEach
((
builder
)
=>
{
void
builder
.
dispose
();
});
}
}
export
async
function
buildProject
({
watch
,
}
:
{
watch
:
boolean
;
})
:
Promise
<
void
>
{
try
{
await
build
(
watch
);
}
catch
(
e
)
{
console
.
log
(
"CAUGHT!"
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
console
.
error
(
e
.
message
);
if
(
!
watch
)
{
process
.
exit
(
1
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624952
Default Alt Text
build.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment