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: dal gen support pkg alias #261

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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));
});
});
});
Loading