kontent-ai / cli Goto Github PK
View Code? Open in Web Editor NEWKontent.ai command line interface supporting migrations scripts processing written by Management SDK JS.
License: MIT License
Kontent.ai command line interface supporting migrations scripts processing written by Management SDK JS.
License: MIT License
Include the timestamp in the migration data contract.
Add an option to use this timestamp for orders.
Q: Validate to include the timestamp in the file name. (maybe as a custom extension and then use the filename instead of module property.
Q: Validate how to work with time ranges.
See: https://github.com/digital-detox/kontent-migration-cli/blob/main/src/lib/run.ts#L19-L33
Readme is too long and can get lost easily. The migration example describes the whole process of using a boilerplate. Wouldn't it be better to only reference the boilerplate repo and say to follow instructions there?
Reduce the migration example paragraph to only navigate to the migration-boilerplate. It has a fully covered readme by itself.
Add any other context, screenshots, or reference links about the feature request here.
I noticed there's no documentation on using content groups and adding elements into them.
I used the following syntax but I get the following error:
code:
const BuildResourceModuleTypeData = (builder: ContentTypeElementsBuilder): ContentTypeModels.IAddContentTypeData => {
let titleRef = builder.textElement({
name: 'Title',
codename: 'title',
type: 'text'
});
return {
name: 'Resource Module Test',
codename: 'resource_module_test',
elements: [
titleRef,
builder.urlSlugElement({
name: 'URL Slug',
codename: 'url_slug',
type: 'url_slug',
depends_on: {
element: titleRef
}
}),
builder.linkedItemsElement({
name: 'Configuration',
type: 'modular_content',
allowed_content_types: [
{
codename: 'ui_configuration'
}
],
item_count_limit: {
condition: 'at_most',
value: 1
},
content_group: {
codename: 'settings'
}
}),
builder.contentGroup({
name: 'settings'
})
]
};
Error:
An error occurred while running migration: 02_createResourceModule.js see the output from running the script.
Error details
Message: The provided request body is invalid. See the 'validation_errors' attribute for more information and specify a valid JSON object.
Code: 5
Validation Errors: [
ValidationError {
message: "The object must contain the property 'type'."
}
]
builder
constructor method contentGroup
does not allow a property named type
as its not defined in its interface
Could you please elaborate and include some examples on usage.
Also it would be nice that errors have some more detailed references.Sometimes its very difficult to find where the problem is in a long script with current given feedback
status.json
could be decoupled.
Default implementation should stay the same.
Introduce a customization interface to be able to store data in i.e. local DB/maybe Kontent storage.
The plugin functionality would work -> i.e. module with specific Data.
Think about the testability -> the test could be prepared for the interface for better DX.
What went wrong?
Running the already executed migration is aborted by error from the management client.
Should skip the already executed migration.
Add any other context about the problem here.
Add links to screenshots, if possible.
The last migration is saved into a status file, however, the tool skips only this last migration and tries to run all migrations before this one.
Update @kentico/kontent-management
dependency to version 0.3.2
which adds support for following endpoints:
and
For list of changes see changelog at https://github.com/Kentico/kontent-management-sdk-js/blob/master/CHANGELOG.md
When keeping the state of the migrations not in the status.json file, it would be easier to implement migrations in a CICD pipeline. My suggestion would be to keep this state as close as possible to the project / environment and store it as separate content-type(s).
If the CLI could figure out based on projected & environment what the current state of the migrations is it would be really easy to run the migrations in an automatic stateless deployment process without telling the CLI exactly what to migrate.
With the current implementation we need to keep the status.json in sync between different deployment-agents in our CICD pipeline which makes it really hard to implement
The proposed solution is heavily inspired by the EF Core Code first migration
Add codecov to know how much of the code by tests
Find out how to add codecov to readme and implement it.
Add any other context, screenshots, or reference links about the feature request here.
The kbm backup command should accept --environmentId according to documentation, but instead it accepts --projectId
The backup command should accept --environmentId
There is a bug that rollback function does not execute
migration rollback should be executed and status.json updated
Add any other context about the problem here.
Add links to screenshots, if possible.
Extends & unifies use of kontent CLI actions so that devs are able to easily backup & restore their projects using this repo without the need of using backup manager separately.
Add set of CLI commands that will make use of the https://github.com/Kentico/kontent-backup-manager-js
To be able to use it as rollback from: https://github.com/digital-detox/kontent-migration-cli#commands
Think about the state information setup.
Attempting to update a taxonomy group in a CLI script. All other migration scripts are working as intended so my overall setup is fine.
What went wrong?
Check out the test script below. Adding the taxonomy works. I get an error that "apiClient.modifyTaxonomy is not a function" when I try to update it.
An error occurred while running migration: update_taxonomy_test.js see the output from running the script.
Message: apiClient.modifyTaxonomy is not a function
Run the following:
const migration = {
order: 01,
run: async (apiClient) => {
// Create a test taxonomy - works
const addTaxonomyResponse = await apiClient
.addTaxonomy()
.withData(
{
name: "Test",
codename: "test_group",
terms: [{
name: "Some Term",
codename: "some_term",
terms: []
}],
},
)
.toPromise();
// Try to modify taxonomy - error 'apiClient.modifyTaxonomy is not a function'
await apiClient
.modifyTaxonomy()
.byTaxonomyCodename('test_group')
.withData(
[
{
op: 'replace',
property_name: 'codename',
value: 'updated_test_group'
},
]
)
.toPromise();
}
};
module.exports = migration;
The function should exist and the taxonomy should be updated.
The backup manager is deprecated
What is the correct behavior?
Add any other context about the problem here.
Add links to screenshots, if possible.
The CLI logs verbose errors to the command line and adds a lot of extra noise to the CLI output when errors are handled properly. This can be disabled easily when making requests using the JavaScript SDK.
const managementClient = new ManagementClient({
apiKey: 'x',
projectId: 'y',
httpService: new HttpService({
logErrorsToConsole: false
})
});
The CLI configures it’s own httpService
and doesn't allow additional options to be configured. The default info logged out is easy to confuse with an error in the migration script when infact the error is safely handled in the migration.
Add the ability to disable logging errors to the console through a param on the run command or when invoking apiClient
so users can opt in to their own error handling.
A case where this is useful is when updating all language variants of an item with a new value and some items are translated and others aren’t, so they don't need to be updated and will return a 404 if you attempt to get data from the variant.
If logging were disabled and the following code were in a migration:
for (const language of languages.data.items) {
try {
const languageVariant = await apiClient.viewLanguageVariant()
.byItemCodename("item_codename")
.byLanguageId(language.id)
.toPromise()
// Item isn’t translated in this language
if (!languageVariant) {
return
}
// Do stuff and upsert language variant
} catch(error) {
console.log(error.message)
}
}
Output would be:
The requested variant '{id: cd571471-a7ec-4f9c-b5e5-421f10becf13}' of content item '{codename: item_codename}' was not found.
Instead of the verbose log containing the full response.
Once Kontent Backup Manager is released in v3.0, upgrade the dependency and deal with the breaking changes.
Ideally think of some more elegant way, how to set up this dependency future-proof for new version of backup manager.
See related draft pull request.
Go through // TODO
comments before merge
Usually, when deciding between javascript and typescript, you can write shortcuts 'js' or 'ts' instead of full names 'javascript' and 'typescript'. Slight improvement, but it can reduce the annoyance of always getting errors when specifying only shortcuts.
Add shortcuts into src/cmds/migration.add.ts
.
Add any other context, screenshots, or reference links about the feature request here.
Allow users to make more complicated operations by single and easy call i.e. add content type to allowed content type of another content type's element.
Examples - will be @tommarhall
The Kentico model generator (https://github.com/Kentico/kontent-model-generator-js) allows users to generate TS classes to create strictly typed objects to receive data from the Content Delivery APIs (https://github.com/Kentico/kontent-delivery-sdk-js/blob/master/DOCS.md). However there is no way to maintain a subfolder inside or outside the Migrations folder (https://github.com/Kentico/kontent-migrations-boilerplate/tree/master/Migrations) without running into the following errors during execution of the migration CLI:
Modify the CLI to allow TS files (typically model classes) to be maintained outside or inside the Migrations folder. There should be a way to set the compiler to allow folders with model files during Transpiling. This will allow easier maintenance of code.
Currently the CLI uses management-sdk 3.1 but you already have v5 with new options in it.
Update dependency to version 5 and change project-id usage to environment-id
What went wrong?
Try following the instructions https://github.com/Kentico/kontent-cli/#-migration-example and run a migration, but get a error:
echuvelev@chuvelev-mbp ~/Code/kontent-migrations-boilerplate master ● ? npm run migrate "01_sample_init_createBlogType" 1 ↵ 20:40:55
> kontent-migrations-boilerplate@1.1.1 migrate
> tsc && kontent migration run --environment DEV -n "01_sample_init_createBlogType"
kontent migration run
Runs a migration script specified by its name, or runs multiple migration scripts in the specified order.
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]
--name, -n Migration name [string]
--project-id, -p Project ID to run the migration script on [string]
--api-key, -k Management API key [string]
--environment, -e Environment name [string]
--all, -a Run all migration scripts in the specified order [boolean]
--range, -r Run all migration scripts in the specified range, eg.: 3:5 will run migrations with the "order" property set to 3, 4 and 5 [string]
--force, -f Enforces run of already executed scripts. [boolean] [default: false]
--continue-on-error, -c Continue executing migration scripts even if a migration script fails. [boolean] [default: false]
--debug, -d Run in debug mode [boolean] [default: false]
TypeError: Cannot read properties of undefined (reading 'match')
at Object.exports.getRange (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/@kentico/kontent-cli/lib/cmds/migration/run.js:180:25)
at /Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/@kentico/kontent-cli/lib/cmds/migration/run.js:120:34
at Generator.next (<anonymous>)
at /Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/@kentico/kontent-cli/lib/cmds/migration/run.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/@kentico/kontent-cli/lib/cmds/migration/run.js:4:12)
at Object.handler (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/@kentico/kontent-cli/lib/cmds/migration/run.js:115:24)
at Object.runCommand (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/yargs/build/lib/command.js:196:48)
at Object.parseArgs [as _parseArgs] (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/yargs/build/lib/yargs.js:1043:55)
at Object.runCommand (/Users/echuvelev/Code/kontent-migrations-boilerplate/node_modules/yargs/build/lib/command.js:157:36)
Running the 01_sample_init_createBlogType.js migration.
Status file was updated see /Users/echuvelev/Code/kontent-migrations-boilerplate/status.json
The "01_sample_init_createBlogType.js" migration on a project with ID "7bc88b7e-80d2-0087-4b4e-a33e80420328" executed successfully.
What the correct behavior is?
Add any other context about the problem here.
Add links to screenshots, if possible.
New SDK has a new version with a bunch of new features. We need to accommodate the news.
https://github.com/Kentico/kontent-management-sdk-js/blob/master/CHANGELOG.md
New JS SDK does not need rxjs - Update readme.
Test out that that setting latest version as a peer dependency works fine.
Currently, you can run all migrations (and possibly a range of them #32). It would be great t have some verification mechanism, that would notify you you have order
property in migration properly in place - From 1
to X
.
Raise warning/exception if the migrations do not have a range being set properly.
I am attempting to modify an existing content type and add a linked items with a items_count_limit
restriction but it does not work.
items_count_limit
. Specify the condition and value.kontent migration run -n test -e DEV
.items_count_limit
had no effect.I expect the items_count_limit
restriction to apply.
Below is my migration code.
const migration: MigrationModule = {
order: 1,
run: async apiClient => {
await apiClient
.addContentType()
.withData(BuildChecklistItemType)
.toPromise()
await apiClient
.modifyContentType()
.byTypeCodename('checklist')
.withData(ChecklistModification)
.toPromise()
},
}
const BuildChecklistItemType = (
builder: ContentTypeElementsBuilder,
): ContentTypeModels.IAddContentTypeData => ({
codename: 'checklist_item_1',
elements: [
builder.textElement({
codename: 'text',
is_required: true,
name: 'Text',
type: 'text',
}),
],
name: 'Checklist Item 1',
})
const ChecklistModification: ContentTypeModels.IModifyContentTypeData[] = [
{
op: 'addInto',
path: '/elements',
value: {
allowed_content_types: [
{
codename: 'checklist_item_1',
},
],
codename: 'items_1',
is_required: true,
items_count_limit: { // LOOK HERE
condition: 'exactly',
value: 4,
},
name: 'Items 1',
type: ElementModels.ElementType.modularContent,
},
},
]
Here is the result in Kentico:
Everything worked as expected except the items_count_limit
.
Please let me know if I can provide any additional information. Thank you! :)
There is a way to create both JavaScript and TypeScript migrations but I can only run JavaScript migrations. When I try to run my new TypeScript migration, it says Couldn't import the migration script from C:\CFAS\KenticoKontentCli\Migrations\test.ts.js due to an error: "Cannot find module C:\CFAS\KenticoKontentCli\Migrations\test.ts.js"
.
It looks like it is looking for a JavaScript file by default. It assumes the migration is JavaScript.
kontent migration add --name test --template-type "typescript"
.kontent migration run --name test --environment DEV
.It should run the TypeScript migration file.
I attempted to run the TypeScript migration file provided by the boilerplate. I deleted the JavaScript file and left the TypeScript file alone to see what it would do. It gave me an error because it is looking for a JavaScript file.
I was looking at the code for run
and I have a feeling this might have something to do with it.
Perhaps there could be a flag to specify if the migration is JavaScript or TypeScript. If not, have run determine it automatically. If it cannot find the .js
file, then look for a .ts
file.
Please let me know if I can provide any further details. Thank you! :)
kontent-cli
has a dependency of kontent-management
locked at version 0.3.13
. The kontent-management
version is now at 0.3.17
. The kontent-management
upgrade will fix linting issues for the kontent-cli
.
Perhaps upgrade the kontent-management
dependency or maybe it should be a peer dependency.
Please let me know if I can provide any more details. Thank you!
This feature would allow people who use the https://github.com/Kentico/kontent-migrations-boilerplate to be able to reference the transpiled JS files using the <script> tag in HTML files. Thus API calls could be tested in the browser.
The transpiled JS files also need to be created in a seperate folder (could be named 'dist') by the CLI. The "outDir" config in TSCONFIG could be used, but it creates the error that "all source files must be in the same directory".
The framework now supports just using the kontent cli to perform the migrations. This makes the user heavily dependant on the CLI to test all scenarios.
For the projects that are using Kontent CLI for managing their migrations, it is difficult to set the version of MAPI SDK since it is hardcoded in the dependencies.
Let's verify whether setting this dependency as a peer dependency would fix the issue.
Also, it is hard to verify alpha/beta versions in the kontent migration boilerplate - specifically this verification is blocked: kontent-ai/migrations-boilerplate#3
Also it would fix the issues similar to #17 kontent-ai/management-sdk-js#47
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.