Skip to content

Commit

Permalink
🚀 Deploy new version [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
pabio-escobar committed Nov 24, 2022
1 parent 40d71b1 commit 9b5f2f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
24 changes: 0 additions & 24 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
/// <reference types="node" />
interface Item {
slug: string;
path: string;
source: string;
title?: string;
excerpt?: string;
date: Date;
attributes?: Record<string, unknown>;
caption?: string;
}
type AsyncFunctionArguments = Item & {
require: NodeRequire;
__original_require__: NodeRequire;
};
/**
* Call as async function with arguments
* @param args
* @param source
* @link https://github.com/actions/github-script/blob/main/src/async-function.ts
* @returns
*/
export declare function callAsyncFunction(args: AsyncFunctionArguments, source: string): Promise<string>;
export declare const run: () => Promise<void>;
export {};
23 changes: 7 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = exports.callAsyncFunction = void 0;
exports.run = void 0;
const core_1 = __nccwpck_require__(2186);
const child_process_1 = __nccwpck_require__(2081);
const fs_extra_1 = __nccwpck_require__(5630);
Expand Down Expand Up @@ -66,27 +66,18 @@ const parseItemFile = async (directory, year, file, caption) => {
attributes,
};
if (caption) {
const captionData = await callAsyncFunction({ ...result, require, __original_require__: require }, caption);
// I know, I know...
const captionData = eval(`(function (data) {
const { slug, path, source, title, date, excerpt, attributes } = data;
${caption}
})(${JSON.stringify(result)})`);
if (captionData)
result.caption = captionData;
}
return result;
};
const token = (0, core_1.getInput)("token") || process.env.GH_PAT || process.env.GITHUB_TOKEN;
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
/**
* Call as async function with arguments
* @param args
* @param source
* @link https://github.com/actions/github-script/blob/main/src/async-function.ts
* @returns
*/
function callAsyncFunction(args, source) {
const fn = new AsyncFunction(...Object.keys(args), source);
return fn(...Object.values(args));
}
exports.callAsyncFunction = callAsyncFunction;
const run = async () => {
const token = (0, core_1.getInput)("token") || process.env.GH_PAT || process.env.GITHUB_TOKEN;
if (!token)
throw new Error("GitHub token not found");
const directory = (0, core_1.getInput)("directory");
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit 9b5f2f7

Please sign in to comment.