From 4752e375ff7b5c4bd22acd69792a634675dd132c Mon Sep 17 00:00:00 2001 From: Ivan Kiral Date: Mon, 29 Apr 2024 12:12:15 +0200 Subject: [PATCH] remove backup manager --- package.json | 3 +- src/cmds/backup.ts | 153 --------------------------------------------- src/index.ts | 6 -- 3 files changed, 1 insertion(+), 161 deletions(-) delete mode 100644 src/cmds/backup.ts diff --git a/package.json b/package.json index c797dc3..83dfc8f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ }, "homepage": "https://github.com/kontent-ai/cli#readme", "dependencies": { - "@kontent-ai/backup-manager": "4.2.4", "chalk": "^4.1.2", "dotenv": "^16.3.1", "yargs": "^17.7.2" @@ -70,4 +69,4 @@ "ts-jest": "^28.0.8", "typescript": "~4.9.5" } -} +} \ No newline at end of file diff --git a/src/cmds/backup.ts b/src/cmds/backup.ts deleted file mode 100644 index 43950b3..0000000 --- a/src/cmds/backup.ts +++ /dev/null @@ -1,153 +0,0 @@ -import yargs from 'yargs'; -import chalk from 'chalk'; -import { environmentConfigExists, getEnvironmentsConfig } from '../utils/environmentUtils'; -import { CleanService, ExportService, ImportService, ZipService, IProcessedItem } from '@kontent-ai/backup-manager'; -import { getFileBackupName } from '../utils/fileUtils'; -import { FileService } from '@kontent-ai/backup-manager/dist/cjs/lib/node'; - -const kontentBackupCommand: yargs.CommandModule = { - command: 'backup', - describe: 'Kontent.ai backup tool to backup & restore environments through Management API.', - builder: (yargs: any) => - yargs - .options({ - action: { - alias: 'a', - describe: 'Action for backup', - type: 'string', - }, - name: { - alias: 'n', - describe: 'Name of zip file', - type: 'string', - }, - log: { - alias: 'l', - describe: 'Enables/Disables logging', - type: 'boolean', - default: true, - }, - 'environment-id': { - alias: 'eid', - describe: 'Environment ID to run the migration script on', - type: 'string', - }, - 'api-key': { - alias: 'k', - describe: 'Management API key', - type: 'string', - }, - environment: { - alias: 'e', - describe: 'Environment name', - type: 'string', - }, - 'preserve-workflow': { - alias: 'ep', - describe: 'Indicates if language variant workflow information should be preserved. Enabled by default', - type: 'boolean', - default: true, - }, - }) - .conflicts('environment', 'api-key') - .conflicts('environment', 'environment-id') - .check((args: any) => { - if (!args.environment && !(args.environmentId && args.apiKey)) { - throw new Error(chalk.red('Specify an environment or a environment ID with its Management API key.')); - } - - if (args.environment) { - if (!environmentConfigExists()) { - throw new Error(chalk.red(`Cannot find the environment configuration file. Add an environment named \"${args.environment}\" first.`)); - } - - const environments = getEnvironmentsConfig(); - - if (!environments[args.environment]) { - throw new Error(chalk.red(`Cannot find the \"${args.environment}\" environment.`)); - } - } - - return true; - }), - handler: async (argv: any) => { - let environmentId = argv.environmentId; - let apiKey = argv.apiKey; - if (argv.environment) { - const environments = getEnvironmentsConfig(); - - environmentId = environments[argv.environment].environmentId || argv.environmentId; - apiKey = environments[argv.environment].apiKey || argv.apiKey; - } - - const defaultBackupName = getFileBackupName(); - const zipService = new ZipService({ - context: 'node.js', - enableLog: argv.log, - }); - - console.log('Starting backup tool'); - - const fileService = new FileService({ - enableLog: argv.log, - }); - - switch (argv.action) { - case 'backup': - const exportService = new ExportService({ - apiKey: apiKey, - environmentId: environmentId, - onExport: (item: IProcessedItem) => { - if (argv.log) { - console.log(`Exported: ${item.title} | ${item.type}`); - } - }, - }); - const exportedData = await exportService.exportAllAsync(); - await zipService.createZipAsync(exportedData); - const backupZipData = await zipService.createZipAsync(exportedData); - await fileService.writeFileAsync(argv.name || defaultBackupName, backupZipData); - break; - - case 'restore': - const zipData = await zipService.extractZipAsync(await fileService.loadFileAsync(argv.name || defaultBackupName)); - const importService = new ImportService({ - onImport: (item: IProcessedItem) => { - if (argv.log) { - console.log(`Imported: ${item.title} | ${item.type}`); - } - }, - preserveWorkflow: argv.preserveWorkflow, - environmentId: environmentId, - apiKey: apiKey, - enableLog: argv.log, - fixLanguages: true, - }); - await importService.importFromSourceAsync(zipData); - break; - - case 'clean': - const cleanService = new CleanService({ - onDelete: (item: IProcessedItem) => { - if (argv.log) { - console.log(`Deleted: ${item.title} | ${item.type}`); - } - }, - environmentId: environmentId, - apiKey: apiKey, - }); - - await cleanService.cleanAllAsync(); - break; - - default: - throw new Error('Unknown action type'); - } - - console.log('Completed'); - process.exit(0); - }, -}; - -// yargs needs exported command in exports object -Object.assign(exports, kontentBackupCommand); diff --git a/src/index.ts b/src/index.ts index 5986c97..d6d3ac0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,12 +17,6 @@ const createMigrationTool = (): number => { .example('kontent', 'migration run --name migration01 --environment DEV --debug true') .example('kontent', 'migration run --all --environment DEV') .example('kontent', 'migration run --range 1:4 --environment DEV') - - .example('kontent', 'backup --action backup --environment-id --api-key ') - .example('kontent', 'backup --action backup --environment ') - .example('kontent', 'backup --action restore --name backup_file --environment-id --api-key ') - .example('kontent', 'backup --action restore --name backup_file --environment --preserve-workflow false') - .example('kontent', 'backup --action clean --environment-id --api-key ') .strict().argv; return 0;