Files
now-deployment/node_modules/now/dist/util/dev/static-builder.ts
2019-10-17 12:36:15 +09:00

34 lines
830 B
TypeScript

import { basename, extname, join } from 'path';
import { BuilderParams, BuildResult, ShouldServeParams } from './types';
export const version = 2;
export function build({ files, entrypoint }: BuilderParams): BuildResult {
const output = {
[entrypoint]: files[entrypoint],
};
const watch = [entrypoint];
return { output, routes: [], watch };
}
export function shouldServe({
entrypoint,
files,
requestPath,
}: ShouldServeParams) {
if (isIndex(entrypoint)) {
const indexPath = join(requestPath, basename(entrypoint));
if (entrypoint === indexPath && indexPath in files) {
return true;
}
}
return entrypoint === requestPath && requestPath in files;
}
function isIndex(path: string): boolean {
const ext = extname(path);
const name = basename(path, ext);
return name === 'index';
}