-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attempt to use pre-run hook to create package.json
- Loading branch information
1 parent
cf0d4a2
commit e66a8d1
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |