@amplience/dc-cli
Version:
Dynamic Content CLI Tool
63 lines (62 loc) • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.steps = exports.LOG_FILENAME = exports.desc = exports.command = void 0;
const log_helpers_1 = require("../../common/log-helpers");
const configure_1 = require("../configure");
const schema_clean_step_1 = require("./steps/schema-clean-step");
const type_clean_step_1 = require("./steps/type-clean-step");
const content_clean_step_1 = require("./steps/content-clean-step");
const cli_1 = require("../../cli");
exports.command = 'clean';
exports.desc = 'Cleans an entire hub. This will archive all content items, types and schemas. Note that these are not fully deleted, but they can be resurrected by a future import.';
const LOG_FILENAME = (platform = process.platform) => (0, log_helpers_1.getDefaultLogPath)('hub', 'clean', platform);
exports.LOG_FILENAME = LOG_FILENAME;
exports.steps = [new content_clean_step_1.ContentCleanStep(), new type_clean_step_1.TypeCleanStep(), new schema_clean_step_1.SchemaCleanStep()];
const builder = (yargs) => {
yargs
.options(configure_1.configureCommandOptions)
.config('config', cli_1.readConfig)
.alias('f', 'force')
.option('f', {
type: 'boolean',
boolean: true,
describe: 'Overwrite content, create and assign content types, and ignore content with missing types/references without asking.'
})
.option('logFile', {
type: 'string',
default: exports.LOG_FILENAME,
describe: 'Path to a log file to write to.',
coerce: log_helpers_1.createLog
})
.option('step', {
type: 'string',
describe: 'Start at a specific step. Steps after the one you specify will also run.',
choices: exports.steps.map(step => step.getId())
})
.option('ignoreSchemaValidation', {
type: 'boolean',
boolean: false,
describe: 'Ignore content item schema validation during clean'
});
};
exports.builder = builder;
const handler = async (argv) => {
const log = argv.logFile.open();
argv.logFile = log;
const stepIndex = Math.max(0, exports.steps.findIndex(step => step.getId() === argv.step));
for (let i = stepIndex; i < exports.steps.length; i++) {
const step = exports.steps[i];
log.switchGroup(step.getName());
log.appendLine(`=== Running Step ${i} - ${step.getName()} ===`);
const success = await step.run(argv);
if (!success) {
log.appendLine(`Step ${i} ('${step.getId()}': ${step.getName()}) Failed. Terminating.`);
log.appendLine('');
log.appendLine('To continue the clean from this point, use the option:');
log.appendLine(`--step ${step.getId()}`);
break;
}
}
await log.close();
};
exports.handler = handler;