@qiwi/semrel-plugin-creator
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -0,1 +1,8 @@ | ||
# @qiwi/semrel-plugin-creator [1.3.0](https://github.com/qiwi/semantic-release-toolkit/compare/@qiwi/semrel-plugin-creator@1.2.0...@qiwi/semrel-plugin-creator@1.3.0) (2021-01-06) | ||
### Features | ||
* **plugin-creator:** make `metaContext` unique for each semrel exec context ([16f3121](https://github.com/qiwi/semantic-release-toolkit/commit/16f3121abd4c646a5e3a66260377ed8ff91ff58d)) | ||
# @qiwi/semrel-plugin-creator [1.2.0](https://github.com/qiwi/semantic-release-toolkit/compare/@qiwi/semrel-plugin-creator@1.1.1...@qiwi/semrel-plugin-creator@1.2.0) (2021-01-05) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@qiwi/semrel-plugin-creator", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -29,1 +29,28 @@ # @qiwi/semrel-plugin-creator | ||
``` | ||
## API | ||
```typescript | ||
export type TPluginHandlerContext = { | ||
pluginConfig: TPluginConfig | ||
stepConfig: TPluginConfig | ||
stepConfigs: TStepConfigs | ||
context: TSemrelContext | ||
step: TReleaseStep | ||
} | ||
export type TPluginFactoryOptionsNormalized = { | ||
handler: TReleaseHandler | ||
name?: string | ||
include: TReleaseStep[] | ||
exclude: TReleaseStep[] | ||
require: TReleaseStep[] | ||
} | ||
export type TPluginFactoryOptions = Partial<TPluginFactoryOptionsNormalized> | ||
export type TReleaseHandler = (context: TPluginHandlerContext) => Promise<any> | ||
export type TPluginFactory = ( | ||
handler: TPluginFactoryOptions | TReleaseHandler, | ||
) => TPlugin | ||
``` |
@@ -1,1 +0,1 @@ | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.getStepConfigs=exports.getStepConfig=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;var tslib_1=require("tslib"),lodash_1=require("lodash"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","addChannel","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:function(){return tslib_1.__awaiter(void 0,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2]}))}))},name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};var normalizeOptions=function(e){var t="function"==typeof e?{handler:e}:e;return tslib_1.__assign(tslib_1.__assign({},exports.defaultOptions),t)};exports.normalizeOptions=normalizeOptions;var checkPrevSteps=function(e,t,r){var n=e.invoked,i=t.name,o=t.require;if(0!==o.length){var s=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(r)).find((function(e){return o.includes(e)&&!n.includes(e)}));if(s)throw new Error("plugin '"+i+"' requires "+s+" to be invoked before "+r)}},getStepConfig=function(e,t,r){var n;return void 0===r&&(r=""),lodash_1.castArray(null===(n=e.options)||void 0===n?void 0:n[t]).map((function(e){if(Array.isArray(e)){var t=tslib_1.__read(e,2),r=t[0],n=t[1];return tslib_1.__assign(tslib_1.__assign({},n),{path:r})}return e})).find((function(e){return(null==e?void 0:e.path)===r}))||{}};exports.getStepConfig=getStepConfig;var getStepConfigs=function(e,t){return void 0===t&&(t=""),exports.releaseSteps.reduce((function(r,n){return r[n]=exports.getStepConfig(e,n,t),r}),{})};exports.getStepConfigs=getStepConfigs;var createPlugin=function(e){var t=exports.normalizeOptions(e),r=t.handler,n=t.include,i=t.exclude,o=t.name,s={invoked:[]};return exports.releaseSteps.filter((function(e){return n.includes(e)&&!i.includes(e)})).reduce((function(e,n){return e[n]=function(e,i){checkPrevSteps(s,t,n),s.invoked.push(n);var a=exports.getStepConfigs(i,o),u=a[n];return r({pluginConfig:e,context:i,step:n,stepConfig:u,stepConfigs:a})},e}),{})};exports.createPlugin=createPlugin; | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.getStepConfigs=exports.getStepConfig=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;var tslib_1=require("tslib"),lodash_1=require("lodash"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","addChannel","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:function(){return tslib_1.__awaiter(void 0,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2]}))}))},name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};var normalizeOptions=function(e){var t="function"==typeof e?{handler:e}:e;return tslib_1.__assign(tslib_1.__assign({},exports.defaultOptions),t)};exports.normalizeOptions=normalizeOptions;var checkPrevSteps=function(e,t,r){var n=e.invoked,i=t.name,o=t.require;if(0!==o.length){var s=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(r)).find((function(e){return o.includes(e)&&!n.includes(e)}));if(s)throw new Error("plugin '"+i+"' requires "+s+" to be invoked before "+r)}},getStepConfig=function(e,t,r){var n;return void 0===r&&(r=""),lodash_1.castArray(null===(n=e.options)||void 0===n?void 0:n[t]).map((function(e){if(Array.isArray(e)){var t=tslib_1.__read(e,2),r=t[0],n=t[1];return tslib_1.__assign(tslib_1.__assign({},n),{path:r})}return e})).find((function(e){return(null==e?void 0:e.path)===r}))||{}};exports.getStepConfig=getStepConfig;var getStepConfigs=function(e,t){return void 0===t&&(t=""),exports.releaseSteps.reduce((function(r,n){return r[n]=exports.getStepConfig(e,n,t),r}),{})};exports.getStepConfigs=getStepConfigs;var metaContexts=new WeakMap,getMetaContext=function(e){var t=metaContexts.get(e);return t||(t={invoked:[]},metaContexts.set(e,t)),t},createPlugin=function(e){var t=exports.normalizeOptions(e),r=t.handler,n=t.include,i=t.exclude,o=t.name;return exports.releaseSteps.filter((function(e){return n.includes(e)&&!i.includes(e)})).reduce((function(e,n){return e[n]=function(e,i){var s=getMetaContext(i);checkPrevSteps(s,t,n),s.invoked.push(n);var a=exports.getStepConfigs(i,o),u=a[n];return r({pluginConfig:e,context:i,step:n,stepConfig:u,stepConfigs:a})},e}),{})};exports.createPlugin=createPlugin; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.getStepConfigs=exports.getStepConfig=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;const tslib_1=require("tslib"),lodash_1=require("lodash"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","addChannel","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:()=>tslib_1.__awaiter(void 0,void 0,void 0,(function*(){})),name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};const normalizeOptions=e=>{const t="function"==typeof e?{handler:e}:e;return Object.assign(Object.assign({},exports.defaultOptions),t)};exports.normalizeOptions=normalizeOptions;const checkPrevSteps=({invoked:e},{name:t,require:r},s)=>{if(0===r.length)return;const o=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(s)).find((t=>r.includes(t)&&!e.includes(t)));if(o)throw new Error(`plugin '${t}' requires ${o} to be invoked before ${s}`)},getStepConfig=(e,t,r="")=>{var s;return lodash_1.castArray(null===(s=e.options)||void 0===s?void 0:s[t]).map((e=>{if(Array.isArray(e)){const[t,r]=e;return Object.assign(Object.assign({},r),{path:t})}return e})).find((e=>(null==e?void 0:e.path)===r))||{}};exports.getStepConfig=getStepConfig;const getStepConfigs=(e,t="")=>exports.releaseSteps.reduce(((r,s)=>(r[s]=exports.getStepConfig(e,s,t),r)),{});exports.getStepConfigs=getStepConfigs;const createPlugin=e=>{const t=exports.normalizeOptions(e),{handler:r,include:s,exclude:o,name:n}=t,i={invoked:[]};return exports.releaseSteps.filter((e=>s.includes(e)&&!o.includes(e))).reduce(((e,s)=>(e[s]=(e,o)=>{checkPrevSteps(i,t,s),i.invoked.push(s);const p=exports.getStepConfigs(o,n),a=p[s];return r({pluginConfig:e,context:o,step:s,stepConfig:a,stepConfigs:p})},e)),{})};exports.createPlugin=createPlugin; | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.getStepConfigs=exports.getStepConfig=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;const tslib_1=require("tslib"),lodash_1=require("lodash"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","addChannel","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:()=>tslib_1.__awaiter(void 0,void 0,void 0,(function*(){})),name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};const normalizeOptions=e=>{const t="function"==typeof e?{handler:e}:e;return Object.assign(Object.assign({},exports.defaultOptions),t)};exports.normalizeOptions=normalizeOptions;const checkPrevSteps=({invoked:e},{name:t,require:s},n)=>{if(0===s.length)return;const o=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(n)).find((t=>s.includes(t)&&!e.includes(t)));if(o)throw new Error(`plugin '${t}' requires ${o} to be invoked before ${n}`)},getStepConfig=(e,t,s="")=>{var n;return lodash_1.castArray(null===(n=e.options)||void 0===n?void 0:n[t]).map((e=>{if(Array.isArray(e)){const[t,s]=e;return Object.assign(Object.assign({},s),{path:t})}return e})).find((e=>(null==e?void 0:e.path)===s))||{}};exports.getStepConfig=getStepConfig;const getStepConfigs=(e,t="")=>exports.releaseSteps.reduce(((s,n)=>(s[n]=exports.getStepConfig(e,n,t),s)),{});exports.getStepConfigs=getStepConfigs;const metaContexts=new WeakMap,getMetaContext=e=>{let t=metaContexts.get(e);return t||(t={invoked:[]},metaContexts.set(e,t)),t},createPlugin=e=>{const t=exports.normalizeOptions(e),{handler:s,include:n,exclude:o,name:r}=t;return exports.releaseSteps.filter((e=>n.includes(e)&&!o.includes(e))).reduce(((e,n)=>(e[n]=(e,o)=>{const i=getMetaContext(o);checkPrevSteps(i,t,n),i.invoked.push(n);const p=exports.getStepConfigs(o,r),a=p[n];return s({pluginConfig:e,context:o,step:n,stepConfig:a,stepConfigs:p})},e)),{})};exports.createPlugin=createPlugin; |
@@ -97,8 +97,21 @@ import { castArray } from 'lodash' | ||
const metaContexts: WeakMap<TSemrelContext, TPluginMetaContext> = new WeakMap() | ||
const getMetaContext = (context: TSemrelContext): TPluginMetaContext => { | ||
let metaContext = metaContexts.get(context) | ||
if (!metaContext) { | ||
metaContext = { | ||
invoked: [], | ||
} | ||
metaContexts.set(context, metaContext) | ||
} | ||
return metaContext | ||
} | ||
export const createPlugin: TPluginFactory = (options) => { | ||
const normalizedOpions = normalizeOptions(options) | ||
const { handler, include, exclude, name } = normalizedOpions | ||
const metaContext: TPluginMetaContext = { | ||
invoked: [], | ||
} | ||
@@ -109,2 +122,4 @@ return releaseSteps | ||
m[step] = (pluginConfig: TPluginConfig, context: TSemrelContext) => { | ||
const metaContext = getMetaContext(context) | ||
checkPrevSteps(metaContext, normalizedOpions, step) | ||
@@ -111,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43683
586
56