UNPKG

4.63 kBTypeScriptView Raw
1import { Command } from './command';
2import { Hooks } from './hooks';
3import { PJSON } from './pjson';
4import * as Plugin from './plugin';
5import { Topic } from './topic';
6export declare type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos';
7export declare type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86';
8export interface Options extends Plugin.Options {
9 devPlugins?: boolean;
10 userPlugins?: boolean;
11}
12export interface IConfig {
13 name: string;
14 version: string;
15 pjson: PJSON.CLI;
16 /**
17 * process.arch
18 */
19 arch: ArchTypes;
20 /**
21 * bin name of CLI command
22 */
23 bin: string;
24 /**
25 * cache directory to use for CLI
26 *
27 * example ~/Library/Caches/mycli or ~/.cache/mycli
28 */
29 cacheDir: string;
30 /**
31 * config directory to use for CLI
32 *
33 * example: ~/.config/mycli
34 */
35 configDir: string;
36 /**
37 * data directory to use for CLI
38 *
39 * example: ~/.local/share/mycli
40 */
41 dataDir: string;
42 /**
43 * base dirname to use in cacheDir/configDir/dataDir
44 */
45 dirname: string;
46 /**
47 * points to a file that should be appended to for error logs
48 *
49 * example: ~/Library/Caches/mycli/error.log
50 */
51 errlog: string;
52 /**
53 * path to home directory
54 *
55 * example: /home/myuser
56 */
57 home: string;
58 /**
59 * process.platform
60 */
61 platform: PlatformTypes;
62 /**
63 * active shell
64 */
65 shell: string;
66 /**
67 * user agent to use for http calls
68 *
69 * example: mycli/1.2.3 (darwin-x64) node-9.0.0
70 */
71 userAgent: string;
72 /**
73 * if windows
74 */
75 windows: boolean;
76 /**
77 * debugging level
78 *
79 * set by ${BIN}_DEBUG or DEBUG=$BIN
80 */
81 debug: number;
82 /**
83 * npm registry to use for installing plugins
84 */
85 npmRegistry: string;
86 userPJSON?: PJSON.User;
87 plugins: Plugin.IPlugin[];
88 readonly commands: Command.Plugin[];
89 readonly topics: Topic[];
90 readonly commandIDs: string[];
91 runCommand(id: string, argv?: string[]): Promise<void>;
92 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
93 findCommand(id: string, opts: {
94 must: true;
95 }): Command.Plugin;
96 findCommand(id: string, opts?: {
97 must: boolean;
98 }): Command.Plugin | undefined;
99 findTopic(id: string, opts: {
100 must: true;
101 }): Topic;
102 findTopic(id: string, opts?: {
103 must: boolean;
104 }): Topic | undefined;
105}
106export declare class Config implements IConfig {
107 _base: string;
108 name: string;
109 version: string;
110 root: string;
111 arch: ArchTypes;
112 bin: string;
113 cacheDir: string;
114 configDir: string;
115 dataDir: string;
116 dirname: string;
117 errlog: string;
118 home: string;
119 platform: PlatformTypes;
120 shell: string;
121 windows: boolean;
122 userAgent: string;
123 debug: number;
124 npmRegistry: string;
125 pjson: PJSON.CLI;
126 userPJSON?: PJSON.User;
127 plugins: Plugin.IPlugin[];
128 protected warned: boolean;
129 constructor(opts: Options);
130 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
131 runCommand(id: string, argv?: string[]): Promise<void>;
132 scopedEnvVar(k: string): string | undefined;
133 scopedEnvVarTrue(k: string): boolean;
134 scopedEnvVarKey(k: string): string;
135 findCommand(id: string, opts: {
136 must: true;
137 }): Command.Plugin;
138 findCommand(id: string, opts?: {
139 must: boolean;
140 }): Command.Plugin | undefined;
141 findTopic(id: string, opts: {
142 must: true;
143 }): Topic;
144 findTopic(id: string, opts?: {
145 must: boolean;
146 }): Topic | undefined;
147 readonly commands: Command.Plugin[];
148 readonly commandIDs: string[];
149 readonly topics: Topic[];
150 protected dir(category: 'cache' | 'data' | 'config'): string;
151 protected windowsHome(): string | undefined;
152 protected windowsHomedriveHome(): string | undefined;
153 protected windowsUserprofileHome(): string | undefined;
154 protected macosCacheDir(): string | undefined;
155 protected _shell(): string;
156 protected _debug(): number;
157 protected loadPlugins(root: string, type: string, plugins: (string | {
158 root?: string;
159 name?: string;
160 tag?: string;
161 })[], options?: {
162 must?: boolean;
163 }): void;
164 protected warn(err: any, scope?: string): void;
165}
166export declare type LoadOptions = Options | string | IConfig | undefined;
167export declare function load(opts?: LoadOptions): IConfig;