Skip to content

CLI

CLI

cozy-jobs-cli is a npm package providing CLI tools allowing to run your connector in different modes.

  • development
  • or in dedicated REPL

You can install it in your connector as a dev dependency.

cozy-run-dev

If you want to run your connector linked to a cozy-stack, even remotely, the “dev” mode is for you. Add the following code in the scripts section of your package.json file:

   "scripts": {
+    "dev": "cozy-run-dev"
   }

and run:

yarn dev

This command will register your konnector as an OAuth application to the cozy-stack and then set the COZY_CREDENTIALS and COZY_FIELDS environment variable. By default, the cozy-stack is expected to run at http://cozy.tools:8080. If this is not your case, update the COZY_URL field in [./konnector-dev-config.json].

After that, your connector is running but will not work since credentials to the target service are not configured. You can do this also in [./konnector-dev-config.json] in the “fields” section.

 "fields": {
+  "login": "homer.simpson@gmail.com",
+  "password": "maggieisthebest"
 }

Please note that the [./konnector-dev-config.json] file accepts javascript comments. They will be stripped out when read by cozy-run commands.

The files are saved in the /cozy-konnector-dev-root directory of your cozy.

It is also possible to add an argument to this command which tells which file to run. Default is defined in package.json main section or ./src/index.js

When your connector is run with this command, a global function is available in your connector : global.openInBrowser, which can take an html string or a cheerio object as input and will show the corresponding html page in your default browser.

Arguments
$ cozy-run-dev <file> [-t token.json] [-m manifest.webapp]
  • -t, --token : Specify where the token should be saved
  • -m, --manifest : Specify the manifest.path that should be used for the permissions

cozy-run-shell

When you are developping a connector, it is possible to get a REPL with all the cozy-konnector-libs tools available and some enhancements.

  scripts: {
    dev: "cozy-run-shell"
  }

and run:

yarn shell

In this REPL, all the cozy-konnector-libs tools are available as globals and a default global request instance initialized with cheerio and cookie handling is available. For example run :

request('http://quotes.toscrape.com/')

After running a request, a global $ object with a cheerio instance is available. Enter :

$

A full global request-promise response object is also available.

If you always want the details of the request and the response to be displayed. Just run once:

debug()

And you get a syntax colored html representation of the result of the request. If you run :

$('p')

You get an array of elements with for each element: - the type of the element (p) - the html of the element - the cleaned text of the element

It is also possible to load a html file into the shell. Run :

yarn shell index.html

The html file will load and $ will be correctly initialized.

The openInBrowser is also available , which can take an html string or a cheerio object as input and will show the corresponding html page in your default browser.

Arguments
$ cozy-run-shell [<file>]