Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize generator download #6377

Merged
merged 33 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
eab18c5
feat: bump codesmith version
caohuilin Sep 29, 2024
0e92265
feat: optimize generator download
caohuilin Sep 30, 2024
f0999aa
feat: create tools remove @modern-js/utils dependency
caohuilin Sep 30, 2024
67068be
feat: add umdGlobals
caohuilin Sep 30, 2024
7cbdcb1
fix: run error
caohuilin Sep 30, 2024
004d2cc
feat: update codesmith version
caohuilin Sep 30, 2024
4819474
feat: revert i18n plugin change && update codesmith version
caohuilin Oct 12, 2024
a0f4ed7
fix: getModernVersion exits the process
caohuilin Oct 12, 2024
f6f590d
feat: external codesmith utils subpath
caohuilin Oct 14, 2024
3678b5a
fix: generator build config
caohuilin Oct 14, 2024
79fcd92
feat: create tools build config
caohuilin Oct 14, 2024
185199d
feat: op get package version utils
caohuilin Oct 14, 2024
e0100a8
fix: registryUrl
caohuilin Oct 14, 2024
2aa351f
feat: create tools version
caohuilin Oct 14, 2024
bc6f5b5
fix: get npm package version loading
caohuilin Oct 14, 2024
a6f13da
fix: ci
caohuilin Oct 15, 2024
bb40045
feat: new and upgrade command prepare global and generator
caohuilin Oct 15, 2024
4b03633
feat: update codesmith version
caohuilin Oct 15, 2024
52714b9
feat: add run time log and fix test error
caohuilin Oct 15, 2024
620c7eb
fix: ut error
caohuilin Oct 15, 2024
aaa0daf
feat: compat old create tools
caohuilin Oct 15, 2024
7431e7c
feat: bundle upgrade tools
caohuilin Oct 15, 2024
df17252
fix: new action and upgrade get registry error
caohuilin Oct 15, 2024
bac8009
fix: run repo next generator
caohuilin Oct 15, 2024
0da2677
feat: add prepare global loading
caohuilin Oct 15, 2024
b595452
fix: registry value
caohuilin Oct 15, 2024
b77b919
fix: get package manager func
caohuilin Oct 15, 2024
0b7c620
feat: new and upgrade command add --time option
caohuilin Oct 16, 2024
c7f578d
feat: update lock file
caohuilin Oct 16, 2024
7f23e1d
feat: update codesmith version
caohuilin Oct 16, 2024
22b1529
fix: registry
caohuilin Oct 16, 2024
a76cf32
feat: bump codesmith version
caohuilin Oct 16, 2024
c7ea863
feat: update codesmith version
caohuilin Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .changeset/four-donkeys-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@modern-js/storybook-next-generator': minor
'@modern-js/tailwindcss-generator': minor
'@modern-js/dependence-generator': minor
'@modern-js/module-doc-generator': minor
'@modern-js/changeset-generator': minor
'@modern-js/generator-generator': minor
'@modern-js/router-v5-generator': minor
'@modern-js/packages-generator': minor
'@modern-js/upgrade-generator': minor
'@modern-js/module-generator': minor
'@modern-js/server-generator': minor
'@modern-js/entry-generator': minor
'@modern-js/base-generator': minor
'@modern-js/repo-generator': minor
'@modern-js/bff-generator': minor
'@modern-js/mwa-generator': minor
'@modern-js/ssg-generator': minor
'@modern-js/generator-plugin-plugin': minor
'@modern-js/generator-common': minor
'@modern-js/generator-plugin': minor
'@modern-js/generator-utils': minor
'@modern-js/sandpack-react': patch
'@modern-js/new-action': patch
'@modern-js/plugin-i18n': patch
'@modern-js/create': patch
---

feat: optimize generator download

feat: 优化生成器下载
2 changes: 2 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"node_modules/**/*",
"dist/**/*",
"dist-1/**/*",
"dist-2/**/*",
"dist-swc/**/*",
"output/**/*",
".output/**/*",
".netlify/**/*",
Expand Down
8 changes: 4 additions & 4 deletions packages/generator/generator-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
"test": "jest --passWithNoTests"
},
"dependencies": {
"@modern-js/codesmith-formily": "2.5.2",
"@modern-js/codesmith-formily": "2.6.3",
"@modern-js/plugin-i18n": "workspace:*",
"@swc/helpers": "0.5.13"
},
"devDependencies": {
"@modern-js/codesmith": "2.5.2",
"@modern-js/codesmith-api-app": "2.5.2",
"@modern-js/utils": "workspace:*",
"@modern-js/codesmith": "2.6.3",
"@modern-js/codesmith-api-app": "2.6.3",
"@modern-js/codesmith-utils": "2.6.3",
"@scripts/build": "workspace:*",
"@scripts/jest-config": "workspace:*",
"@types/jest": "^29",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MaterialsManager,
} from '@modern-js/codesmith';
import { AppAPI } from '@modern-js/codesmith-api-app';
import { fs } from '@modern-js/utils';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { getPackageManagerSchema } from '../src/common/packageManager';

describe('test package manager schema', () => {
Expand Down
16 changes: 9 additions & 7 deletions packages/generator/generator-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
"test": "jest"
},
"dependencies": {
"@modern-js/codesmith": "2.5.2",
"@modern-js/codesmith-api-git": "2.5.2",
"@modern-js/codesmith-api-json": "2.5.2",
"@modern-js/codesmith-api-npm": "2.5.2",
"@modern-js/codesmith-formily": "2.5.2",
"@modern-js/codesmith": "2.6.3",
"@modern-js/codesmith-api-git": "2.6.3",
"@modern-js/codesmith-api-json": "2.6.3",
"@modern-js/codesmith-api-npm": "2.6.3",
"@modern-js/codesmith-formily": "2.6.3",
"@modern-js/codesmith-utils": "2.6.3",
"@modern-js/generator-common": "workspace:*",
"@modern-js/generator-utils": "workspace:*",
"@modern-js/new-action": "workspace:*",
"@modern-js/plugin-i18n": "workspace:*",
"@modern-js/utils": "workspace:*",
"@swc/helpers": "0.5.13",
"ejs": "^3.1.9",
"handlebars": "^4.7.7"
"globby": "11.1.0",
"handlebars": "^4.7.7",
"json5": "2.2.3"
},
"devDependencies": {
"@scripts/build": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/generator/generator-plugin/src/context/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Schema } from '@modern-js/codesmith-formily';
import { isFunction } from '@modern-js/utils/lodash';
import { isFunction } from '@modern-js/codesmith-utils/lodash';

export type { Schema };
export class PluginInputContext {
Expand Down Expand Up @@ -97,7 +97,7 @@ export class PluginInputContext {
const schema = this.solutionSchema[key];
if (schema) {
(schema as Record<string, unknown>)[field] = isFunction(value)
? value(schema)
? (value as (input: Schema) => unknown)(schema)
: value;
return;
}
Expand All @@ -107,15 +107,15 @@ export class PluginInputContext {
if (beforeSchema) {
findFlag = true;
(beforeSchema as Record<string, unknown>)[field] = isFunction(value)
? value(schema)
? (value as (input: Schema) => unknown)(schema)
: value;
break;
}
const afterSchema = this.extendInputMap[inputKey].after[key];
if (afterSchema) {
findFlag = true;
(afterSchema as Record<string, unknown>)[field] = isFunction(value)
? value(schema)
? (value as (input: Schema) => unknown)(schema)
: value;
break;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/generator/generator-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
getPackageInfo,
} from '@modern-js/codesmith';
import type { Schema } from '@modern-js/codesmith-formily';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { isFunction, merge } from '@modern-js/codesmith-utils/lodash';
import {
type Solution,
SolutionSchemas,
i18n as commonI18n,
} from '@modern-js/generator-common';
import { fs, i18n as utilsI18n } from '@modern-js/generator-utils';
import { isFunction, merge } from '@modern-js/utils/lodash';
import { i18n as utilsI18n } from '@modern-js/generator-utils';
import type { ICustomInfo } from './common';
import {
LifeCycle,
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/generator-plugin/src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { fs } from '@modern-js/generator-utils';
import { globby } from '@modern-js/utils';
import globby from 'globby';

export enum FileType {
Text = 'text',
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/generator-plugin/src/utils/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from '@modern-js/utils/lodash';
import { get } from '@modern-js/codesmith-utils/lodash';

export function requireModule(modulePath: string) {
const module = require(modulePath);
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/generator-plugin/tests/input.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject } from '@modern-js/utils/lodash';
import { isObject } from '@modern-js/codesmith-utils';
import { PluginInputContext, type Schema } from '../src/context/input';

describe('PluginInputContext Test', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/generator/generator-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@
"dependencies": {
"@modern-js/generator-common": "workspace:*",
"@modern-js/plugin-i18n": "workspace:*",
"@modern-js/utils": "workspace:*",
"@modern-js/codesmith-utils": "2.6.3",
"glob": "7.2.0",
"js-yaml": "4.1.0",
"json5": "2.2.3",
"@swc/helpers": "0.5.13"
},
"devDependencies": {
"@modern-js/codesmith": "2.5.2",
"@modern-js/codesmith": "2.6.3",
"@scripts/build": "workspace:*",
"@scripts/jest-config": "workspace:*",
"@types/jest": "^29",
"@types/glob": "7.2.0",
"@types/js-yaml": "4.0.9",
"@types/node": "^14",
"jest": "^29",
"typescript": "^5"
Expand Down
57 changes: 18 additions & 39 deletions packages/generator/generator-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
import path from 'path';
import type { GeneratorContext } from '@modern-js/codesmith';
import { getNpmVersion, getPackageInfo } from '@modern-js/codesmith';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { ora } from '@modern-js/codesmith-utils/ora';
import { Solution, SolutionToolsMap } from '@modern-js/generator-common';
import {
fs,
canUseNpm,
canUsePnpm,
execa,
getMonorepoPackages,
ora,
} from '@modern-js/utils';
import { i18n, localeKeys } from './locale';
import { fileExist } from './utils/fsExist';
import { getMonorepoPackages } from './utils/monorepo';
import { getAvailableVersion, isPackageExist } from './utils/package';
import { stripAnsi } from './utils/stripAnsi';

export * from './utils';

export {
ora,
fs,
semver,
execa,
chalk,
readTsConfigByFile,
getPackageManager,
canUseNpm,
canUsePnpm,
canUseYarn,
isReact18,
} from '@modern-js/utils';
} from '@modern-js/codesmith-utils/npm';
export { fs } from '@modern-js/codesmith-utils/fs-extra';
export { ora } from '@modern-js/codesmith-utils/ora';
export { semver } from '@modern-js/codesmith-utils/semver';
export { execa } from '@modern-js/codesmith-utils/execa';
export { chalk } from '@modern-js/codesmith-utils/chalk';

export { i18n } from './locale';

export async function getPackageVersion(
packageName: string,
registry?: string,
) {
registryUrl?: string,
): Promise<string> {
const spinner = ora({
text: 'Load Generator...',
spinner: 'runner',
}).start();
if (await canUsePnpm()) {
const args = ['info', packageName, 'version'];
if (registry) {
args.push(`--registry=${registry}`);
}
const result = await execa('pnpm', args);
spinner.stop();
return stripAnsi(result.stdout);
}
if (await canUseNpm()) {
const args = ['view', packageName, 'version'];
if (registry) {
args.push(`--registry=${registry}`);
}
const result = await execa('npm', args);
spinner.stop();
return stripAnsi(result.stdout);
}
const { name, version: pkgVersion } = getPackageInfo(packageName);
const version = await getNpmVersion(name, {
version: pkgVersion,
registryUrl,
});
spinner.stop();
throw new Error('not found npm, please install npm before');
return version;
}

export async function getModernVersion(
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/generator-utils/src/utils/fsExist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fs } from '@modern-js/utils';
import { fs } from '@modern-js/codesmith-utils/fs-extra';

export async function fileExist(filePath: string) {
try {
Expand Down
12 changes: 12 additions & 0 deletions packages/generator/generator-utils/src/utils/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from 'path';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import json5 from 'json5';

export const readTsConfig = (root: string) => {
return readTsConfigByFile(path.resolve(root, './tsconfig.json'));
};

export const readTsConfigByFile = (filename: string) => {
const content = fs.readFileSync(path.resolve(filename), 'utf-8');
return json5.parse(content);
};
4 changes: 3 additions & 1 deletion packages/generator/generator-utils/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './stripAnsi';
export * from './package';
export { getGeneratorPath } from './getGeneratorPath';
export * from './getGeneratorPath';
export * from './get';
export * from './is';
23 changes: 23 additions & 0 deletions packages/generator/generator-utils/src/utils/is.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from 'path';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { semver } from '@modern-js/codesmith-utils/semver';

export const isReact18 = (cwd: string = process.cwd()) => {
const pkgPath = path.join(cwd, 'package.json');

if (!fs.existsSync(pkgPath)) {
return false;
}

const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const deps = {
...pkgInfo.devDependencies,
...pkgInfo.dependencies,
};

if (typeof deps.react !== 'string') {
return false;
}

return semver.satisfies(semver.minVersion(deps.react)!, '>=18.0.0');
};
Loading
Loading