UNPKG

4.95 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 scopedEnvVar(key: string): string | undefined;
106 scopedEnvVarKey(key: string): string;
107 scopedEnvVarTrue(key: string): boolean;
108}
109export declare class Config implements IConfig {
110 options: Options;
111 _base: string;
112 name: string;
113 version: string;
114 root: string;
115 arch: ArchTypes;
116 bin: string;
117 cacheDir: string;
118 configDir: string;
119 dataDir: string;
120 dirname: string;
121 errlog: string;
122 home: string;
123 platform: PlatformTypes;
124 shell: string;
125 windows: boolean;
126 userAgent: string;
127 debug: number;
128 npmRegistry: string;
129 pjson: PJSON.CLI;
130 userPJSON?: PJSON.User;
131 plugins: Plugin.IPlugin[];
132 protected warned: boolean;
133 constructor(options: Options);
134 load(): Promise<void>;
135 loadCorePlugins(): Promise<void>;
136 loadDevPlugins(): Promise<void>;
137 loadUserPlugins(): Promise<void>;
138 runHook<T extends Hooks, K extends keyof T>(event: K, opts: T[K]): Promise<void>;
139 runCommand(id: string, argv?: string[]): Promise<void>;
140 scopedEnvVar(k: string): string | undefined;
141 scopedEnvVarTrue(k: string): boolean;
142 scopedEnvVarKey(k: string): string;
143 findCommand(id: string, opts: {
144 must: true;
145 }): Command.Plugin;
146 findCommand(id: string, opts?: {
147 must: boolean;
148 }): Command.Plugin | undefined;
149 findTopic(id: string, opts: {
150 must: true;
151 }): Topic;
152 findTopic(id: string, opts?: {
153 must: boolean;
154 }): Topic | undefined;
155 readonly commands: Command.Plugin[];
156 readonly commandIDs: string[];
157 readonly topics: Topic[];
158 protected dir(category: 'cache' | 'data' | 'config'): string;
159 protected windowsHome(): string | undefined;
160 protected windowsHomedriveHome(): string | undefined;
161 protected windowsUserprofileHome(): string | undefined;
162 protected macosCacheDir(): string | undefined;
163 protected _shell(): string;
164 protected _debug(): number;
165 protected loadPlugins(root: string, type: string, plugins: (string | {
166 root?: string;
167 name?: string;
168 tag?: string;
169 })[], options?: {
170 must?: boolean;
171 }): Promise<void>;
172 protected warn(err: any, scope?: string): void;
173}
174export declare type LoadOptions = Options | string | IConfig | undefined;
175export declare function load(opts?: LoadOptions): Promise<IConfig>;