Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F4637605
build.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
build.ts
View Options
import
{
build
,
BuildContext
,
BuildResult
,
context
}
from
"esbuild"
;
import
{
promises
as
fs
}
from
"fs"
;
import
*
as
chokidar
from
"chokidar"
;
import
{
default
as
glob
}
from
"tiny-glob"
;
import
{
generate_css_includes
}
from
"./find-css-includes.js"
;
import
{
sleep
}
from
"./utils/sleep.js"
;
import
{
generateCollections
}
from
"./generate-collections.js"
;
import
{
generateRoutes
}
from
"./generate-routes.js"
;
import
{
generateComponents
}
from
"./generate-components.js"
;
import
{
make_notifier
}
from
"./notifier.js"
;
import
getPort
from
"get-port"
;
import
{
remove_named_imports
}
from
"../remove-named-imports.js"
;
import
_locreq
from
"locreq"
;
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_ts
()
{
await
Promise
.
all
([
generateCollections
(),
generateRoutes
(),
generateComponents
(),
]);
const
entryPoints
=
(
await
glob
(
"./src/back/**/*.{ts,tsx}"
)).
filter
(
(
path
)
=>
!
path
.
includes
(
".#"
)
);
try
{
await
build
({
entryPoints
,
sourcemap
:
true
,
bundle
:
false
,
jsxFactory
:
"TempstreamJSX.createElement"
,
outdir
:
"./dist/back"
,
logLevel
:
"info"
,
platform
:
"node"
,
target
:
"es2022"
,
format
:
"esm"
,
plugins
:
[
remove_named_imports
],
});
}
catch
(
e
)
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
console
.
error
(
e
.
message
);
}
}
async
function
complex_build
(
watch
:
boolean
)
:
Promise
<
void
>
{
const
loader
=
Object
.
fromEntries
(
(
<
const
>
[
"png"
,
"svg"
,
"jpg"
,
"gif"
,
"jpeg"
,
"otf"
,
"ttf"
]).
map
(
(
ext
)
=>
<
const
>
[
"."
+
ext
,
"file"
]
)
);
let
css_build
:
BuildContext
=
await
context
({
entryPoints
:
[
"./src/main.css"
],
sourcemap
:
true
,
bundle
:
true
,
outdir
:
"./public/dist"
,
logLevel
:
"info"
,
// plugins: [sassPlugin()],
loader
,
});
let
ongoing_ts
=
false
;
let
ongoing_css
=
false
;
let
ongoing_ts_promise
:
Promise
<
any
>
|
null
=
null
;
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"
,
async
(
_
,
path
)
=>
{
if
(
!
css_build
)
return
;
if
(
path
.
includes
(
".#"
))
return
;
if
(
path
.
endsWith
(
".css"
)
&&
!
path
.
endsWith
(
"/includes.css"
))
{
if
(
ongoing_css
)
{
return
;
}
ongoing_css
=
true
;
// refresh the list of all css files in includes.css
await
generate_css_includes
();
try
{
await
css_build
?
.
rebuild
?
.();
console
.
log
(
`Built main.css [on
${
path
}
]`
);
}
catch
(
e
)
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
console
.
error
(
e
.
message
);
await
sleep
(
200
);
css_build
?
.
rebuild
?
.()
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.
catch
((
e
)
=>
console
.
error
(
e
?
.
message
));
}
if
(
ongoing_ts_promise
)
{
await
ongoing_ts_promise
;
}
notifier
(
"css"
);
ongoing_css
=
false
;
}
if
(
(
path
.
endsWith
(
".ts"
)
||
path
.
endsWith
(
".tsx"
))
&&
!
path
.
endsWith
(
"src/back/collections/collections.ts"
)
&&
!
path
.
endsWith
(
"src/back/routes/routes.ts"
)
&&
!
path
.
endsWith
(
"src/back/routes/urls.ts"
)
)
{
if
(
ongoing_ts
)
{
return
;
}
ongoing_ts
=
true
;
ongoing_ts_promise
=
build_ts
();
await
ongoing_ts_promise
;
notifier
(
"ts"
);
ongoing_ts_promise
=
null
;
console
.
log
(
`Finished TS build [on
${
path
}
]`
);
ongoing_ts
=
false
;
}
});
}
else
{
await
write_notifier_config
(
watch
);
}
await
generate_css_includes
();
await
Promise
.
all
([
css_build
.
rebuild
(),
build_ts
()]);
if
(
watch
)
{
css_build
?
.
rebuild
?
.();
}
else
{
css_build
.
dispose
();
}
}
export
async
function
buildProject
({
watch
,
}
:
{
watch
:
boolean
;
})
:
Promise
<
void
>
{
try
{
await
build
({
entryPoints
:
[
"./src/front/index.ts"
],
sourcemap
:
true
,
outfile
:
"./public/dist/bundle.js"
,
logLevel
:
"info"
,
bundle
:
true
,
});
await
complex_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
Tue, May 27, 23:48 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
629099
Default Alt Text
build.ts (4 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment