sinotron
Version:
Simple framework for Typescript Electron projects
35 lines (34 loc) • 1.23 kB
JavaScript
import { CliHelper } from '../cli.helper.js';
import { ask } from '../../utils/ask.js';
import { logNotice } from '../../utils/log.js';
import { GenerateApiFiles } from './GenerateApiFiles.js';
import { _str } from '../../utils/_str.js';
export class ApiCommand {
static name = 'api';
static description = 'Generate api client and service files';
static async init(app) {
app.command(ApiCommand.name)
.description(ApiCommand.description)
.argument('[apiName]', 'The api name.')
.action(async (...args) => {
const ctx = CliHelper.getContext(args);
let apiName = ctx.arg0?.trim();
if (!apiName) {
const { ans } = await ask.input('ans', 'Enter the api name:');
if (ans) {
apiName = ans;
}
else {
logNotice('No api name provided. Aborting.');
return;
}
}
// sanitise input.
apiName = _str.sanitizeIdentifier(apiName);
await GenerateApiFiles.task({
apiName,
seekRoot: process.cwd()
});
});
}
}