From 5876fafcc7a29b9e59b7e79a75e995e2e219992e Mon Sep 17 00:00:00 2001 From: killa Date: Wed, 27 Mar 2024 11:32:26 +0800 Subject: [PATCH] feat: dal gen support pkg alias (#261) --- lib/cmd/dal/gen.js | 12 ++++++++++++ lib/dal-gen.js | 6 ++++++ test/lib/cmd/dal.test.js | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/cmd/dal/gen.js b/lib/cmd/dal/gen.js index 07ef180..82d4f61 100644 --- a/lib/cmd/dal/gen.js +++ b/lib/cmd/dal/gen.js @@ -11,6 +11,16 @@ class DalGenCommand extends Command { description: 'directory of application, default to `process.cwd()`', type: 'string', }, + teggPkgName: { + description: 'tegg package name', + type: 'string', + default: '@eggjs/tegg', + }, + teggDalPkgName: { + description: 'tegg dal package name', + type: 'string', + default: '@eggjs/tegg/dal', + }, }; this.genBin = path.join(__dirname, '../../dal-gen'); } @@ -40,6 +50,8 @@ class DalGenCommand extends Command { await this.helper.forkNode(this.genBin, [ moduleReference.path, moduleReference.name, + argv.teggPkgName, + argv.teggDalPkgName, ], options); } } diff --git a/lib/dal-gen.js b/lib/dal-gen.js index 5616e89..b44df00 100644 --- a/lib/dal-gen.js +++ b/lib/dal-gen.js @@ -9,12 +9,18 @@ assert(moduleDir, 'miss module dir'); const moduleName = process.argv[3]; assert(moduleName, 'miss module name'); +const teggPkgName = process.argv[4]; + +const teggDalPkgName = process.argv[5]; + (async () => { try { console.log('[egg-bin] start dal gen for %s', moduleName); const generator = new CodeGenerator({ moduleDir, moduleName, + teggPkg: teggPkgName, + dalPkg: teggDalPkgName, }); const loader = LoaderFactory.createLoader(moduleDir, 'MODULE'); const clazzList = loader.load(); diff --git a/test/lib/cmd/dal.test.js b/test/lib/cmd/dal.test.js index 0501a70..1dc734a 100644 --- a/test/lib/cmd/dal.test.js +++ b/test/lib/cmd/dal.test.js @@ -18,7 +18,7 @@ describe('test/lib/cmd/dal.test.js', () => { }); it('egg-bin dal gen should work', async () => { - await coffee.fork(eggBin, [ 'dal', 'gen' ], { cwd }) + await coffee.fork(eggBin, [ 'dal', 'gen', '--teggPkgName', '@eggjs/xianyadan', '--teggDalPkgName', '@eggjs/xianyadan/dal' ], { cwd }) .debug() .expect('code', 0) .end(); @@ -37,6 +37,10 @@ describe('test/lib/cmd/dal.test.js', () => { ]) { assert.ok(await fs.stat(path.join(cwd, file))); } + + const content = await fs.readFile(path.join(cwd, 'app/modules/dal/dal/dao/base/BaseFooDAO.ts'), 'utf8'); + assert(/import type { InsertResult, UpdateResult, DeleteResult } from '@eggjs\/xianyadan\/dal';/.test(content)); + assert(/import { SingletonProto, AccessLevel, Inject } from '@eggjs\/xianyadan';/.test(content)); }); }); });