@initx-plugin/core 0.0.33 → 0.0.34
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.mjs +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{platform as D,homedir as R}from"node:os";import c,{resolve as m}from"pathe";import{useInitxMatcher as b}from"matchinitx";import{defu as E}from"defu";import a
|
|
1
|
+
import{platform as D,homedir as R}from"node:os";import c,{resolve as m}from"pathe";import{useInitxMatcher as b}from"matchinitx";import{defu as E}from"defu";import a from"fs-extra";import h from"node:process";import{c as $}from"@initx-plugin/utils";const J=D()==="win32",y=m(R(),".initx"),g=m(y,"stores"),w="store.json",l=m(y,"plugins"),f=J?"node_modules":"lib/node_modules";let x=!1,S={};const I=o=>c.resolve(g,o,w);function v(o,n={}){a.ensureDirSync(c.resolve(g,o));const t=I(o),r=i=>(O(t,i),L(i));if(!a.existsSync(t))return r(n);let e;try{const i=a.readJsonSync(t);e=E(i,n)}catch{e=n}return r(e)}function k(o){x&&O(I(o),S)}function O(o,n){a.writeJsonSync(o,n,{spaces:2})}function L(o={}){const n=r=>typeof r=="object"&&r!==null&&new Set(["[object Object]","[object Array]"]).has(Object.prototype.toString.call(r)),t=r=>new Proxy(r,{get(e,i){const s=Reflect.get(e,i);return n(s)?t(s):s},set(e,i,s){const u=Reflect.set(e,i,s);return x=!0,u},deleteProperty(e,i){const s=Reflect.deleteProperty(e,i);return x=!0,s}});return S=t(o),S}const d={plugin:/^(?:@initx-plugin\/|initx-plugin-)/,exclude:/@initx-plugin\/(?:core|utils)$/};async function M(){const o=c.resolve(h.cwd(),"package.json");if(!a.existsSync(o))return[];const n=a.readJsonSync(o),{dependencies:t={},devDependencies:r={}}=n;return Object.keys({...t,...r}).filter(e=>d.plugin.test(e)&&!d.exclude.test(e)).map(e=>({name:e,root:c.resolve(h.cwd(),"node_modules",e)}))}async function P(){a.ensureDirSync(l);const o=a.readdirSync(c.resolve(l,f)),n=c.resolve(l,f,"@initx-plugin");return[...a.existsSync(n)?a.readdirSync(n).map(t=>`@initx-plugin/${t}`):[],...o].filter(t=>d.plugin.test(t)&&!d.exclude.test(t)).map(t=>({name:t,root:c.resolve(l,f,t)}))}async function N(){const o=await M(),n=o.map(({name:e})=>e),t=[...(await P()).filter(({name:e})=>!n.includes(e)),...o],r=await import("importx");return Promise.all(t.map(async({root:e})=>{const i=await r.import(e,import.meta.url).then(u=>u.default),s=a.readJsonSync(c.resolve(e,"package.json"));return{packageInfo:{root:e,name:s.name,version:s.version,description:s.description,author:s.author,homepage:s.homepage},instance:new i}}))}async function T(o,{key:n,cliOptions:t},...r){const e=[];for(const i of o){const{instance:s,packageInfo:u}=i,_=await s.run({key:n,cliOptions:t,packageInfo:u,optionsList:Object.keys(t).filter(p=>t[p]===!0).map(p=>`--${p}`)},...r);e.push(..._.map(p=>({handler:p.handler,description:p.description,packageInfo:u})))}return e}function A(o,n){return o.some(t=>typeof t=="string"||typeof t>"u"?t===n:t.test(n))}class H{defaultStore;async run(n,...t){const r=b((e,...i)=>({handler:()=>this.executeHandle(n,e,...i),...e}));return(await Promise.all(r.match(this.rules,n.key,...t).map(async e=>e.verify&&!e.verify(n,...t)||e.optional&&!A(e.optional,t[0])?!1:e))).filter(Boolean)}async executeHandle(n,t,...r){const e=v(n.packageInfo.name,this.defaultStore);await this.handle({...n,rule:t,store:e},...r),k(n.packageInfo.name)}}const j="@initx-plugin/manager";function U(){return a.existsSync(m(l,f,j))}async function B(){U()||await $("npm",["install","-g",j,"--prefix",l])}export{y as INITX_DIR,H as InitxPlugin,f as NODE_MODULES_DIR,l as PLUGIN_DIR,g as STORE_DIR,w as STORE_FILE_NAME,v as createStore,P as fetchPlugins,B as installManager,N as loadPlugins,T as matchPlugins,k 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.
|
|
4
|
+
"version": "0.0.34",
|
|
5
5
|
"description": "core module for initx plugins",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/initx-collective/initx#readme",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"importx": "^0.5.2",
|
|
28
28
|
"matchinitx": "^0.0.4",
|
|
29
29
|
"pathe": "^2.0.3",
|
|
30
|
-
"@initx-plugin/utils": "0.0.
|
|
30
|
+
"@initx-plugin/utils": "0.0.34"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/fs-extra": "^11.0.4"
|