/
build.js
executable file
·42 lines (39 loc) · 1.42 KB
/
build.js
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
42
#!/usr/bin/env node
import path from "path";
import { promises as fs } from "fs";
import { globby } from "globby";
import viteProd from "./vite-prod.js";
import debug from "./debug.js";
import { getMetaJsonString } from "./vite-plugin/generate/get-meta-json.js";
import { getEntryData } from "./vite-plugin/parse/get-entry-data.js";
import getFolderSize from "./get-folder-size.js";
import applyCLIConfig from "./apply-cli-config.js";
/**
* @param params {import("../shared/types").CLIParams}
*/
const build = async (params = {}) => {
const startTime = performance.now();
debug("Starting build command");
const { configFolder, config } = await applyCLIConfig(params);
await viteProd(config, configFolder);
const entryData = await getEntryData(await globby([config.stories]));
const jsonContent = getMetaJsonString(entryData);
await fs.writeFile(
path.join(process.cwd(), config.outDir, "meta.json"),
jsonContent,
);
console.log("✓ Meta.json successfully created.");
const folderSize = await getFolderSize(
path.join(process.cwd(), config.outDir),
);
const stopTime = performance.now();
const inSeconds = (stopTime - startTime) / 1000;
console.log(
`⏱️ Ladle finished the production build in ${Number(inSeconds).toFixed(
0,
)}s producing ${folderSize} MiB of assets.`,
);
console.log('💡 Tip: Run "ladle preview" to check that the build works!');
return true;
};
export default build;