Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
feat: add plugin-info hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed Dec 15, 2021
1 parent 9cabc18 commit 3dd4018
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"oclif.manifest.json",
"dist/**/*.js",
"scripts/include-sf.js",
"scripts/post-install-release-notes.js",
"!dist/**/*.test.js"
],
"oclif": {
Expand All @@ -37,7 +38,8 @@
],
"update": [
"./dist/hooks/lazyRequire.js",
"./dist/hooks/postupdate.js"
"./dist/hooks/postupdate.js",
"./dist/hooks/displayReleaseNotes.js"
]
},
"plugins": [
Expand Down Expand Up @@ -135,7 +137,7 @@
"@salesforce/plugin-custom-metadata": "1.0.12",
"@salesforce/plugin-data": "0.6.6",
"@salesforce/plugin-generator": "^1.1.7",
"@salesforce/plugin-info": "1.1.4",
"@salesforce/plugin-info": "^1.1.4",
"@salesforce/plugin-limits": "1.3.0",
"@salesforce/plugin-org": "1.11.0",
"@salesforce/plugin-schema": "1.1.0",
Expand Down Expand Up @@ -217,6 +219,7 @@
"pack:tarballs": "oclif pack:tarballs",
"pack:verify": "sf-release cli:tarballs:verify",
"pack:win": "oclif pack:win --additional-cli sf",
"postinstall": "node ./scripts/post-install-release-notes.js",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn test:deprecation-policy ",
"prepack": "yarn compile && yarn lint && yarn oclif-artifacts",
Expand Down
34 changes: 34 additions & 0 deletions scripts/post-install-release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

const { spawn } = require('child_process');
const { join } = require('path');

if (process.env.SFDX_HIDE_RELEASE_NOTES === 'true') process.exit(0);

const logAndExit = (msg) => {
console.log('NOTE: This error can be ignored in CI and may be silenced in the future');
console.log('- Set the SFDX_HIDE_RELEASE_NOTES env var to "true" to skip this script\n');
console.log(msg.toString());

process.exit(0);
};

var executable = process.platform === 'win32' ? 'run.cmd' : 'run';

var cmd = spawn(join(__dirname, '..', 'bin', executable), ['whatsnew', '--hook'], {
stdio: ['ignore', 'inherit', 'pipe'],
timeout: 10000,
});

cmd.stderr.on('data', (error) => {
logAndExit(error);
});

cmd.on('error', (error) => {
logAndExit(error);
});

// 'exit' fires whether or not the stream are finished
cmd.on('exit', (code) => {
process.exit(0);
});
47 changes: 47 additions & 0 deletions src/hooks/displayReleaseNotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { join } from 'path';
import { spawn } from 'child_process';
import { Hook } from '@oclif/config';
import { cli } from 'cli-ux';

if (process.env.SFDX_HIDE_RELEASE_NOTES === 'true') process.exit(0);

const logAndExit = (msg: Error): void => {
cli.log('NOTE: This error can be ignored in CI and may be silenced in the future');
cli.log('- Set the SFDX_HIDE_RELEASE_NOTES env var to "true" to skip this script\n');
cli.log(msg.toString());

process.exit(0);
};

const hook: Hook.Update = () => {
// NOTE: This is `sfdx.cmd` here and not `run.cmd` because it gets renamed here:
// https://github.com/salesforcecli/sfdx-cli/blob/4428505ab69aa6e21214dba96557e2ce396a82e0/src/hooks/postupdate.ts#L62
const executable = process.platform === 'win32' ? 'sfdx.cmd' : 'run';

const cmd = spawn(join(__dirname, '..', '..', 'bin', executable), ['whatsnew', '--hook'], {
stdio: ['ignore', 'inherit', 'pipe'],
timeout: 10000,
});

cmd.stderr.on('data', (error: Error) => {
logAndExit(error);
});

cmd.on('error', (error: Error) => {
logAndExit(error);
});

// 'exit' fires whether or not the stream are finished
cmd.on('exit', () => {
process.exit(0);
});
};

export default hook;
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@
yeoman-generator "4.0.1"
yosay "^2.0.2"

"@salesforce/[email protected]":
"@salesforce/plugin-info@^1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@salesforce/plugin-info/-/plugin-info-1.1.4.tgz#7ed26d0634f4855f9e0ac506385d9a113d74f595"
integrity sha512-gWKMDg93IihIIyc5trp6TCmxTMfDXujrW4EOkNp7qoy3L8fYMVEr0KXBtwepC6DgKqznZkUnu2QrG4q/b3GQGQ==
Expand Down

0 comments on commit 3dd4018

Please sign in to comment.