Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
fix: moves file helper to proper location
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed May 19, 2020
1 parent bfd046c commit e97462a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kentico/kontent-backup-manager",
"version": "1.5.0-next.0",
"version": "1.5.0-next.1",
"description": "This utility enables backup & restore of Kentico Kontent projects",
"preferGlobal": true,
"bin": {
Expand Down
1 change: 0 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './core.models';
export * from './translation-helper';
export * from './id-translate-helper';
export * from './file-helper';
export * from './global-helper';
77 changes: 41 additions & 36 deletions src/node-js/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import * as fs from 'fs';
import yargs = require('yargs');

import { CleanService } from '../../clean';
import { ICliFileConfig, fileHelper, getFilenameWithoutExtension, CliAction } from '../../core';
import { ICliFileConfig, getFilenameWithoutExtension, CliAction } from '../../core';
import { ExportService } from '../../export';
import { IImportSource, ImportService } from '../../import';
import { ZipService } from '../../zip';
import { ProjectContracts, SharedModels } from '@kentico/kontent-management';
import { FileService } from '..';
import { FileService } from '../file/file.service';
import { fileHelper } from '../file/file-helper';

const argv = yargs.argv;

const backupAsync = async (config: ICliFileConfig) => {
const exportService = new ExportService({
apiKey: config.apiKey,
projectId: config.projectId,
onExport: item => {
onExport: (item) => {
if (config.enableLog) {
console.log(`Exported: ${item.title} | ${item.type}`);
}
Expand Down Expand Up @@ -52,12 +53,12 @@ const backupAsync = async (config: ICliFileConfig) => {
};

const getLogFilename = (filename: string) => {
return`${getFilenameWithoutExtension(filename)}_log.json`;
}
return `${getFilenameWithoutExtension(filename)}_log.json`;
};

const cleanAsync = async (config: ICliFileConfig) => {
const cleanService = new CleanService({
onDelete: item => {
onDelete: (item) => {
if (config.enableLog) {
console.log(`Deleted: ${item.title} | ${item.type}`);
}
Expand All @@ -82,7 +83,7 @@ const restoreAsync = async (config: ICliFileConfig) => {
});

const importService = new ImportService({
onImport: item => {
onImport: (item) => {
if (config.enableLog) {
console.log(`Imported: ${item.title} | ${item.type}`);
}
Expand All @@ -93,7 +94,7 @@ const restoreAsync = async (config: ICliFileConfig) => {
enableLog: config.enableLog,
workflowIdForImportedItems: undefined,
process: {
contentItem: item => {
contentItem: (item) => {
return true;
}
}
Expand Down Expand Up @@ -176,32 +177,32 @@ const canImport = (importData: IImportSource, config: ICliFileConfig) => {
return false;
};

const getConfig = async() => {
const getConfig = async () => {
const configFilename: string = argv.config as string;

if (configFilename) {
// get config from file
const configFile = await fs.promises.readFile(`./${configFilename}`);

return JSON.parse(configFile.toString()) as ICliFileConfig;
}
}

const action: CliAction | undefined = argv.action as CliAction | undefined;
const apiKey: string | undefined = argv.apiKey as string | undefined;
const enableLog: boolean | undefined = (argv.enableLog as boolean | undefined) ?? true;
const force: boolean | undefined = (argv.force as boolean | undefined) ?? true;
const projectId: string | undefined = argv.projectId as string | undefined;
const zipFilename: string | undefined = (argv.zipFilename as string | undefined) ?? getDefaultBackupFilename()
const action: CliAction | undefined = argv.action as CliAction | undefined;
const apiKey: string | undefined = argv.apiKey as string | undefined;
const enableLog: boolean | undefined = (argv.enableLog as boolean | undefined) ?? true;
const force: boolean | undefined = (argv.force as boolean | undefined) ?? true;
const projectId: string | undefined = argv.projectId as string | undefined;
const zipFilename: string | undefined = (argv.zipFilename as string | undefined) ?? getDefaultBackupFilename();

if (!action) {
throw Error(`No action was provided`);
}
if (!action) {
throw Error(`No action was provided`);
}

if (!apiKey) {
throw Error(`Api key was not provided`);
}
if (!apiKey) {
throw Error(`Api key was not provided`);
}

if (!projectId) {
if (!projectId) {
throw Error(`Project id was not provided`);
}

Expand All @@ -216,20 +217,24 @@ const getConfig = async() => {
};

return config;
}
};

const getDefaultBackupFilename = () => {
const date = new Date();
return `kontent-backup-${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}-${date.getHours()}-${date.getMinutes()}`;
}

process().then(m => {}).catch(err => {
if (err instanceof SharedModels.ContentManagementBaseKontentError) {
console.log(`Management API error occured:`, err.message);
for (const validationError of err.validationErrors) {
console.log(validationError.message);
return `kontent-backup-${date.getDate()}-${
date.getMonth() + 1
}-${date.getFullYear()}-${date.getHours()}-${date.getMinutes()}`;
};

process()
.then((m) => {})
.catch((err) => {
if (err instanceof SharedModels.ContentManagementBaseKontentError) {
console.log(`Management API error occured:`, err.message);
for (const validationError of err.validationErrors) {
console.log(validationError.message);
}
} else {
console.log(`There was an error processing your request: `, err);
}
} else {
console.log(`There was an error processing your request: `, err);
}
});
});
File renamed without changes.
3 changes: 2 additions & 1 deletion src/node-js/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './file/file.service';
export * from './file/file.models';
export * from './file/file.models';
export * from './file/file-helper';

0 comments on commit e97462a

Please sign in to comment.