-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
41 lines (39 loc) · 1.41 KB
/
mod.ts
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
import { buildCss, type BuildCssOptions } from './src/buildCss.ts';
import { buildJavascript, type BuildJavascriptOptions } from './src/buildJavascript.ts';
import { combineToXhtml, type CombineXhtmlOptions } from './src/combineToXhtml.ts';
import { CopyStaticsOptions } from './src/copyAssets.ts';
import { copyAssets } from './src/copyAssets.ts';
import { WriteToDirOptions } from './src/writeToDir.ts';
import { writeToDir } from './src/writeToDir.ts';
export type BuildOptions = BuildJavascriptOptions &
CombineXhtmlOptions &
BuildCssOptions &
CopyStaticsOptions &
WriteToDirOptions & {
showSlapTime?: boolean;
};
/**
* Compiles an XHTML page, CSS and JS embedded into it, and writes it to a location on disk.
*
* For example:
*
* await slap(
* import.meta.resolve('./application.tsx'),
* import.meta.resolve('./application.css')
* );
*/
export default async function slap(
tsModule: string | null,
cssModule: string | null,
options?: BuildOptions,
): Promise<void> {
const start = Date.now();
const js = tsModule ? [await buildJavascript(tsModule, options || {})] : [];
const css = cssModule ? [await buildCss(new URL(cssModule), options || {})] : [];
const files = [combineToXhtml(js, css, options || {})];
await copyAssets(options || {});
await writeToDir(files, options || { destination: '_site' });
if (options?.showSlapTime) {
console.error(`slap: ${Date.now() - start}ms`);
}
}