diff --git a/.gitignore b/.gitignore index 38e480b..4ba4c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.log index.html -lib +build node_modules .parcel-cache \ No newline at end of file diff --git a/.mjmlconfig b/.mjmlconfig deleted file mode 100644 index e5e61c6..0000000 --- a/.mjmlconfig +++ /dev/null @@ -1,5 +0,0 @@ -{ - "packages": [ - "./lib/index.js" - ] -} diff --git a/package-lock.json b/package-lock.json index 28c0487..33a3937 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,12 +11,14 @@ "license": "MIT", "dependencies": { "mjml": "^4.14.1", - "mjml-core": "^4.14.1" + "mjml-core": "^4.14.1", + "mjml-validator": "^4.13.0" }, "devDependencies": { "@types/jest": "^29.5.10", "@types/mjml": "^4.7.4", "@types/mjml-core": "^4.7.4", + "@types/mjml-validator": "^4.13.4", "jest": "^29.7.0", "npm-check": "^6.0.1", "prettier": "^3.1.0", @@ -1395,6 +1397,15 @@ "integrity": "sha512-hajbYITLm/wJU99Of50Dmn/k4ok+mrhJs4qDdnveJsINdiNJhQd+03C6Kt09vF9biB23cEI4pPeLrJNYfIZf7g==", "dev": true }, + "node_modules/@types/mjml-validator": { + "version": "4.13.4", + "resolved": "https://registry.npmjs.org/@types/mjml-validator/-/mjml-validator-4.13.4.tgz", + "integrity": "sha512-FhZw4DXcrm4j8dUbMzFGjVd6NKAD8a1B2GFT1DoqquTgdXhLTVrWBWaatEiRT/xHCGtBc7k3aX+O+oXMnhq/6g==", + "dev": true, + "dependencies": { + "@types/mjml-core": "*" + } + }, "node_modules/@types/node": { "version": "20.4.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.1.tgz", @@ -9458,6 +9469,15 @@ "integrity": "sha512-hajbYITLm/wJU99Of50Dmn/k4ok+mrhJs4qDdnveJsINdiNJhQd+03C6Kt09vF9biB23cEI4pPeLrJNYfIZf7g==", "dev": true }, + "@types/mjml-validator": { + "version": "4.13.4", + "resolved": "https://registry.npmjs.org/@types/mjml-validator/-/mjml-validator-4.13.4.tgz", + "integrity": "sha512-FhZw4DXcrm4j8dUbMzFGjVd6NKAD8a1B2GFT1DoqquTgdXhLTVrWBWaatEiRT/xHCGtBc7k3aX+O+oXMnhq/6g==", + "dev": true, + "requires": { + "@types/mjml-core": "*" + } + }, "@types/node": { "version": "20.4.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.1.tgz", diff --git a/package.json b/package.json index faf85f6..ae66aa5 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "version": "1.1.1", "description": "A simple MJML component to make static bar charts", "source": "src/index.ts", - "main": "lib/index.js", "scripts": { "watch": "tsc --watch", + "prebuild": "rm -rf build", "build": "tsc", "postinstall": "npm run build", "test": "jest", @@ -29,6 +29,7 @@ "@types/jest": "^29.5.10", "@types/mjml": "^4.7.4", "@types/mjml-core": "^4.7.4", + "@types/mjml-validator": "^4.13.4", "jest": "^29.7.0", "npm-check": "^6.0.1", "prettier": "^3.1.0", @@ -37,9 +38,25 @@ }, "dependencies": { "mjml": "^4.14.1", - "mjml-core": "^4.14.1" + "mjml-core": "^4.14.1", + "mjml-validator": "^4.13.0" }, "jest": { - "testEnvironment": "node" + "detectOpenHandles": true, + "verbose": true, + "coverageDirectory": "/coverage", + "coverageReporters": [ + "text-summary", + "cobertura" + ], + "preset": "ts-jest", + "testEnvironment": "node", + "moduleFileExtensions": [ + "ts", + "js" + ], + "testMatch": [ + "**/*.spec.ts" + ] } } diff --git a/src/index.spec.ts b/src/index.spec.ts index 175cf66..2564ab7 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,6 +1,6 @@ import mjml2html from "mjml"; import { registerComponent } from "mjml-core"; -import MjmlBarChart from "./index"; +import MjBarChart from "./index"; function toHtml(mjml: string): string { const { html, errors } = mjml2html(mjml); @@ -9,7 +9,7 @@ function toHtml(mjml: string): string { describe("mjml-bar-chart", () => { beforeAll(() => { - registerComponent(MjmlBarChart); + registerComponent(MjBarChart); }); it("should render the bar chart", () => { diff --git a/src/index.ts b/src/index.ts index f96c12a..bf256c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { BodyComponent } from "mjml-core"; +import { registerDependencies } from "mjml-validator"; type dataset = { label: string; @@ -54,6 +55,8 @@ export default class MjBarChart extends BodyComponent { this.#barWidth * this.#datasets.length * this.#groups.length; } + static componentName = "mj-bar-chart"; + static endingTag = true; static dependencies = { @@ -342,3 +345,5 @@ export default class MjBarChart extends BodyComponent { `; } } + +registerDependencies(MjBarChart.dependencies); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 4c5093d..188a869 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,15 @@ { "$schema": "https://json.schemastore.org/tsconfig", "display": "Node 20", - "files": ["src/index.ts"], "compilerOptions": { - "lib": ["es2022"], - "module": "ESNext", - "target": "es2022", - "sourceMap": true, - "outDir": "./lib", - "strict": true, + "types": ["node", "jest", "mjml"], + "outDir": "build", + "target": "ES2022", + "moduleResolution": "node", + "inlineSourceMap": true, + "alwaysStrict": true, "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "allowUnreachableCode": false, - "allowUnusedLabels": false, - "noUnusedLocals": true, - "noUnusedParameters": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "useUnknownInCatchVariables": true - } + "skipLibCheck": true + }, + "include": ["src/index.ts"] }