chore(prettier): full repo linting and code reformatting once and for all (#3627)

This commit is contained in:
Alireza authored and GitHub committed 2023-09-01 16:19:39 -04:00
1 parent 01500a2d4c
commit 9045ddaedc
656 files changed
+21737 -20628

No files matched your search

+1 -3
View File
@@ -44,9 +44,7 @@ export default async function addExtension(packageName, version) {
.run()
.then(ctx => {
console.log(
`${chalk.green.bold(
`Added ohif-extension ${packageName}@${ctx.yarnInfo.version}`
)} `
`${chalk.green.bold(`Added ohif-extension ${packageName}@${ctx.yarnInfo.version}`)} `
);
})
.catch(error => {
+1 -3
View File
@@ -28,9 +28,7 @@ export default async function addExtensions(ohifExtensions) {
extensonsString += ` ${packageName}@${version}`;
});
console.log(
`${chalk.green.bold(`Extensions added:${extensonsString}`)} `
);
console.log(`${chalk.green.bold(`Extensions added:${extensonsString}`)} `);
})
.catch(error => {
console.log(error.message);
+2 -8
View File
@@ -39,9 +39,7 @@ export default async function addMode(packageName, version) {
{
title: 'Detecting required ohif-extensions...',
task: async ctx => {
ctx.ohifExtensions = await findRequiredOhifExtensionsForMode(
ctx.yarnInfo
);
ctx.ohifExtensions = await findRequiredOhifExtensionsForMode(ctx.yarnInfo);
},
},
],
@@ -53,11 +51,7 @@ export default async function addMode(packageName, version) {
await tasks
.run()
.then(async ctx => {
console.log(
`${chalk.green.bold(
`Added ohif-mode ${packageName}@${ctx.yarnInfo.version}`
)} `
);
console.log(`${chalk.green.bold(`Added ohif-mode ${packageName}@${ctx.yarnInfo.version}`)} `);
const ohifExtensions = ctx.ohifExtensions;
+7 -27
View File
@@ -28,11 +28,7 @@ const createPackage = async options => {
{
title: 'Copying template files',
task: () =>
createDirectoryContents(
options.templateDir,
options.targetDir,
options.prettier
),
createDirectoryContents(options.templateDir, options.targetDir, options.prettier),
},
{
title: 'Editing Package.json with provided information',
@@ -59,36 +55,20 @@ const createPackage = async options => {
await tasks.run();
console.log();
console.log(
chalk.green(`Done: ${packageType} is ready at`, options.targetDir)
);
console.log(chalk.green(`Done: ${packageType} is ready at`, options.targetDir));
console.log();
console.log(
chalk.green(`NOTE: In order to use this ${packageType} for development,`)
);
console.log(
chalk.green(
`run the following command inside the root of the OHIF monorepo`
)
);
console.log(chalk.green(`NOTE: In order to use this ${packageType} for development,`));
console.log(chalk.green(`run the following command inside the root of the OHIF monorepo`));
console.log();
console.log(
chalk.green.bold(
` yarn run cli link-${packageType} ${options.targetDir}`
)
);
console.log(chalk.green.bold(` yarn run cli link-${packageType} ${options.targetDir}`));
console.log();
console.log(
chalk.yellow(
"and when you don't need it anymore, run the following command to unlink it"
)
chalk.yellow("and when you don't need it anymore, run the following command to unlink it")
);
console.log();
console.log(
chalk.yellow(` yarn run cli unlink-${packageType} ${options.name}`)
);
console.log(chalk.yellow(` yarn run cli unlink-${packageType} ${options.name}`));
console.log();
return true;
+2 -10
View File
@@ -2,11 +2,7 @@ import fs from 'fs';
import path from 'path';
import { execa } from 'execa';
import { keywords } from './enums/index.js';
import {
validateYarn,
addExtensionToConfig,
addModeToConfig,
} from './utils/index.js';
import { validateYarn, addExtensionToConfig, addModeToConfig } from './utils/index.js';
async function linkPackage(packageDir, options, addToConfig, keyword) {
const { viewerDirectory } = options;
@@ -43,11 +39,7 @@ async function linkPackage(packageDir, options, addToConfig, keyword) {
// Add the node_modules of the linked package so that webpack
// can find the linked package externals if there are
const webpackPwaPath = path.join(
viewerDirectory,
'.webpack',
'webpack.pwa.js'
);
const webpackPwaPath = path.join(viewerDirectory, '.webpack', 'webpack.pwa.js');
async function updateWebpackConfig(webpackConfigPath, packageDir) {
const packageNodeModules = path.join(packageDir, 'node_modules');
+2 -5
View File
@@ -19,8 +19,7 @@ export default async function removeExtension(packageName) {
},
{
title: `Checking if ${packageName} is in use by an installed mode`,
task: async () =>
await throwIfExtensionUsedByInstalledMode(packageName),
task: async () => await throwIfExtensionUsedByInstalledMode(packageName),
},
{
title: `Uninstalling npm package: ${packageName}`,
@@ -39,9 +38,7 @@ export default async function removeExtension(packageName) {
await tasks
.run()
.then(() => {
console.log(
`${chalk.green.bold(`Removed ohif-extension ${packageName}`)} `
);
console.log(`${chalk.green.bold(`Removed ohif-extension ${packageName}`)} `);
})
.catch(error => {
console.log(error.message);
@@ -28,9 +28,7 @@ export default async function removeExtensions(ohifExtensionsToRemove) {
extensonsString += ` ${packageName}`;
});
console.log(
`${chalk.green.bold(`Extensions removed:${extensonsString}`)} `
);
console.log(`${chalk.green.bold(`Extensions removed:${extensonsString}`)} `);
})
.catch(error => {
console.log(error.message);
+3 -12
View File
@@ -1,11 +1,7 @@
import { execa } from 'execa';
import fs from 'fs';
import path from 'path';
import {
validateYarn,
removeExtensionFromConfig,
removeModeFromConfig,
} from './utils/index.js';
import { validateYarn, removeExtensionFromConfig, removeModeFromConfig } from './utils/index.js';
const linkPackage = async (packageName, options, removeFromConfig) => {
const { viewerDirectory } = options;
@@ -19,11 +15,7 @@ const linkPackage = async (packageName, options, removeFromConfig) => {
const results = await execa(`yarn`, ['unlink', packageName]);
console.log(results.stdout);
const webpackPwaPath = path.join(
viewerDirectory,
'.webpack',
'webpack.pwa.js'
);
const webpackPwaPath = path.join(viewerDirectory, '.webpack', 'webpack.pwa.js');
await removePathFromWebpackConfig(webpackPwaPath, packageName);
@@ -58,8 +50,7 @@ async function removePathFromWebpackConfig(webpackConfigPath, packageName) {
endIndex++;
}
const modifiedFileContent =
fileContent.slice(0, startIndex) + fileContent.slice(endIndex);
const modifiedFileContent = fileContent.slice(0, startIndex) + fileContent.slice(endIndex);
await fs.promises.writeFile(webpackConfigPath, modifiedFileContent);
}
@@ -1,11 +1,7 @@
import fs from 'fs';
// https://github.dev/leoroese/template-cli/blob/628dd24db7df399ebb520edd0bc301bc7b5e8b66/index.js#L19
const createDirectoryContents = (
templatePath,
targetDirPath,
copyPrettierRules
) => {
const createDirectoryContents = (templatePath, targetDirPath, copyPrettierRules) => {
const filesToCreate = fs.readdirSync(templatePath);
filesToCreate.forEach(file => {
@@ -1,9 +1,7 @@
import { readPluginConfigFile } from './private/index.js';
import getYarnInfo from './getYarnInfo.js';
export default async function findOhifExtensionsToRemoveAfterRemovingMode(
removedModeYarnInfo
) {
export default async function findOhifExtensionsToRemoveAfterRemovingMode(removedModeYarnInfo) {
const pluginConfig = readPluginConfigFile();
if (!pluginConfig) {
@@ -13,27 +11,21 @@ export default async function findOhifExtensionsToRemoveAfterRemovingMode(
const { modes, extensions } = pluginConfig;
const registeredExtensions = extensions.map(
extension => extension.packageName
);
const registeredExtensions = extensions.map(extension => extension.packageName);
// TODO this is not a function
const ohifExtensionsOfMode = Object.keys(
removedModeYarnInfo.peerDependencies
).filter(peerDependency => registeredExtensions.includes(peerDependency));
const ohifExtensionsUsedInOtherModes = ohifExtensionsOfMode.map(
packageName => {
return {
packageName,
used: false,
};
}
const ohifExtensionsOfMode = Object.keys(removedModeYarnInfo.peerDependencies).filter(
peerDependency => registeredExtensions.includes(peerDependency)
);
const ohifExtensionsUsedInOtherModes = ohifExtensionsOfMode.map(packageName => {
return {
packageName,
used: false,
};
});
// Check if other modes use each extension used by this mode
const otherModes = modes.filter(
mode => mode.packageName !== removedModeYarnInfo.name
);
const otherModes = modes.filter(mode => mode.packageName !== removedModeYarnInfo.name);
for (let i = 0; i < otherModes.length; i++) {
const mode = otherModes[i];
+1 -4
View File
@@ -10,10 +10,7 @@ import {
import getYarnInfo from './getYarnInfo.js';
import { addExtensionToConfig, addModeToConfig } from './addToConfig.js';
import findRequiredOhifExtensionsForMode from './findRequiredOhifExtensionsForMode.js';
import {
removeExtensionFromConfig,
removeModeFromConfig,
} from './removeFromConfig.js';
import { removeExtensionFromConfig, removeModeFromConfig } from './removeFromConfig.js';
import throwIfExtensionUsedByInstalledMode from './throwIfExtensionUsedByInstalledMode.js';
import findOhifExtensionsToRemoveAfterRemovingMode from './findOhifExtensionsToRemoveAfterRemovingMode.js';
import initGit from './initGit.js';
@@ -17,9 +17,7 @@ function removeModeFromConfigJson(pluginConfig, { packageName }) {
function removeFromList(listName, pluginConfig, { packageName }) {
const list = pluginConfig[listName];
const indexOfExistingEntry = list.findIndex(
entry => entry.packageName === packageName
);
const indexOfExistingEntry = list.findIndex(entry => entry.packageName === packageName);
if (indexOfExistingEntry !== -1) {
pluginConfig[listName].splice(indexOfExistingEntry, 1);
+6 -22
View File
@@ -25,9 +25,7 @@ async function validateExtensionYarnInfo(packageName) {
function validateYarnInfo(packageName, keyword) {
return new Promise(async (resolve, reject) => {
function rejectIfNotFound() {
const error = new Error(
`${chalk.red.bold('Error')} extension ${packageName} not installed`
);
const error = new Error(`${chalk.red.bold('Error')} extension ${packageName} not installed`);
reject(error);
}
@@ -116,16 +114,11 @@ function validate(packageName, version, keyword) {
Authorization: `Bearer ${process.env.NPM_TOKEN}`,
};
}
const response = await fetch(
`${registryUrlOfPackage}${packageName}`,
options
);
const response = await fetch(`${registryUrlOfPackage}${packageName}`, options);
const json = await response.json();
if (json.error && json.error === NOT_FOUND) {
const error = new Error(
`${chalk.red.bold('Error')} package ${packageName} not found`
);
const error = new Error(`${chalk.red.bold('Error')} package ${packageName} not found`);
reject(error);
return;
}
@@ -142,27 +135,18 @@ function validate(packageName, version, keyword) {
resolve(true);
} else {
const error = new Error(
`${chalk.red.bold(
'Error'
)} package ${packageName} is not an ${keyword}`
`${chalk.red.bold('Error')} package ${packageName} is not an ${keyword}`
);
reject(error);
}
} else {
// Particular version undefined
const error = new Error(
`${chalk.red.bold(
'Error'
)} version ${packageVersion} of package ${packageName} not found`
`${chalk.red.bold('Error')} version ${packageVersion} of package ${packageName} not found`
);
reject(error);
}
});
}
export {
validateMode,
validateExtension,
validateModeYarnInfo,
validateExtensionYarnInfo,
};
export { validateMode, validateExtension, validateModeYarnInfo, validateExtensionYarnInfo };
+6 -20
View File
@@ -32,15 +32,11 @@ try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
if (packageJson.name !== 'ohif-monorepo-root') {
console.log(packageJson);
console.log(
chalk.red('ohif-cli must run from the root of the OHIF platform')
);
console.log(chalk.red('ohif-cli must run from the root of the OHIF platform'));
process.exit(1);
}
} catch (error) {
console.log(
chalk.red('ohif-cli must run from the root of the OHIF platform')
);
console.log(chalk.red('ohif-cli must run from the root of the OHIF platform'));
process.exit(1);
}
@@ -142,15 +138,11 @@ program
program
.command('link-extension <packageDir>')
.description(
'Links a local OHIF Extension to the Viewer to be used for development'
)
.description('Links a local OHIF Extension to the Viewer to be used for development')
.action(packageDir => {
if (!fs.existsSync(packageDir)) {
console.log(
chalk.red(
'The Extension directory does not exist, please provide a valid directory'
)
chalk.red('The Extension directory does not exist, please provide a valid directory')
);
process.exit(1);
}
@@ -171,16 +163,10 @@ program
program
.command('link-mode <packageDir>')
.description(
'Links a local OHIF Mode to the Viewer to be used for development'
)
.description('Links a local OHIF Mode to the Viewer to be used for development')
.action(packageDir => {
if (!fs.existsSync(packageDir)) {
console.log(
chalk.red(
'The Mode directory does not exist, please provide a valid directory'
)
);
console.log(chalk.red('The Mode directory does not exist, please provide a valid directory'));
process.exit(1);
}
linkMode(packageDir, { viewerDirectory });