UNPKG

5.78 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' | 'wsl';
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 channel?: string;
12 version?: string;
13}
14export interface IConfig {
15 name: string;
16 version: string;
17 channel: string;
18 pjson: PJSON.CLI;
19 root: string;
20 /**
21 * process.arch
22 */
23 arch: ArchTypes;
24 /**
25 * bin name of CLI command
26 */
27 bin: string;
28 /**
29 * cache directory to use for CLI
30 *
31 * example ~/Library/Caches/mycli or ~/.cache/mycli
32 */
33 cacheDir: string;
34 /**
35 * config directory to use for CLI
36 *
37 * example: ~/.config/mycli
38 */
39 configDir: string;
40 /**
41 * data directory to use for CLI
42 *
43 * example: ~/.local/share/mycli
44 */
45 dataDir: string;
46 /**
47 * base dirname to use in cacheDir/configDir/dataDir
48 */
49 dirname: string;
50 /**
51 * points to a file that should be appended to for error logs
52 *
53 * example: ~/Library/Caches/mycli/error.log
54 */
55 errlog: string;
56 /**
57 * path to home directory
58 *
59 * example: /home/myuser
60 */
61 home: string;
62 /**
63 * process.platform
64 */
65 platform: PlatformTypes;
66 /**
67 * active shell
68 */
69 shell: string;
70 /**
71 * user agent to use for http calls
72 *
73 * example: mycli/1.2.3 (darwin-x64) node-9.0.0
74 */
75 userAgent: string;
76 /**
77 * if windows
78 */
79 windows: boolean;
80 /**
81 * debugging level
82 *
83 * set by ${BIN}_DEBUG or DEBUG=$BIN
84 */
85 debug: number;
86 /**
87 * npm registry to use for installing plugins
88 */
89 npmRegistry?: string;
90 userPJSON?: PJSON.User;
91 plugins: Plugin.IPlugin[];
92 binPath?: string;
93 valid: boolean;
94 readonly commands: Command.Plugin[];
95 readonly topics: Topic[];
96 readonly commandIDs: string[];
97 runCommand(id: string, argv?: string[]): Promise<void>;
98 runHook<T extends Hooks, K extends Extract<keyof T, string>>(event: K, opts: T[K]): Promise<void>;
99 findCommand(id: string, opts: {
100 must: true;
101 }): Command.Plugin;
102 findCommand(id: string, opts?: {
103 must: boolean;
104 }): Command.Plugin | undefined;
105 findTopic(id: string, opts: {
106 must: true;
107 }): Topic;
108 findTopic(id: string, opts?: {
109 must: boolean;
110 }): Topic | undefined;
111 scopedEnvVar(key: string): string | undefined;
112 scopedEnvVarKey(key: string): string;
113 scopedEnvVarTrue(key: string): boolean;
114 s3Url(key: string): string;
115 s3Key(type: 'versioned' | 'unversioned', ext: '.tar.gz' | '.tar.xz', options?: IConfig.s3Key.Options): string;
116 s3Key(type: keyof PJSON.S3.Templates, options?: IConfig.s3Key.Options): string;
117}
118export declare namespace IConfig {
119 namespace s3Key {
120 interface Options {
121 platform?: PlatformTypes;
122 arch?: ArchTypes;
123 [key: string]: any;
124 }
125 }
126}
127export declare class Config implements IConfig {
128 options: Options;
129 _base: string;
130 name: string;
131 version: string;
132 channel: string;
133 root: string;
134 arch: ArchTypes;
135 bin: string;
136 cacheDir: string;
137 configDir: string;
138 dataDir: string;
139 dirname: string;
140 errlog: string;
141 home: string;
142 platform: PlatformTypes;
143 shell: string;
144 windows: boolean;
145 userAgent: string;
146 debug: number;
147 npmRegistry?: string;
148 pjson: PJSON.CLI;
149 userPJSON?: PJSON.User;
150 plugins: Plugin.IPlugin[];
151 binPath?: string;
152 valid: boolean;
153 protected warned: boolean;
154 constructor(options: Options);
155 load(): Promise<void>;
156 loadCorePlugins(): Promise<void>;
157 loadDevPlugins(): Promise<void>;
158 loadUserPlugins(): Promise<void>;
159 runHook<T>(event: string, opts: T): Promise<void>;
160 runCommand(id: string, argv?: string[]): Promise<void>;
161 scopedEnvVar(k: string): string | undefined;
162 scopedEnvVarTrue(k: string): boolean;
163 scopedEnvVarKey(k: string): string;
164 findCommand(id: string, opts: {
165 must: true;
166 }): Command.Plugin;
167 findCommand(id: string, opts?: {
168 must: boolean;
169 }): Command.Plugin | undefined;
170 findTopic(id: string, opts: {
171 must: true;
172 }): Topic;
173 findTopic(id: string, opts?: {
174 must: boolean;
175 }): Topic | undefined;
176 get commands(): Command.Plugin[];
177 get commandIDs(): string[];
178 get topics(): Topic[];
179 s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
180 s3Url(key: string): string;
181 protected dir(category: 'cache' | 'data' | 'config'): string;
182 protected windowsHome(): string | undefined;
183 protected windowsHomedriveHome(): string | undefined;
184 protected windowsUserprofileHome(): string | undefined;
185 protected macosCacheDir(): string | undefined;
186 protected _shell(): string;
187 protected _debug(): number;
188 protected loadPlugins(root: string, type: string, plugins: (string | {
189 root?: string;
190 name?: string;
191 tag?: string;
192 })[], parent?: Plugin.Plugin): Promise<void>;
193 protected warn(err: string | Error | {
194 name: string;
195 detail: string;
196 }, scope?: string): void;
197}
198export declare type LoadOptions = Options | string | IConfig | undefined;
199export declare function load(opts?: LoadOptions): Promise<IConfig | Config>;