From a93ff882cd801d85be83d1650f14f15895d86c2f Mon Sep 17 00:00:00 2001 From: Carter Snook Date: Tue, 1 Jun 2021 00:32:43 -0500 Subject: [PATCH 1/4] feat: add json spec --- index.json | 1 + index.spec.json | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 index.spec.json diff --git a/index.json b/index.json index 8bc4c79..ffa95e8 100644 --- a/index.json +++ b/index.json @@ -1,4 +1,5 @@ { + "$schema": "./index.spec.json", "types": { "feat": { "description": "A new feature", diff --git a/index.spec.json b/index.spec.json new file mode 100644 index 0000000..7079138 --- /dev/null +++ b/index.spec.json @@ -0,0 +1,27 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Conventional Commit Types Data Schema", + "additionalProperties": true, + "definitions": { + "commitType": { + "type": "object", + "additionalProperties": false, + "properties": { + "description": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": ["description", "title"] + } + }, + "properties": { + "types": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/commitType" } + } + }, + "required": ["types"] +} From 5174c76d3b34bc28fd765d4a14b483aa528ff302 Mon Sep 17 00:00:00 2001 From: Carter Snook Date: Tue, 1 Jun 2021 00:33:03 -0500 Subject: [PATCH 2/4] test(spec): add tests for json spec --- index.spec.mjs | 12 ++++++++++++ package-lock.json | 32 ++++++++++++++++++++++++++++++++ package.json | 4 ++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 index.spec.mjs create mode 100644 package-lock.json diff --git a/index.spec.mjs b/index.spec.mjs new file mode 100644 index 0000000..f184a13 --- /dev/null +++ b/index.spec.mjs @@ -0,0 +1,12 @@ +import { readFile } from "fs/promises"; +import { validate } from "jsonschema"; + +(async () => { + const dataStrs = await Promise.all( + ["./index.json", "./index.spec.json"].map((file) => readFile(file, "utf-8")) + ); + const [data, schema] = dataStrs.map(JSON.parse); + validate(data, schema, { + throwAll: true, + }); +})(); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9c4cd86 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,32 @@ +{ + "name": "conventional-commit-types", + "version": "3.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "version": "3.0.0", + "license": "ISC", + "devDependencies": { + "jsonschema": "^1.4.0" + } + }, + "node_modules/jsonschema": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.4.0.tgz", + "integrity": "sha512-/YgW6pRMr6M7C+4o8kS+B/2myEpHCrxO4PEWnqJNBFMjn7EWXqlQ4tGwL6xTHeRplwuZmcAncdvfOad1nT2yMw==", + "dev": true, + "engines": { + "node": "*" + } + } + }, + "dependencies": { + "jsonschema": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.4.0.tgz", + "integrity": "sha512-/YgW6pRMr6M7C+4o8kS+B/2myEpHCrxO4PEWnqJNBFMjn7EWXqlQ4tGwL6xTHeRplwuZmcAncdvfOad1nT2yMw==", + "dev": true + } + } +} diff --git a/package.json b/package.json index 985dc7e..532e8aa 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "List of conventional commit types.", "main": "index.json", "scripts": { - "test": "json -f index.json" + "test": "node index.spec.mjs" }, "keywords": [], "author": "Anders D. Johnson", @@ -14,6 +14,6 @@ "url": "https://github.com/commitizen/conventional-commit-types.git" }, "devDependencies": { - "json": "^9.0.4" + "jsonschema": "^1.4.0" } } From 62c2def7d06de14b6012ccfa082ba144e49bc890 Mon Sep 17 00:00:00 2001 From: Carter Snook Date: Tue, 1 Jun 2021 00:38:51 -0500 Subject: [PATCH 3/4] fix(node): downgrade to common js --- index.spec.js | 7 +++++++ index.spec.mjs | 12 ------------ package.json | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 index.spec.js delete mode 100644 index.spec.mjs diff --git a/index.spec.js b/index.spec.js new file mode 100644 index 0000000..6da196c --- /dev/null +++ b/index.spec.js @@ -0,0 +1,7 @@ +const { validate } = require("jsonschema"); + +const [data, schema] = [require("./index.json"), require("./index.spec.json")]; + +validate(data, schema, { + throwAll: true, +}); diff --git a/index.spec.mjs b/index.spec.mjs deleted file mode 100644 index f184a13..0000000 --- a/index.spec.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import { readFile } from "fs/promises"; -import { validate } from "jsonschema"; - -(async () => { - const dataStrs = await Promise.all( - ["./index.json", "./index.spec.json"].map((file) => readFile(file, "utf-8")) - ); - const [data, schema] = dataStrs.map(JSON.parse); - validate(data, schema, { - throwAll: true, - }); -})(); diff --git a/package.json b/package.json index 532e8aa..bea43f9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "List of conventional commit types.", "main": "index.json", "scripts": { - "test": "node index.spec.mjs" + "test": "node index.spec" }, "keywords": [], "author": "Anders D. Johnson", From 3ab0d8e1eade2d90c5ebf2a66b947995751e854a Mon Sep 17 00:00:00 2001 From: Carter Snook Date: Tue, 1 Jun 2021 00:43:57 -0500 Subject: [PATCH 4/4] fix: downgrade code to es5 --- index.spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.spec.js b/index.spec.js index 6da196c..4b4eaa5 100644 --- a/index.spec.js +++ b/index.spec.js @@ -1,7 +1,9 @@ -const { validate } = require("jsonschema"); +var jsonschema = require("jsonschema"); +var fs = require("fs"); -const [data, schema] = [require("./index.json"), require("./index.spec.json")]; +var data = fs.readFileSync("./index.json"); +var schema = fs.readFileSync("./index.spec.json"); -validate(data, schema, { +jsonschema.validate(JSON.parse(data), JSON.parse(schema), { throwAll: true, });