UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

65 lines (62 loc) 2.53 kB
import { __name } from './chunk-IRPJW6HH.js'; import { parseTypeDefinition } from '@stryke/convert/parse-type-definition'; import { listFiles } from '@stryke/fs/list-files'; import { hash } from '@stryke/hash/hash'; import { findFileExtension } from '@stryke/path/file-path-fns'; import { joinPaths } from '@stryke/path/join-paths'; import { replacePath } from '@stryke/path/replace'; function resolveEntryInputFile(context, typeDefinition) { return replacePath(typeDefinition.file, joinPaths(context.options.workspaceRoot, context.options.projectRoot)); } __name(resolveEntryInputFile, "resolveEntryInputFile"); function resolveEntryInput(context, typeDefinition) { return { file: resolveEntryInputFile(context, typeDefinition), name: typeDefinition.name }; } __name(resolveEntryInput, "resolveEntryInput"); function resolveEntryOutput(context, typeDefinition) { return joinPaths(context.options.output.outputPath, "dist", replacePath(replacePath(typeDefinition.file, joinPaths(context.options.workspaceRoot, context.options.sourceRoot)), joinPaths(context.options.workspaceRoot, context.options.projectRoot))).replace(findFileExtension(typeDefinition.file) || "", ""); } __name(resolveEntryOutput, "resolveEntryOutput"); function resolveEntry(context, typeDefinition) { const input = resolveEntryInput(context, typeDefinition); return { ...input, input, output: resolveEntryOutput(context, typeDefinition) }; } __name(resolveEntry, "resolveEntry"); async function resolveEntries(context, typeDefinitions) { return (await Promise.all(typeDefinitions.map(async (typeDefinition) => { const parsed = parseTypeDefinition(typeDefinition); return (await listFiles(parsed.file)).map((file) => resolveEntry(context, { file, name: parsed.name })); }))).flat().filter(Boolean); } __name(resolveEntries, "resolveEntries"); function resolveVirtualEntry(context, typeDefinition) { const parsed = parseTypeDefinition(typeDefinition); const resolved = resolveEntry(context, parsed); const file = joinPaths(context.artifactsPath, `entry-${hash({ file: resolved.file, name: resolved.name }, { maxLength: 24 }).replaceAll("-", "0").replaceAll("_", "1")}.ts`); return { file, name: resolved.name, input: { file, name: resolved.name }, output: file }; } __name(resolveVirtualEntry, "resolveVirtualEntry"); export { resolveEntries, resolveEntry, resolveEntryInput, resolveEntryInputFile, resolveEntryOutput, resolveVirtualEntry };