Skip to content

Commit 6970f14

Browse files
authored
Merge pull request #14 from xymopen/master
Add JSON Schema
2 parents 6cb8004 + a5e2e8e commit 6970f14

24 files changed

+197
-28
lines changed

CONTRIBUTING.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@ Let's get started
1616
2. Create a JSON file for your repository metadata. End its filename with `.meta.json`, for example, `foo.meta.json`
1717
3. If you decide to host your repository on this GitHub repo
1818
1. Metadata JSON file should follow [this interface](https://github.com/cloud-emoticon/store-repos/blob/master/linter/src/api/RepositoryMetadata.ts). Don't worry about TypeScript, the interface alone should be easy to follow. If you are still not sure, look at [this example](https://github.com/cloud-emoticon/store-repos/blob/master/kt-favorites.meta.json)
19+
1. Bonus: If your editor supports JSON schema, add the following line to aid you:
20+
21+
```
22+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23+
```
24+
1925
2. Create a JSON file for your actual repository in JSON format (sorry no XML). Name the file to have the same name as the repository metadata JSON file, e.g. if your metadata JSON file is named `foo.meta.json`, this file should be named `foo.json`
20-
3. Repository JSON file should follow [this interface](https://github.com/cloud-emoticon/store-repos/blob/master/linter/src/api/JsonRepository.ts). Again, no worries on TypeScript. Here is [an example](https://github.com/cloud-emoticon/store-repos/blob/master/kt-favorites.json).
26+
3. Repository JSON file should follow [this interface](https://github.com/cloud-emoticon/store-repos/blob/master/linter/src/api/JsonRepository.ts). Again, no worries on TypeScript. Here is [an example](https://github.com/cloud-emoticon/store-repos/blob/master/kt-favorites.json).should be easy to follow. If you are still not sure, look at [this example](https://github.com/cloud-emoticon/store-repos/blob/master/kt-favorites.json)
27+
1. Bonus: If your editor supports JSON schema, add the following line to aid you:
28+
29+
```
30+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/JsonRepository.json",
31+
```
32+
2133
4. If you decide to host your repository on your own server
2234
1. Metadata JSON file should still follow [this interface](https://github.com/cloud-emoticon/store-repos/blob/master/linter/src/api/RepositoryMetadata.ts). Don't worry about TypeScript, the interface alone should be easy to follow. If you are still not sure, look at [this example](https://github.com/cloud-emoticon/store-repos/blob/master/remote-demo.meta.json)
35+
1. Bonus: If your editor supports JSON schema, add the following line to aid you:
36+
37+
```
38+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
39+
```
40+
2341
5. You can optinoally add an avatar for author of your repo to the branch. See exmaple in `a-land.meta.json`.
2442
6. Push the branch, create a merge request to this repo's master. There is a CI bot to check the integrity of the JSON files. Please assign the reviewer to `KTachibanaM`(me).
2543
7. Wait for review, merge, wait for about 5 minutes for your repository to appear in the store, and profit :P

a-land.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "A岛颜文字汇集",
34
"location": {
45
"type": "localXml"

japaneseemoticons.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "japaneseemoticons.net",
34
"location": {
45
"type": "localXml"

kaomojiya.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "颜文字屋",
34
"location": {
45
"type": "localXml"

kt-cia.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/JsonRepository.json",
23
"information":[
34
"Thanks to CIA",
45
"http://ktachibana.party/cloudemoticon/cia.json",

kt-cia.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "CIA",
34
"location": {
45
"type": "localJson"

kt-favorites.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/JsonRepository.json",
23
"categories": [
34
{
45
"name": "G+都亡了",

kt-favorites.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "KT's favorites",
34
"location": {
45
"type": "localJson"

linter/README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Linter for store repos
1212
yarn
1313
```
1414

15-
## Build
15+
## Build (Optional)
1616

1717
```bash
1818
yarn built-ts
@@ -22,4 +22,12 @@ yarn built-ts
2222

2323
```bash
2424
yarn run-linter
25-
```
25+
```
26+
27+
## Generate schemas
28+
29+
If you make any changes to [src/api/](src/api/), run this script to generate new JSON schemas for emoticon authors.
30+
31+
```bash
32+
yarn gen-schema
33+
```

linter/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"private": false,
88
"scripts": {
99
"build-ts": "tsc",
10-
"run-linter": "node dist/index.js"
10+
"prerun-linter": "yarn run build-ts",
11+
"run-linter": "node dist/index.js",
12+
"pregen-schema": "yarn run build-ts",
13+
"gen-schema": "node dist/bin/genSchema.js"
1114
},
1215
"devDependencies": {
1316
"tslint": "^5.18.0",

linter/src/api/JsonRepositorySchema.ts

-10
This file was deleted.

linter/src/api/RepositoryMetadata.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
export interface RepositoryMetadata {
33
name: string,
44
location: {
5-
type: "localJson" | "localXml" | "remoteJson",
6-
remoteUrl?: string
5+
type: "localJson" | "localXml"
6+
} | {
7+
type: "remoteJson",
8+
remoteUrl: string
79
},
810
description: string,
911
author: {

linter/src/api/RepositoryMetadataSchema.ts

-10
This file was deleted.

linter/src/bin/genSchema.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as fs from 'fs'
2+
import toJsonSchema from "../lib/toJsonSchema"
3+
4+
const JsonRepositorySchema = toJsonSchema("./src/api/JsonRepository.ts", "JsonRepository")
5+
const RepositoryMetadataSchema = toJsonSchema("./src/api/RepositoryMetadata.ts", "RepositoryMetadata")
6+
7+
fs.mkdirSync("../schema", { recursive: true })
8+
fs.writeFileSync("../schema/JsonRepository.json", JSON.stringify(JsonRepositorySchema, null, ' '))
9+
fs.writeFileSync("../schema/RepositoryMetadata.json", JSON.stringify(RepositoryMetadataSchema, null, ' '))

linter/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as fs from 'fs'
22
import * as process from "process"
33
import Ajv from "ajv"
4-
import JsonRepositorySchema from "./api/JsonRepositorySchema"
5-
import RepositoryMetadataSchema from "./api/RepositoryMetadataSchema"
4+
import toJsonSchema from "./lib/toJsonSchema"
5+
6+
const JsonRepositorySchema = toJsonSchema("./src/api/JsonRepository.ts", "JsonRepository")
7+
const RepositoryMetadataSchema = toJsonSchema("./src/api/RepositoryMetadata.ts", "RepositoryMetadata")
68

79
const ajv = new Ajv()
810
const validateJsonRepository = ajv.compile(JsonRepositorySchema)
File renamed without changes.

linter/src/lib/toJsonSchema.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { resolve } from "path";
2+
import * as TJS from "typescript-json-schema";
3+
import { compilerOptions, settings } from "./tjsSettings"
4+
5+
const toJsonSchema = (pathname: string, fullTypeName: string) => {
6+
const program = TJS.getProgramFromFiles(
7+
[resolve(pathname)],
8+
compilerOptions
9+
);
10+
11+
return TJS.generateSchema(program, fullTypeName, settings);
12+
};
13+
14+
export default toJsonSchema;

midori.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "Midori",
34
"location": {
45
"type": "localXml"

oliver-wang.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "Oliver Wang",
34
"location": {
45
"type": "localXml"

remote-demo.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "Remote repo demo",
34
"location": {
45
"type": "remoteJson",

schema/DO_NOT_EDIT.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Files in this folder are generated by `yarn run gen-schema`; DO NOT EDIT.

schema/JsonRepository.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"information": {
5+
"type": "array",
6+
"items": {
7+
"type": "string"
8+
}
9+
},
10+
"categories": {
11+
"type": "array",
12+
"items": {
13+
"type": "object",
14+
"properties": {
15+
"name": {
16+
"type": "string"
17+
},
18+
"entries": {
19+
"type": "array",
20+
"items": {
21+
"type": "object",
22+
"properties": {
23+
"emoticon": {
24+
"type": "string"
25+
},
26+
"description": {
27+
"type": "string"
28+
}
29+
},
30+
"required": [
31+
"description",
32+
"emoticon"
33+
]
34+
}
35+
}
36+
},
37+
"required": [
38+
"entries",
39+
"name"
40+
]
41+
}
42+
}
43+
},
44+
"required": [
45+
"categories",
46+
"information"
47+
],
48+
"$schema": "http://json-schema.org/draft-07/schema#"
49+
}

schema/RepositoryMetadata.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string"
6+
},
7+
"location": {
8+
"anyOf": [
9+
{
10+
"type": "object",
11+
"properties": {
12+
"type": {
13+
"enum": [
14+
"localJson",
15+
"localXml"
16+
],
17+
"type": "string"
18+
}
19+
},
20+
"required": [
21+
"type"
22+
]
23+
},
24+
{
25+
"type": "object",
26+
"properties": {
27+
"type": {
28+
"type": "string",
29+
"enum": [
30+
"remoteJson"
31+
]
32+
},
33+
"remoteUrl": {
34+
"type": "string"
35+
}
36+
},
37+
"required": [
38+
"remoteUrl",
39+
"type"
40+
]
41+
}
42+
]
43+
},
44+
"description": {
45+
"type": "string"
46+
},
47+
"author": {
48+
"type": "object",
49+
"properties": {
50+
"name": {
51+
"type": "string"
52+
},
53+
"url": {
54+
"type": "string"
55+
},
56+
"avatarUrl": {
57+
"type": "string"
58+
}
59+
},
60+
"required": [
61+
"name"
62+
]
63+
}
64+
},
65+
"required": [
66+
"author",
67+
"description",
68+
"location",
69+
"name"
70+
],
71+
"$schema": "http://json-schema.org/draft-07/schema#"
72+
}

yashi-poi.meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://github.com/cloud-emoticon/store-repos/raw/master/schema/RepositoryMetadata.json",
23
"name": "Yashi-poi",
34
"location": {
45
"type": "localXml"

0 commit comments

Comments
 (0)