Skip to content

Commit

Permalink
fix: replace colors with chalk (#2666)
Browse files Browse the repository at this point in the history
* chore(deps): upgrade electron-rebuild to ^3.2.6
  • Loading branch information
malept authored Jan 9, 2022
1 parent 0a71bc6 commit e909ae8
Show file tree
Hide file tree
Showing 32 changed files with 303 additions and 192 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ updates:
- dependency-name: '@aws-sdk/lib-storage'
- dependency-name: '@aws-sdk/types'
- dependency-name: '@types/node-fetch'
- dependency-name: 'chalk'
- dependency-name: commander
- dependency-name: electron-notarize
- dependency-name: find-up
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
"@octokit/plugin-retry": "^3.0.9",
"@octokit/rest": "^18.0.11",
"@octokit/types": "^6.1.2",
"chalk": "^4.0.0",
"colors": "^1.4.0",
"commander": "^4.1.1",
"cross-spawn": "^7.0.3",
"cross-zip": "^4.0.0",
"debug": "^4.3.1",
"electron-osx-sign": "^0.5.0",
"electron-packager": "^15.4.0",
"electron-rebuild": "^3.2.2",
"electron-rebuild": "^3.2.6",
"express": "^4.17.1",
"express-ws": "^5.0.2",
"fast-glob": "^3.2.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@electron-forge/core": "6.0.0-beta.61",
"@electron-forge/shared-types": "6.0.0-beta.61",
"@electron/get": "^1.9.0",
"colors": "^1.4.0",
"chalk": "^4.0.0",
"commander": "^4.1.1",
"debug": "^4.3.1",
"fs-extra": "^10.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/api/cli/src/electron-forge-install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { api, InstallAsset } from '@electron-forge/core';

import chalk from 'chalk';
import fs from 'fs-extra';
import inquirer from 'inquirer';
import program from 'commander';
Expand Down Expand Up @@ -28,7 +29,7 @@ import './util/terminate';
choices,
type: 'list',
name: 'assetID',
message: 'Multiple potential assets found, please choose one from the list below:'.cyan,
message: chalk.cyan('Multiple potential assets found, please choose one from the list below:'),
});

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
8 changes: 4 additions & 4 deletions packages/api/cli/src/electron-forge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'colors';
import { asyncOra } from '@electron-forge/async-ora';
import chalk from 'chalk';
import program from 'commander';

import './util/terminate';
Expand Down Expand Up @@ -41,7 +41,7 @@ program
// eslint-disable-next-line no-underscore-dangle
if (!program._execs.has(commands[0])) {
console.error();
console.error(`Unknown command "${program.args.join(' ')}".`.red);
console.error(chalk.red(`Unknown command "${program.args.join(' ')}".`));
console.error('See --help for a list of available commands.');
process.exit(1);
}
Expand All @@ -55,8 +55,8 @@ program

if (!goodSystem) {
console.error(
`It looks like you are missing some dependencies you need to get Electron running.
Make sure you have git installed and Node.js version ${metadata.engines.node}`.red
chalk.red(`It looks like you are missing some dependencies you need to get Electron running.
Make sure you have git installed and Node.js version ${metadata.engines.node}`)
);
process.exit(1);
}
Expand Down
24 changes: 14 additions & 10 deletions packages/api/cli/src/util/terminate.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import colors from 'colors';
import chalk from 'chalk';

function redConsoleError(msg: string) {
console.error(chalk.red(msg));
}

process.on('unhandledRejection', (reason: string, promise: Promise<unknown>) => {
console.error('\nAn unhandled rejection has occurred inside Forge:'.red);
console.error(colors.red(reason.toString()));
console.error('\nElectron Forge was terminated. Location:'.red);
console.error(colors.red(JSON.stringify(promise)));
redConsoleError('\nAn unhandled rejection has occurred inside Forge:');
redConsoleError(reason.toString());
redConsoleError('\nElectron Forge was terminated. Location:');
redConsoleError(JSON.stringify(promise));
process.exit(1);
});

process.on('uncaughtException', (err) => {
if (err && err.message && err.stack) {
console.error('\nAn unhandled exception has occurred inside Forge:'.red);
console.error(colors.red(err.message));
console.error(colors.red(err.stack));
redConsoleError('\nAn unhandled exception has occurred inside Forge:');
redConsoleError(err.message);
redConsoleError(err.stack);
} else {
console.error('\nElectron Forge was terminated:'.red);
console.error(colors.red(typeof err === 'string' ? err : JSON.stringify(err)));
redConsoleError('\nElectron Forge was terminated:');
redConsoleError(typeof err === 'string' ? err : JSON.stringify(err));
}
process.exit(1);
});
4 changes: 2 additions & 2 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"@electron-forge/template-webpack": "6.0.0-beta.61",
"@electron/get": "^1.9.0",
"@malept/cross-spawn-promise": "^2.0.0",
"colors": "^1.4.0",
"chalk": "^4.0.0",
"debug": "^4.3.1",
"electron-packager": "^15.4.0",
"electron-rebuild": "^3.2.2",
"electron-rebuild": "^3.2.6",
"fast-glob": "^3.2.7",
"find-up": "^5.0.0",
"fs-extra": "^10.0.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/api/core/src/api/import.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { merge } from 'lodash';
import { asyncOra } from '@electron-forge/async-ora';
import baseTemplate from '@electron-forge/template-base';
import chalk from 'chalk';
import debug from 'debug';
import fs from 'fs-extra';
import { merge } from 'lodash';
import path from 'path';

import initGit from './init-scripts/init-git';
Expand Down Expand Up @@ -85,7 +86,7 @@ export default async ({
let packageJSON = await readRawPackageJson(dir);
if (packageJSON.config && packageJSON.config.forge) {
if (packageJSON.config.forge.makers) {
warn(interactive, 'It looks like this project is already configured for Electron Forge'.green);
warn(interactive, chalk.green('It looks like this project is already configured for Electron Forge'));
if (typeof shouldContinueOnExisting === 'function') {
if (!(await shouldContinueOnExisting())) {
// TODO: figure out if we can just return early here
Expand All @@ -96,8 +97,9 @@ export default async ({
} else if (typeof packageJSON.config.forge === 'string') {
warn(
interactive,
"We can't tell if the Electron Forge config is compatible because it's in an external JavaScript file, not trying to convert it and continuing anyway"
.yellow
chalk.yellow(
"We can't tell if the Electron Forge config is compatible because it's in an external JavaScript file, not trying to convert it and continuing anyway"
)
);
} else {
d('Upgrading an Electron Forge < 6 project');
Expand Down Expand Up @@ -191,7 +193,7 @@ export default async ({
packageJSON = await readRawPackageJson(dir);

if (!packageJSON.version) {
warn(interactive, 'Please set the "version" in your application\'s package.json'.yellow);
warn(interactive, chalk.yellow('Please set the "version" in your application\'s package.json'));
}

packageJSON.config = packageJSON.config || {};
Expand Down Expand Up @@ -225,6 +227,6 @@ export default async ({
We have ATTEMPTED to convert your app to be in a format that electron-forge understands.
Thanks for using ${'"electron-forge"'.green}!!!`
Thanks for using ${chalk.green('Electron Forge')}!!!`
);
};
1 change: 0 additions & 1 deletion packages/api/core/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'colors';
import { ElectronProcess, ForgeMakeResult } from '@electron-forge/shared-types';

import _import, { ImportOptions } from './import';
Expand Down
8 changes: 4 additions & 4 deletions packages/api/core/src/api/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'colors';
import { asyncOra } from '@electron-forge/async-ora';
import InstallerBase from '@electron-forge/installer-base';
import chalk from 'chalk';
import debug from 'debug';
import fetch from 'node-fetch';
import fs from 'fs-extra';
Expand All @@ -9,6 +8,7 @@ import path from 'path';
import { promisify } from 'util';
import semver from 'semver';

import InstallerBase from '@electron-forge/installer-base';
import DMGInstaller from '@electron-forge/installer-dmg';
import ZipInstaller from '@electron-forge/installer-zip';
import DebInstaller from '@electron-forge/installer-deb';
Expand Down Expand Up @@ -133,11 +133,11 @@ export default async ({ interactive = false, prerelease = false, repo, chooseAss
});

if (possibleAssets.length === 0) {
throw new Error(`Failed to find any installable assets for target platform: ${`${process.platform}`.cyan}`);
throw new Error(`Failed to find any installable assets for target platform: ${chalk.cyan(`${process.platform}`)}`);
}
});

info(interactive, `Found latest release${prerelease ? ' (including prereleases)' : ''}: ${latestRelease.tag_name.cyan}`);
info(interactive, `Found latest release${prerelease ? ' (including prereleases)' : ''}: ${chalk.cyan(latestRelease.tag_name)}`);

let targetAsset = possibleAssets[0];
if (possibleAssets.length > 1) {
Expand Down
1 change: 0 additions & 1 deletion packages/api/core/src/api/lint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'colors';
import { asyncOra } from '@electron-forge/async-ora';
import debug from 'debug';
import { yarnOrNpmSpawn } from '../util/yarn-or-npm';
Expand Down
99 changes: 51 additions & 48 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'colors';
import { asyncOra } from '@electron-forge/async-ora';
import chalk from 'chalk';
import { getHostArch } from '@electron/get';
import { IForgeResolvableMaker, ForgeConfig, ForgeArch, ForgePlatform, ForgeMakeResult } from '@electron-forge/shared-types';
import MakerBase from '@electron-forge/maker-base';
Expand Down Expand Up @@ -157,7 +157,7 @@ export default async ({
}

if (!skipPackage) {
info(interactive, 'We need to package your application before we can make it'.green);
info(interactive, chalk.green('We need to package your application before we can make it'));
await packager({
dir,
interactive,
Expand All @@ -166,7 +166,7 @@ export default async ({
platform: actualTargetPlatform,
});
} else {
warn(interactive, 'WARNING: Skipping the packaging step, this could result in an out of date build'.red);
warn(interactive, chalk.red('WARNING: Skipping the packaging step, this could result in an out of date build'));
}

targets = targets.filter((_, i) => makers[i]);
Expand All @@ -175,7 +175,7 @@ export default async ({
throw new Error(`Could not find any make targets configured for the "${actualTargetPlatform}" platform.`);
}

info(interactive, `Making for the following targets: ${`${targets.map((_t, i) => makers[i].name).join(', ')}`.cyan}`);
info(interactive, `Making for the following targets: ${chalk.cyan(`${targets.map((_t, i) => makers[i].name).join(', ')}`)}`);

const packageJSON = await readMutatedPackageJson(dir, forgeConfig);
const appName = forgeConfig.packagerConfig.name || packageJSON.productName || packageJSON.name;
Expand All @@ -196,52 +196,55 @@ export default async ({
targetId += 1;

// eslint-disable-next-line no-loop-func
await asyncOra(`Making for target: ${maker.name.green} - On platform: ${actualTargetPlatform.cyan} - For arch: ${targetArch.cyan}`, async () => {
try {
/**
* WARNING: DO NOT ATTEMPT TO PARALLELIZE MAKERS
*
* Currently it is assumed we have 1 maker per make call but that is
* not enforced. It is technically possible to have 1 maker be called
* multiple times. The "prepareConfig" method however implicitly
* requires a lock that is not enforced. There are two options:
*
* * Provide makers a getConfig() method
* * Remove support for config being provided as a method
* * Change the entire API of maker from a single constructor to
* providing a MakerFactory
*/
maker.prepareConfig(targetArch);
const artifacts = await maker.make({
appName,
forgeConfig,
packageJSON,
targetArch,
dir: packageDir,
makeDir: path.resolve(actualOutDir, 'make'),
targetPlatform: actualTargetPlatform,
});

outputs.push({
artifacts,
packageJSON,
platform: actualTargetPlatform,
arch: targetArch,
});
} catch (err) {
if (err instanceof Error) {
// eslint-disable-next-line no-throw-literal
throw {
message: `An error occured while making for target: ${maker.name}`,
stack: `${err.message}\n${err.stack}`,
};
} else if (err) {
throw err;
} else {
throw new Error(`An unknown error occured while making for target: ${maker.name}`);
await asyncOra(
`Making for target: ${chalk.green(maker.name)} - On platform: ${chalk.cyan(actualTargetPlatform)} - For arch: ${chalk.cyan(targetArch)}`,
async () => {
try {
/**
* WARNING: DO NOT ATTEMPT TO PARALLELIZE MAKERS
*
* Currently it is assumed we have 1 maker per make call but that is
* not enforced. It is technically possible to have 1 maker be called
* multiple times. The "prepareConfig" method however implicitly
* requires a lock that is not enforced. There are two options:
*
* * Provide makers a getConfig() method
* * Remove support for config being provided as a method
* * Change the entire API of maker from a single constructor to
* providing a MakerFactory
*/
maker.prepareConfig(targetArch);
const artifacts = await maker.make({
appName,
forgeConfig,
packageJSON,
targetArch,
dir: packageDir,
makeDir: path.resolve(actualOutDir, 'make'),
targetPlatform: actualTargetPlatform,
});

outputs.push({
artifacts,
packageJSON,
platform: actualTargetPlatform,
arch: targetArch,
});
} catch (err) {
if (err instanceof Error) {
// eslint-disable-next-line no-throw-literal
throw {
message: `An error occured while making for target: ${maker.name}`,
stack: `${err.message}\n${err.stack}`,
};
} else if (err) {
throw err;
} else {
throw new Error(`An unknown error occured while making for target: ${maker.name}`);
}
}
}
});
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'colors';
import { ora as realOra, fakeOra, OraImpl } from '@electron-forge/async-ora';
import { ForgeArch, ForgePlatform } from '@electron-forge/shared-types';
import chalk from 'chalk';
import debug from 'debug';
import fs from 'fs-extra';
import { getHostArch } from '@electron/get';
Expand Down Expand Up @@ -82,7 +82,7 @@ export default async ({
}: PackageOptions): Promise<void> => {
const ora = interactive ? realOra : fakeOra;

let prepareSpinner = ora(`Preparing to Package Application for arch: ${(arch === 'all' ? 'ia32' : arch).cyan}`).start();
let prepareSpinner = ora(`Preparing to Package Application for arch: ${chalk.cyan(arch === 'all' ? 'ia32' : arch)}`).start();
let prepareCounter = 0;

const resolvedDir = await resolveDir(dir);
Expand All @@ -108,7 +108,7 @@ export default async ({
if (packagerSpinner) {
packagerSpinner.succeed();
prepareCounter += 1;
prepareSpinner = ora(`Preparing to Package Application for arch: ${(prepareCounter === 2 ? 'armv7l' : 'x64').cyan}`).start();
prepareSpinner = ora(`Preparing to Package Application for arch: ${chalk.cyan(prepareCounter === 2 ? 'armv7l' : 'x64')}`).start();
}
const bins = await glob(path.join(buildPath, '**/.bin/**/*'));
for (const bin of bins) {
Expand Down Expand Up @@ -183,7 +183,7 @@ export default async ({
// eslint-disable-next-line max-len
warn(
interactive,
'Please set "version" or "config.forge.packagerConfig.appVersion" in your application\'s package.json so auto-updates work properly'.yellow
chalk.yellow('Please set "version" or "config.forge.packagerConfig.appVersion" in your application\'s package.json so auto-updates work properly')
);
}

Expand Down
Loading

0 comments on commit e909ae8

Please sign in to comment.