Skip to content

Commit

Permalink
Merge pull request #285 from jovotech/v4/improvement/docs
Browse files Browse the repository at this point in the history
📝 Improve docs
  • Loading branch information
rubenaeg authored Jan 26, 2022
2 parents f78f4b8 + 4b36d71 commit a9f8d99
Show file tree
Hide file tree
Showing 17 changed files with 11,688 additions and 11,573 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
- run: npm install
- run: npm run bootstrap
- run: npm run eslint
- run: npm run tsc
- run: npm run build
- run: npm run test
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"jovo": "./bin/run"
},
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest",
"link": "node bin/link",
Expand Down
3 changes: 2 additions & 1 deletion commands/command-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
Expand Down
3 changes: 2 additions & 1 deletion commands/command-deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
Expand Down
3 changes: 2 additions & 1 deletion commands/command-get/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
Expand Down
3 changes: 2 additions & 1 deletion commands/command-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
Expand Down
4 changes: 2 additions & 2 deletions commands/command-run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
"dependencies": {
"@jovotech/cli-core": "^4.0.1",
"@oclif/parser": "^3.8.5",
"boxen": "^5.0.0",
"global-dirs": "^3.0.0",
"lodash.merge": "^4.6.2",
"nodemon": "^2.0.7",
Expand Down
25 changes: 1 addition & 24 deletions commands/command-run/src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import {
execAsync,
ExecResponse,
JovoCliError,
JovoUserConfigFile,
Package,
UserConfig,
} from '@jovotech/cli-core';

/**
* Compile TypeScript code of Jovo project to JavaScript.
* @param sourceFolder - Source folder.
*/
export async function compileTypeScriptProject(sourceFolder: string): Promise<void> {
try {
await execAsync('npm run tsc', { cwd: sourceFolder });
} catch (error) {
throw new JovoCliError({
message: (error as ExecResponse).stderr!,
module: 'RunCommand',
details: (error as ExecResponse).stdout,
});
}
}
import { JovoUserConfigFile, Package, UserConfig } from '@jovotech/cli-core';

/**
* Checks whether to display an update message for out-of-date packages or not.
Expand Down
5 changes: 3 additions & 2 deletions commands/command-update/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@jovotech/cli-command-update",
"description": "Jovo CLI Plugin for updating dependencies",
"description": "Jovo CLI Plugin for updating Jovo packages",
"version": "4.0.0-alpha.0",
"author": "jovotech",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src --ext .ts --fix",
"test": "jest"
},
Expand Down
3 changes: 2 additions & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "Apache-2.0",
"scripts": {
"test": "jest",
"tsc": "tsc",
"build": "tsc",
"build:watch": "tsc --watch",
"eslint": "eslint src test --ext .ts --fix"
},
"dependencies": {
Expand Down
43 changes: 41 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ With the Jovo CLI, you can do many things, including:

Learn how to install the Jovo CLI in the [installation](#installation) section. In the [configuration](#configuration) section, we'll take a look at configurations and plugins that can be added to the CLI.

After that, we'll take a look at all [CLI commands](#commands) and ways to [extend the Jovo CLI](#extend-the-jovo-cli).
After that, we'll take a look at all [CLI commands](#commands) and ways to [extend the Jovo CLI](#extend-the-jovo-cli). For bugfixes, take a look at the [local setup](#local-setup) section.

## Installation

Expand Down Expand Up @@ -62,7 +62,7 @@ Learn more about the Jovo CLI commands:
- [`new`](https://www.jovo.tech/docs/new-command): Create a new Jovo project
- [`run`](https://www.jovo.tech/docs/run-command): Start the local development server
- [`build`](https://www.jovo.tech/docs/build-command): Create platform-specific project files
- [`deploy`](https://www.jovo.tech/docs/deplooy-command): Deploy to various platforms and services
- [`deploy`](https://www.jovo.tech/docs/deploy-command): Deploy to various platforms and services
- [`get`](https://www.jovo.tech/docs/get-command): Sync your local files with platform files
- [`update](https://www.jovo.tech/docs/update-command): Update Jovo packages in your project

Expand All @@ -82,3 +82,42 @@ There are two ways how you can extend the Jovo CLI:

- [CLI hooks](https://www.jovo.tech/docs/project-config#hooks): Hook into existing CLI commands. For example, call an API and retrieve data as part of the `build` command.
- [CLI plugins](https://www.jovo.tech/docs/cli-plugins): Create your own plugins that could hook into commands, or even create commands on their own.

### Local Setup

If you want to extend the Jovo CLI functionality, it should be sufficient to follow the steps mentioned above. However, if you encounter any issues or want to dig deeper into core functionality, it might be useful to set up the CLI for local development.

To get started, clone the CLI repository to your workspace. Here is a list of options:

```sh
# HTTPS
$ git clone https://github.com/jovotech/jovo-cli.git

# SSH
$ git clone git@github.com:jovotech/jovo-cli.git

# GitHub ClI
$ gh repo clone jovotech/jovo-cli
```

Now, go to the created project and run the local setup script:

```sh
# Change directory to the created project
$ cd jovo-cli

# Run the local setup script
$ npm run setup:dev
```

This will install all necessary dependencies and link the local binary to `jovodev`. This allows you to apply and test changes in the code directly by recompiling the corresponding module and running `jovodev`.

```sh
$ jovodev
```

For example, if you need to make some changes to the `build:platform` command, you need to go into `jovo-cli/commands/command-build`, adjust the code to your needs and recompile it using `npm run build`, or `npm run build:watch` if you want to recompile on code changes automatically (similar to `nodemon`). When running the command using `jovodev`, you should see your changes implemented:

```sh
$ jovodev build:platform
```
77 changes: 40 additions & 37 deletions docs/cli-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,36 @@ A CLI command file looks like this:
import { PluginCommand } from '@jovotech/cli-core';

export class SomeCommand extends PluginCommand {
static id = 'build:serverless';
static description = 'Build serverless configuration file.';
static examples: string[] = ['jovo build:serverless'];
static id = '<id>';
static description = 'This command does something.';
static examples: string[] = ['jovo <id>'];
static flags = {
clean: flags.boolean({
description:
'Deletes all platform folders and executes a clean build. If --platform is specified, it deletes only the respective platforms folder.',
description: 'Executes the command cleanly, making sure data is erased before execution.',
}),
deploy: flags.boolean({
char: 'd',
description: 'Runs deploy after build.',
exclusive: ['reverse'],
locale: flags.string({
char: 'l',
description: 'A locale the user might provide.',
multiple: true,
}),
// Insert global flags that are shared between commands
...PluginCommand.flags,
};

async run(): Promise<void> {}
static args = [
<const>{
name: 'platform',
description: 'Specifies a platform',
},
];

async run(): Promise<void> {
// ...
}
}
```

Since `PluginCommand` is an extension to oclif's `Command` class, you can learn more about it's structure [here](https://oclif.io/docs/commands).

### Command Decorators

You can use the `@ProjectCommand` decorator to check if the command is eligible to be run in the current working directory.
Expand All @@ -126,7 +136,7 @@ export class SomeCommand extends PluginCommand {
}
```

If the command is used outside a Jovo project, the CLI will display an error, letting the user know to go to a valid Jovo project directory.
If the command is used outside of a Jovo project, the CLI will display an error, letting the user know to go to a valid Jovo project directory.

## Configuration

Expand All @@ -148,7 +158,7 @@ It is also possible to add configurations like this, for example:

```js
new YourPlugin({
someConfig: true,
foo: 'bar',
}),
```

Expand All @@ -158,29 +168,24 @@ This is how a plugin that accepts config looks like:
import { JovoCliPlugin, PluginType, PluginConfig } from '@jovotech/cli-core';

export interface YourPluginConfig extends PluginConfig {
someConfig: boolean;
foo: string;
// ...
}

export class YourPlugin extends JovoCliPlugin {
export class YourPlugin extends JovoCliPlugin<YourPluginConfig> {
// ...

constructor(config: YourPluginConfig) {
super(config);
}

getDefaultConfig(): YourPluginConfig {
return {
someConfig: false,
foo: 'bar',
};
}
}
```

It includes the following elements:

- An type interface (in the example `YourPluginConfig`) where all config options are defined.
- A `constructor()` that passes the `config` to the `JovoCliPlugin` class.
- An interface definition (in the example `YourPluginConfig`) where all config options are defined.
- [A `getDefaultConfig()` method](#getdefaultconfig) that returns the default configuration options in case the config is not defined in the project configuration.
- [A `getInitConfig()` method](#getinitconfig) that returns the configuration options that should always be added to the `jovo.project.js` file.

Expand All @@ -194,16 +199,16 @@ The `getDefaultConfig()` method returns the default configuration of your plugin
import { JovoCliPlugin, PluginConfig } from '@jovotech/cli-core';

export interface YourPluginConfig extends PluginConfig {
someConfig: boolean;
foo: string;
// ...
}

export class YourPlugin extends JovoCliPlugin {
export class YourPlugin extends JovoCliPlugin<YourPluginConfig> {
// ...

getDefaultConfig(): YourPluginConfig {
return {
someConfig: false,
foo: 'bar',
};
}
}
Expand All @@ -221,7 +226,7 @@ export interface YourPluginConfig extends PluginConfig {
// ...
}

export class YourPlugin extends JovoCliPlugin {
export class YourPlugin extends JovoCliPlugin<YourPluginConfig> {
// ...

getInitConfig(): YourPluginConfig {
Expand All @@ -240,7 +245,7 @@ new YourPlugin({
}),
```

You can also make use of the `RequiredOnlyWhere` type to specify which keys of your type are required, while all other elements are optional.
You can also make use of the [`RequiredOnlyWhere`](https://www.jovo.tech/docs/types#requiredonlywhere) type to specify which keys of your type are required, while all other elements are optional.
This allows you to differentiate between keys that are required to be set by the user, and keys that are required, but can be set in `getDefaultConfig()`.

```typescript
Expand All @@ -255,15 +260,13 @@ export interface YourPluginConfig extends PluginConfig {

export type YourPluginInitConfig = RequiredOnlyWhere<YourPluginConfig, 'apiKey'>;

getInitConfig(): YourPluginInitConfig {
return {
apiKey: '<YOUR-API-KEY>',
};
}
```

You can also reference multiple keys like this:
export class YourPlugin extends JovoCliPlugin<YourPluginConfig> {
// ...

```typescript
export type YourPluginInitConfig = RequiredOnlyWhere<YourPluginConfig, 'apiKey' | 'someKey'>;
getInitConfig(): YourPluginInitConfig {
return {
apiKey: '<YOUR-API-KEY>',
};
}
}
```
10 changes: 5 additions & 5 deletions docs/project-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ const project = new ProjectConfig({
});
```

You can into any command, for example `before.build` or `after.build`:
You can hook into any command, for example `before.build:platform` or `after.build:platform`:

```js
const project = new ProjectConfig({
// ...
hooks: {
'before.build': [
'before.build:platform': [
() => {
/* Do something here */
},
Expand All @@ -236,7 +236,7 @@ A first example to test hooks might be to log something:
const project = new ProjectConfig({
// ...
hooks: {
'before.build': [
'before.build:platform': [
() => console.log('Starting the build process now');
]
},
Expand All @@ -254,7 +254,7 @@ const { fetchLanguageModel } = require('./hooks/fetchLanguageModel.hook.js');
const project = new ProjectConfig({
// ...
hooks: {
'before.build': [fetchLanguageModel],
'before.build:platform': [fetchLanguageModel],
},
});
```
Expand All @@ -265,7 +265,7 @@ You can also pass the `context` to a hook to access specific information:
const project = new ProjectConfig({
// ...
hooks: {
'before.build': [(context) => console.log(`Skill ID: ${context.alexa.skillId}`)],
'before.build:platform': [(context) => console.log(`Skill ID: ${context.alexa.skillId}`)],
},
});
```
Loading

0 comments on commit a9f8d99

Please sign in to comment.