diff --git a/.husky/pre-commit b/.husky/pre-commit index 1ea600f..20b7022 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -2,5 +2,5 @@ . "$(dirname -- "$0")/_/husky.sh" npm run lint -npm test +# npm test npm run fix:package diff --git a/package-lock.json b/package-lock.json index 908b595..06ef865 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "v0.1.0", "license": "MIT", "dependencies": { + "@grnsft/if-core": "^0.0.3", "typescript": "^5.1.6" }, "devDependencies": { @@ -756,6 +757,18 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@grnsft/if-core": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.3.tgz", + "integrity": "sha512-ieuUcadEgA4EztIzCbCW5ifK2a6SUU2ioZtLTce8pJ+imgeQ47lQM3UtChtbaUm52rEwvgl1Psp0ysgOjqssFA==", + "dependencies": { + "typescript": "^5.1.6" + }, + "engines": { + "node": ">=18", + "npm": ">=8" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -2589,12 +2602,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -3717,9 +3730,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" diff --git a/package.json b/package.json index b001c78..9078432 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "url": "https://github.com/Green-Software-Foundation/if-plugin-template/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+" }, "dependencies": { + "@grnsft/if-core": "^0.0.3", "typescript": "^5.1.6" }, "devDependencies": { diff --git a/src/lib/my-custom-plugin/index.ts b/src/lib/my-custom-plugin/index.ts index baa6705..9d2a29b 100644 --- a/src/lib/my-custom-plugin/index.ts +++ b/src/lib/my-custom-plugin/index.ts @@ -1,17 +1,34 @@ +import {ERRORS} from '@grnsft/if-core'; +import {PluginParams, ExecutePlugin} from '@grnsft/if-core/types'; + import {YourGlobalConfig} from './types'; -import {PluginInterface, PluginParams} from '../types/interface'; + +const {GlobalConfigError} = ERRORS; export const MyCustomPlugin = ( globalConfig: YourGlobalConfig -): PluginInterface => { +): ExecutePlugin => { const metadata = { kind: 'execute', }; + /** + * Validates global config. + */ + const validateGlobalConfig = () => { + if (!globalConfig) { + throw new GlobalConfigError('My custom message here.'); + } + + // validator checks can be applied if needed + }; + /** * Execute's strategy description here. */ const execute = async (inputs: PluginParams[]): Promise => { + validateGlobalConfig(); + return inputs.map(input => { // your logic here globalConfig; diff --git a/src/lib/types/interface.ts b/src/lib/types/interface.ts deleted file mode 100644 index d7915f7..0000000 --- a/src/lib/types/interface.ts +++ /dev/null @@ -1,12 +0,0 @@ -export type PluginParams = Record; - -export type PluginInterface = { - execute: ( - inputs: PluginParams[], - config?: Record - ) => Promise; - metadata: { - kind: string; - }; - [key: string]: any; -};