From 74a963bccfe2bcc373dc189f1d16cf4f38003b9d Mon Sep 17 00:00:00 2001 From: caohuilin Date: Tue, 15 Oct 2024 16:46:26 +0800 Subject: [PATCH] feat: add prepare global loading --- packages/toolkit/create/src/createAction.ts | 11 ++++++++++- packages/toolkit/upgrade/package.json | 3 ++- packages/toolkit/upgrade/src/index.ts | 2 +- packages/toolkit/upgrade/src/upgrade.ts | 11 ++++++++++- pnpm-lock.yaml | 9 ++++++--- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/toolkit/create/src/createAction.ts b/packages/toolkit/create/src/createAction.ts index 7f30aff2ec6a..1c62fe9deb26 100644 --- a/packages/toolkit/create/src/createAction.ts +++ b/packages/toolkit/create/src/createAction.ts @@ -1,5 +1,6 @@ import path from 'path'; import { CodeSmith, type Logger } from '@modern-js/codesmith'; +import { ora } from '@modern-js/codesmith-utils/ora'; import { getLocaleLanguage } from '@modern-js/plugin-i18n/language-detector'; import { version as pkgVersion } from '../package.json'; import { i18n, localeKeys } from './locale'; @@ -134,6 +135,10 @@ export async function createAction(projectDir: string, options: Options) { } smith.logger?.timing('🕒 Run Create Tools'); + const spinner = ora({ + text: 'Load Generator...', + spinner: 'runner', + }).start(); const prepareGlobalPromise = smith.prepareGlobal(); const prepareGeneratorPromise = smith.prepareGenerators([ @@ -172,9 +177,13 @@ export async function createAction(projectDir: string, options: Options) { generator = require.resolve(REPO_GENERATOR); } else if (!path.isAbsolute(generator) && distTag) { generator = `${generator}@${distTag}`; - await Promise.all([prepareGlobalPromise, prepareGeneratorPromise]); + await prepareGeneratorPromise; } + await prepareGlobalPromise; + + spinner.stop(); + const task: RunnerTask = [ { name: generator, diff --git a/packages/toolkit/upgrade/package.json b/packages/toolkit/upgrade/package.json index d8ecb400775a..93edb4b1eb4e 100644 --- a/packages/toolkit/upgrade/package.json +++ b/packages/toolkit/upgrade/package.json @@ -43,9 +43,10 @@ "test": "jest --passWithNoTests" }, "devDependencies": { + "commander": "10.0.1", "@modern-js/codesmith": "2.6.0", + "@modern-js/codesmith-utils": "2.6.0", "@modern-js/plugin-i18n": "workspace:*", - "@modern-js/utils": "workspace:*", "@modern-js/upgrade-generator": "workspace:*", "@scripts/build": "workspace:*", "@scripts/jest-config": "workspace:*", diff --git a/packages/toolkit/upgrade/src/index.ts b/packages/toolkit/upgrade/src/index.ts index 308e5ab09733..c3a1da6e64cc 100644 --- a/packages/toolkit/upgrade/src/index.ts +++ b/packages/toolkit/upgrade/src/index.ts @@ -1,5 +1,5 @@ import { getLocaleLanguage } from '@modern-js/plugin-i18n/language-detector'; -import { Command } from '@modern-js/utils/commander'; +import { Command } from 'commander'; import { i18n, localeKeys } from './locale'; import type { Options } from './upgrade'; diff --git a/packages/toolkit/upgrade/src/upgrade.ts b/packages/toolkit/upgrade/src/upgrade.ts index 67334d53dcd8..835a3a6c6903 100644 --- a/packages/toolkit/upgrade/src/upgrade.ts +++ b/packages/toolkit/upgrade/src/upgrade.ts @@ -1,4 +1,5 @@ import { CodeSmith } from '@modern-js/codesmith'; +import { ora } from '@modern-js/codesmith-utils/ora'; export interface Options { cwd?: string; @@ -26,6 +27,10 @@ export async function upgradeAction(options: Options) { smith.logger?.timing('🕒 Run Upgrade Tools'); + const spinner = ora({ + text: 'Load Generator...', + spinner: 'runner', + }).start(); const prepareGlobalPromise = smith.prepareGlobal(); const prepareGeneratorPromise = smith.prepareGenerators([UPGRADE_GENERATOR]); @@ -37,9 +42,13 @@ export async function upgradeAction(options: Options) { generator = require.resolve(UPGRADE_GENERATOR); } else if (distTag) { generator = `${UPGRADE_GENERATOR}@${distTag}`; - await Promise.all([prepareGlobalPromise, prepareGeneratorPromise]); + await prepareGeneratorPromise; } + await prepareGlobalPromise; + + spinner.stop(); + try { await smith.forge({ tasks: [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d3c00f81d1a5..f26f09491539 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4438,15 +4438,15 @@ importers: '@modern-js/codesmith': specifier: 2.6.0 version: 2.6.0 + '@modern-js/codesmith-utils': + specifier: 2.6.0 + version: 2.6.0 '@modern-js/plugin-i18n': specifier: workspace:* version: link:../../cli/plugin-i18n '@modern-js/upgrade-generator': specifier: workspace:* version: link:../../generator/generators/upgrade-generator - '@modern-js/utils': - specifier: workspace:* - version: link:../utils '@scripts/build': specifier: workspace:* version: link:../../../scripts/build @@ -4459,6 +4459,9 @@ importers: '@types/node': specifier: ^14 version: 14.18.35 + commander: + specifier: 10.0.1 + version: 10.0.1 jest: specifier: ^29 version: 29.5.0(@types/node@14.18.35)(ts-node@10.9.2)