DynamicWeb CLI
Get started with our command-line interface.
DynamicWeb CLI is a powerful command line tool designed to help developers quickly and efficiently manage any given DynamicWeb 10 solution they may have access to. These tools includes an easy setup and handling of different environments, access to the Management API and an easy way to update a Swift solution.
Logging into a DynamicWeb 10 solution through the DynamicWeb CLI will create an API Key for the given user, which in turn lets you use any Queries and Commands the solution has, meaning you can control everything you can do in the backend, from your command line. With this, you can hook it up to your own build pipelines and processes, if certain requests needs to happen before or after deployments or changes.
The DynamicWeb CLI can also help with active development of custom addins to solutions. With a simple dw install
command it will upload and install your custom code to the solution you're connected to.
Extracting files from solutions is just as easy as well, with the DynamicWeb CLI you can list out the structure of a solution and get full exports of the files structure and the database. Importing files into a solution is just as easy as well, as long as you have access to the files and the solution, they can be imported with a simple command using the DynamicWeb CLI.
Get started
DynamicWeb CLI can either be installed from npm or cloned from github and installed locally.
npm
If you plan on just using DynamicWeb CLI, do the following; Install from npm by running the command
$ npm i @dynamicweb/cli -g
GitHub
If you plan on extending the functionality or contributing to DynamicWeb CLI, clone the repository so all the code is available locally, to do that do the following; Clone from github then move to project dir and run
$ npm install -g
$ npm install
Note
Specific installations might be necessary if you're faced with errors such as Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'yargs'
In which case try installing that module specifically;
$ npm install yargs
Commands
All commands and options can be viewed by running
$ dw --help
$ dw <command> --help
Users and environments
As all queries and commands are pulling or pushing data from the Management API, the necessary authorization is required.
To generate an API-key that the CLI will use, login to your environment
$ dw login
This will start an interactive session asking for username and password, as well as the name of the environment, so it's possible to switch between different environments easily.
It will ask for a protocol and a host, if you're running a local environment, set this to the host it starts up with, i.e localhost:12345
. The protocol should be http or https.
Each environment has its own users, and each user has its own API-key assigned to it, swap between environments by using
$ dw env <env>
Swap between users by simply supplying the name of the user in the login command
$ dw login <username>
You can view the current environment and user being used by typing
$ dw
The configuration will automatically be created when setting up your first environment, but if you already have an API-key you want to use for a user, you can modify the config directly in the file located in usr/.dwc
. The structure should look like the following
{
"env": {
"dev": {
"host": "localhost:12345",
"users": {
"DemoUser": {
"apiKey": "<keyPrefix>.<key>"
}
},
"current": {
"user": "DemoUser"
}
}
},
"current": {
"env": "dev"
}
}
Files
$ dw files <dirPath> <outPath>
The files command is used to list out and export the structure in your Dynamicweb files archive, as such is has multiple options;
-l
--list
This will list the directory given in <dirPath>-f
--includeFiles
The list will now also show all files in the directories-r
--recursive
By default it only handles the <dirPath>, but with this option it will handle all directories under this recursively-e
--export
It will export <dirPath> into <outPath> on your local machine, unzipped by default--raw
This will keep the content zipped--iamstupid
This will include the export of the /files/system/log and /files/.cache folders
Examples:
Exporting all templates from current environment to local solution
$ cd DynamicWebSolution/Files
$ dw files templates ./templates -fre
Listing the system files structure of the current environment
$ dw files system -lr
Swift
$ dw swift <outPath>
The swift command is used to easily get your local environment up to date with the latest swift release. It will override all existing directories and content in those, which can then be adjusted in your source control afterwards. It has multiple options to specify which tag or branch to pull;
-t
--tag <tag>
The tag/branch/release to pull-l
--list
Will list all the release versions-n
--nightly
Will pull #HEAD, as default is latest release--force
Used if <outPath> is not an empty folder, to override all the content
Examples:
Getting all the available releases
$ dw swift -l
Pulling and overriding local solution with latest nightly build
$ cd DynamicWebSolution/Swift
$ dw swift . -n --force
Query
$ dw query <query>
The query command will use any query towards the Management API with the given query parameters. This means any query parameter that's mandatory for the given query, is required as an option in this command. It's also possible to list which parameters is necessary for the given query through the options;
-l
--list
Will list all the properties for the given <query>-i
--interactive
Will perform the <query> but without any parameters, as they will be asked for one by one in interactive mode--<queryParam>
Any parameter the query needs will be sent by--key value
Examples:
Getting all properties for a query
$ dw query FileByName -l
Getting file information on a specific file by name
$ dw query FileByName --name DefaultMail.html --directorypath /Templates/Forms/Mail
Command
$ dw command <command>
Using command will, like query, use any given command in the solution. It works like query, given the query parameters necessary, however if a DataModel
is required for the command, it is given in a json-format, either through a path to a .json file or a literal json-string in the command.
--json
Takes a path to a .json file or a literal json, i.e--json '{ abc: "123" }'
Examples:
Creating a copy of a page using a json-string
$ dw command PageCopy --json '{ "model": { "SourcePageId": 1189, "DestinationParentPageId": 1129 } }'
Removing a page using a json file
$ dw command PageMove --json ./PageMove.json
Where PageMove.json contains
{
"model": {
"SourcePageId": 1383,
"DestinationParentPageId": 1376
}
}
Deleting a page
$ dw command PageDelete --json '{ "id": "1383" }'
Install
$ dw install <filePath>
Install is somewhat of a shorthand for a few commands. It will upload and install a given .dll or .nupkg addin to your current environment.
It's meant to be used to easily apply custom dlls to a given project, it being local or otherwise, so after having a dotnet library compiled locally, this command can be run, pointing to the compiled .dll and it will handle the rest with all the addin installation, and it will be available in the DynamicWeb solution as soon as the command finishes.
Examples:
$ dw install ./bin/Release/net6.0/CustomProject.dll
Database
$ dw database <outPath>
This command is used for actions towards your current environments database.
-e
--export
Exports your current environments database to a .bacpac file at <outPath>
Examples:
$ dw database -e ./backup
Config
$ dw config
Config is used to manage the .dwc file through the CLI, given any property it will create the key/value with the path to it.
--<property>
The path and name of the property to set
Examples: Changing the host for the dev environment
$ dw config --env.dev.host localhost:12345