Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22399270
build.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
build.ts
View Options
import
{
build
,
BuildResult
}
from
"esbuild"
;
import
{
sassPlugin
}
from
"esbuild-sass-plugin"
;
import
*
as
chokidar
from
"chokidar"
;
import
{
default
as
glob
}
from
"tiny-glob"
;
import
{
generateScssIncludes
}
from
"./find-scss-includes"
;
import
{
sleep
}
from
"./utils/sleep"
;
import
{
generateCollections
}
from
"./generate-collections"
;
import
{
generateRoutes
}
from
"./generate-routes"
;
async
function
build_ts
()
{
await
Promise
.
all
([
generateCollections
(),
generateRoutes
()]);
const
entryPoints
=
await
glob
(
"./src/back/**/*.ts"
);
try
{
await
build
({
entryPoints
,
sourcemap
:
true
,
outdir
:
"./dist/back"
,
logLevel
:
"info"
,
platform
:
"node"
,
target
:
"es2022"
,
format
:
"cjs"
,
});
}
catch
(
e
)
{
console
.
error
(
e
.
message
);
}
}
async
function
complex_build
(
watch
:
boolean
)
:
Promise
<
void
>
{
let
scss_build
:
BuildResult
|
null
=
null
;
if
(
watch
)
{
const
watcher
=
chokidar
.
watch
(
"src"
,
{
ignoreInitial
:
true
});
watcher
.
on
(
"all"
,
async
(
_
,
path
)
=>
{
if
(
!
scss_build
)
return
;
if
(
path
.
includes
(
".#"
))
return
;
if
(
path
.
endsWith
(
".scss"
)
&&
!
path
.
endsWith
(
"/includes.scss"
))
{
// refresh the list of all scss files in includes.scss
await
generateScssIncludes
();
try
{
await
scss_build
?
.
rebuild
?
.();
console
.
log
(
`Built main.scss [on
${
path
}
]`
);
}
catch
(
e
)
{
console
.
error
(
e
.
message
);
await
sleep
(
200
);
scss_build
?
.
rebuild
?
.()
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.
catch
((
e
)
=>
console
.
error
(
e
?
.
message
));
}
}
if
(
path
.
endsWith
(
".ts"
)
&&
!
path
.
endsWith
(
"src/back/collections/collections.ts"
)
&&
!
path
.
endsWith
(
"src/back/routes/routes.ts"
)
&&
!
path
.
endsWith
(
"src/back/routes/urls.ts"
)
)
{
await
build_ts
();
console
.
log
(
`Finished TS build [on
${
path
}
]`
);
}
});
}
await
generateScssIncludes
();
scss_build
=
await
build
({
entryPoints
:
[
"./src/main.scss"
],
sourcemap
:
true
,
outfile
:
"./public/dist/style.css"
,
logLevel
:
"info"
,
incremental
:
watch
,
plugins
:
[
sassPlugin
()],
});
await
build_ts
();
watch
&&
scss_build
?
.
rebuild
?
.();
}
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
,
watch
,
});
await
complex_build
(
watch
);
}
catch
(
e
)
{
console
.
log
(
"CAUGHT!"
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
console
.
error
(
e
.
message
);
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:30 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200426
Default Alt Text
build.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline