Skip to content

Commit 109d945

Browse files
author
Tomáš Winkler
authored
Merge pull request #24 from Kentico/feature/21
Make MAPI JSD SDK Peer dependency
2 parents cad87ce + 483e70b commit 109d945

File tree

18 files changed

+215
-215
lines changed

18 files changed

+215
-215
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
node-version: ${{ matrix.node-version }}
2020
registry-url: 'https://registry.npmjs.org'
2121
- run: npm install
22+
- run: npm run lint
2223
- run: npm run build
2324
- run: npm publish
2425
env:

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ jobs:
1313
with:
1414
node-version: ${{ matrix.node-version }}
1515
- run: npm i
16+
- run: npm run lint
17+
- run: npm run build
1618
- run: npm run test
19+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
Migrations/.environments.json
66
Migrations/status.json
77
/package-lock.json
8+
9+
# Generated by tests
10+
status.json

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"name": "@kentico/kontent-cli",
3-
"version": "0.0.11",
3+
"version": "0.1.0",
44
"description": "Command line interface tool that can be used for generating and running Kontent migration scripts",
55
"main": "./lib/index.js",
66
"types": "./lib/types/index.d.ts",
77
"scripts": {
88
"build": "tsc",
9+
"watch": "tsc -w",
910
"test": "jest",
10-
"lint": "tslint --project tsconfig.json --fix \"src/**/*.ts\" && prettier --write \"src/**/*.ts\"",
11+
"lint": "tslint --project tsconfig.json \"src/**/*.ts\" && prettier --check \"src/**/*.ts\"",
12+
"lint:fix": "tslint --project tsconfig.json --fix \"src/**/*.ts\" && prettier --write \"src/**/*.ts\"",
1113
"debug": "node --inspect ./lib/index.js migration run --all -e DEV"
1214
},
1315
"publishConfig": {
@@ -45,14 +47,13 @@
4547
},
4648
"homepage": "https://github.com/Kentico/kontent-cli#readme",
4749
"dependencies": {
50+
"@kentico/kontent-backup-manager": "3.0.1",
4851
"chalk": "^4.0.0",
49-
"yargs": "^15.3.1",
50-
"@kentico/kontent-management": "~0.4.7",
51-
"@kentico/kontent-backup-manager": "~1.2.2",
52-
"dotenv": "^8.2.0"
52+
"dotenv": "^8.2.0",
53+
"yargs": "^15.3.1"
5354
},
5455
"peerDependencies": {
55-
"rxjs": "^6.5.5"
56+
"@kentico/kontent-management": "^1.2.0"
5657
},
5758
"devDependencies": {
5859
"@babel/core": "~7.9.0",

src/cmds/backup.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import yargs from 'yargs';
22
import chalk from 'chalk';
33
import { environmentConfigExists, getEnvironmentsConfig } from '../utils/environmentUtils';
4-
import { CleanService, ExportService, ImportService, ZipService } from '@kentico/kontent-backup-manager';
4+
import { CleanService, ExportService, ImportService, ZipService, IProcessedItem } from '@kentico/kontent-backup-manager';
55
import { getFileBackupName } from '../utils/fileUtils';
6-
import { IProcessedItem } from '@kentico/kontent-backup-manager/_commonjs/src';
6+
import { FileService } from '@kentico/kontent-backup-manager/dist/cjs/lib/node';
77

88
const kontentBackupCommand: yargs.CommandModule = {
99
command: 'backup',
@@ -42,6 +42,12 @@ const kontentBackupCommand: yargs.CommandModule = {
4242
describe: 'Environment name',
4343
type: 'string',
4444
},
45+
'enable-publish': {
46+
alias: 'ep',
47+
describe: 'Indicates if language variants published on the source project are also published on target. Enabled by default',
48+
type: 'boolean',
49+
default: true,
50+
},
4551
})
4652
.conflicts('environment', 'api-key')
4753
.conflicts('environment', 'project-id')
@@ -76,12 +82,16 @@ const kontentBackupCommand: yargs.CommandModule = {
7682

7783
const defaultBackupName = getFileBackupName();
7884
const zipService = new ZipService({
79-
filename: argv.name || defaultBackupName,
85+
context: 'node.js',
8086
enableLog: argv.log,
8187
});
8288

8389
console.log('Starting backup tool');
8490

91+
const fileService = new FileService({
92+
enableLog: argv.log,
93+
});
94+
8595
switch (argv.action) {
8696
case 'backup':
8797
const exportService = new ExportService({
@@ -95,21 +105,23 @@ const kontentBackupCommand: yargs.CommandModule = {
95105
});
96106
const exportedData = await exportService.exportAllAsync();
97107
await zipService.createZipAsync(exportedData);
108+
const backupZipData = await zipService.createZipAsync(exportedData);
109+
await fileService.writeFileAsync(argv.name || defaultBackupName, backupZipData);
98110
break;
99111

100112
case 'restore':
101-
const zipData = await zipService.extractZipAsync();
113+
const zipData = await zipService.extractZipAsync(await fileService.loadFileAsync(argv.name || defaultBackupName));
102114
const importService = new ImportService({
103115
onImport: (item: IProcessedItem) => {
104116
if (argv.log) {
105117
console.log(`Imported: ${item.title} | ${item.type}`);
106118
}
107119
},
120+
enablePublish: argv.enablePublish,
108121
projectId: projectId,
109122
apiKey: apiKey,
110123
enableLog: argv.log,
111124
fixLanguages: true,
112-
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000',
113125
});
114126
await importService.importFromSourceAsync(zipData);
115127
break;

src/cmds/environment.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import yargs from 'yargs';
2-
3-
const environmentCommand: yargs.CommandModule = {
4-
command: 'environment <command>',
5-
describe: 'Environment commands',
6-
builder: (yargs: any) => {
7-
return yargs.commandDir('environment').demandCommand(2, 'Please specify a environment arguments');
8-
},
9-
handler: (argv: any) => {}
10-
};
11-
12-
// yargs needs exported command in exports object
13-
Object.assign(exports, environmentCommand);
1+
import yargs from 'yargs';
2+
3+
const environmentCommand: yargs.CommandModule = {
4+
command: 'environment <command>',
5+
describe: 'Environment commands',
6+
builder: (yargs: any) => {
7+
return yargs.commandDir('environment').demandCommand(2, 'Please specify a environment arguments');
8+
},
9+
handler: (argv: any) => {},
10+
};
11+
12+
// yargs needs exported command in exports object
13+
Object.assign(exports, environmentCommand);

src/cmds/environment/add.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { saveEnvironmentConfig } from '../../utils/environmentUtils';
33

44
const addEnvironmentCommand: yargs.CommandModule = {
55
command: 'add',
6-
describe: "Store information about the environment locally. The environment is defined as a named pair of values. For example, a 'DEV' environment can be defined as a pair of specific project ID and Management API key.",
6+
describe: 'Store information about the environment locally. The environment is defined as a named pair of values. For example, a "DEV" environment can be defined as a pair of specific project ID and Management API key.',
77
builder: (yargs: any) =>
88
yargs
99
.options({

src/cmds/migration.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import yargs from 'yargs';
2-
3-
const migrationCommand: yargs.CommandModule = {
4-
command: 'migration <command>',
5-
describe: 'Migration commands',
6-
builder: (yargs: any) => {
7-
return yargs.commandDir('migration').demandCommand(2, 'Please specify a migration arguments');
8-
},
9-
handler: (argv: any) => {}
10-
};
11-
12-
// yargs needs exported command in exports object
13-
Object.assign(exports, migrationCommand);
1+
import yargs from 'yargs';
2+
3+
const migrationCommand: yargs.CommandModule = {
4+
command: 'migration <command>',
5+
describe: 'Migration commands',
6+
builder: (yargs: any) => {
7+
return yargs.commandDir('migration').demandCommand(2, 'Please specify a migration arguments');
8+
},
9+
handler: (argv: any) => {},
10+
};
11+
12+
// yargs needs exported command in exports object
13+
Object.assign(exports, migrationCommand);

src/cmds/migration/add.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import yargs from 'yargs';
2-
import chalk from 'chalk';
3-
import { createMigration } from '../../utils/migrationUtils';
4-
import { TemplateType } from '../../models/templateType';
5-
6-
const addMigrationCommand: yargs.CommandModule = {
7-
command: 'add',
8-
describe: 'Generates a template script (in JavaScript or TypeScript) for running a migration on a Kentico Kontent project.',
9-
builder: (yargs: any) =>
10-
yargs
11-
.options({
12-
name: {
13-
alias: 'n',
14-
describe: 'Migration name',
15-
type: 'string'
16-
},
17-
'template-type': {
18-
alias: 't',
19-
describe: 'Determines whether the template script is in TypeScript or plain JavaScript',
20-
type: 'string',
21-
default: 'javascript'
22-
}
23-
})
24-
.demandOption(['name', 'template-type']),
25-
handler: (argv: any) => {
26-
if (!['javascript', 'typescript'].includes(argv.templateType)) {
27-
console.error(chalk.redBright(`Unexpected template type ${argv.templateType} allowed is [typescript, javascript]`));
28-
process.exit(1);
29-
}
30-
31-
const templateType = argv.templateType === 'javascript' ? TemplateType.Javascript : TemplateType.TypeScript;
32-
createMigration(argv.name, templateType);
33-
}
34-
};
35-
36-
// yargs needs exported command in exports object
37-
Object.assign(exports, addMigrationCommand);
1+
import yargs from 'yargs';
2+
import chalk from 'chalk';
3+
import { createMigration } from '../../utils/migrationUtils';
4+
import { TemplateType } from '../../models/templateType';
5+
6+
const addMigrationCommand: yargs.CommandModule = {
7+
command: 'add',
8+
describe: 'Generates a template script (in JavaScript or TypeScript) for running a migration on a Kentico Kontent project.',
9+
builder: (yargs: any) =>
10+
yargs
11+
.options({
12+
name: {
13+
alias: 'n',
14+
describe: 'Migration name',
15+
type: 'string',
16+
},
17+
'template-type': {
18+
alias: 't',
19+
describe: 'Determines whether the template script is in TypeScript or plain JavaScript',
20+
type: 'string',
21+
default: 'javascript',
22+
},
23+
})
24+
.demandOption(['name', 'template-type']),
25+
handler: (argv: any) => {
26+
if (!['javascript', 'typescript'].includes(argv.templateType)) {
27+
console.error(chalk.redBright(`Unexpected template type ${argv.templateType} allowed is [typescript, javascript]`));
28+
process.exit(1);
29+
}
30+
31+
const templateType = argv.templateType === 'javascript' ? TemplateType.Javascript : TemplateType.TypeScript;
32+
createMigration(argv.name, templateType);
33+
},
34+
};
35+
36+
// yargs needs exported command in exports object
37+
Object.assign(exports, addMigrationCommand);

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const createMigrationTool = (): number => {
2020
.example('kontent', 'backup --action backup --project-id <YOUR_PROJECT_ID> --api-key <YOUR_MANAGEMENT_API_KEY>')
2121
.example('kontent', 'backup --action backup --environment <YOUR_ENVIRONMENT>')
2222
.example('kontent', 'backup --action restore --name backup_file --project-id <YOUR_PROJECT_ID> --api-key <YOUR_MANAGEMENT_API_KEY>')
23+
.example('kontent', 'backup --action restore --name backup_file --environment <YOUR_ENVIRONMENT> --enable-publish false')
2324
.example('kontent', 'backup --action clean --project-id <YOUR_PROJECT_ID> --api-key <YOUR_MANAGEMENT_API_KEY>')
2425
.strict().argv;
2526

0 commit comments

Comments
 (0)