Skip to content

Commit

Permalink
feat: attempt to use pre-run hook to create package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Nov 18, 2024
1 parent cf0d4a2 commit e66a8d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ outputs:
description: The rdme command result output
runs:
using: node20
pre: bin/write-gha-pjson.js
main: dist-gha/run.cjs
35 changes: 35 additions & 0 deletions bin/write-gha-pjson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env node
// @ts-check

import fs from 'node:fs';
import path from 'node:path';

const newTarget = './cmds.js';

/**
* We need to duplicate the `package.json` file (with a few modifications) from the root of the project to the
* `dist-gha` directory, so that the GitHub Actions-flavored `oclif` configuration can find it.
*/
function writeGitHubActionsPackageJson() {
const current = JSON.parse(
fs.readFileSync(path.resolve(import.meta.dirname, '../package.json'), { encoding: 'utf-8' }),
);

current.private = true;

// set the correct targets for GitHub Actions
current.oclif.commands.target = newTarget;
Object.values(current.oclif.hooks).forEach(hook => {
// eslint-disable-next-line no-param-reassign
hook.target = newTarget;
});

// remove properties that are only applicable in a CLI context
delete current.oclif.helpClass;
delete current.oclif.plugins;

// write the new package.json file
fs.writeFileSync(path.resolve(import.meta.dirname, '../dist-gha/package.json'), JSON.stringify(current, null, 2));
}

writeGitHubActionsPackageJson();

0 comments on commit e66a8d1

Please sign in to comment.