initx 0.3.4 → 0.3.6
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/bin/initx.mjs +4 -1
- package/dist/cli/index.d.mts +43 -0
- package/dist/cli/index.d.ts +43 -0
- package/dist/cli/index.mjs +1 -0
- package/package.json +3 -3
- package/dist/cli.d.mts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/cli.mjs +0 -1
package/bin/initx.mjs
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as cac from 'cac';
|
|
2
|
+
import { LoadPluginResult, InitxBaseContext, MatchedPlugin } from '@initx-plugin/core';
|
|
3
|
+
|
|
4
|
+
interface CliLogger {
|
|
5
|
+
setLevel: (level: 'debug' | 'info' | 'success' | 'warn' | 'error') => void;
|
|
6
|
+
debug: (message: string) => void;
|
|
7
|
+
info: (message: string) => void;
|
|
8
|
+
success: (message: string) => void;
|
|
9
|
+
warn: (message: string) => void;
|
|
10
|
+
error: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
interface CliDeps {
|
|
13
|
+
detectManager: () => Promise<boolean>;
|
|
14
|
+
installManager: () => Promise<void>;
|
|
15
|
+
loadPlugins: () => Promise<LoadPluginResult[]>;
|
|
16
|
+
matchPlugins: (plugins: LoadPluginResult[], context: InitxBaseContext, ...others: string[]) => Promise<MatchedPlugin[]>;
|
|
17
|
+
select: (message: string, options: string[]) => Promise<number>;
|
|
18
|
+
loadingFunction: <T>(message: string, fn: () => Promise<T>) => Promise<T>;
|
|
19
|
+
logger: CliLogger;
|
|
20
|
+
}
|
|
21
|
+
interface ParsedCliInput {
|
|
22
|
+
key?: string;
|
|
23
|
+
others: string[];
|
|
24
|
+
cliOptions: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
type CliParseResult = {
|
|
27
|
+
type: 'help';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'version';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'run';
|
|
32
|
+
input: ParsedCliInput;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
declare function createCli(): cac.CAC;
|
|
36
|
+
declare function parseCliInput(argv: string[]): CliParseResult;
|
|
37
|
+
|
|
38
|
+
declare function runCli(input: ParsedCliInput, deps: CliDeps): Promise<void>;
|
|
39
|
+
|
|
40
|
+
declare function runCliFromProcess(argv?: string[]): Promise<number>;
|
|
41
|
+
|
|
42
|
+
export { createCli, parseCliInput, runCli, runCliFromProcess };
|
|
43
|
+
export type { CliDeps, CliParseResult, ParsedCliInput };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as cac from 'cac';
|
|
2
|
+
import { LoadPluginResult, InitxBaseContext, MatchedPlugin } from '@initx-plugin/core';
|
|
3
|
+
|
|
4
|
+
interface CliLogger {
|
|
5
|
+
setLevel: (level: 'debug' | 'info' | 'success' | 'warn' | 'error') => void;
|
|
6
|
+
debug: (message: string) => void;
|
|
7
|
+
info: (message: string) => void;
|
|
8
|
+
success: (message: string) => void;
|
|
9
|
+
warn: (message: string) => void;
|
|
10
|
+
error: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
interface CliDeps {
|
|
13
|
+
detectManager: () => Promise<boolean>;
|
|
14
|
+
installManager: () => Promise<void>;
|
|
15
|
+
loadPlugins: () => Promise<LoadPluginResult[]>;
|
|
16
|
+
matchPlugins: (plugins: LoadPluginResult[], context: InitxBaseContext, ...others: string[]) => Promise<MatchedPlugin[]>;
|
|
17
|
+
select: (message: string, options: string[]) => Promise<number>;
|
|
18
|
+
loadingFunction: <T>(message: string, fn: () => Promise<T>) => Promise<T>;
|
|
19
|
+
logger: CliLogger;
|
|
20
|
+
}
|
|
21
|
+
interface ParsedCliInput {
|
|
22
|
+
key?: string;
|
|
23
|
+
others: string[];
|
|
24
|
+
cliOptions: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
type CliParseResult = {
|
|
27
|
+
type: 'help';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'version';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'run';
|
|
32
|
+
input: ParsedCliInput;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
declare function createCli(): cac.CAC;
|
|
36
|
+
declare function parseCliInput(argv: string[]): CliParseResult;
|
|
37
|
+
|
|
38
|
+
declare function runCli(input: ParsedCliInput, deps: CliDeps): Promise<void>;
|
|
39
|
+
|
|
40
|
+
declare function runCliFromProcess(argv?: string[]): Promise<number>;
|
|
41
|
+
|
|
42
|
+
export { createCli, parseCliInput, runCli, runCliFromProcess };
|
|
43
|
+
export type { CliDeps, CliParseResult, ParsedCliInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import x from"node:process";import{detectManager as k,installManager as C,loadPlugins as F,matchPlugins as I}from"@initx-plugin/core";import{inquirer as L,loadingFunction as O,logger as D}from"@initx-plugin/utils";import N from"cac";const R={version:"0.3.6"};function f(){const e=N("initx");return e.help().command("<something>","see https://github.com/initx-collective/initx").usage("").option("-v, --version","Display version number").option("-d, --debug","Debug mode"),e}function m(e){const t=f(),{args:s,options:o}=t.parse(e);if(o.h||o.help)return{type:"help"};if(o.v||o.version)return{type:"version"};const[u,...r]=s;return{type:"run",input:{key:u,others:r,cliOptions:o}}}const j=/^@?initx-plugin[-/]/;function q(e){return Object.keys(e).filter(t=>e[t]===!0).map(t=>`--${t}`)}async function b(e,t){const{detectManager:s,installManager:o,loadPlugins:u,loadingFunction:r,logger:n,matchPlugins:y,select:v}=t,{key:a,others:w,cliOptions:l}=e;if((l.d||l.debug)&&(n.setLevel("debug"),n.debug("Debug mode enabled")),!a||typeof a!="string"){n.error("Please enter something");return}n.debug(`Input: ${a}`);let g=!1;await r("initx",async()=>{g=await s()}),n.debug(`Manager: ${g?"installed":"not found"}`),g||await r("Installing manager plugin",o);const c=await r("Loading plugins",u);if(c.length===0){n.error("No plugin installed");return}n.debug(`Loaded ${c.length} plugins`);const $={key:a,cliOptions:l,optionsList:q(l)},i=await y(c,$,...w);if(n.debug(`Matched ${i.length} handlers`),i.length===0){n.warn("No handler found");return}if(i.length===1){const[{handler:p,description:h}]=i;n.debug(`Running: ${h}`),await p();return}const d=await v("Which handler do you want to run?",i.map(({description:p,packageInfo:h})=>`[${h.name.replace(j,"")}] ${p}`));if(!i[d]||typeof i[d].handler!="function"){n.error("Handler not found");return}const{handler:M,description:P}=i[d];n.debug(`Running: ${P}`),await M()}const H={detectManager:k,installManager:C,loadPlugins:F,matchPlugins:I,select:L.select,loadingFunction:O,logger:D};async function W(e=x.argv){const t=m(e);return t.type==="help"?0:t.type==="version"?(console.log(R.version),0):(await b(t.input,H),0)}export{f as createCli,m as parseCliInput,b as runCli,W as runCliFromProcess};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "initx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.6",
|
|
5
5
|
"description": "A more convenient scripting engine",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/initx-collective/initx#readme",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"cac": "^7.0.0",
|
|
31
|
-
"@initx-plugin/
|
|
32
|
-
"@initx-plugin/
|
|
31
|
+
"@initx-plugin/utils": "0.3.6",
|
|
32
|
+
"@initx-plugin/core": "0.3.6"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"stub": "unbuild --stub",
|
package/dist/cli.d.mts
DELETED
package/dist/cli.d.ts
DELETED
package/dist/cli.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import o from"node:process";import{detectManager as m,installManager as b,loadPlugins as f,matchPlugins as x}from"@initx-plugin/core";import{logger as n,loadingFunction as d,inquirer as v}from"@initx-plugin/utils";import w from"cac";const $={version:"0.3.4"},y=/^@?initx-plugin[-/]/,u=w("initx");u.help().command("<something>","see https://github.com/initx-collective/initx").usage("").option("-v, --version","Display version number").option("-d, --debug","Debug mode");const{args:M,options:e}=u.parse();(e.h||e.help)&&o.exit(0),(e.v||e.version)&&(console.log($.version),o.exit(0)),(e.d||e.debug)&&(n.setLevel("debug"),n.debug("Debug mode enabled"));const[a,...I]=M;(!a||typeof a!="string")&&(n.error("Please enter something"),o.exit(0)),n.debug(`Input: ${a}`),(async function(){let r;await d("initx",async()=>{r=await m()}),n.debug(`Manager: ${r?"installed":"not found"}`),r||await d("Installing manager plugin",b);const s=await d("Loading plugins",f);s.length===0&&(n.error("No plugin installed"),o.exit(0)),n.debug(`Loaded ${s.length} plugins`);const c={key:a,cliOptions:e,optionsList:Object.keys(e).filter(i=>e[i]===!0).map(i=>`--${i}`)},t=await x(s,c,...I);if(n.debug(`Matched ${t.length} handlers`),t.length===0&&(n.warn("No handler found"),o.exit(0)),t.length===1){const[{handler:i,description:g}]=t;n.debug(`Running: ${g}`),await i(),o.exit(0)}const l=await v.select("Which handler do you want to run?",t.map(({description:i,packageInfo:g})=>`[${g.name.replace(y,"")}] ${i}`));(!t[l]||typeof t[l].handler!="function")&&(n.error("Handler not found"),o.exit(0));const{handler:p,description:h}=t[l];n.debug(`Running: ${h}`),await p()})();
|