@initx-plugin/manager 0.2.0 → 0.3.1
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 +6 -0
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
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
|
|
1
|
+
import{pluginSystem as p,fetchPlugins as v,PLUGIN_DIR as b,InitxPlugin as D}from"@initx-plugin/core";import{useColors as m,loadingFunction as g,logger as o,inquirer as d,c as F}from"@initx-plugin/utils";import{cwd as L}from"node:process";import $ from"fs-extra";import{resolve as U}from"pathe";import P from"columnify";const C=/^@initx-plugin\//,j=/^@initx-plugin\/|^initx-plugin-/,f={once:!1,names:[]},w=n=>`@initx-plugin/${n}`,h=n=>`initx-plugin-${n}`;function x(n){return j.test(n)}function O(n,i){return w(n)===i||h(n)===i}function l(n){return C.test(n)?m(n).green().toString():m(n).blue().toString()}async function R(){if(f.once)return f.names;const n=await v();return f.names=n.map(({name:i})=>i),f.once=!0,f.names}async function A(n){return(await R()).includes(n)}async function S(n){const i=[],t=[];for(const r of n){const c=await p.search(r);try{for(const e of c)if(!t.includes(e.name)){t.push(e.name),i.push(e);break}}catch{return[]}}return i}async function E(n,i={}){if(n==="."){await M();return}if(i.raw){try{await g("Installing plugin",()=>I(n)),o.success(`Plugin ${l(n)} installed`)}catch(s){throw o.error(`Failed to install plugin ${l(n)}`),s}return}const t=await g("Searching plugin",()=>W(n));if(t.length===0){o.error(`Plugin ${l(w(n))} or ${l(h(n))} not found`);return}let r=0,c=!0;if(t.length===2){const s=[];for(const a of t)s.push(await k(a,!0));r=await d.select("Which plugin do you want to install?",s),c=!1}const e={name:t[r].name,version:t[r].version,description:t[r].description};if(c&&!await d.confirm(`Do you want to install ${await k(e)} ?`)){o.warn("Installation canceled");return}try{await g("Installing plugin",()=>I(e.name))}catch{o.error(`Failed to install plugin ${l(e.name)}`);return}o.success(`Plugin ${l(e.name)} installed`)}async function M(){const n=U(L(),"package.json");if(!$.existsSync(n)){o.error("Is not a valid plugin directory");return}const i=$.readJSONSync(n);if(!i.name||!x(i.name)){o.error("Is not a valid plugin name");return}await p.install("."),o.success(`Plugin ${l(i.name)} installed`)}async function W(n){const i=[w(n),h(n)];return(await S(i))?.filter(t=>x(t.name)&&O(n,t.name))}async function I(n){await p.install(n)}async function k({name:n,version:i,description:t},r=!1){const c=await A(n),e=r?" ":" ",s={name:l(n),version:m(`@${i}`).dim().gray().toString(),description:`${e}${t}`,installed:c?m(" [already]").dim().green().toString():e};return`${s.name}${s.version}${s.installed}${s.description}`}async function q(){const n=await g("Fetching plugins",v),i=[];n.forEach(t=>{i.push({name:l(t.name),version:m(t.version).gray().toString(),description:m(t.description).gray().toString()})}),console.log(P(i))}async function G(n){const i=await g("Fetching plugins",v),t=[w(n),h(n)],r=i.filter(({name:a})=>t.includes(a));if(r.length===0){const a=t.map(l).join(" or ");o.warn(`Plugin ${a} is not installed`);return}let c=0,e=!0;r.length===2&&(c=await d.select("Which plugin do you want to remove?",r.map(({name:a})=>l(a))),e=!1);const s=r[c];e&&!await d.confirm(`Are you sure you want to remove ${l(s.name)}?`)||(await g(`Removing ${l(s.name)}...`,()=>p.uninstall(s.name)),o.success(`Removed ${l(s.name)}`))}async function J(n){await g("Updating core packages",_);const i=n.dev||!1,t=(await g("Fetching plugins",()=>p.list())).filter(a=>i||!a.isLocal),r=t.map(a=>a.name),c=await g("Checking plugins",()=>S(r)),e=[];if(t.forEach(a=>{const u=c.find(y=>y.name===a.name);if(u){if(a.isLocal&&i){e.push({name:a.name,version:a.version,target:u.version,isDev:!0});return}a.isLocal&&!i||a.version!==u.version&&e.push({name:a.name,version:a.version,target:u.version,isDev:!1})}}),e.length===0){o.success("All plugins are up to date");return}if(o.info("Need update plugins:"),console.log(P(e.map(({name:a,version:u,target:y,isDev:N})=>({name:l(a),version:m(`${N?"[dev] ":""}${u}`).dim().gray().toString(),target:y})))),!await d.confirm("Do you want to update these plugins?")){o.warn("Update canceled");return}const s=e.map(({name:a,target:u})=>`${l(a)}${m(`@${u}`).dim().gray().toString()}`).join(" ");await g(`Updating ${s}`,()=>Promise.all([...e.map(({name:a,target:u})=>p.update(a,u))])),o.success(`Plugins updated: ${s}`)}async function _(){await F("npm",["install","@initx-plugin/core","@initx-plugin/utils","--prefix",b])}class z extends D{rules=[{matching:"plugin",description:"Plugin Manager",optional:["list","add","update","remove"]}];async handle(i,t,...r){const[c]=r;switch(t){case"list":{await q();break}case"add":{await E(c,i.cliOptions);break}case"update":{await J(i.cliOptions);break}case"remove":{await G(c);break}default:o.warn(`Unknown command: ${t}`)}}}export{z as default};
|