Skip to content

Commit

Permalink
move hbs delegate into GitHub CI plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Mar 27, 2024
1 parent ba69ff3 commit 897ecc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkgs/create-neon/src/ci.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface CI {
readonly type: string;
templates(): Record<string, string>;
setup(): void;
}
9 changes: 9 additions & 0 deletions pkgs/create-neon/src/ci/github.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import handlebars from 'handlebars';
import { CI } from '../ci.js';
import path from 'node:path';

Expand All @@ -10,6 +11,10 @@ const TEMPLATES: Record<string, string> = {
"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() { }

Expand All @@ -18,4 +23,8 @@ export class GitHub implements CI {
templates(): Record<string, string> {
return TEMPLATES;
}

setup(): void {
handlebars.registerHelper('$', githubDelegate);
}
}
5 changes: 0 additions & 5 deletions pkgs/create-neon/src/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/create-neon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 897ecc0

Please sign in to comment.