Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes and reduce to one schema #20

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
build/
dist/
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
README.md
/README.md
/package.json
/package-lock.json
44 changes: 7 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Configuration types

Contains TypeScript declarations and generates JSONSchema files for the [CloudCannon](https://cloudcannon.com/) configuration file.
Contains TypeScript declarations and generates JSON Schema files for the [CloudCannon](https://cloudcannon.com/) configuration file.

[<img src="https://img.shields.io/npm/v/@cloudcannon%2Fconfiguration-types?logo=npm" alt="version badge">](https://www.npmjs.com/package/@cloudcannon%2Fconfiguration-types)

---

- [Installation](#installation)
- [Usage](#usage)
- [YAML and JSON](#yaml-and-json)
- [JavaScript](#javascript)
- [Development](#development)
- [License](#license)

Expand All @@ -23,19 +21,16 @@ npm i -D @cloudcannon/configuration-types

## Usage

The primary use of this package is to validate your configuration file. You can also use it to autocomplete and read inline documention while editing. Here are some suggested workflows below.

### YAML and JSON

We plan to add the configuration schema to [JSON Schema Store](https://www.schemastore.org/json/), which would automatically enable in-editor validation, autocomplete and tooltips with the YAML or JSON LSP enabled.

Alternatively, you can add a comment to the top of your file to use a specific schema for YAML files:

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/CloudCannon/configuration-types/main/build/cloudcannon-config.json
# yaml-language-server: $schema=https://raw.githubusercontent.com/CloudCannon/configuration-types/main/dist/cloudcannon-config.schema.json

collections_config:
posts:
path: content/posts
name: Blog
icon: event
```
Expand All @@ -44,10 +39,11 @@ Or the top-level `$schema` entry for JSON files:

```json
{
"$schema": "https://raw.githubusercontent.com/CloudCannon/configuration-types/main/build/cloudcannon-config.json",
"$schema": "https://raw.githubusercontent.com/CloudCannon/configuration-types/main/dist/cloudcannon-config.schema.json",

"collections_config": {
"posts": {
"path": "content/posts",
"name": "Blog",
"icon": "event"
}
Expand All @@ -59,33 +55,7 @@ You could also/alternatively validate the file on the command line with somethin

```sh
npm i @cloudcannon/configuration-types ajv-cli
npm run ajv validate -s node_modules/@cloudcannon/configuration-types/cloudcannon-config.json -d cloudcannon.config.yml
```

### JavaScript

For a CommonJS formatted configuration file (e.g. `/cloudcannon.config.cjs`), you can use a JSDoc comment to indicate the type of the module export:

```javascript
/** @type {import("@cloudcannon/configuration-types").Configuration} */
const config = {
collections_config: {
posts: {
name: 'Blog',
icon: 'event',
},
},
};

module.exports = config;
```

Then use the TypeScript LSP in your supported editor, ensuring it is set up to check JavaScript files. This would provide in-editor validation, autocomplete and tooltips as you modify the file.

You could also/alternatively run `tsc` over your file to validate there are no issues outside of your editor:

```sh
npx tsc test/cloudcannon.config.js --allowJs --checkJs --noEmit
npm run ajv validate -s node_modules/@cloudcannon/configuration-types/schema/cloudcannon-config.schema.json -d cloudcannon.config.yml
```

***
Expand All @@ -98,7 +68,7 @@ Install dependencies:
npm i
```

Build JSONSchema files:
Build:

```sh
npm run build
Expand Down
Loading
Loading