@initx-plugin/core 0.0.28 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -96,4 +96,4 @@ declare abstract class InitxPlugin<TStore extends object = object> {
96
96
  declare function createStore(name: string, defaultStore?: Record<string, any>): any;
97
97
  declare function writeStore(name: string): void;
98
98
 
99
- export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules as InitxMatchers, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
99
+ export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
package/dist/index.d.ts CHANGED
@@ -96,4 +96,4 @@ declare abstract class InitxPlugin<TStore extends object = object> {
96
96
  declare function createStore(name: string, defaultStore?: Record<string, any>): any;
97
97
  declare function writeStore(name: string): void;
98
98
 
99
- export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules as InitxMatchers, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
99
+ export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatcherRules, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, writeStore };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useInitxMatcher as S}from"matchinitx";import{homedir as k}from"node:os";import u from"node:path";import{defu as j}from"defu";import c from"fs-extra";import{c as w}from"@initx-plugin/utils";let p=null;const m=u.resolve(k(),".initx"),I="store.json",f=r=>u.resolve(m,r,I);function d(r,e={}){c.ensureDirSync(u.resolve(m,r));const n=f(r),i=o=>(h(n,o),P(o));if(!c.existsSync(n))return i(e);let t;try{const o=c.readJsonSync(n);t=j(o,e)}catch{t=e}return i(t)}function g(r){p&&h(f(r),p)}function h(r,e){c.writeJsonSync(r,e,{spaces:2})}function P(r={}){const e=i=>Object.prototype.toString.call(i)==="[object Object]",n=i=>new Proxy(i,{get(t,o){const a=Reflect.get(t,o);return e(a)?n(a):a},set(t,o,a){const l=Reflect.set(t,o,a);return p=t,l}});return n(r)}class v{defaultStore;run(e,...n){return S((i,...t)=>({handler:()=>this.executeHandle(e,i,...t),description:i.description})).match(this.rules,e.key,...n)}async executeHandle(e,n,...i){const t=d(e.packageInfo.name,this.defaultStore);await this.handle({...e,rule:n,store:t},...i),g(e.packageInfo.name)}}async function y(){const{content:r}=await w("npm",["root","-g"]),e=c.readdirSync(r),n=u.join(r,"@initx-plugin"),i=c.existsSync(n)?c.readdirSync(n).map(o=>`@initx-plugin/${o}`):[],t={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};return[...i,...e].filter(o=>t.plugin.test(o)&&!t.exclude.test(o)).map(o=>({name:o,root:u.join(r,o)}))}async function O(){const r=await y(),e=await import("importx");return Promise.all(r.map(async({root:n})=>{const i=await e.import(n,import.meta.url).then(o=>o.default),t=c.readJsonSync(u.join(n,"package.json"));return{packageInfo:{root:n,name:t.name,version:t.version,description:t.description,author:t.author,homepage:t.homepage},instance:new i}}))}function b(r,{key:e,cliOptions:n},...i){const t=[];for(const o of r){const{instance:a,packageInfo:l}=o,x=a.run({key:e,cliOptions:n,packageInfo:l,optionsList:Object.keys(n).filter(s=>n[s]===!0).map(s=>`--${s}`)},...i);t.push(...x.map(s=>({handler:s.handler,description:s.description,packageInfo:l})))}return t}export{v as InitxPlugin,d as createStore,y as fetchPlugins,O as loadPlugins,b as matchPlugins,g as writeStore};
1
+ import{useInitxMatcher as k}from"matchinitx";import{homedir as w}from"node:os";import a from"node:path";import{defu as I}from"defu";import s from"fs-extra";import d from"node:process";import{c as $}from"@initx-plugin/utils";let m=null;const f=a.resolve(w(),".initx"),v="store.json",g=n=>a.resolve(f,n,v);function y(n,o={}){s.ensureDirSync(a.resolve(f,n));const i=g(n),e=c=>(x(i,c),O(c));if(!s.existsSync(i))return e(o);let t;try{const c=s.readJsonSync(i);t=I(c,o)}catch{t=o}return e(t)}function h(n){m&&x(g(n),m)}function x(n,o){s.writeJsonSync(n,o,{spaces:2})}function O(n={}){const o=e=>Object.prototype.toString.call(e)==="[object Object]",i=e=>new Proxy(e,{get(t,c){const r=Reflect.get(t,c);return o(r)?i(r):r},set(t,c,r){const u=Reflect.set(t,c,r);return m=t,u}});return i(n)}class P{defaultStore;run(o,...i){return k((e,...t)=>({handler:()=>this.executeHandle(o,e,...t),description:e.description})).match(this.rules,o.key,...i)}async executeHandle(o,i,...e){const t=y(o.packageInfo.name,this.defaultStore);await this.handle({...o,rule:i,store:t},...e),h(o.packageInfo.name)}}const l={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function b(){const n=a.join(d.cwd(),"package.json");if(!s.existsSync(n))return[];const o=s.readJsonSync(n),{dependencies:i={},devDependencies:e={}}=o;return Object.keys({...i,...e}).filter(t=>l.plugin.test(t)&&!l.exclude.test(t)).map(t=>({name:t,root:a.join(d.cwd(),"node_modules",t)}))}async function S(){const{content:n}=await $("npm",["root","-g"]),o=s.readdirSync(n),i=a.join(n,"@initx-plugin");return[...s.existsSync(i)?s.readdirSync(i).map(e=>`@initx-plugin/${e}`):[],...o].filter(e=>l.plugin.test(e)&&!l.exclude.test(e)).map(e=>({name:e,root:a.join(n,e)}))}async function J(){const n=await b(),o=n.map(({name:t})=>t),i=[...(await S()).filter(({name:t})=>!o.includes(t)),...n],e=await import("importx");return Promise.all(i.map(async({root:t})=>{const c=await e.import(t,import.meta.url).then(u=>u.default),r=s.readJsonSync(a.join(t,"package.json"));return{packageInfo:{root:t,name:r.name,version:r.version,description:r.description,author:r.author,homepage:r.homepage},instance:new c}}))}function D(n,{key:o,cliOptions:i},...e){const t=[];for(const c of n){const{instance:r,packageInfo:u}=c,j=r.run({key:o,cliOptions:i,packageInfo:u,optionsList:Object.keys(i).filter(p=>i[p]===!0).map(p=>`--${p}`)},...e);t.push(...j.map(p=>({handler:p.handler,description:p.description,packageInfo:u})))}return t}export{P as InitxPlugin,y as createStore,S as fetchPlugins,J as loadPlugins,D as matchPlugins,h as writeStore};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.28",
4
+ "version": "0.0.29",
5
5
  "description": "core module for initx plugins",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -26,7 +26,7 @@
26
26
  "fs-extra": "^11.2.0",
27
27
  "importx": "^0.5.1",
28
28
  "matchinitx": "^0.0.2",
29
- "@initx-plugin/utils": "0.0.28"
29
+ "@initx-plugin/utils": "0.0.29"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/fs-extra": "^11.0.4"