Skip to content

Commit

Permalink
feat: deprecatedCommands utils
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Sep 13, 2024
1 parent e896562 commit b321918
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 72 deletions.
30 changes: 1 addition & 29 deletions packages/solutions/app-tools/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { PluginAPI } from '@modern-js/core';
import { castArray } from '@modern-js/uni-builder';
import {
type Command,
logger,
newAction,
upgradeAction,
} from '@modern-js/utils';
import { type Command, newAction, upgradeAction } from '@modern-js/utils';
import { i18n, localeKeys } from '../locale';
import type { AppTools } from '../types';
import type {
Expand Down Expand Up @@ -191,26 +186,3 @@ export const upgradeCommand = (program: Command) => {
await upgradeAction();
});
};

export const deprecatedCommands = (program: Command) => {
program
.command('lint [...files]')
.allowUnknownOption()
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern lint" command is deprecated, please use "eslint" or "biome" instead.',
);
});

// @deprecated
// Can be removed in the next major version
program
.command('pre-commit')
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern pre-commit" command is deprecated, please use "lint-staged" instead.',
);
});
};
2 changes: 1 addition & 1 deletion packages/solutions/app-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CliPlugin } from '@modern-js/core';
import { getLocaleLanguage } from '@modern-js/plugin-i18n/language-detector';
import {
cleanRequireCache,
deprecatedCommands,
emptyDir,
getArgv,
getCommand,
Expand All @@ -18,7 +19,6 @@ import type { AppTools } from './types';
import {
buildCommand,
deployCommand,
deprecatedCommands,
devCommand,
inspectCommand,
newCommand,
Expand Down
23 changes: 2 additions & 21 deletions packages/solutions/module-tools/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CliPlugin } from '@modern-js/core';
import { fs, dotenv, logger } from '@modern-js/utils';
import { fs, deprecatedCommands, dotenv } from '@modern-js/utils';
import {
buildCommand,
devCommand,
Expand Down Expand Up @@ -53,26 +53,7 @@ const setup: CliPlugin<ModuleTools>['setup'] = async api => {
await devCommand(program, api);
await newCommand(program);
await upgradeCommand(program);
program
.command('lint [...files]')
.allowUnknownOption()
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern lint" command is deprecated, please use "eslint" or "biome" instead.',
);
});

// @deprecated
// Can be removed in the next major version
program
.command('pre-commit')
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern pre-commit" command is deprecated, please use "lint-staged" instead.',
);
});
deprecatedCommands(program);
},
};
};
23 changes: 2 additions & 21 deletions packages/solutions/monorepo-tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CliPlugin } from '@modern-js/core';
import { changesetPlugin } from '@modern-js/plugin-changeset';
import { getLocaleLanguage } from '@modern-js/plugin-i18n/language-detector';
import { logger } from '@modern-js/utils';
import { deprecatedCommands } from '@modern-js/utils';
import { clearCli, deployCli, newCli, upgradeCli } from './cli';
import { hooks } from './hooks';
import { i18n } from './locale';
Expand Down Expand Up @@ -29,26 +29,7 @@ export const monorepoTools = (): CliPlugin<MonorepoTools> => ({
deployCli(program, api);
newCli(program);
upgradeCli(program);
program
.command('lint [...files]')
.allowUnknownOption()
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern lint" command is deprecated, please use "eslint" or "biome" instead.',
);
});

// @deprecated
// Can be removed in the next major version
program
.command('pre-commit')
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern pre-commit" command is deprecated, please use "lint-staged" instead.',
);
});
deprecatedCommands(program);
},
};
},
Expand Down
33 changes: 33 additions & 0 deletions packages/toolkit/utils/src/cli/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { Command } from '../../compiled/commander';
import { logger } from './logger';

export const getFullArgv = () => {
return process.env.MODERN_ARGV?.split(' ') || process.argv;
};
Expand All @@ -16,3 +19,33 @@ export const isDevCommand = () => {
const command = getCommand();
return command === 'dev' || command === 'start';
};

// @deprecated
// Can be removed in the next major version
export const deprecatedCommands = (
program: Command & { commandsMap: Map<string, Command> },
) => {
const lintCommand = program.commandsMap.get('lint');
if (!lintCommand) {
program
.command('lint [...files]')
.allowUnknownOption()
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern lint" command is deprecated, please use "eslint" or "biome" instead.',
);
});
}
const preCommitCommand = program.commandsMap.get('pre-commit');
if (!preCommitCommand) {
program
.command('pre-commit')
.description('Deprecated')
.action(() => {
logger.warn(
'The "modern pre-commit" command is deprecated, please use "lint-staged" instead.',
);
});
}
};

0 comments on commit b321918

Please sign in to comment.