diff --git a/lib/events/register_skill.ts b/lib/events/register_skill.ts index fb30ded..32f0891 100644 --- a/lib/events/register_skill.ts +++ b/lib/events/register_skill.ts @@ -113,7 +113,7 @@ export const handler: MappingEventHandler< skill.version = await version(ctx, skill); skill.apiVersion = apiVersion(ctx); - await inlineDatalogResources(p, skill, skillYaml.skill); + await inlineDatalogResources(p, skill); if (isContainer(ctx)) { await createArtifact(skill, ctx, registry); } else { @@ -381,13 +381,13 @@ type DatalogSubscription = { name: string; query: string; limit?: number; -} +}; async function getDatalogSubscriptionFileMatches( p: project.Project, - matchPath: string + matchPath: string, ): Promise> { - return (await project.withGlobMatches<{ + return await project.withGlobMatches<{ name: string; query: string; limit?: number; @@ -399,12 +399,12 @@ async function getDatalogSubscriptionFileMatches( query: (await fs.readFile(filePath)).toString(), name: fileName.replace(extName, ""), }; - })) + }); } function updateSubscriptions( datalogSubscriptions: Array, - updates: Array + updates: Array, ): void { updates.forEach(d => { const eds = datalogSubscriptions.find(ds => d.name === ds.name); @@ -419,24 +419,30 @@ function updateSubscriptions( export async function inlineDatalogResources( p: project.Project, - skill: AtomistSkillInput, - skillYaml: any, + skill: AtomistYaml["skill"], ): Promise { - const datalogSubscriptions = new Array(); + const datalogSubscriptions: Array = []; // common subscriptions datalogSubscriptions.push( - ...(await getDatalogSubscriptionFileMatches(p, "datalog/subscription/*.edn")), + ...(await getDatalogSubscriptionFileMatches( + p, + "datalog/subscription/*.edn", + )), ); // subscription paths defined in yaml - for (const subscriptionPath of (skillYaml.datalogSubscriptionPaths || [])) { - const groupMatches = await getDatalogSubscriptionFileMatches(p, `datalog/subscription/${subscriptionPath}`) - updateSubscriptions(datalogSubscriptions, groupMatches) + for (const subscriptionPath of skill.datalogSubscriptionPaths || []) { + const groupMatches = await getDatalogSubscriptionFileMatches( + p, + `datalog/subscription/${subscriptionPath}`, + ); + updateSubscriptions(datalogSubscriptions, groupMatches); } + delete skill.datalogSubscriptionPaths; // subscriptions defined in yaml - updateSubscriptions(datalogSubscriptions, skill.datalogSubscriptions || []) + updateSubscriptions(datalogSubscriptions, skill.datalogSubscriptions || []); skill.datalogSubscriptions = datalogSubscriptions; const schemata = [...(skill.schemata || [])]; diff --git a/lib/util.ts b/lib/util.ts index 7c5aeb4..8b542fd 100644 --- a/lib/util.ts +++ b/lib/util.ts @@ -15,6 +15,7 @@ */ import { handle } from "@atomist/skill"; +import { AtomistSkillInput } from "@atomist/skill/lib/definition/subscription/typings/types"; import { Project } from "@atomist/skill/lib/project/project"; import * as fs from "fs-extra"; import * as yaml from "js-yaml"; @@ -23,7 +24,7 @@ import { Configuration } from "./configuration"; import { RegisterSkill } from "./types"; export interface AtomistYaml { - skill: any; + skill: AtomistSkillInput & { datalogSubscriptionPaths?: string[] }; } export const AtomistYamlFileName = "skill.package.yaml";