@initx-plugin/manager 0.1.0 → 0.2.0
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 +9 -10
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pluginSystem as g,fetchPlugins as
|
|
1
|
+
import{pluginSystem as g,fetchPlugins as y,InitxPlugin as N}from"@initx-plugin/core";import{useColors as p,loadingFunction as m,logger as c,inquirer as d}from"@initx-plugin/utils";import{cwd as b}from"node:process";import P,{pathExists as C,readJSON as j}from"fs-extra";import{resolve as D,join as F}from"pathe";import S from"columnify";const L=/^@initx-plugin\//,U=/^@initx-plugin\/|^initx-plugin-/,f={once:!1,names:[]},w=n=>`@initx-plugin/${n}`,h=n=>`initx-plugin-${n}`;function x(n){return U.test(n)}function E(n,i){return w(n)===i||h(n)===i}function l(n){return L.test(n)?p(n).green().toString():p(n).blue().toString()}async function O(){if(f.once)return f.names;const n=await y();return f.names=n.map(({name:i})=>i),f.once=!0,f.names}async function A(n){return(await O()).includes(n)}async function $(n){const i=[],a=[];for(const s of n){const o=await g.search(s);try{for(const e of o)if(!a.includes(e.name)){a.push(e.name),i.push(e);break}}catch{return[]}}return i}async function J(n){if(n==="."){await M();return}const i=await m("Searching plugin",()=>R(n));if(i.length===0){c.error(`Plugin ${l(w(n))} or ${l(h(n))} not found`);return}let a=0,s=!0;if(i.length===2){const e=[];for(const r of i)e.push(await k(r,!0));a=await d.select("Which plugin do you want to install?",e),s=!1}const o={name:i[a].name,version:i[a].version,description:i[a].description};if(s&&!await d.confirm(`Do you want to install ${await k(o)} ?`)){c.warn("Installation canceled");return}try{await m("Installing plugin",()=>W(o.name))}catch{c.error(`Failed to install plugin ${l(o.name)}`);return}c.success(`Plugin ${l(o.name)} installed`)}async function M(){const n=D(b(),"package.json");if(!P.existsSync(n)){c.error("Is not a valid plugin directory");return}const i=P.readJSONSync(n);if(!i.name||!x(i.name)){c.error("Is not a valid plugin name");return}await g.install("."),c.success(`Plugin ${l(i.name)} installed`)}async function R(n){const i=[w(n),h(n)];return(await $(i))?.filter(a=>x(a.name)&&E(n,a.name))}async function W(n){await g.install(n)}async function k({name:n,version:i,description:a},s=!1){const o=await A(n),e=s?" ":" ",r={name:l(n),version:p(`@${i}`).dim().gray().toString(),description:`${e}${a}`,installed:o?p(" [already]").dim().green().toString():e};return`${r.name}${r.version}${r.installed}${r.description}`}async function q(){const n=await m("Fetching plugins",y),i=[];n.forEach(a=>{i.push({name:l(a.name),version:p(a.version).gray().toString(),description:p(a.description).gray().toString()})}),console.log(S(i))}async function V(n){const i=await m("Fetching plugins",y),a=[w(n),h(n)],s=i.filter(({name:t})=>a.includes(t));if(s.length===0){const t=a.map(l).join(" or ");c.warn(`Plugin ${t} is not installed`);return}let o=0,e=!0;s.length===2&&(o=await d.select("Which plugin do you want to remove?",s.map(({name:t})=>l(t))),e=!1);const r=s[o];e&&!await d.confirm(`Are you sure you want to remove ${l(r.name)}?`)||(await m(`Removing ${l(r.name)}...`,()=>g.uninstall(r.name)),c.success(`Removed ${l(r.name)}`))}async function _(n){await m("Updating core packages",z);const i=n.dev||!1,a=(await m("Fetching plugins",()=>g.list())).filter(t=>i||!t.isLocal),s=a.map(t=>t.name),o=await m("Checking plugins",()=>$(s)),e=[];if(a.forEach(t=>{const u=o.find(v=>v.name===t.name);if(u){if(t.isLocal&&i){e.push({name:t.name,version:t.version,target:u.version,isDev:!0});return}t.isLocal&&!i||t.version!==u.version&&e.push({name:t.name,version:t.version,target:u.version,isDev:!1})}}),e.length===0){c.success("All plugins are up to date");return}if(c.info("Need update plugins:"),console.log(S(e.map(({name:t,version:u,target:v,isDev:I})=>({name:l(t),version:p(`${I?"[dev] ":""}${u}`).dim().gray().toString(),target:v})))),!await d.confirm("Do you want to update these plugins?")){c.warn("Update canceled");return}const r=e.map(({name:t,target:u})=>`${l(t)}${p(`@${u}`).dim().gray().toString()}`).join(" ");await m(`Updating ${r}`,()=>Promise.all([...e.map(({name:t,target:u})=>g.update(t,u))])),c.success(`Plugins updated: ${r}`)}async function z(){const n=await $(["@initx-plugin/core","@initx-plugin/utils"]);for(const i of n){const a=F("node_modules",i.name,"package.json");if(await C(a)){if((await j(a,"utf-8")).version===i.version)continue;await g.update(i.name,i.version)}}await g.ensureCacheValid()}class B extends N{rules=[{matching:"plugin",description:"Plugin Manager",optional:["list","add","update","remove"]}];async handle(i,a,...s){const[o]=s;switch(a){case"list":{await q();break}case"add":{await J(o);break}case"update":{await _(i.cliOptions);break}case"remove":{await V(o);break}default:c.warn(`Unknown command: ${a}`)}}}export{B as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@initx-plugin/manager",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "initx plugin manager",
|
|
6
6
|
"author": "imba97",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,23 +28,22 @@
|
|
|
28
28
|
"@initx-plugin/utils": "*"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@antfu/eslint-config": "^7.7.3",
|
|
31
32
|
"columnify": "^1.6.0",
|
|
32
|
-
"fs-extra": "^11.3.
|
|
33
|
-
"pathe": "^2.0.3"
|
|
34
|
-
"picocolors": "^1.1.1"
|
|
33
|
+
"fs-extra": "^11.3.4",
|
|
34
|
+
"pathe": "^2.0.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@imba97/eslint-config": "^0.0.6",
|
|
38
37
|
"@initx-plugin/core": "*",
|
|
39
38
|
"@initx-plugin/utils": "*",
|
|
40
39
|
"@types/columnify": "^1.5.4",
|
|
41
40
|
"@types/fs-extra": "^11.0.4",
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"bumpp": "^
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"lint-staged": "^16.
|
|
41
|
+
"@types/node": "^25.5.0",
|
|
42
|
+
"bumpp": "^11.0.1",
|
|
43
|
+
"eslint": "^10.1.0",
|
|
44
|
+
"lint-staged": "^16.4.0",
|
|
46
45
|
"simple-git-hooks": "^2.13.1",
|
|
47
|
-
"typescript": "^5.9.
|
|
46
|
+
"typescript": "^5.9.3",
|
|
48
47
|
"unbuild": "^3.6.1"
|
|
49
48
|
},
|
|
50
49
|
"simple-git-hooks": {
|