From b8462da2b734853081a65035320fa9dd6ffaf81d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 8 Jan 2022 18:15:37 +1100 Subject: [PATCH] Use resolved path for actions-yml (#232) (#233) Co-authored-by: James Forbes --- lib/index.js | 12 +++++++++--- package.json | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4580b30..79515c3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ /* globals console, process */ import { Buffer } from 'buffer' import path from 'path' +import { URL } from 'url' import { chalk, argv as _argv, $, fs } from 'zx' import dotenv from 'dotenv' import { Octokit as OriginalOctokit } from 'octokit' @@ -10,7 +11,6 @@ import Module from 'module' let require = Module.createRequire(import.meta.url) let pkg = require('../package.json') - let Octokit = OriginalOctokit.plugin(throttling) dotenv.config() @@ -18,6 +18,12 @@ let argv = { ..._argv } argv.verbose = argv.verbose || argv.v $.verbose = argv.verbose +let __dirname = + path.dirname(new URL('', import.meta.url).pathname); + +let repoPath = + filepath => path.resolve(__dirname, '..', filepath); + /** * @typedef { import("octokit").Octokit } Octokit */ @@ -251,7 +257,7 @@ async function generateTemplates(){ z=z.replace(/\bmain\b/gm, '$target') z = z.replace(/(.*)#\s+prr:comment/gm, '#$1') z = z.replace(/(.*)#\s+prr:remove/gm, '') - await fs.writeFile(`./templates/${x}`, z) + await fs.writeFile(repoPath(`./templates/${x}`), z) } } @@ -265,7 +271,7 @@ async function actionsYML(){ ] for( let file of templates ) { - let x = await fs.readFile(`./templates/${file}`, 'utf8') + let x = await fs.readFile(repoPath(`./templates/${file}`), 'utf8') x = x.replace(/\$target/g, target) x = x.replace(/\$source/g, source) await fs.writeFile(`./.github/workflows/${file}`, x) diff --git a/package.json b/package.json index 98cf66e..35334a9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ ], "files": [ "lib/*", - "dist/*" + "dist/*", + "templates/*" ], "author": "JAForbes", "license": "MIT",