(opts: StaticGenerateOptions)
| 9 | |
| 10 | /** @public */ |
| 11 | export async function createSystem(opts: StaticGenerateOptions) { |
| 12 | patchGlobalThis(); |
| 13 | |
| 14 | const createWriteStream = (filePath: string) => { |
| 15 | return fs.createWriteStream(filePath, { |
| 16 | flags: 'w', |
| 17 | }); |
| 18 | }; |
| 19 | |
| 20 | const NS_PER_SEC = 1e9; |
| 21 | const MS_PER_NS = 1e-6; |
| 22 | |
| 23 | const createTimer = () => { |
| 24 | const start = process.hrtime(); |
| 25 | return () => { |
| 26 | const diff = process.hrtime(start); |
| 27 | return (diff[0] * NS_PER_SEC + diff[1]) * MS_PER_NS; |
| 28 | }; |
| 29 | }; |
| 30 | |
| 31 | const createLogger = async () => { |
| 32 | return { |
| 33 | debug: opts.log === 'debug' ? console.debug.bind(console) : () => {}, |
| 34 | error: console.error.bind(console), |
| 35 | info: console.info.bind(console), |
| 36 | }; |
| 37 | }; |
| 38 | |
| 39 | const outDir = normalizePath(opts.outDir); |
| 40 | |
| 41 | const basePathname = opts.basePathname || '/'; |
| 42 | const basenameLen = basePathname.length; |
| 43 | |
| 44 | const getRouteFilePath = (pathname: string, isHtml: boolean) => { |
| 45 | pathname = decodeURIComponent(pathname.slice(basenameLen)); |
| 46 | if (isHtml) { |
| 47 | if (!pathname.endsWith('.html')) { |
| 48 | if (pathname.endsWith('/')) { |
| 49 | pathname += 'index.html'; |
| 50 | } else { |
| 51 | pathname += '/index.html'; |
| 52 | } |
| 53 | } |
| 54 | } else { |
| 55 | if (pathname.endsWith('/')) { |
| 56 | pathname = pathname.slice(0, -1); |
| 57 | } |
| 58 | } |
| 59 | return join(outDir, pathname); |
| 60 | }; |
| 61 | |
| 62 | const getDataFilePath = (pathname: string) => { |
| 63 | pathname = decodeURIComponent(pathname.slice(basenameLen)); |
| 64 | if (pathname.endsWith('/')) { |
| 65 | pathname += 'q-data.json'; |
| 66 | } else { |
| 67 | pathname += '/q-data.json'; |
| 68 | } |
no test coverage detected
searching dependent graphs…