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: support set eggTsHelper #183

Merged
merged 5 commits into from Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/command.js
Expand Up @@ -23,7 +23,7 @@ class Command extends BaseCommand {
},

declarations: {
description: 'whether create dts, will load `egg-ts-helper/register`',
description: 'whether create dts, will load options.eggTsHelper',
type: 'boolean',
alias: 'dts',
default: undefined,
Expand All @@ -35,6 +35,13 @@ class Command extends BaseCommand {
alias: 'tsc',
default: undefined,
},

eggTsHelper: {
description: 'egg-ts-helper register, default use `egg-ts-helper/register`',
type: 'string',
alias: 'ets',
default: require.resolve('egg-ts-helper/register'),
mansonchor marked this conversation as resolved.
Show resolved Hide resolved
},
};
}

Expand Down Expand Up @@ -107,7 +114,7 @@ class Command extends BaseCommand {

// load egg-ts-helper
if (argv.declarations) {
execArgvObj.require.push(require.resolve('egg-ts-helper/register'));
execArgvObj.require.push(argv.eggTsHelper);
}

return context;
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/my-egg-bin/lib/cmd/echo.js
Expand Up @@ -3,6 +3,19 @@
const Command = require('../../../../../');

class EchoCommand extends Command {
constructor(rawArgv) {
super(rawArgv);

this.options = {
eggTsHelper: {
description: 'egg-ts-helper register, default use `egg-ts-helper/register`',
type: 'string',
alias: 'ets',
default: require.resolve('../egg-ts-helper'),
},
};
}

get description() {
return 'echo test';
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/my-egg-bin/lib/egg-ts-helper.js
@@ -0,0 +1,3 @@
'use strict';

console.log('custom egg-ts-helper');
13 changes: 13 additions & 0 deletions test/my-egg-bin.test.js
Expand Up @@ -99,4 +99,17 @@ describe('test/my-egg-bin.test.js', () => {
.expect('code', 1)
.end(done);
});

it('should custom eggTsHelper success', done => {
const args = [
'echo',
'--typescript',
'--declarations',
];
coffee.fork(eggBin, args, { cwd })
// .debug()
.expect('stdout', /my-egg-bin\/lib\/egg-ts-helper\.js/)
.expect('code', 0)
.end(done);
});
});