UNPKG

5.5 kBTypeScriptView Raw
1/// <reference types="read-pkg" />
2import * as readPkg from 'read-pkg';
3import { IEngine } from './engine';
4import { IPJSON } from './pjson';
5import { ITopic } 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 IConfig {
9 /**
10 * @anycli/config version
11 */
12 _base: string;
13 /**
14 * base path of root plugin
15 */
16 root: string;
17 /**
18 * process.arch
19 */
20 arch: ArchTypes;
21 /**
22 * bin name of CLI command
23 */
24 bin: string;
25 /**
26 * cache directory to use for CLI
27 *
28 * example ~/Library/Caches/mycli or ~/.cache/mycli
29 */
30 cacheDir: string;
31 /**
32 * full path to command dir of plugin
33 */
34 commandsDir: string | undefined;
35 /**
36 * full path to command dir of plugin's typescript files for development
37 */
38 commandsDirTS?: string;
39 /**
40 * normalized full paths to hooks
41 */
42 hooks: {
43 [k: string]: string[];
44 };
45 /**
46 * normalized full paths to typescript hooks
47 */
48 hooksTS?: {
49 [k: string]: string[];
50 };
51 /**
52 * if plugins points to a module this is the full path to that module
53 *
54 * for dynamic plugin loading
55 */
56 pluginsModule: string | undefined;
57 /**
58 * if plugins points to a module this is the full path to that module's typescript
59 */
60 pluginsModuleTS: string | undefined;
61 /**
62 * config directory to use for CLI
63 *
64 * example: ~/.config/mycli
65 */
66 configDir: string;
67 /**
68 * data directory to use for CLI
69 *
70 * example: ~/.local/share/mycli
71 */
72 dataDir: string;
73 /**
74 * base dirname to use in cacheDir/configDir/dataDir
75 */
76 dirname: string;
77 /**
78 * points to a file that should be appended to for error logs
79 *
80 * example: ~/Library/Caches/mycli/error.log
81 */
82 errlog: string;
83 /**
84 * path to home directory
85 *
86 * example: /home/myuser
87 */
88 home: string;
89 /**
90 * CLI name from package.json
91 */
92 name: string;
93 /**
94 * full package.json
95 *
96 * parsed with read-pkg
97 */
98 pjson: IPJSON;
99 /**
100 * process.platform
101 */
102 platform: PlatformTypes;
103 /**
104 * active shell
105 */
106 shell: string;
107 /**
108 * parsed tsconfig.json
109 */
110 tsconfig: TSConfig | undefined;
111 /**
112 * user agent to use for http calls
113 *
114 * example: mycli/1.2.3 (darwin-x64) node-9.0.0
115 */
116 userAgent: string;
117 /**
118 * cli version from package.json
119 *
120 * example: 1.2.3
121 */
122 version: string;
123 /**
124 * if windows
125 */
126 windows: boolean;
127 /**
128 * debugging level
129 *
130 * set by ${BIN}_DEBUG or DEBUG=$BIN
131 */
132 debug: number;
133 /**
134 * active @anycli/engine
135 */
136 engine: IEngine;
137 /**
138 * npm registry to use for installing plugins
139 */
140 npmRegistry: string;
141 /**
142 * a Heroku pre-anycli plugin
143 */
144 legacy: boolean;
145 /**
146 * list of topics
147 */
148 topics: ITopic[];
149}
150export interface TSConfig {
151 compilerOptions: {
152 rootDirs?: string[];
153 outDir?: string;
154 };
155}
156export interface ConfigOptions {
157 name?: string;
158 root?: string;
159 baseConfig?: IConfig;
160}
161export declare class Config implements IConfig {
162 /**
163 * registers ts-node for reading typescript source (./src) instead of compiled js files (./lib)
164 * there are likely issues doing this any the tsconfig.json files are not compatible with others
165 */
166 readonly _base: string;
167 arch: ArchTypes;
168 bin: string;
169 cacheDir: string;
170 configDir: string;
171 dataDir: string;
172 dirname: string;
173 errlog: string;
174 home: string;
175 name: string;
176 pjson: any;
177 platform: PlatformTypes;
178 root: string;
179 shell: string;
180 version: string;
181 windows: boolean;
182 userAgent: string;
183 commandsDir: string | undefined;
184 commandsDirTS: string | undefined;
185 pluginsModule: string | undefined;
186 pluginsModuleTS: string | undefined;
187 tsconfig: TSConfig | undefined;
188 debug: number;
189 hooks: {
190 [k: string]: string[];
191 };
192 hooksTS?: {
193 [k: string]: string[];
194 };
195 engine: IEngine;
196 npmRegistry: string;
197 legacy: boolean;
198 topics: ITopic[];
199 constructor();
200 load(root: string, pjson: readPkg.Package, baseConfig?: IConfig): Promise<this>;
201 scopedEnvVar(k: string): string | undefined;
202 scopedEnvVarTrue(k: string): boolean;
203 scopedEnvVarKey(k: string): string;
204 protected _topics(): void;
205 private dir(category);
206 private windowsHome();
207 private windowsHomedriveHome();
208 private windowsUserprofileHome();
209 private macosCacheDir();
210 private _tsConfig();
211 /**
212 * convert a path from the compiled ./lib files to the ./src typescript source
213 * this is for developing typescript plugins/CLIs
214 * if there is a tsconfig and the original sources exist, it attempts to require ts-
215 */
216 private _tsPath(orig);
217 private _hooks();
218 private _shell();
219 private _debug();
220}
221/**
222 * returns true if config is instantiated and not ConfigOptions
223 */
224export declare function isIConfig(o: any): o is IConfig;
225/**
226 * reads a plugin/CLI's config
227 */
228export declare function read(opts?: ConfigOptions): Promise<IConfig>;