Files
speckle-automate-github-action/src/filesystem/parser.ts
T
Iain Sproat 1fceda4724 test(coverage): 100% test coverage & refactor to vitest and msw (#6)
* chore(refactor): tests use vitest and msw
* fix(directory): Ensure filenames conform to eslint requirements
* chore(yarn): Specify node engine version
* fix(yarn): use the proper nodelinker
* fix(GitHub workflow): yarn install with caching
* docs(README): update to match changes

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2023-03-23 15:37:32 +00:00

33 lines
976 B
TypeScript

import { FileSystem } from './files.js'
import { SpeckleFunction, SpeckleFunctionSchema } from '../schema/specklefunction.js'
import * as path from 'path'
import { Logger } from '../logging/logger.js'
import { handleZodError } from '../schema/errors.js'
export type ParserOptions = {
logger: Logger
fileSystem: FileSystem
}
export async function findAndParseManifest(
pathToSpeckleFunctionFile: string,
opts: ParserOptions
): Promise<SpeckleFunction> {
if (!pathToSpeckleFunctionFile.toLocaleLowerCase().endsWith('specklefunction.yaml')) {
pathToSpeckleFunctionFile = path.join(
pathToSpeckleFunctionFile,
'specklefunction.yaml'
)
}
const speckleFunctionRaw = await opts.fileSystem.loadYaml(pathToSpeckleFunctionFile)
let speckleFunction: SpeckleFunction
try {
speckleFunction = await SpeckleFunctionSchema.parseAsync(speckleFunctionRaw)
} catch (err) {
throw handleZodError(err, opts.logger)
}
return speckleFunction
}