Skip to content

Commit

Permalink
feat: dal gen support pkg alias (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Mar 27, 2024
1 parent b8403e7 commit 5876faf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/cmd/dal/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -40,6 +50,8 @@ class DalGenCommand extends Command {
await this.helper.forkNode(this.genBin, [
moduleReference.path,
moduleReference.name,
argv.teggPkgName,
argv.teggDalPkgName,
], options);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/dal-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion test/lib/cmd/dal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
});
});
});

0 comments on commit 5876faf

Please sign in to comment.