Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f0a09f4
feat: optimize the function for downloading npm packages
caohuilin Sep 26, 2024
3b78ebe
feat: delete get npm tarball url function
caohuilin Sep 26, 2024
75a1dd1
feat: expend generator cache time
caohuilin Sep 26, 2024
6222ec3
feat: optimize the function for get npm package version
caohuilin Sep 26, 2024
81a44b6
feat: update dependencies
caohuilin Sep 26, 2024
475d4a4
feat: run install add time log
caohuilin Sep 26, 2024
51021ee
feat: support prepareGenerators function
caohuilin Sep 26, 2024
c4060d9
feat: prepare generator add cache
caohuilin Sep 29, 2024
8af3679
docs: changeset
caohuilin Sep 29, 2024
bc85d83
fix: loca remote generator cash not work
caohuilin Sep 29, 2024
7060c2d
fix: detail
caohuilin Sep 29, 2024
cd30315
fix: lint error
caohuilin Sep 29, 2024
5e66f7b
feat: delete easy form package && remove @modern-js/utils dependency
caohuilin Sep 29, 2024
d73c734
fix: changeset config error
caohuilin Sep 29, 2024
09dfe02
fix: lint error
caohuilin Sep 29, 2024
42b3bf7
fix: test error
caohuilin Sep 29, 2024
103b650
fix: changeset fixed config
caohuilin Sep 29, 2024
b7b6aed
fix: lint error
caohuilin Sep 29, 2024
a57a62b
feat: op lodash dependency
caohuilin Sep 29, 2024
8df8162
fix: lodash import order
caohuilin Sep 29, 2024
0fa2b83
feat: bump modern version
caohuilin Sep 29, 2024
8336ca9
feat: add global package and prepare global function
caohuilin Sep 30, 2024
e6798d7
fix: global import order
caohuilin Sep 30, 2024
c5ec4b6
feat: revet download function
caohuilin Sep 30, 2024
7ed5742
fix: lint error
caohuilin Sep 30, 2024
1af7cd0
feat: update modern.js version
caohuilin Oct 12, 2024
7741b3b
feat: global package minify
caohuilin Oct 12, 2024
063d05a
fix: prepare flag
caohuilin Oct 12, 2024
8a347b4
feat: global add utils sub path
caohuilin Oct 14, 2024
07a1d6a
fix: lint error
caohuilin Oct 14, 2024
4e52a27
feat: op prepareGenerators cache
caohuilin Oct 14, 2024
9889a5f
fix: prepareGenerators
caohuilin Oct 14, 2024
1ae9a4c
feat: bundle codesmith cli
caohuilin Oct 14, 2024
a664904
fix: typo
caohuilin Oct 14, 2024
e7e5a62
feat: open formily test
caohuilin Oct 15, 2024
2348ca9
docs: changeset use minor version
caohuilin Oct 15, 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
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [["@modern-js/easy-form-*"], ["!(@modern-js/easy-form-*)"]],
"fixed": [["@modern-js/*"]],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
Expand Down
9 changes: 9 additions & 0 deletions .changeset/friendly-games-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@modern-js/codesmith-api-app": minor
"@modern-js/codesmith": minor
"@modern-js/codesmith-cli": minor
---

feat: optimize generator download

feat: 优化生成器下载
8 changes: 4 additions & 4 deletions packages/api/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@modern-js/codesmith-api-handlebars": "workspace:*",
"@modern-js/codesmith-api-npm": "workspace:*",
"@modern-js/codesmith-formily": "workspace:*",
"@modern-js/plugin-i18n": "^2.58.0",
"@modern-js/utils": "^2.58.0",
"@modern-js/codesmith-utils": "workspace:*",
"@modern-js/plugin-i18n": "2.60.3",
"comment-json": "^4.2.3",
"extra": "^0.2.1",
"inquirer": "8.1.3"
Expand All @@ -47,8 +47,8 @@
},
"devDependencies": {
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/inquirer": "^7.3.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
Expand Down
11 changes: 8 additions & 3 deletions packages/api/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
CLIReader as FormilyCLIReader,
type Schema as FormilySchema,
} from '@modern-js/codesmith-formily';
/* eslint-disable max-lines */
import { fs, execa, semver } from '@modern-js/utils';
import { merge } from '@modern-js/utils/lodash';
import { execa } from '@modern-js/codesmith-utils/execa';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { merge } from '@modern-js/codesmith-utils/lodash';
import { semver } from '@modern-js/codesmith-utils/semver';
import { parse, stringify } from 'comment-json';
import inquirer, { type Question } from 'inquirer';
import { type I18n, i18n, localeKeys } from './locale';
Expand Down Expand Up @@ -84,6 +85,7 @@ export class AppAPI {
ignoreScripts?: boolean;
},
) {
this.generatorCore.logger?.timing?.('🕒 Run Install');
const {
config: { packageManager, noNeedInstall, noNeedCheckNvm },
} = this.generatorContext;
Expand Down Expand Up @@ -125,13 +127,15 @@ export class AppAPI {
})}`,
);
}
this.generatorCore.logger?.timing?.('🕒 Run Install', true);
}

// custom install func
public async runGitAndInstall(
commitMessage?: string,
installFunc?: () => Promise<void>,
) {
this.generatorCore.logger?.timing?.('🕒 Run Git and Install');
const {
config: { isMonorepoSubProject = false, noNeedGit },
} = this.generatorContext;
Expand Down Expand Up @@ -166,6 +170,7 @@ export class AppAPI {
this.generatorCore.logger.debug('❗️ [Git Add and Commit Failed]:', e);
this.generatorCore.logger.warn(`🟡 ${i18n.t(localeKeys.git.failed)}`);
}
this.generatorCore.logger?.timing?.('🕒 Run Git and Install', true);
}

public async forgeTemplate(
Expand Down
4 changes: 3 additions & 1 deletion packages/api/app/src/utils/checkUseNvm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path';
import { type ILogger, fsExists } from '@modern-js/codesmith';
import { canUseNvm, execaWithStreamLog } from '@modern-js/codesmith-api-npm';
import { fs, execa, semver } from '@modern-js/utils';
import { execa } from '@modern-js/codesmith-utils/execa';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import { semver } from '@modern-js/codesmith-utils/semver';

const NODE_MAJOR_VERSION_MAP: Record<string, number> = {
'lts/*': 18,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/app/src/utils/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isString } from '@modern-js/utils/lodash';
import { isString } from '@modern-js/codesmith-utils/lodash';
import type { Question } from 'inquirer';

export function transformInquirerSchema(
Expand Down
4 changes: 2 additions & 2 deletions packages/api/ejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"devDependencies": {
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/ejs": "^3.1.2",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/fs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
},
"dependencies": {
"@swc/helpers": "0.5.1",
"@modern-js/utils": "^2.58.0"
"@modern-js/codesmith-utils": "workspace:*"
},
"peerDependencies": {
"@modern-js/codesmith": "workspace:^2.5.2"
},
"devDependencies": {
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"typescript": "^4.9.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/fs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type FsResource,
type GeneratorCore,
} from '@modern-js/codesmith';
import { fs } from '@modern-js/utils';
import { fs } from '@modern-js/codesmith-utils/fs-extra';

type RenderDirOptions = {
nodir?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/api/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
},
"dependencies": {
"@swc/helpers": "0.5.1",
"@modern-js/utils": "^2.58.0"
"@modern-js/codesmith-utils": "workspace:*"
},
"peerDependencies": {
"@modern-js/codesmith": "workspace:^2.5.2"
},
"devDependencies": {
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"typescript": "^4.9.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/git/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execa } from '@modern-js/utils';
import { execa } from '@modern-js/codesmith-utils/execa';

export async function canUseGit() {
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/api/git/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
initGitRepo,
isInGitRepo,
} from '@/utils';
import { fs, execa } from '@modern-js/utils';
import { execa } from '@modern-js/codesmith-utils/execa';
import { fs } from '@modern-js/codesmith-utils/fs-extra';

const cwd = path.join(os.tmpdir(), 'codesmith_test', Math.random().toString());

Expand Down
4 changes: 2 additions & 2 deletions packages/api/handlebars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"devDependencies": {
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"typescript": "^4.9.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/api/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"declaration-update": "^0.0.2"
},
"devDependencies": {
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"typescript": "^4.9.5"
Expand Down
11 changes: 7 additions & 4 deletions packages/api/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
},
"dependencies": {
"@swc/helpers": "0.5.1",
"@modern-js/codesmith": "workspace:*",
"@modern-js/utils": "^2.58.0"
"@modern-js/codesmith-utils": "workspace:*"
},
"peerDependencies": {
"@modern-js/codesmith": "workspace:^2.5.1"
},
"devDependencies": {
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/codesmith": "workspace:*",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"typescript": "^4.9.5"
Expand Down
7 changes: 4 additions & 3 deletions packages/api/npm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { GeneratorCore } from '@modern-js/codesmith';
import type { ExecaReturnValue } from '@modern-js/codesmith-utils/execa';
import { npmInstall, pnpmInstall, yarnInstall } from './utils';

export * from './utils';
Expand All @@ -18,7 +19,7 @@ export class NpmAPI {
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
return npmInstall({
cwd: cwd || this.generatorCore.outputPath,
registryUrl,
Expand All @@ -35,7 +36,7 @@ export class NpmAPI {
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
return yarnInstall({
cwd: cwd || this.generatorCore.outputPath,
registryUrl,
Expand All @@ -52,7 +53,7 @@ export class NpmAPI {
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
return pnpmInstall({
cwd: cwd || this.generatorCore.outputPath,
registryUrl,
Expand Down
7 changes: 6 additions & 1 deletion packages/api/npm/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export { canUseNvm, canUseNpm, canUseYarn, canUsePnpm } from './env';
export {
canUseNvm,
canUseNpm,
canUseYarn,
canUsePnpm,
} from '@modern-js/codesmith-utils/npm';
export {
npmInstall,
yarnInstall,
Expand Down
18 changes: 11 additions & 7 deletions packages/api/npm/src/utils/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { execa } from '@modern-js/utils';
import { canUseNpm, canUsePnpm, canUseYarn } from './env';
import { type ExecaReturnValue, execa } from '@modern-js/codesmith-utils/execa';
import {
canUseNpm,
canUsePnpm,
canUseYarn,
} from '@modern-js/codesmith-utils/npm';

export function execaWithStreamLog(
command: string,
Expand All @@ -18,8 +22,8 @@ export function execaWithStreamLog(
export async function runInstallWithNvm(
command: string,
options: Record<string, any>,
) {
await execa(`~/.nvm/nvm-exec ${command}`, {
): Promise<ExecaReturnValue> {
return await execa(`~/.nvm/nvm-exec ${command}`, {
...options,
shell: true,
stdin: 'inherit',
Expand All @@ -38,7 +42,7 @@ export async function npmInstall({
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
const canUse = await canUseNpm();
if (canUse) {
const params = ['install'];
Expand Down Expand Up @@ -72,7 +76,7 @@ export async function yarnInstall({
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
const canUse = await canUseYarn();
if (canUse) {
const params = ['install'];
Expand Down Expand Up @@ -103,7 +107,7 @@ export async function pnpmInstall({
registryUrl?: string;
ignoreScripts?: boolean;
useNvm?: boolean;
}) {
}): Promise<ExecaReturnValue> {
const canUse = await canUsePnpm();
if (canUse) {
const params = ['install'];
Expand Down
8 changes: 6 additions & 2 deletions packages/api/npm/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import os from 'os';
import path from 'path';
import { canUseNpm, canUseNvm, canUseYarn } from '@/utils/env';
import {
execaWithStreamLog,
npmInstall,
pnpmInstall,
yarnInstall,
} from '@/utils/install';
import { fs } from '@modern-js/utils';
import { fs } from '@modern-js/codesmith-utils/fs-extra';
import {
canUseNpm,
canUseNvm,
canUseYarn,
} from '@modern-js/codesmith-utils/npm';

describe('Env utils cases', () => {
test('can use nvm', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { defineConfig, moduleTools } from '@modern-js/module-tools';
import { testingPlugin } from '@modern-js/plugin-testing';

export default defineConfig({
buildPreset: 'modern-js-universal',
buildConfig: {
autoExternal: false,
dts: false,
sideEffects: false,
},
plugins: [moduleTools(), testingPlugin()],
});
11 changes: 6 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"version": "2.5.2",
"jsnext:source": "./src/index.ts",
"main": "./dist/cjs/index.js",
"main": "./dist/index.js",
"bin": {
"codesmith": "./bin/run.js"
},
Expand All @@ -33,14 +33,15 @@
"test": "modern test --passWithNoTests"
},
"dependencies": {
"commander": "10.0.0",
"@swc/helpers": "0.5.1",
"@modern-js/codesmith": "workspace:*",
"@modern-js/plugin-i18n": "^2.58.0",
"@modern-js/utils": "^2.58.0"
"@modern-js/codesmith-utils": "workspace:*",
"@modern-js/plugin-i18n": "2.60.3"
},
"devDependencies": {
"@modern-js/module-tools": "^2.58.0",
"@modern-js/plugin-testing": "^2.58.0",
"@modern-js/module-tools": "2.60.3",
"@modern-js/plugin-testing": "2.60.3",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.42",
"ts-node": "^10.9.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/actions/genAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export async function genAction(generator: string, genOptions: LocalOptions) {
registryUrl: registry,
});

await smith.prepareGlobal();

smith.logger.debug('💡 [Runtime Gen Action]');
smith.logger.debug('💡 [Generator Name]:', generator);
smith.logger.debug('💡 [Generator Pwd]:', pwd);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command } from '@modern-js/utils';
import { Command } from 'commander';
import { genAction } from './actions/genAction';

export default function () {
Expand All @@ -14,7 +14,7 @@ export default function () {
.option(
'--registry <registry>',
'set npm registry url to run npm command',
false,
undefined,
)
.action(genAction);

Expand Down
Loading
Loading