UNPKG

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