@cloudcannon/configuration-types 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,96 @@
1
1
  # Configuration types
2
2
 
3
- Contains types and generates JSON Schemas for the [CloudCannon](https://cloudcannon.com/) configuration file.
3
+ Contains TypeScript declarations and generates JSONSchema files for the [CloudCannon](https://cloudcannon.com/) configuration file.
4
4
 
5
5
  [<img src="https://img.shields.io/npm/v/@cloudcannon%2Fconfiguration-types?logo=npm" alt="version badge">](https://www.npmjs.com/package/@cloudcannon%2Fconfiguration-types)
6
6
 
7
- ## Run
7
+ ---
8
+
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [YAML and JSON](#yaml-and-json)
12
+ - [JavaScript](#javascript)
13
+ - [Development](#development)
14
+ - [License](#license)
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```sh
21
+ npm i -D @cloudcannon/configuration-types
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ 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.
27
+
28
+ ### YAML and JSON
29
+
30
+ 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.
31
+
32
+ Alternatively, you can add a comment to the top of your file to use a specific schema for YAML files:
33
+
34
+ ```yaml
35
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/CloudCannon/configuration-types/main/build/cloudcannon-config.json
36
+
37
+ collections_config:
38
+ posts:
39
+ name: Blog
40
+ icon: event
41
+ ```
42
+
43
+ Or the top-level `$schema` entry for JSON files:
44
+
45
+ ```json
46
+ {
47
+ "$schema": "https://raw.githubusercontent.com/CloudCannon/configuration-types/main/build/cloudcannon-config.json",
48
+
49
+ "collections_config": {
50
+ "posts": {
51
+ "name": "Blog",
52
+ "icon": "event"
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ You could also/alternatively validate the file on the command line with something like [ajv-cli](https://github.com/ajv-validator/ajv-cli):
59
+
60
+ ```sh
61
+ npm i @cloudcannon/configuration-types ajv-cli
62
+ npm run ajv validate -s node_modules/@cloudcannon/configuration-types/cloudcannon-config.json -d cloudcannon.config.yml
63
+ ```
64
+
65
+ ### JavaScript
66
+
67
+ 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:
68
+
69
+ ```javascript
70
+ /** @type {import("@cloudcannon/configuration-types").DefaultConfiguration} */
71
+ const config = {
72
+ collections_config: {
73
+ posts: {
74
+ name: 'Blog',
75
+ icon: 'event',
76
+ },
77
+ },
78
+ };
79
+
80
+ module.exports = config;
81
+ ```
82
+
83
+ 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.
84
+
85
+ You could also/alternatively run `tsc` over your file to validate there are no issues outside of your editor:
86
+
87
+ ```sh
88
+ npx tsc test/cloudcannon.config.js --allowJs --checkJs --noEmit
89
+ ```
90
+
91
+ ***
92
+
93
+ ## Development
8
94
 
9
95
  Install dependencies:
10
96
 
@@ -12,16 +98,12 @@ Install dependencies:
12
98
  npm i
13
99
  ```
14
100
 
15
- Build JSON schema files:
101
+ Build JSONSchema files:
16
102
 
17
103
  ```sh
18
104
  npm run build
19
105
  ```
20
106
 
21
- ## Test
22
-
23
- Not yet set up.
24
-
25
107
  ## License
26
108
 
27
109
  MIT