Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add upgrade reminder #3569

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"devDependencies": {
"@malept/cross-spawn-promise": "^2.0.0",
"@types/update-notifier": "6.0.8",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"mocha": "^9.0.1"
Expand All @@ -25,7 +26,9 @@
"debug": "^4.3.1",
"fs-extra": "^10.0.0",
"listr2": "^7.0.2",
"semver": "^7.2.1"
"semver": "^7.2.1",
"update-notifier": "5.1.0",
"boxen": "5.1.2"
},
"engines": {
"node": ">= 16.4.0"
Expand Down
46 changes: 46 additions & 0 deletions packages/api/cli/src/electron-forge-start.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
import { createRequire } from 'module';
import path from 'path';

import { api, StartOptions } from '@electron-forge/core';
import { ElectronProcess } from '@electron-forge/shared-types';
import boxen, { Options } from 'boxen';
import chalk from 'chalk';
import program from 'commander';
import fs from 'fs-extra';
// eslint-disable-next-line node/no-unpublished-import
import updateNotifier from 'update-notifier';

import './util/terminate';
import workingDir from './util/working-dir';

let userPackage;
try {
userPackage = createRequire(path.resolve('package.json'))('./package.json');
} catch {
console.warn(`path=${'package.json'} file not found at CWD: path=${process.cwd()}.`);
}
(async () => {
let commandArgs = process.argv;
let appArgs;
const notifier = updateNotifier({
pkg: await fs.readJson(path.resolve(__dirname, '../package.json')),
// Use 0 for debugging.
updateCheckInterval: 1000 * 60 * 60,
});
if (notifier.update) {
const sitePackagesForUpdate = Object.keys({
...userPackage.devDependencies,
})
.filter((p) => p.startsWith('@electron-forge'))
.map((p) => p.concat('@latest'))
.join(' ');
const boxenOptions: Options = {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'cyan',
borderStyle: {
topLeft: '╭',
topRight: '╮',
bottomLeft: '╰',
bottomRight: '╯',
horizontal: '─',
vertical: '│',
},
};
const forgeUpdateMessage = boxen(
`Update available ${chalk.dim(`${notifier.update.current}`)} → ${chalk.green(`${notifier.update.latest}`)}

To upgrade Electron Forge packages to the latest version, execute the following command:
${chalk.cyanBright(`npm i ${sitePackagesForUpdate}`)}`,
boxenOptions
);
console.log(forgeUpdateMessage);
}

const doubleDashIndex = process.argv.indexOf('--');
if (doubleDashIndex !== -1) {
Expand Down
Loading