From 897ecc082f91a992b40168b08bf79f80ded409e9 Mon Sep 17 00:00:00 2001 From: David Herman Date: Wed, 27 Mar 2024 08:58:54 -0700 Subject: [PATCH] move hbs delegate into GitHub CI plugin --- pkgs/create-neon/src/ci.ts | 1 + pkgs/create-neon/src/ci/github.ts | 9 +++++++++ pkgs/create-neon/src/expand.ts | 5 ----- pkgs/create-neon/src/index.ts | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkgs/create-neon/src/ci.ts b/pkgs/create-neon/src/ci.ts index 1cd13e077..de18547bc 100644 --- a/pkgs/create-neon/src/ci.ts +++ b/pkgs/create-neon/src/ci.ts @@ -1,4 +1,5 @@ export interface CI { readonly type: string; templates(): Record; + setup(): void; } diff --git a/pkgs/create-neon/src/ci/github.ts b/pkgs/create-neon/src/ci/github.ts index 8dd1beaa2..65ec39e8e 100644 --- a/pkgs/create-neon/src/ci/github.ts +++ b/pkgs/create-neon/src/ci/github.ts @@ -1,3 +1,4 @@ +import handlebars from 'handlebars'; import { CI } from '../ci.js'; import path from 'node:path'; @@ -10,6 +11,10 @@ const TEMPLATES: Record = { "test.yml.hbs": path.join(".github", "workflows", "test.yml") }; +function githubDelegate(this: any, options: handlebars.HelperOptions): handlebars.SafeString { + return new handlebars.SafeString("${{" + options.fn(this) +"}}"); +} + export class GitHub implements CI { constructor() { } @@ -18,4 +23,8 @@ export class GitHub implements CI { templates(): Record { return TEMPLATES; } + + setup(): void { + handlebars.registerHelper('$', githubDelegate); + } } diff --git a/pkgs/create-neon/src/expand.ts b/pkgs/create-neon/src/expand.ts index 1d563711b..15d56d366 100644 --- a/pkgs/create-neon/src/expand.ts +++ b/pkgs/create-neon/src/expand.ts @@ -13,14 +13,9 @@ export interface Metadata { versions: Versions; } -// FIXME: move this into the GitHub plugin -function ghaDelegate(this: any, options: handlebars.HelperOptions): handlebars.SafeString { - return new handlebars.SafeString("${{" + options.fn(this) +"}}"); -} const COMPARISON_HELPERS = helpers('comparison'); -handlebars.registerHelper('$', ghaDelegate); handlebars.registerHelper('eq', COMPARISON_HELPERS.eq); export async function expand(source: string, metadata: Metadata): Promise { diff --git a/pkgs/create-neon/src/index.ts b/pkgs/create-neon/src/index.ts index 435258c28..b8041f169 100644 --- a/pkgs/create-neon/src/index.ts +++ b/pkgs/create-neon/src/index.ts @@ -51,6 +51,10 @@ export async function createNeon(name: string, options: CreateNeonOptions) { await die("Could not create `package.json`: " + err.message, tmpPackagePath); } if (pkg) { + if (options.library && options.library.ci) { + options.library.ci.setup(); + } + for (const source of Object.keys(options.templates)) { const target = path.join(tmpPackagePath, options.templates[source]); await expandTo(source, target, metadata);