@o3r/amaterasu-api-spec
Version:
Commands relative to the Digital Apis
43 lines • 2.77 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExtension = void 0;
const node_fs_1 = require("node:fs");
const path = require("node:path");
const core_1 = require("@ama-terasu/core");
/**
* Create an Otter Extension
* @param context Context of the command
* @param options Options
*/
const createExtension = async (context, options) => {
const { logger } = context;
const cwd = path.resolve(process.cwd(), options.path);
const { version } = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', 'package.json'), { encoding: 'utf8' }));
const npmrcFile = 'tmp.npmrc';
const deps = {
'@ama-sdk/schematics': version === '0.0.0-placeholder' ? 'latest' : version,
yo: 'latest'
};
await context.getSpinner('Generating extension module...').fromPromise((async () => {
await (0, core_1.promiseSpawn)('npm init -y', { cwd, stderrLogger: (...args) => logger.debug(...args), logger });
await (0, core_1.promiseSpawn)(`npm install --userconfig ${npmrcFile} --include dev ${Object.entries(deps).map(([n, v]) => `${n}@${v}`).join(' ')}`, { cwd, stderrLogger: (...args) => logger.debug(...args), logger });
await (0, core_1.promiseSpawn)(
// eslint-disable-next-line @stylistic/max-len -- keep the command on the same line
`npx -p @angular-devkit/schematics-cli schematics @ama-sdk/schematics:api-extension --name "${options.name}" --core-type ${options.type.replace(/^core-/, '')} --core-version "${options['spec-version']}"`, { cwd, stderrLogger: (...args) => logger.debug(...args), logger });
})(),
// TODO: simplify to the following line when migrated to schematics generation
// promiseSpawn(
// eslint-disable-next-line @stylistic/max-len -- keep the command on the same line
// `npx ${Object.entries(deps).map(([n, v]) => `-p ${n}@${v}`).join(' ')} --userconfig ${npmrcFile} yo${options.yes ? ' --force=true' : ''} @ama-sdk/sdk:api-extension --name "${options.name}" --coreType ${options.type.replace(/^core-/, '')} --coreVersion "${options['spec-version']}"`,
// { cwd, stderrLogger: logger.debug, logger }
// ),
`API Extension generated (in ${cwd})`);
await context.getSpinner('Clean up setup materials').fromPromise(Promise.all([
node_fs_1.promises.unlink(path.resolve(cwd, npmrcFile)),
node_fs_1.promises.rm(path.resolve(cwd, 'node_modules'), { force: true, recursive: true }),
options.path === '.' ? undefined : node_fs_1.promises.unlink(path.resolve(cwd, 'package.json'))
]), 'Setup material removed');
logger.info(`API extension created in ${cwd}`);
};
exports.createExtension = createExtension;
//# sourceMappingURL=create-extension.command.js.map
;