diff --git a/.gitignore b/.gitignore index c8becca..3568a5c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ coverage .nyc_output npm-debug.log .idea +grafana diff --git a/babel.config.js b/babel.config.js index cc26ec9..c54a625 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,6 @@ module.exports = { - presets: [['@babel/preset-env', { targets: { node: 'current' } }]], + presets: [ + ['@babel/preset-env', { targets: { node: 'current' } }], + ['@babel/preset-typescript', { allowDeclareFields: true }], + ], }; diff --git a/eslint.config.mjs b/eslint.config.mjs index 03df09a..6fd39f0 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -6,7 +6,7 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended' export default defineConfig([ { - ignores: ['coverage'], + ignores: ['coverage', 'grafana'], }, { files: ['**/*.{js,mjs,cjs,ts,mts,cts}'], diff --git a/index.js b/index.js index 92cfedb..242fbb3 100644 --- a/index.js +++ b/index.js @@ -20,30 +20,4 @@ 'use strict'; -var Dashboard = require('./grafana/dashboard'); -var Row = require('./grafana/row'); -var ExternalLink = require('./grafana/external-link'); -var Target = require('./grafana/target'); -var Panels = require('./grafana/panels'); -var Alert = require('./grafana/alert/alert'); -var Condition = require('./grafana/alert/condition'); -var Templates = require('./grafana/templates'); -var publish = require('./grafana/publish'); -var generateGraphId = require('./grafana/id'); -var config = require('./grafana/config'); -var Annotations = require('./grafana/annotations'); - -module.exports = { - Dashboard: Dashboard, - Row: Row, - ExternalLink: ExternalLink, - Panels: Panels, - Templates: Templates, - Alert, - Condition, - Annotations: Annotations, - Target: Target, - publish: publish, - generateGraphId: generateGraphId, - configure: config.configure, -}; +module.exports = require('./grafana/index'); diff --git a/package-lock.json b/package-lock.json index 35c965b..72d6f84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1901,6 +1901,16 @@ "@types/istanbul-lib-report": "*" } }, + "@types/jest": { + "version": "30.0.0", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-30.0.0.tgz", + "integrity": "sha512-XTYugzhuwqWjws0CVz8QpM36+T+Dz5mTEBKhNs/esGLnCIlGdRy+Dq78NRjd7ls7r8BC8ZRMOrKlkO1hU0JOwA==", + "dev": true, + "requires": { + "expect": "^30.0.0", + "pretty-format": "^30.0.0" + } + }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1916,12 +1926,34 @@ "undici-types": "~7.16.0" } }, + "@types/node-fetch": { + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.13.tgz", + "integrity": "sha512-QGpRVpzSaUs30JBSGPjOg4Uveu384erbHBoT1zeONvyCfwQxIkUshLAOqN/k9EjGviPRmWTTe6aH2qySWKTVSw==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^4.0.4" + } + }, "@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==", "dev": true }, + "@types/underscore": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.13.0.tgz", + "integrity": "sha512-L6LBgy1f0EFQZ+7uSA57+n2g/s4Qs5r06Vwrwn0/nuK1de+adz00NWaztRQ30aEqw5qOaWbPI8u2cGQ52lj6VA==", + "dev": true + }, + "@types/xtend": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/@types/xtend/-/xtend-4.0.6.tgz", + "integrity": "sha512-lOPBpPQ9AFXDY78rLRyLDZg/PgSCN/m1jCdjRC06RzUTRkaxMkirPx6RUQH2tV5im8gmJ8/7/i1BVLLy0vaBVg==", + "dev": true + }, "@types/yargs": { "version": "17.0.34", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.34.tgz", @@ -2292,6 +2324,12 @@ "sprintf-js": "~1.0.2" } }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "babel-jest": { "version": "30.2.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-30.2.0.tgz", @@ -2459,6 +2497,16 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, + "call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dev": true, + "requires": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2543,6 +2591,15 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2603,12 +2660,29 @@ "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", "integrity": "sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==", "dev": true }, + "dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dev": true, + "requires": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + } + }, "eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2647,6 +2721,39 @@ "is-arrayish": "^0.2.1" } }, + "es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "dev": true + }, + "es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true + }, + "es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "dev": true, + "requires": { + "es-errors": "^1.3.0" + } + }, + "es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "dev": true, + "requires": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + } + }, "escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -2976,6 +3083,19 @@ "signal-exit": "^4.0.1" } }, + "form-data": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz", + "integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -3007,12 +3127,40 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "dev": true, + "requires": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + } + }, "get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dev": true, + "requires": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + } + }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -3068,6 +3216,12 @@ "integrity": "sha512-ob/2LcVVaVGCYN+r14cnwnoDPUufjiYgSqRhiFD0Q1iI4Odora5RE8Iv1D24hAz5oMophRGkGz+yuvQmmUMnMw==", "dev": true }, + "gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "dev": true + }, "graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -3086,6 +3240,21 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, + "has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "dev": true + }, + "has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.3" + } + }, "hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -3846,6 +4015,12 @@ "tmpl": "1.0.5" } }, + "math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "dev": true + }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -3868,6 +4043,21 @@ "picomatch": "^2.3.1" } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -4535,8 +4725,7 @@ "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, - "peer": true + "dev": true }, "typescript-eslint": { "version": "8.46.2", diff --git a/package.json b/package.json index 1873f97..adef0ef 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,17 @@ "name": "grafana-dash-gen", "version": "4.0.2", "description": "A grafana dashboard generator", - "main": "index.js", + "main": "grafana/index.js", + "types": "grafana/index.d.ts", "scripts": { "fast-test": "jest", "test-cover": "jest --coverage", "view-cover": "rm -rf ./coverage && npm run test-cover && open ./coverage/index.html", "test": "npm run fast-test && npm run test-cover", - "lint": "eslint" + "lint": "eslint", + "build": "tsc -p tsconfig.build.json", + "typecheck": "tsc", + "prepublish": "npm run build" }, "repository": { "type": "git", @@ -32,6 +36,11 @@ "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", "@eslint/js": "^9.38.0", + "@types/jest": "^30.0.0", + "@types/node": "^24.9.1", + "@types/node-fetch": "^2.6.13", + "@types/underscore": "^1.13.0", + "@types/xtend": "^4.0.6", "babel-jest": "^30.2.0", "eslint": "^9.38.0", "eslint-config-prettier": "^10.1.8", @@ -40,6 +49,7 @@ "jest": "^30.2.0", "nock": "^13.5.6", "prettier": "3.6.2", + "typescript": "^5.9.3", "typescript-eslint": "^8.46.2" }, "files": [ @@ -49,6 +59,7 @@ "README.md", "example.js", "grafana", + "src", "index.js", "package.json" ], diff --git a/grafana/alert/alert.js b/src/alert/alert.js similarity index 100% rename from grafana/alert/alert.js rename to src/alert/alert.js diff --git a/grafana/alert/condition.js b/src/alert/condition.js similarity index 100% rename from grafana/alert/condition.js rename to src/alert/condition.js diff --git a/grafana/alert/index.js b/src/alert/index.js similarity index 100% rename from grafana/alert/index.js rename to src/alert/index.js diff --git a/grafana/annotations/graphite.js b/src/annotations/graphite.js similarity index 100% rename from grafana/annotations/graphite.js rename to src/annotations/graphite.js diff --git a/grafana/annotations/index.js b/src/annotations/index.js similarity index 100% rename from grafana/annotations/index.js rename to src/annotations/index.js diff --git a/grafana/config.js b/src/config.js similarity index 100% rename from grafana/config.js rename to src/config.js diff --git a/grafana/dashboard.js b/src/dashboard.js similarity index 100% rename from grafana/dashboard.js rename to src/dashboard.js diff --git a/grafana/errors.js b/src/errors.js similarity index 100% rename from grafana/errors.js rename to src/errors.js diff --git a/grafana/external-link.js b/src/external-link.js similarity index 100% rename from grafana/external-link.js rename to src/external-link.js diff --git a/grafana/id.js b/src/id.js similarity index 100% rename from grafana/id.js rename to src/id.js diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..a601eff --- /dev/null +++ b/src/index.js @@ -0,0 +1,49 @@ +// Copyright (c) 2015 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +'use strict'; + +var Dashboard = require('./dashboard'); +var Row = require('./row'); +var ExternalLink = require('./external-link'); +var Target = require('./target'); +var Panels = require('./panels'); +var Alert = require('./alert/alert'); +var Condition = require('./alert/condition'); +var Templates = require('./templates'); +var publish = require('./publish'); +var generateGraphId = require('./id'); +var config = require('./config'); +var Annotations = require('./annotations'); + +module.exports = { + Dashboard: Dashboard, + Row: Row, + ExternalLink: ExternalLink, + Panels: Panels, + Templates: Templates, + Alert, + Condition, + Annotations: Annotations, + Target: Target, + publish: publish, + generateGraphId: generateGraphId, + configure: config.configure, +}; diff --git a/grafana/panels/dashboard_list.js b/src/panels/dashboard_list.js similarity index 100% rename from grafana/panels/dashboard_list.js rename to src/panels/dashboard_list.js diff --git a/grafana/panels/graph.js b/src/panels/graph.js similarity index 100% rename from grafana/panels/graph.js rename to src/panels/graph.js diff --git a/grafana/panels/index.js b/src/panels/index.js similarity index 100% rename from grafana/panels/index.js rename to src/panels/index.js diff --git a/grafana/panels/singlestat.js b/src/panels/singlestat.js similarity index 100% rename from grafana/panels/singlestat.js rename to src/panels/singlestat.js diff --git a/grafana/panels/table.js b/src/panels/table.js similarity index 100% rename from grafana/panels/table.js rename to src/panels/table.js diff --git a/grafana/panels/text.js b/src/panels/text.js similarity index 100% rename from grafana/panels/text.js rename to src/panels/text.js diff --git a/grafana/publish.js b/src/publish.js similarity index 100% rename from grafana/publish.js rename to src/publish.js diff --git a/grafana/row.js b/src/row.js similarity index 100% rename from grafana/row.js rename to src/row.js diff --git a/grafana/target.js b/src/target.js similarity index 100% rename from grafana/target.js rename to src/target.js diff --git a/grafana/templates/custom.js b/src/templates/custom.js similarity index 100% rename from grafana/templates/custom.js rename to src/templates/custom.js diff --git a/grafana/templates/index.js b/src/templates/index.js similarity index 100% rename from grafana/templates/index.js rename to src/templates/index.js diff --git a/grafana/templates/query.js b/src/templates/query.js similarity index 100% rename from grafana/templates/query.js rename to src/templates/query.js diff --git a/test/alert/alert.test.js b/test/alert/alert.test.js index 6f6e311..0784543 100644 --- a/test/alert/alert.test.js +++ b/test/alert/alert.test.js @@ -1,5 +1,5 @@ -const Alert = require('../../grafana/alert/alert'); -const Condition = require('../../grafana/alert/condition'); +const Alert = require('../../src/alert/alert'); +const Condition = require('../../src/alert/condition'); const simpleAlert = require('../fixtures/alert/simple_alert'); const alertWithCondition = require('../fixtures/alert/alert_with_condition'); diff --git a/test/alert/condition.test.js b/test/alert/condition.test.js index 199fb28..b8bbfa6 100644 --- a/test/alert/condition.test.js +++ b/test/alert/condition.test.js @@ -1,4 +1,4 @@ -const Condition = require('../../grafana/alert/condition'); +const Condition = require('../../src/alert/condition'); test('condition .withEvaluator', () => { const condition = new Condition().withEvaluator(2, 'gt').generate(); diff --git a/test/annotations/graphite.test.js b/test/annotations/graphite.test.js index ae010e9..19412fd 100644 --- a/test/annotations/graphite.test.js +++ b/test/annotations/graphite.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Graphite = require('../../grafana/annotations/graphite'); +var Graphite = require('../../src/annotations/graphite'); var simpleGraphite = require('../fixtures/annotations/simple_graphite'); var overrideGraphite = require('../fixtures/annotations/override_graphite'); diff --git a/test/config.test.js b/test/config.test.js index da6141a..9124d98 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -20,7 +20,7 @@ 'use strict'; -var config = require('../grafana/config'); +var config = require('../src/config'); test('config extends default configuration', function () { var foo = 'foo'; diff --git a/test/dashboard.test.js b/test/dashboard.test.js index 5d32c97..61e7065 100644 --- a/test/dashboard.test.js +++ b/test/dashboard.test.js @@ -20,9 +20,9 @@ 'use strict'; -var Dashboard = require('../grafana/dashboard'); -var ExternalLink = require('../grafana/external-link'); -require('../grafana/panels'); // for coverage +var Dashboard = require('../src/dashboard'); +var ExternalLink = require('../src/external-link'); +require('../src/panels'); // for coverage var simpleDashboard = require('./fixtures/simple_dashboard'); var overrideDashboard = require('./fixtures/override_dashboard'); diff --git a/test/external-link.test.js b/test/external-link.test.js index 11ca8ec..a0e3e17 100644 --- a/test/external-link.test.js +++ b/test/external-link.test.js @@ -20,7 +20,7 @@ 'use strict'; -var ExternalLink = require('../grafana/external-link'); +var ExternalLink = require('../src/external-link'); var defaultExternalLink = require('./fixtures/external_link'); test('default external link', function () { diff --git a/test/fixtures/alert/alert.mock.js b/test/fixtures/alert/alert.mock.js index 53c536d..f0ba15d 100644 --- a/test/fixtures/alert/alert.mock.js +++ b/test/fixtures/alert/alert.mock.js @@ -1,5 +1,5 @@ -const Condition = require('../../../grafana/alert/condition'); -const Alert = require('../../../grafana/alert/alert'); +const Condition = require('../../../src/alert/condition'); +const Alert = require('../../../src/alert/alert'); const getAlert = () => { const condition = new Condition() diff --git a/test/panels/dashboard_list.test.js b/test/panels/dashboard_list.test.js index 216ff3f..ab517cb 100644 --- a/test/panels/dashboard_list.test.js +++ b/test/panels/dashboard_list.test.js @@ -20,7 +20,7 @@ 'use strict'; -var DashboardList = require('../../grafana/panels/dashboard_list'); +var DashboardList = require('../../src/panels/dashboard_list'); var dashboardList = require('../fixtures/panels/simple_dashboard_list.js'); var overrideDashboardList = require('../fixtures/panels/override_dashboard_list.js'); diff --git a/test/panels/graph.test.js b/test/panels/graph.test.js index 2e468a7..76bf311 100644 --- a/test/panels/graph.test.js +++ b/test/panels/graph.test.js @@ -20,7 +20,7 @@ 'use strict'; -const Graph = require('../../grafana/panels/graph'); +const Graph = require('../../src/panels/graph'); const getAlert = require('../fixtures/alert/alert.mock').getAlert; const simpleGraph = require('../fixtures/panels/simple_graph.js'); diff --git a/test/panels/singlestat.test.js b/test/panels/singlestat.test.js index 1a30531..ecbee5e 100644 --- a/test/panels/singlestat.test.js +++ b/test/panels/singlestat.test.js @@ -20,7 +20,7 @@ 'use strict'; -var SingleStat = require('../../grafana/panels/singlestat'); +var SingleStat = require('../../src/panels/singlestat'); var simpleSingleStat = require('../fixtures/panels/simple_singlestat.js'); var overrideSingleStat = require('../fixtures/panels/override_singlestat.js'); diff --git a/test/panels/table.test.js b/test/panels/table.test.js index 4cb859e..bc63037 100644 --- a/test/panels/table.test.js +++ b/test/panels/table.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Table = require('../../grafana/panels/table'); +var Table = require('../../src/panels/table'); var simpleTable = require('../fixtures/panels/simple_table.js'); var overrideTable = require('../fixtures/panels/override_table.js'); diff --git a/test/panels/text.test.js b/test/panels/text.test.js index ed4f607..6ab95f7 100644 --- a/test/panels/text.test.js +++ b/test/panels/text.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Text = require('../../grafana/panels/text'); +var Text = require('../../src/panels/text'); var simpleText = require('../fixtures/panels/simple_text.js'); var overrideText = require('../fixtures/panels/override_text.js'); diff --git a/test/publish.test.js b/test/publish.test.js index f42bdb1..055f6e8 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -20,10 +20,10 @@ 'use strict'; const nock = require('nock'); -const config = require('../grafana/config'); -const publish = require('../grafana/publish'); -const Dashboard = require('../grafana/dashboard'); -const ExternalLink = require('../grafana/external-link'); +const config = require('../src/config'); +const publish = require('../src/publish'); +const Dashboard = require('../src/dashboard'); +const ExternalLink = require('../src/external-link'); // configuration values, held constant for assertions const baseUrl = 'http://awesome.com'; diff --git a/test/row.test.js b/test/row.test.js index aeb603f..356d207 100644 --- a/test/row.test.js +++ b/test/row.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Row = require('../grafana/row'); +var Row = require('../src/row'); var simpleRow = require('./fixtures/simple_row.js'); var overrideRow = require('./fixtures/override_row.js'); diff --git a/test/target.test.js b/test/target.test.js index 42ef810..9745243 100644 --- a/test/target.test.js +++ b/test/target.test.js @@ -21,7 +21,7 @@ 'use strict'; var util = require('util'); -var Target = require('../grafana/target'); +var Target = require('../src/target'); test('Target throws exception on invalid invocation', function () { expect(function shouldThrow() { diff --git a/test/templates/custom.test.js b/test/templates/custom.test.js index a500505..b5f925c 100644 --- a/test/templates/custom.test.js +++ b/test/templates/custom.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Custom = require('../../grafana/templates/custom'); +var Custom = require('../../src/templates/custom'); var simpleCustom = require('../fixtures/templates/simple_custom'); var overrideCustom = require('../fixtures/templates/override_custom'); diff --git a/test/templates/query.test.js b/test/templates/query.test.js index b23434a..c990ba3 100644 --- a/test/templates/query.test.js +++ b/test/templates/query.test.js @@ -20,7 +20,7 @@ 'use strict'; -var Query = require('../../grafana/templates/query'); +var Query = require('../../src/templates/query'); var simpleQuery = require('../fixtures/templates/simple_query'); var overrideQuery = require('../fixtures/templates/override_query'); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..df51c4c --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + // Visit https://aka.ms/tsconfig to read more about this file + "compilerOptions": { + "rootDir": "./src", + "outDir": "./grafana", + "noEmit": false, + }, + "include": ["./src"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b387160 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,43 @@ +{ + // Visit https://aka.ms/tsconfig to read more about this file + "compilerOptions": { + "allowJs": true, + "checkJs": false, + // File Layout + "rootDir": "./", + "noEmit": true, + // Environment Settings + // See also https://aka.ms/tsconfig/module + "module": "CommonJS", + "target": "es5", + "lib": ["esnext"], + "types": ["node", "jest"], + + // Other Outputs + "sourceMap": true, + "declaration": false, + "declarationMap": false, + + // Stricter Typechecking Options + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + + // Style Options + // "noImplicitReturns": true, + // "noImplicitOverride": true, + // "noUnusedLocals": true, + // "noUnusedParameters": true, + // "noFallthroughCasesInSwitch": true, + // "noPropertyAccessFromIndexSignature": true, + + // Recommended Options + "strict": true, + "verbatimModuleSyntax": false, + "isolatedModules": true, + "noUncheckedSideEffectImports": true, + "moduleDetection": "force", + "skipLibCheck": true, + "esModuleInterop": true + }, + "exclude": ["coverage", "grafana"] +}