cli now uses DI
This commit is contained in:
parent
b680ede093
commit
9246da2e84
3 changed files with 46 additions and 13 deletions
35
src/cli.js
35
src/cli.js
|
|
@ -1,13 +1,32 @@
|
|||
const { Command } = require('commander');
|
||||
const program = new Command();
|
||||
const { buildDependencies } = require('./dependencies');
|
||||
|
||||
const createAppInviteCommand = require('./commands/createAppInvite');
|
||||
function buildCLIDependencies() {
|
||||
const appDependencies = buildDependencies();
|
||||
|
||||
program.version('1.0.0').description('CLI for managing web app tasks');
|
||||
const CreateAppInviteProvider = require('./commands/createAppInvite');
|
||||
const createAppInvite = new CreateAppInviteProvider({
|
||||
nostrService: appDependencies.services.nostrService,
|
||||
invitesService: appDependencies.services.invitesService,
|
||||
}).provide();
|
||||
|
||||
program
|
||||
.command('createAppInvite <inviterNpub>')
|
||||
.description('Create an invite')
|
||||
.action(createAppInviteCommand);
|
||||
return { createAppInviteCommand: createAppInvite };
|
||||
}
|
||||
|
||||
program.parse(process.argv);
|
||||
function buildCLI({ createAppInviteCommand }) {
|
||||
const wipCli = new Command();
|
||||
wipCli.version('1.0.0').description('CLI for managing web app tasks');
|
||||
|
||||
wipCli
|
||||
.command('createAppInvite <inviterNpub>')
|
||||
.description('Create an invite')
|
||||
.action(createAppInviteCommand);
|
||||
|
||||
return wipCli;
|
||||
}
|
||||
|
||||
const cliDependencies = buildCLIDependencies();
|
||||
|
||||
const cli = buildCLI(cliDependencies);
|
||||
|
||||
cli.parse(process.argv);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,21 @@ const invitesService = new InvitesServiceProvider({
|
|||
nostrService,
|
||||
}).provide();
|
||||
|
||||
module.exports = async function createAppInvite(inviterNpub) {
|
||||
const appInvite = await invitesService.createAppInvite(inviterNpub);
|
||||
console.log('Invite created');
|
||||
console.log(`Check at http://localhost/invite/${appInvite.uuid}`);
|
||||
};
|
||||
class CreateAppInviteProvider {
|
||||
constructor({ nostrService, invitesService }) {
|
||||
this.nostrService = nostrService;
|
||||
this.invitesService = invitesService;
|
||||
}
|
||||
|
||||
provide() {
|
||||
const createAppInvite = async (inviterNpub) => {
|
||||
const appInvite = await invitesService.createAppInvite(inviterNpub);
|
||||
console.log('Invite created');
|
||||
console.log(`Check at http://localhost/invite/${appInvite.uuid}`);
|
||||
};
|
||||
|
||||
return createAppInvite;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CreateAppInviteProvider;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ function buildDependencies() {
|
|||
|
||||
const ServicesProvider = require('./services');
|
||||
const services = new ServicesProvider().provide();
|
||||
dependencies.services = services;
|
||||
|
||||
const MiddlewaresProvider = require('./middlewares');
|
||||
const middlewares = new MiddlewaresProvider({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue