UNPKG

20 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as ζframework from '@ionic/cli-framework';
3import { ShellCommandOptions } from '@ionic/cli-framework/utils/shell';
4import { NetworkInterface } from '@ionic/utils-network';
5import { ChildProcess, SpawnOptions } from 'child_process';
6import * as fs from 'fs';
7import * as ζsuperagent from 'superagent';
8import * as ζbuild from './lib/build';
9import * as ζgenerate from './lib/generate';
10import * as ζserve from './lib/serve';
11export { CommandLineInputs, CommandLineOptions, CommandMetadataInput, NamespaceMetadata, PackageJson } from '@ionic/cli-framework';
12export interface SuperAgentError extends Error {
13 response: ζsuperagent.Response;
14}
15export declare type LogFn = (msg: string) => void;
16export interface ILogger extends ζframework.Logger {
17 ok: LogFn;
18 rawmsg: LogFn;
19}
20export interface StarterManifest {
21 name: string;
22 baseref: string;
23 welcome?: string;
24}
25export interface CordovaPackageJson extends ζframework.PackageJson {
26 cordova: {
27 platforms: string[];
28 plugins: {
29 [key: string]: {};
30 };
31 };
32}
33export interface Runner<T extends object, U> {
34 run(options: T): Promise<U>;
35}
36export declare type ProjectType = 'angular' | 'ionic-angular' | 'ionic1' | 'custom';
37export declare type HookName = 'build:before' | 'build:after' | 'serve:before' | 'serve:after';
38export interface BaseHookContext {
39 project: {
40 type: ProjectType;
41 dir: string;
42 srcDir: string;
43 };
44 argv: string[];
45 env: NodeJS.ProcessEnv;
46}
47export interface BuildHookInput {
48 readonly name: 'build:before' | 'build:after';
49 readonly build: AngularBuildOptions | IonicAngularBuildOptions | Ionic1BuildOptions;
50}
51export interface ServeBeforeHookInput {
52 readonly name: 'serve:before';
53 readonly serve: AngularServeOptions | IonicAngularServeOptions | Ionic1ServeOptions;
54}
55export interface ServeAfterHookInput {
56 readonly name: 'serve:after';
57 readonly serve: (AngularServeOptions | IonicAngularServeOptions | Ionic1ServeOptions) & ServeDetails;
58}
59export declare type HookInput = BuildHookInput | ServeBeforeHookInput | ServeAfterHookInput;
60export declare type HookContext = BaseHookContext & HookInput;
61export declare type HookFn = (ctx: HookContext) => Promise<void>;
62export declare type IntegrationName = 'capacitor' | 'cordova';
63export interface ProjectIntegration {
64 enabled?: boolean;
65 root?: string;
66}
67export interface ProjectIntegrations {
68 cordova?: ProjectIntegration;
69 capacitor?: ProjectIntegration;
70}
71export interface Response<T extends object> extends APIResponseSuccess {
72 data: T;
73}
74export interface ResourceClientLoad<T extends object> {
75 load(id: string | number, modifiers: ResourceClientRequestModifiers): Promise<T>;
76}
77export interface ResourceClientDelete {
78 delete(id: string | number): Promise<void>;
79}
80export interface ResourceClientCreate<T extends object, U extends object> {
81 create(details: U): Promise<T>;
82}
83export interface ResourceClientPaginate<T extends object> {
84 paginate(args?: Partial<PaginateArgs<Response<T[]>>>): IPaginator<Response<T[]>, PaginatorState>;
85}
86export interface ResourceClientRequestModifiers {
87 fields?: string[];
88}
89export interface Org {
90 name: string;
91}
92export interface GithubRepo {
93 full_name: string;
94 id: number;
95}
96export interface GithubBranch {
97 name: string;
98}
99export interface AppAssociation {
100 repository: RepoAssociation;
101}
102export interface RepoAssociationBase {
103 html_url: string;
104 clone_url: string;
105 full_name: string;
106}
107export interface GithubRepoAssociation extends RepoAssociationBase {
108 type: 'github';
109 id: number;
110}
111export interface BitbucketCloudRepoAssociation extends RepoAssociationBase {
112 type: 'bitbucket_cloud';
113 id: string;
114}
115export interface BitbucketServerRepoAssociation extends RepoAssociationBase {
116 type: 'bitbucket_server';
117 id: number;
118}
119export declare type RepoAssociation = GithubRepoAssociation | BitbucketCloudRepoAssociation | BitbucketServerRepoAssociation;
120export declare type AssociationType = 'github' | 'bitbucket_cloud' | 'bitbucket_server';
121export interface App {
122 id: string;
123 name: string;
124 slug: string;
125 org: null | Org;
126 repo_url?: string;
127 association?: null | AppAssociation;
128}
129export interface Login {
130 user: User;
131 token: string;
132}
133export interface User {
134 id: number;
135 email: string;
136 oauth_identities?: OAuthIdentity;
137}
138export declare type OAuthIdentity = {
139 [A in AssociationType]?: OAuthIdentityDetails;
140};
141export interface OAuthIdentityDetails {
142 username: string;
143 name: string;
144 html_url: string;
145}
146export interface Snapshot {
147 id: string;
148 sha: string;
149 ref: string;
150 state: string;
151 created: string;
152 note: string;
153}
154export interface SSHKey {
155 id: string;
156 pubkey: string;
157 fingerprint: string;
158 annotation: string;
159 name: string;
160 created: string;
161 updated: string;
162}
163export interface SecurityProfile {
164 name: string;
165 tag: string;
166 type: 'development' | 'production';
167 created: string;
168 credentials: {
169 android?: object;
170 ios?: object;
171 };
172}
173export interface IConfig extends ζframework.BaseConfig<ConfigFile> {
174 getAPIUrl(): string;
175 getDashUrl(): string;
176 getGitHost(): string;
177 getGitPort(): number;
178 getHTTPConfig(): CreateRequestOptions;
179}
180export interface ProjectPersonalizationDetails {
181 name: string;
182 projectId: string;
183 packageId?: string;
184 version?: string;
185 description?: string;
186}
187export interface IProjectConfig {
188 name: string;
189 type?: ProjectType;
190 pro_id?: string;
191 readonly integrations: ProjectIntegrations;
192 readonly hooks?: Record<HookName, string | string[] | undefined>;
193 ssl?: {
194 key?: string;
195 cert?: string;
196 };
197}
198export interface MultiProjectConfig {
199 defaultProject?: string;
200 projects: {
201 [key: string]: IProjectConfig | undefined;
202 };
203}
204export declare type ProjectFile = IProjectConfig | MultiProjectConfig;
205export interface IProject {
206 readonly directory: string;
207 readonly filePath: string;
208 readonly name?: string;
209 readonly type: ProjectType;
210 readonly config: ζframework.BaseConfig<IProjectConfig>;
211 getDocsUrl(): Promise<string>;
212 getSourceDir(sourceRoot?: string): Promise<string>;
213 getDistDir(): Promise<string>;
214 getInfo(): Promise<InfoItem[]>;
215 detected(): Promise<boolean>;
216 createIntegration(name: IntegrationName): Promise<IIntegration>;
217 getIntegration(name: IntegrationName): Promise<Required<ProjectIntegration>>;
218 requireProId(): Promise<string>;
219 getPackageJson(pkgName?: string): Promise<[ζframework.PackageJson | undefined, string | undefined]>;
220 requirePackageJson(pkgName?: string): Promise<ζframework.PackageJson>;
221 personalize(details: ProjectPersonalizationDetails): Promise<void>;
222 registerAilments(registry: IAilmentRegistry): Promise<void>;
223 getBuildRunner(): Promise<ζbuild.BuildRunner<any> | undefined>;
224 getServeRunner(): Promise<ζserve.ServeRunner<any> | undefined>;
225 getGenerateRunner(): Promise<ζgenerate.GenerateRunner<any> | undefined>;
226 requireBuildRunner(): Promise<ζbuild.BuildRunner<any>>;
227 requireServeRunner(): Promise<ζserve.ServeRunner<any>>;
228 requireGenerateRunner(): Promise<ζgenerate.GenerateRunner<any>>;
229}
230export interface IIntegrationAddOptions {
231 enableArgs?: string[];
232 conflictHandler?(f: string, stats: fs.Stats): Promise<boolean>;
233 onFileCreate?(f: string): void;
234}
235export interface IIntegration {
236 readonly name: IntegrationName;
237 readonly summary: string;
238 readonly archiveUrl?: string;
239 add(opts?: IIntegrationAddOptions): Promise<void>;
240 enable(): Promise<void>;
241 disable(): Promise<void>;
242 getInfo(): Promise<InfoItem[]>;
243 personalize(details: ProjectPersonalizationDetails): Promise<void>;
244}
245export interface PackageVersions {
246 [key: string]: string;
247}
248export interface CommandMetadataOption extends ζframework.CommandMetadataOption {
249 private?: boolean;
250 hint?: string;
251}
252export interface ExitCodeException extends Error {
253 exitCode: number;
254}
255export interface CommandMetadata extends ζframework.CommandMetadata<ζframework.CommandMetadataInput, CommandMetadataOption> {
256 type: 'global' | 'project';
257}
258export declare type HydratedCommandMetadata = CommandMetadata & ζframework.HydratedCommandMetadata<ICommand, INamespace, CommandMetadata, ζframework.CommandMetadataInput, CommandMetadataOption>;
259export declare type CommandInstanceInfo = ζframework.CommandInstanceInfo<ICommand, INamespace, CommandMetadata, ζframework.CommandMetadataInput, CommandMetadataOption>;
260export declare type NamespaceLocateResult = ζframework.NamespaceLocateResult<ICommand, INamespace, CommandMetadata, ζframework.CommandMetadataInput, CommandMetadataOption>;
261export interface ISession {
262 login(email: string, password: string): Promise<void>;
263 tokenLogin(token: string): Promise<void>;
264 logout(): Promise<void>;
265 isLoggedIn(): boolean;
266 getUser(): {
267 id: number;
268 };
269 getUserToken(): string;
270}
271export interface IShellSpawnOptions extends SpawnOptions {
272 showCommand?: boolean;
273}
274export interface IShellOutputOptions extends IShellSpawnOptions {
275 fatalOnError?: boolean;
276 fatalOnNotFound?: boolean;
277 showError?: boolean;
278}
279export interface IShellRunOptions extends IShellOutputOptions {
280 stream?: NodeJS.WritableStream;
281 killOnExit?: boolean;
282 truncateErrorOutput?: number;
283}
284export interface IShell {
285 alterPath: (path: string) => string;
286 run(command: string, args: string[], options: IShellRunOptions): Promise<void>;
287 output(command: string, args: string[], options: IShellOutputOptions): Promise<string>;
288 spawn(command: string, args: string[], options: IShellSpawnOptions): ChildProcess;
289 cmdinfo(cmd: string, args?: string[], options?: ShellCommandOptions): Promise<string | undefined>;
290}
291export interface ITelemetry {
292 sendCommand(command: string, args: string[]): Promise<void>;
293}
294export declare type NpmClient = 'yarn' | 'npm';
295export declare type FeatureId = 'ssl-commands';
296export interface ConfigFile {
297 'version': string;
298 'telemetry': boolean;
299 'npmClient': NpmClient;
300 'interactive'?: boolean;
301 'proxy'?: string;
302 'ssl.cafile'?: string | string[];
303 'ssl.certfile'?: string | string[];
304 'ssl.keyfile'?: string | string[];
305 'urls.api'?: string;
306 'urls.dash'?: string;
307 'git.host'?: string;
308 'git.port'?: number;
309 'git.setup'?: boolean;
310 'user.id'?: number;
311 'user.email'?: string;
312 'tokens.user'?: string;
313 'tokens.telemetry'?: string;
314 'features.ssl-commands'?: boolean;
315}
316export interface SSLConfig {
317 cafile?: string | string[];
318 certfile?: string | string[];
319 keyfile?: string | string[];
320}
321export interface CreateRequestOptions {
322 ssl?: SSLConfig;
323 proxy?: string;
324}
325export declare type APIResponse = APIResponseSuccess | APIResponseError;
326export interface APIResponseMeta {
327 status: number;
328 version: string;
329 request_id: string;
330}
331export declare type APIResponseData = object | object[] | string;
332export interface APIResponseErrorDetails {
333 error_type: string;
334 parameter: string;
335 errors: string[];
336}
337export interface APIResponseError {
338 error: APIResponseErrorError;
339 meta: APIResponseMeta;
340}
341export interface APIResponseErrorError {
342 message: string;
343 link: string | null;
344 type: string;
345 details?: APIResponseErrorDetails[];
346}
347export interface APIResponseSuccess {
348 data: APIResponseData;
349 meta: APIResponseMeta;
350}
351export interface APIResponsePageTokenMeta extends APIResponseMeta {
352 prev_page_token?: string;
353 next_page_token?: string;
354}
355export declare type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'PURGE' | 'HEAD' | 'OPTIONS';
356export interface IClient {
357 config: IConfig;
358 make(method: HttpMethod, path: string): Promise<{
359 req: ζsuperagent.SuperAgentRequest;
360 }>;
361 do(req: ζsuperagent.SuperAgentRequest): Promise<APIResponseSuccess>;
362 paginate<T extends Response<object[]>>(args: PaginateArgs<T>): IPaginator<T>;
363}
364export declare type PaginateArgs<T extends Response<object[]>> = Pick<PaginatorDeps<T>, 'reqgen' | 'guard' | 'state' | 'max'>;
365export interface IPaginator<T extends Response<object[]>, S = PaginatorState> extends IterableIterator<Promise<T>> {
366 readonly state: S;
367}
368export declare type PaginatorRequestGenerator = () => Promise<{
369 req: ζsuperagent.SuperAgentRequest;
370}>;
371export declare type PaginatorGuard<T extends Response<object[]>> = (res: APIResponseSuccess) => res is T;
372export interface PaginatorState {
373 done: boolean;
374 loaded: number;
375}
376export interface PagePaginatorState extends PaginatorState {
377 page: number;
378 page_size?: number;
379}
380export interface TokenPaginatorState extends PaginatorState {
381 page_token?: string;
382}
383export interface PaginatorDeps<T extends Response<object[]>, S = PaginatorState> {
384 readonly client: IClient;
385 readonly reqgen: PaginatorRequestGenerator;
386 readonly guard: PaginatorGuard<T>;
387 readonly state?: Partial<S>;
388 readonly max?: number;
389}
390export declare type InfoItemGroup = 'ionic' | 'capacitor' | 'cordova' | 'system' | 'environment';
391export interface InfoItem {
392 group: InfoItemGroup;
393 key: string;
394 value: string;
395 flair?: string;
396 path?: string;
397}
398export interface BaseBuildOptions {
399 engine: string;
400 platform?: string;
401 project?: string;
402 '--': string[];
403}
404export interface BuildOptions<T extends ProjectType> extends BaseBuildOptions {
405 type: T;
406}
407export interface AngularBuildOptions extends BuildOptions<'angular'> {
408 /**
409 * The Angular architect configuration to use for builds.
410 *
411 * The `--prod` command line flag is a shortcut which translates to the
412 * 'production' configuration.
413 */
414 configuration?: string;
415 sourcemaps?: boolean;
416}
417export interface IonicAngularBuildOptions extends BuildOptions<'ionic-angular'> {
418 prod: boolean;
419 sourcemaps?: boolean;
420 aot: boolean;
421 minifyjs: boolean;
422 minifycss: boolean;
423 optimizejs: boolean;
424 env?: string;
425}
426export interface Ionic1BuildOptions extends BuildOptions<'ionic1'> {
427}
428export interface GenerateOptions {
429 type: string;
430 name: string;
431}
432export interface AngularGenerateOptions extends GenerateOptions {
433 [key: string]: any;
434}
435export interface IonicAngularGenerateOptions extends GenerateOptions {
436 module: boolean;
437 constants: boolean;
438}
439export interface ServeOptions {
440 address: string;
441 port: number;
442 ssl: boolean;
443 livereload: boolean;
444 proxy: boolean;
445 lab: boolean;
446 labHost: string;
447 labPort: number;
448 open: boolean;
449 browser?: string;
450 browserOption?: string;
451 devapp: boolean;
452 platform?: string;
453 project?: string;
454 '--': string[];
455 externalAddressRequired?: boolean;
456 engine: string;
457}
458export interface AngularServeOptions extends ServeOptions {
459 configuration?: string;
460 sourcemaps?: boolean;
461}
462export interface IonicAngularServeOptions extends ServeOptions {
463 sourcemaps?: boolean;
464 consolelogs: boolean;
465 serverlogs: boolean;
466 env?: string;
467 livereloadPort: number;
468 notificationPort: number;
469}
470export interface Ionic1ServeOptions extends ServeOptions {
471 consolelogs: boolean;
472 serverlogs: boolean;
473 livereloadPort: number;
474 notificationPort: number;
475}
476export interface LabServeDetails {
477 protocol: string;
478 address: string;
479 port: number;
480 ssl?: {
481 key: string;
482 cert: string;
483 };
484}
485export interface DevAppDetails {
486 channel?: string;
487 port: number;
488 commPort: number;
489 interfaces: {
490 address: string;
491 broadcast: string;
492 }[];
493}
494export interface ServeDetails {
495 custom: boolean;
496 protocol: string;
497 localAddress: string;
498 externalAddress: string;
499 port: number;
500 externalNetworkInterfaces: NetworkInterface[];
501 externallyAccessible: boolean;
502}
503export interface IAilment {
504 readonly id: string;
505 implicit: boolean;
506 projects?: ProjectType[];
507 getMessage(): Promise<string>;
508 detected(): Promise<boolean>;
509 getTreatmentSteps(): Promise<PatientTreatmentStep[]>;
510}
511export interface TreatableAilment extends IAilment {
512 readonly treatable: boolean;
513 getTreatmentSteps(): Promise<DoctorTreatmentStep[]>;
514}
515export interface PatientTreatmentStep {
516 message: string;
517}
518export interface DoctorTreatmentStep extends PatientTreatmentStep {
519 treat(): Promise<void>;
520}
521export interface IAilmentRegistry {
522 ailments: IAilment[];
523 register(ailment: IAilment): void;
524 get(id: string): IAilment | undefined;
525}
526export interface IonicContext {
527 readonly binPath: string;
528 readonly libPath: string;
529 readonly execPath: string;
530 readonly version: string;
531}
532export interface IonicEnvironment {
533 readonly flags: IonicEnvironmentFlags;
534 readonly client: IClient;
535 readonly config: IConfig;
536 readonly log: ILogger;
537 readonly prompt: ζframework.PromptModule;
538 readonly ctx: IonicContext;
539 readonly session: ISession;
540 readonly shell: IShell;
541 getInfo(): Promise<InfoItem[]>;
542}
543export interface IonicEnvironmentFlags {
544 readonly interactive: boolean;
545 readonly confirm: boolean;
546}
547export declare type DistTag = 'testing' | 'canary' | 'latest';
548export interface ICommand extends ζframework.ICommand<ICommand, INamespace, CommandMetadata, ζframework.CommandMetadataInput, CommandMetadataOption> {
549 readonly env: IonicEnvironment;
550 readonly project?: IProject;
551 execute(inputs: ζframework.CommandLineInputs, options: ζframework.CommandLineOptions, metadata: CommandInstanceInfo): Promise<void>;
552}
553export interface CommandPreRun extends ICommand {
554 preRun(inputs: ζframework.CommandLineInputs, options: ζframework.CommandLineOptions, metadata: CommandInstanceInfo): Promise<void>;
555}
556export interface INamespace extends ζframework.INamespace<ICommand, INamespace, CommandMetadata, ζframework.CommandMetadataInput, CommandMetadataOption> {
557 env: IonicEnvironment;
558 project?: IProject;
559}
560export interface ImageResource {
561 platform: string;
562 imageId?: string;
563 dest: string;
564 resType: string;
565 nodeName: string;
566 nodeAttributes: string[];
567 name: string;
568 width: number;
569 height: number;
570 density?: string;
571 orientation?: 'landscape' | 'portrait';
572}
573export interface ImageResourceTransformResult {
574 resource: ImageResource;
575 error?: Error;
576 tmpDest: string;
577}
578export interface ResourcesImageConfig {
579 name: string;
580 width: number;
581 height: number;
582 density?: string;
583 orientation?: 'landscape' | 'portrait';
584}
585export interface SourceImage {
586 ext: string;
587 imageId?: string;
588 cachedId?: string;
589 platform: string;
590 resType: string;
591 path: string;
592 vector: boolean;
593 width: number;
594 height: number;
595}
596export interface ImageUploadResponse {
597 Error: string;
598 Width: number;
599 Height: number;
600 Type: string;
601 Vector: boolean;
602}
603export interface ResourcesPlatform {
604 [imgType: string]: {
605 images: ResourcesImageConfig[];
606 nodeName: string;
607 nodeAttributes: string[];
608 };
609}
610export interface ResourcesConfig {
611 [propName: string]: ResourcesPlatform;
612}
613export declare type KnownPlatform = 'ios' | 'android' | 'wp8' | 'windows' | 'browser';
614export declare type KnownResourceType = 'icon' | 'splash';
615export interface StarterList {
616 starters: {
617 name: string;
618 id: string;
619 type: ProjectType;
620 }[];
621 integrations: {
622 name: IntegrationName;
623 id: string;
624 }[];
625}
626export interface StarterTemplate {
627 name: string;
628 type: ProjectType;
629 id: string;
630 description?: string;
631}
632export interface ResolvedStarterTemplate extends StarterTemplate {
633 archive: string;
634}
635export interface IPCMessage {
636 type: 'telemetry';
637 data: {
638 command: string;
639 args: string[];
640 };
641}