Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kentico/kontent-cli

Package Overview
Dependencies
Maintainers
11
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kentico/kontent-cli - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0-next.1

lib/tests/invalidOrderMigration.test.d.ts

0

lib/cmds/backup.d.ts
export {};
//# sourceMappingURL=backup.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=environment.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=add.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=migration.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=add.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

2

lib/cmds/migration/run.d.ts

@@ -1,2 +0,2 @@

export {};
export declare const getRange: (range: string) => [number, number] | null;
//# sourceMappingURL=run.d.ts.map

@@ -51,2 +51,7 @@ "use strict";

},
range: {
alias: 'r',
describe: 'Run all migration scripts in the specified range, eg.: 3:5 will run migrations with the "order" property set to 3, 4 and 5',
type: 'string',
},
force: {

@@ -72,5 +77,7 @@ alias: 'f',

.conflicts('all', 'name')
.conflicts('range', 'name')
.conflicts('all', 'range')
.conflicts('environment', 'api-key')
.conflicts('environment', 'project-id')
.check((args) => {
.check((args) => __awaiter(void 0, void 0, void 0, function* () {
if (!args.environment && !(args.projectId && args.apiKey)) {

@@ -80,3 +87,12 @@ throw new Error(chalk_1.default.red('Specify an environment or a project ID with its Management API key.'));

if (!args.all) {
if (args.name) {
if (args.range) {
const range = exports.getRange(args.range);
if (!range) {
throw new Error(chalk_1.default.red(`The range has to be a string of a format "number:number" where the first number is less or equal to the second, eg.: "2:5".`));
}
else if (!(yield migrationUtils_1.containsMigration(range))) {
throw new Error(chalk_1.default.red(`There is no migration in the specified range.`));
}
}
else if (args.name) {
if (!fileUtils_1.isAllowedExtension(args.name)) {

@@ -92,3 +108,3 @@ throw new Error(chalk_1.default.red(`File ${args.name} has not supported extension.`));

else {
throw new Error(chalk_1.default.red('Either the migration script name or all migration options needs to be specified.'));
throw new Error(chalk_1.default.red('Either the migration script name, range or all migration options needs to be specified.'));
}

@@ -106,3 +122,3 @@ }

return true;
}),
})),
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {

@@ -113,2 +129,3 @@ let projectId = argv.projectId;

const runAll = argv.all;
const runRange = exports.getRange(argv.range);
const debugMode = argv.debug;

@@ -129,5 +146,9 @@ const continueOnError = argv.continueOnError;

statusManager_1.loadMigrationsExecutionStatus();
if (runAll) {
if (runAll || runRange) {
let migrationsToRun = yield migrationUtils_1.loadMigrationFiles();
checkForDuplicates(migrationsToRun);
checkForInvalidOrder(migrationsToRun);
if (runRange) {
migrationsToRun = getMigrationsByRange(migrationsToRun, runRange);
}
if (runForce) {

@@ -169,2 +190,11 @@ console.log('Skipping to check already executed migrations');

};
exports.getRange = (range) => {
const match = range.match(/^([0-9]+):([0-9]+)$/);
if (!match) {
return null;
}
const from = Number(match[1]);
const to = Number(match[2]);
return from <= to ? [from, to] : null;
};
const checkForDuplicates = (migrationsToRun) => {

@@ -178,2 +208,19 @@ const duplicateMigrationsOrder = migrationUtils_1.getDuplicates(migrationsToRun, (migration) => migration.module.order);

};
const getMigrationsByRange = (migrationsToRun, range) => {
const migrations = [];
for (const migration of migrationsToRun) {
if (migration.module.order >= range[0] && migration.module.order <= range[1]) {
migrations.push(migration);
}
}
return migrations.filter(String);
};
const checkForInvalidOrder = (migrationsToRun) => {
const migrationsWithInvalidOrder = migrationUtils_1.getMigrationsWithInvalidOrder(migrationsToRun);
if (migrationsWithInvalidOrder.length > 0) {
console.log('Migration order has to be positive integer or zero:');
migrationsWithInvalidOrder.map((migration) => console.error(chalk_1.default.red(`Migration: ${migration.name} order: ${migration.module.order}`)));
process.exit(1);
}
};
const skipExecutedMigrations = (migrations, projectId) => {

@@ -180,0 +227,0 @@ const executedMigrations = migrationUtils_1.getSuccessfullyExecutedMigrations(migrations, projectId);

#!/usr/bin/env node
export {};
//# sourceMappingURL=index.d.ts.map

@@ -22,2 +22,3 @@ #!/usr/bin/env node

.example('kontent', 'migration run --all --environment DEV')
.example('kontent', 'migration run --range 1:4 --environment DEV')
.example('kontent', 'backup --action backup --project-id <YOUR_PROJECT_ID> --api-key <YOUR_MANAGEMENT_API_KEY>')

@@ -24,0 +25,0 @@ .example('kontent', 'backup --action backup --environment <YOUR_ENVIRONMENT>')

@@ -0,0 +0,0 @@ import { ManagementClient } from '@kentico/kontent-management';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export interface IEnvironment {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=environment.js.map

@@ -0,0 +0,0 @@ import { MigrationModule } from '../types';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=migration.js.map

@@ -0,0 +0,0 @@ export interface IMigrationStatus {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=status.js.map

@@ -0,0 +0,0 @@ export declare enum TemplateType {

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=createMigration.test.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=duplicateMigration.test.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=fileUtils.test.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

export {};
//# sourceMappingURL=statusManager.test.d.ts.map

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ManagementClient } from '@kentico/kontent-management';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ import { IEnvironmentsConfig } from '../models/environment';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ /// <reference types="node" />

@@ -0,0 +0,0 @@ "use strict";

@@ -13,5 +13,7 @@ import { ManagementClient } from '@kentico/kontent-management';

export declare const getDuplicates: <T extends any>(array: T[], key: (obj: T) => number) => T[];
export declare const getMigrationsWithInvalidOrder: <T extends any>(array: T[]) => T[];
export declare const loadModule: (migrationFile: string) => Promise<MigrationModule>;
export declare const loadMigrationFiles: () => Promise<IMigration[]>;
export declare const containsMigration: (range: [number, number]) => Promise<Boolean>;
export declare const getSuccessfullyExecutedMigrations: (migrations: IMigration[], projectId: string) => IMigration[];
//# sourceMappingURL=migrationUtils.d.ts.map

@@ -139,2 +139,11 @@ "use strict";

};
exports.getMigrationsWithInvalidOrder = (array) => {
const migrationsWithInvalidOrder = [];
for (const migration of array) {
if (!Number.isInteger(migration.module.order) || Number(migration.module.order) < 0) {
migrationsWithInvalidOrder.push(migration);
}
}
return migrationsWithInvalidOrder;
};
exports.loadModule = (migrationFile) => __awaiter(void 0, void 0, void 0, function* () {

@@ -154,7 +163,16 @@ const migrationPath = exports.getMigrationFilepath(migrationFile);

for (const file of files) {
const migrationModule = yield exports.loadModule(file.name);
migrations.push({ name: file.name, module: migrationModule });
migrations.push({ name: file.name, module: yield exports.loadModule(file.name) });
}
return migrations.filter(String);
});
exports.containsMigration = (range) => __awaiter(void 0, void 0, void 0, function* () {
const files = fileUtils_1.listFiles('.js');
for (const file of files) {
const module = yield exports.loadModule(file.name);
if (module.order >= range[0] && module.order <= range[1]) {
return true;
}
}
return false;
});
exports.getSuccessfullyExecutedMigrations = (migrations, projectId) => {

@@ -161,0 +179,0 @@ const alreadyExecutedMigrations = [];

@@ -0,0 +0,0 @@ export declare const markAsCompleted: (projectId: string, name: string, order: number) => void;

@@ -0,0 +0,0 @@ "use strict";

{
"name": "@kentico/kontent-cli",
"version": "0.3.0",
"version": "0.4.0-next.1",
"description": "Command line interface tool that can be used for generating and running Kontent migration scripts",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -115,3 +115,3 @@ # Kentico Kontent CLI

* `migration run` - Runs a migration script specified by file name (option `--name <file name>`), or runs multiple migration scripts in the order specified in the migration files (option `--all`).
* `migration run` - Runs a migration script specified by file name (option `--name <file name>`), or runs multiple migration scripts in the order specified in the migration files (options `--all` or `--range`).
* You can execute a migration against a specific project (options `--project <YOUR_PROJECT_ID> --api-key <YOUR_MANAGEMENT_API_KEY>`) or environment stored in the local configuration file (option `--environment <YOUR_ENVIRONMENT_NAME>`).

@@ -118,0 +118,0 @@ * After each run of a migration script, the CLI logs the execution into a status file. This file holds data for the next run to prevent running the same migration script more than once. You can choose to override this behavior, for example for debugging purposes, by using the `--force` parameter.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc