1- import {
2- Command ,
3- CommandMap ,
4- CommandMapDefault ,
5- Namespace ,
6- NamespaceMap ,
7- generateCommandPath ,
8- } from '../command' ;
1+ import { CommandMetadata } from '../../definitions' ;
2+ import { Command , CommandMap , CommandMapDefault , Namespace , NamespaceMap , generateCommandPath } from '../command' ;
93
104class MyNamespace extends Namespace {
11- async getMetadata ( ) {
12- return { name : 'my' } ;
5+ async getMetadata ( ) : Promise < CommandMetadata > {
6+ return {
7+ name : 'my' ,
8+ summary : '' ,
9+ } ;
1310 }
1411
15- async getNamespaces ( ) {
12+ async getNamespaces ( ) : Promise < NamespaceMap > {
1613 return new NamespaceMap ( [
1714 [ 'foo' , async ( ) => new FooNamespace ( this ) ] ,
1815 [ 'defns' , async ( ) => new NamespaceWithDefault ( this ) ] ,
@@ -22,23 +19,29 @@ class MyNamespace extends Namespace {
2219}
2320
2421class NamespaceWithDefault extends Namespace {
25- async getMetadata ( ) {
26- return { name : 'defns' } ;
22+ async getMetadata ( ) : Promise < CommandMetadata > {
23+ return {
24+ name : 'defns' ,
25+ summary : '' ,
26+ } ;
2727 }
2828
29- async getCommands ( ) {
29+ async getCommands ( ) : Promise < CommandMap > {
3030 return new CommandMap ( [
3131 [ CommandMapDefault , async ( ) => new DefaultCommand ( this ) ] ,
3232 ] ) ;
3333 }
3434}
3535
3636class FooNamespace extends Namespace {
37- async getMetadata ( ) {
38- return { name : 'foo' } ;
37+ async getMetadata ( ) : Promise < CommandMetadata > {
38+ return {
39+ name : 'foo' ,
40+ summary : '' ,
41+ } ;
3942 }
4043
41- async getCommands ( ) {
44+ async getCommands ( ) : Promise < CommandMap > {
4245 return new CommandMap ( [
4346 [ 'bar' , async ( ) => new BarCommand ( this ) ] ,
4447 [ 'baz' , async ( ) => new BazCommand ( this ) ] ,
@@ -48,37 +51,45 @@ class FooNamespace extends Namespace {
4851}
4952
5053class EmptyNamespace extends Namespace {
51- async getMetadata ( ) {
52- return { name : 'empty' } ;
54+ async getMetadata ( ) : Promise < CommandMetadata > {
55+ return {
56+ name : 'empty' ,
57+ summary : '' ,
58+ } ;
5359 }
5460}
5561
5662class DefaultCommand extends Command {
57- async getMetadata ( ) {
58- return { name : 'def' , description : '' } ;
63+ async getMetadata ( ) : Promise < CommandMetadata > {
64+ return {
65+ name : 'def' ,
66+ summary : '' ,
67+ } ;
5968 }
69+
70+ async run ( ) { }
6071}
6172
6273class BarCommand extends Command {
63- async getMetadata ( ) {
64- return { name : 'bar' , description : '' } ;
74+ async getMetadata ( ) : Promise < CommandMetadata > {
75+ return {
76+ name : 'bar' ,
77+ summary : '' ,
78+ } ;
6579 }
66- }
6780
68- class BazCommand extends Command {
69- async getMetadata ( ) {
70- return { name : 'baz' , description : '' } ;
71- }
81+ async run ( ) { }
7282}
7383
74- class FooCommand extends Command {
75- async getMetadata ( ) {
84+ class BazCommand extends Command {
85+ async getMetadata ( ) : Promise < CommandMetadata > {
7686 return {
77- name : 'foo' ,
78- type : 'global' ,
79- description : '' ,
87+ name : 'baz' ,
88+ summary : '' ,
8089 } ;
8190 }
91+
92+ async run ( ) { }
8293}
8394
8495describe ( '@ionic/cli-framework' , ( ) => {
@@ -90,7 +101,7 @@ describe('@ionic/cli-framework', () => {
90101 describe ( 'root and parent' , ( ) => {
91102
92103 it ( 'should have root attribute' , async ( ) => {
93- const testNamespace = async ns => {
104+ const testNamespace = async ( ns : Namespace ) => {
94105 const namespaces = await ns . getNamespaces ( ) ;
95106
96107 for ( let [ , nsgetter ] of namespaces . entries ( ) ) {
@@ -107,7 +118,7 @@ describe('@ionic/cli-framework', () => {
107118 } ) ;
108119
109120 it ( 'should have parent attribute' , async ( ) => {
110- const testNamespace = async ns => {
121+ const testNamespace = async ( ns : Namespace ) => {
111122 const namespaces = await ns . getNamespaces ( ) ;
112123
113124 for ( let [ , nsgetter ] of namespaces . entries ( ) ) {
@@ -128,7 +139,7 @@ describe('@ionic/cli-framework', () => {
128139 describe ( 'getNamespaces' , ( ) => {
129140
130141 it ( 'should get subnamespaces' , async ( ) => {
131- const testNamespace = async ns => {
142+ const testNamespace = async ( ns : Namespace ) => {
132143 const commands = await ns . getCommands ( ) ;
133144 const namespaces = await ns . getNamespaces ( ) ;
134145
@@ -297,7 +308,9 @@ describe('@ionic/cli-framework', () => {
297308 const ns = new MyNamespace ( ) ;
298309 const result = await ns . getCommandMetadataList ( ) ;
299310 const bar = result . find ( c => c . command instanceof BarCommand ) ;
300- expect ( bar ) . toBeDefined ( ) ;
311+ if ( ! bar ) {
312+ throw new Error ( 'bar not defined' ) ;
313+ }
301314 expect ( bar . path . length ) . toEqual ( 3 ) ;
302315 expect ( bar . path [ 0 ] [ 0 ] ) . toEqual ( 'my' ) ;
303316 expect ( bar . path [ 0 ] [ 1 ] ) . toBe ( ns ) ;
@@ -312,11 +325,17 @@ describe('@ionic/cli-framework', () => {
312325 const result = await ns . getCommandMetadataList ( ) ;
313326 expect ( result . length ) . toEqual ( 3 ) ;
314327 const bar = result . find ( c => c . command instanceof BarCommand ) ;
315- expect ( bar ) . toBeDefined ( ) ;
328+ if ( ! bar ) {
329+ throw new Error ( 'bar not defined' ) ;
330+ }
316331 const baz = result . find ( c => c . command instanceof BazCommand ) ;
317- expect ( baz ) . toBeDefined ( ) ;
332+ if ( ! baz ) {
333+ throw new Error ( 'baz not defined' ) ;
334+ }
318335 const def = result . find ( c => c . command instanceof DefaultCommand ) ;
319- expect ( def ) . toBeDefined ( ) ;
336+ if ( ! def ) {
337+ throw new Error ( 'def not defined' ) ;
338+ }
320339 expect ( bar . aliases ) . toEqual ( [ 'my foo b' ] ) ;
321340 expect ( def . aliases ) . toEqual ( [ ] ) ;
322341 expect ( baz . aliases ) . toEqual ( [ ] ) ;
@@ -333,7 +352,7 @@ describe('@ionic/cli-framework', () => {
333352 it ( 'should get path for single namespace and command' , async ( ) => {
334353 const ns = new FooNamespace ( ) ;
335354 const { obj } = await ns . locate ( [ 'bar' ] ) ;
336- const result = await generateCommandPath ( obj ) ;
355+ const result = await generateCommandPath ( obj as any ) ;
337356 expect ( result . length ) . toEqual ( 2 ) ;
338357 const [ foons , barcmd ] = result ;
339358 expect ( foons ) . toBeDefined ( ) ;
@@ -347,7 +366,7 @@ describe('@ionic/cli-framework', () => {
347366 it ( 'should work back through nested namespace' , async ( ) => {
348367 const ns = new MyNamespace ( ) ;
349368 const { obj } = await ns . locate ( [ 'foo' , 'bar' ] ) ;
350- const result = await generateCommandPath ( obj ) ;
369+ const result = await generateCommandPath ( obj as any ) ;
351370 expect ( result . length ) . toEqual ( 3 ) ;
352371 const [ rootns , foons , barcmd ] = result ;
353372 expect ( rootns ) . toEqual ( [ 'my' , ns ] ) ;
0 commit comments