@initx-plugin/manager 0.2.0 → 0.3.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/README.md CHANGED
@@ -23,12 +23,18 @@ List all installed plugins
23
23
  ```bash
24
24
  # npx initx plugin add <plugin-name>
25
25
  npx initx plugin add git
26
+
27
+ # Skip search and install directly
28
+ npx initx plugin add @initx-plugin/git --raw
26
29
  ```
27
30
 
28
31
  This command will search and install `@initx-plugin/git` or `initx-plugin-git`
29
32
 
30
33
  If there are multiple, let the user choose
31
34
 
35
+ **Options:**
36
+ - `--raw` - Skip search and install with the exact name provided
37
+
32
38
  ### Update
33
39
 
34
40
  ```bash
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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};
1
+ import{pluginSystem as m,fetchPlugins as y,InitxPlugin as b}from"@initx-plugin/core";import{useColors as p,loadingFunction as g,logger as r,inquirer as d}from"@initx-plugin/utils";import{cwd as F}from"node:process";import P,{pathExists as j,readJSON as C}from"fs-extra";import{resolve as D,join as L}from"pathe";import S from"columnify";const O=/^@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 O.test(n)?p(n).green().toString():p(n).blue().toString()}async function A(){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 J(n){return(await A()).includes(n)}async function $(n){const i=[],a=[];for(const s of n){const c=await m.search(s);try{for(const e of c)if(!a.includes(e.name)){a.push(e.name),i.push(e);break}}catch{return[]}}return i}async function M(n,i={}){if(n==="."){await R();return}if(i.raw){try{await g("Installing plugin",()=>k(n)),r.success(`Plugin ${l(n)} installed`)}catch(o){throw r.error(`Failed to install plugin ${l(n)}`),o}return}const a=await g("Searching plugin",()=>W(n));if(a.length===0){r.error(`Plugin ${l(w(n))} or ${l(h(n))} not found`);return}let s=0,c=!0;if(a.length===2){const o=[];for(const t of a)o.push(await I(t,!0));s=await d.select("Which plugin do you want to install?",o),c=!1}const e={name:a[s].name,version:a[s].version,description:a[s].description};if(c&&!await d.confirm(`Do you want to install ${await I(e)} ?`)){r.warn("Installation canceled");return}try{await g("Installing plugin",()=>k(e.name))}catch{r.error(`Failed to install plugin ${l(e.name)}`);return}r.success(`Plugin ${l(e.name)} installed`)}async function R(){const n=D(F(),"package.json");if(!P.existsSync(n)){r.error("Is not a valid plugin directory");return}const i=P.readJSONSync(n);if(!i.name||!x(i.name)){r.error("Is not a valid plugin name");return}await m.install("."),r.success(`Plugin ${l(i.name)} installed`)}async function W(n){const i=[w(n),h(n)];return(await $(i))?.filter(a=>x(a.name)&&E(n,a.name))}async function k(n){await m.install(n)}async function I({name:n,version:i,description:a},s=!1){const c=await J(n),e=s?" ":" ",o={name:l(n),version:p(`@${i}`).dim().gray().toString(),description:`${e}${a}`,installed:c?p(" [already]").dim().green().toString():e};return`${o.name}${o.version}${o.installed}${o.description}`}async function q(){const n=await g("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 g("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 ");r.warn(`Plugin ${t} is not installed`);return}let c=0,e=!0;s.length===2&&(c=await d.select("Which plugin do you want to remove?",s.map(({name:t})=>l(t))),e=!1);const o=s[c];e&&!await d.confirm(`Are you sure you want to remove ${l(o.name)}?`)||(await g(`Removing ${l(o.name)}...`,()=>m.uninstall(o.name)),r.success(`Removed ${l(o.name)}`))}async function _(n){await g("Updating core packages",z);const i=n.dev||!1,a=(await g("Fetching plugins",()=>m.list())).filter(t=>i||!t.isLocal),s=a.map(t=>t.name),c=await g("Checking plugins",()=>$(s)),e=[];if(a.forEach(t=>{const u=c.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){r.success("All plugins are up to date");return}if(r.info("Need update plugins:"),console.log(S(e.map(({name:t,version:u,target:v,isDev:N})=>({name:l(t),version:p(`${N?"[dev] ":""}${u}`).dim().gray().toString(),target:v})))),!await d.confirm("Do you want to update these plugins?")){r.warn("Update canceled");return}const o=e.map(({name:t,target:u})=>`${l(t)}${p(`@${u}`).dim().gray().toString()}`).join(" ");await g(`Updating ${o}`,()=>Promise.all([...e.map(({name:t,target:u})=>m.update(t,u))])),r.success(`Plugins updated: ${o}`)}async function z(){const n=await $(["@initx-plugin/core","@initx-plugin/utils"]);for(const i of n){const a=L("node_modules",i.name,"package.json");if(await j(a)){if((await C(a,"utf-8")).version===i.version)continue;await m.update(i.name,i.version)}}await m.ensureCacheValid()}class B extends b{rules=[{matching:"plugin",description:"Plugin Manager",optional:["list","add","update","remove"]}];async handle(i,a,...s){const[c]=s;switch(a){case"list":{await q();break}case"add":{await M(c,i.cliOptions);break}case"update":{await _(i.cliOptions);break}case"remove":{await V(c);break}default:r.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.2.0",
4
+ "version": "0.3.0",
5
5
  "description": "initx plugin manager",
6
6
  "author": "imba97",
7
7
  "license": "MIT",