@initx-plugin/manager 0.0.10 → 0.1.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
@@ -5,9 +5,11 @@
5
5
  ## Usage
6
6
 
7
7
  ```bash
8
- npm i @initx-plugin/manager -g
8
+ npx initx plugin <command>
9
9
  ```
10
10
 
11
+ This command will automatically install `@initx-plugin/manager` if not already installed.
12
+
11
13
  ### List
12
14
 
13
15
  ```bash
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{fetchPlugins as y,withPluginPrefix as f,InitxPlugin as C}from"@initx-plugin/core";import{c as d,loadingFunction as g,log as r,inquirer as w}from"@initx-plugin/utils";import{cwd as R}from"node:process";import P from"fs-extra";import{resolve as U}from"pathe";import{green as N,blue as A,dim as x,reset as S,gray as h}from"picocolors";import b from"node:path";import J from"columnify";const $={once:!1,names:[]},k=n=>`@initx-plugin/${n}`,j=n=>`initx-plugin-${n}`;function D(n){return/^@initx-plugin\/|^initx-plugin-/.test(n)}function M(n,e){return k(n)===e||j(n)===e}function c(n){return/^@initx-plugin\//.test(n)?N(n):A(n)}async function W(){if($.once)return $.names;const n=await y();return $.names=n.map(({name:e})=>e),$.once=!0,$.names}async function q(n){return(await W()).includes(n)}async function E(n){const e=[],t=[];for(const i of n){const a=await d("npm",["search","--json",i]);if(a.success)try{JSON.parse(a.content).forEach(s=>{t.includes(s.name)||(t.push(s.name),e.push({name:s.name,version:s.version,description:s.description}))})}catch{return[]}}return e}async function L(n){if(n==="."){await z();return}const e=await g("Searching plugin",()=>B(n));if(e.length===0){r.error(`Plugin ${c(k(n))} or ${c(j(n))} not found`);return}let t=0,i=!0;if(e.length===2){const o=[];for(const l of e)o.push(await F(l,!0));t=await w.select("Which plugin do you want to install?",o),i=!1}const a={name:e[t].name,version:e[t].version,description:e[t].description};if(i&&!await w.confirm(`Do you want to install ${await F(a)} ?`)){r.warn("Installation canceled");return}const s=await g("Installing plugin",()=>G(a.name));if(!s.success){r.error(`Failed to install plugin ${c(a.name)}`),console.log(s.content);return}r.success(`Plugin ${c(a.name)} installed`)}async function z(){const n=U(R(),"package.json");if(!P.existsSync(n)){r.error("Is not a valid plugin directory");return}const e=P.readJSONSync(n);if(!e.name||!D(e.name)){r.error("Is not a valid plugin name");return}await d("npm",f(["install",".","--silent"])),r.success(`Plugin ${c(e.name)} installed`)}async function B(n){const e=[k(n),j(n)];return(await E(e))?.filter(t=>D(t.name)&&M(n,t.name))}async function G(n){return d("npm",f(["install",n,"--silent"]))}async function F({name:n,version:e,description:t},i=!1){const a=await q(n),s=i?" ":" ",o={name:c(n),version:S(x(h(`@${e}`))),description:`${s}${S(t)}`,installed:a?x(N(" [already]")):s};return`${o.name}${o.version}${o.installed}${o.description}`}async function H(){const n=await g("Fetching plugins",y),e=[];n.forEach(({root:t})=>{const i=P.readJsonSync(b.join(t,"package.json"));e.push({name:c(i.name),version:h(i.version),description:h(i.description)})}),console.log(J(e))}async function K(n){const e=await y(),t=[k(n),j(n)],i=e.filter(({name:l})=>t.includes(l));if(i.length===0){const l=t.map(c).join(" or ");r.warn(`Plugin ${l} is not installed`);return}let a=0,s=!0;i.length===2&&(a=await w.select("Which plugin do you want to remove?",i.map(({name:l})=>c(l))),s=!1);const o=i[a];s&&!await w.confirm(`Are you sure you want to remove ${c(o.name)}?`)||(await g(`Removing ${c(o.name)}...`,()=>d("npm",f(["uninstall",o.name,"--silent"]))),r.success(`Removed ${c(o.name)}`))}async function Q(n){const e=n.dev||!1,[t,i]=await g("Fetching plugins",()=>Promise.all([T(),y()])),a=[],s=i.reduce((u,{name:m,root:p})=>(!e&&t.includes(m)||(a.push(m),u[m]=p),u),{}),o=await g("Checking plugins",()=>E(a)),l=[];if(Object.keys(s).forEach(u=>{const m=P.readJsonSync(b.join(s[u],"package.json")),p=o.find(O=>O.name===u);if(!p)return;const v=t.includes(u);(v?!e:m.version===p.version)||l.push({name:u,version:m.version,target:p.version,isDev:v})}),l.length===0){r.success("All plugins are up to date");return}if(r.info("Need update plugins:"),console.log(J(l.map(({name:u,version:m,target:p,isDev:v})=>({name:c(u),version:x(h(`${v?"[dev] ":""}${m}`)),target:p})))),!await w.confirm("Do you want to update these plugins?")){r.warn("Update canceled");return}const I=l.map(({name:u,target:m})=>`${c(u)}${x(h(`@${m}`))}`).join(" ");await g(`Updating ${I}`,()=>d("npm",f(["install",...l.map(({name:u,target:m})=>`${u}@${m}`)]))),r.success(`Plugins updated: ${I}`)}async function T(){const n=await d("npm",f(["list"])),e=[];return n.content.split(/\r?\n/).forEach(t=>{const i=/(?:@initx-plugin\/|initx-plugin-)[^@]+/.exec(t);i&&t.includes("->")&&e.push(i[0])}),e}class V extends C{rules=[{matching:"plugin",description:"Plugin Manager",optional:["list","add","update","remove"]}];async handle(e,t,...i){const[a]=i;switch(t){case"list":{await H();break}case"add":{await L(a);break}case"update":{await Q(e.cliOptions);break}case"remove":{await K(a);break}default:r.warn(`Unknown command: ${t}`)}}}export{V as default};
1
+ import{pluginSystem as g,fetchPlugins as $,InitxPlugin as D}from"@initx-plugin/core";import{loadingFunction as m,log as c,inquirer as p}from"@initx-plugin/utils";import{cwd as F}from"node:process";import x,{pathExists as U,readJSON as L}from"fs-extra";import{resolve as C,join as E}from"pathe";import{green as k,blue as O,dim as w,reset as I,gray as f}from"picocolors";import b from"columnify";const d={once:!1,names:[]},v=n=>`@initx-plugin/${n}`,h=n=>`initx-plugin-${n}`;function N(n){return/^@initx-plugin\/|^initx-plugin-/.test(n)}function A(n,i){return v(n)===i||h(n)===i}function l(n){return/^@initx-plugin\//.test(n)?k(n):O(n)}async function J(){if(d.once)return d.names;const n=await $();return d.names=n.map(({name:i})=>i),d.once=!0,d.names}async function M(n){return(await J()).includes(n)}async function P(n){const i=[],a=[];for(const o of n){const s=await g.search(o);try{for(const t of s)if(!a.includes(t.name)){a.push(t.name),i.push(t);break}}catch{return[]}}return i}async function R(n){if(n==="."){await W();return}const i=await m("Searching plugin",()=>q(n));if(i.length===0){c.error(`Plugin ${l(v(n))} or ${l(h(n))} not found`);return}let a=0,o=!0;if(i.length===2){const t=[];for(const r of i)t.push(await S(r,!0));a=await p.select("Which plugin do you want to install?",t),o=!1}const s={name:i[a].name,version:i[a].version,description:i[a].description};if(o&&!await p.confirm(`Do you want to install ${await S(s)} ?`)){c.warn("Installation canceled");return}try{await m("Installing plugin",()=>_(s.name))}catch{c.error(`Failed to install plugin ${l(s.name)}`);return}c.success(`Plugin ${l(s.name)} installed`)}async function W(){const n=C(F(),"package.json");if(!x.existsSync(n)){c.error("Is not a valid plugin directory");return}const i=x.readJSONSync(n);if(!i.name||!N(i.name)){c.error("Is not a valid plugin name");return}await g.install("."),c.success(`Plugin ${l(i.name)} installed`)}async function q(n){const i=[v(n),h(n)];return(await P(i))?.filter(a=>N(a.name)&&A(n,a.name))}async function _(n){await g.install(n)}async function S({name:n,version:i,description:a},o=!1){const s=await M(n),t=o?" ":" ",r={name:l(n),version:I(w(f(`@${i}`))),description:`${t}${I(a)}`,installed:s?w(k(" [already]")):t};return`${r.name}${r.version}${r.installed}${r.description}`}async function z(){const n=await m("Fetching plugins",$),i=[];n.forEach(a=>{i.push({name:l(a.name),version:f(a.version),description:f(a.description)})}),console.log(b(i))}async function B(n){const i=await m("Fetching plugins",$),a=[v(n),h(n)],o=i.filter(({name:e})=>a.includes(e));if(o.length===0){const e=a.map(l).join(" or ");c.warn(`Plugin ${e} is not installed`);return}let s=0,t=!0;o.length===2&&(s=await p.select("Which plugin do you want to remove?",o.map(({name:e})=>l(e))),t=!1);const r=o[s];t&&!await p.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 G(n){await m("Updating core packages",H);const i=n.dev||!1,a=(await m("Fetching plugins",()=>g.list())).filter(e=>i||!e.isLocal),o=a.map(e=>e.name),s=await m("Checking plugins",()=>P(o)),t=[];if(a.forEach(e=>{const u=s.find(y=>y.name===e.name);if(u){if(e.isLocal&&i){t.push({name:e.name,version:e.version,target:u.version,isDev:!0});return}e.isLocal&&!i||e.version!==u.version&&t.push({name:e.name,version:e.version,target:u.version,isDev:!1})}}),t.length===0){c.success("All plugins are up to date");return}if(c.info("Need update plugins:"),console.log(b(t.map(({name:e,version:u,target:y,isDev:j})=>({name:l(e),version:w(f(`${j?"[dev] ":""}${u}`)),target:y})))),!await p.confirm("Do you want to update these plugins?")){c.warn("Update canceled");return}const r=t.map(({name:e,target:u})=>`${l(e)}${w(f(`@${u}`))}`).join(" ");await m(`Updating ${r}`,()=>Promise.all([...t.map(({name:e,target:u})=>g.update(e,u))])),c.success(`Plugins updated: ${r}`)}async function H(){const n=await P(["@initx-plugin/core","@initx-plugin/utils"]);for(const i of n){const a=E("node_modules",i.name,"package.json");if(await U(a)){if((await L(a,"utf-8")).version===i.version)continue;await g.update(i.name,i.version)}}}class K extends D{rules=[{matching:"plugin",description:"Plugin Manager",optional:["list","add","update","remove"]}];async handle(i,a,...o){const[s]=o;switch(a){case"list":{await z();break}case"add":{await R(s);break}case"update":{await G(i.cliOptions);break}case"remove":{await B(s);break}default:c.warn(`Unknown command: ${a}`)}}}export{K 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.0.10",
4
+ "version": "0.1.0",
5
5
  "description": "initx plugin manager",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
@@ -23,25 +23,29 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
+ "peerDependencies": {
27
+ "@initx-plugin/core": "*",
28
+ "@initx-plugin/utils": "*"
29
+ },
26
30
  "dependencies": {
27
- "@initx-plugin/core": "^0.0.35",
28
- "@initx-plugin/utils": "^0.0.35",
29
31
  "columnify": "^1.6.0",
30
- "fs-extra": "^11.3.0",
32
+ "fs-extra": "^11.3.1",
31
33
  "pathe": "^2.0.3",
32
34
  "picocolors": "^1.1.1"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@imba97/eslint-config": "^0.0.6",
38
+ "@initx-plugin/core": "*",
39
+ "@initx-plugin/utils": "*",
36
40
  "@types/columnify": "^1.5.4",
37
41
  "@types/fs-extra": "^11.0.4",
38
- "@types/node": "^22.13.14",
39
- "bumpp": "^10.1.0",
40
- "eslint": "^9.23.0",
41
- "lint-staged": "^15.5.0",
42
- "simple-git-hooks": "^2.12.1",
43
- "typescript": "^5.8.2",
44
- "unbuild": "^3.5.0"
42
+ "@types/node": "^24.3.0",
43
+ "bumpp": "^10.2.3",
44
+ "eslint": "^9.33.0",
45
+ "lint-staged": "^16.1.5",
46
+ "simple-git-hooks": "^2.13.1",
47
+ "typescript": "^5.9.2",
48
+ "unbuild": "^3.6.1"
45
49
  },
46
50
  "simple-git-hooks": {
47
51
  "pre-commit": "pnpm lint-staged"