Skip to content

Commit

Permalink
feat: add prepare global loading
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Oct 15, 2024
1 parent fde4156 commit 74a963b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
11 changes: 10 additions & 1 deletion packages/toolkit/create/src/createAction.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/upgrade/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
11 changes: 10 additions & 1 deletion packages/toolkit/upgrade/src/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CodeSmith } from '@modern-js/codesmith';
import { ora } from '@modern-js/codesmith-utils/ora';

export interface Options {
cwd?: string;
Expand Down Expand Up @@ -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]);

Expand All @@ -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: [
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74a963b

Please sign in to comment.