This repository was archived by the owner on Feb 3, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 3434 "inquirer" : " ^6.2.2" ,
3535 "ora" : " ^3.2.0" ,
3636 "pkg-install" : " ^1.0.0" ,
37+ "twilio-run" : " ^2.0.0-beta.12" ,
3738 "yargs" : " ^12.0.5"
3839 },
3940 "engines" : {
Original file line number Diff line number Diff line change 11const yargs = require ( 'yargs' ) ;
22const { handler, describe, cliInfo } = require ( './command' ) ;
3+ const listTemplates = require ( './commands/list-templates' ) ;
34
45function cli ( cwd ) {
56 yargs . help ( ) ;
@@ -22,6 +23,11 @@ function cli(cwd) {
2223 } ,
2324 argv => handler ( argv )
2425 ) ;
26+ yargs . command ( {
27+ command : 'list-templates' ,
28+ desc : 'List the available templates you can create a project with.' ,
29+ handler : argv => listTemplates ( argv )
30+ } ) ;
2531
2632 return yargs ;
2733}
Original file line number Diff line number Diff line change 1+ const { fetchListOfTemplates } = require ( 'twilio-run/dist/templating/actions' ) ;
2+ const ora = require ( 'ora' ) ;
3+ const chalk = require ( 'chalk' ) ;
4+
5+ const listTemplates = async function ( ) {
6+ const spinner = ora ( ) ;
7+ spinner . start ( 'Fetching available templates' ) ;
8+
9+ try {
10+ const templates = await fetchListOfTemplates ( ) ;
11+ spinner . stop ( ) ;
12+ templates . forEach ( template =>
13+ console . log (
14+ chalk `‣ ${ template . name } ({cyan ${ template . id } })\n {dim ${
15+ template . description
16+ } }`
17+ )
18+ ) ;
19+ } catch ( err ) {
20+ spinner . fail ( 'Could not retrieve templates' ) ;
21+ process . exit ( 1 ) ;
22+ return ;
23+ }
24+ } ;
25+
26+ module . exports = listTemplates ;
Original file line number Diff line number Diff line change 1+ const templateActions = require ( 'twilio-run/dist/templating/actions' ) ;
2+ const listTemplates = require ( '../src/commands/list-templates' ) ;
3+
4+ jest . mock ( 'twilio-run/dist/templating/actions' ) ;
5+
6+ describe ( 'listTemplates' , ( ) => {
7+ it ( 'gets templates from twilio-run and displays them' , async ( ) => {
8+ const consoleSpy = jest
9+ . spyOn ( global . console , 'log' )
10+ . mockImplementation ( ( ) => { } ) ;
11+ const template = {
12+ name : 'Test template' ,
13+ id : 'test-template' ,
14+ description : 'A template to test with'
15+ } ;
16+ templateActions . fetchListOfTemplates . mockResolvedValue ( [ template ] ) ;
17+
18+ await listTemplates ( ) ;
19+
20+ expect ( consoleSpy ) . toHaveBeenCalledTimes ( 1 ) ;
21+ expect ( consoleSpy ) . toHaveBeenCalledWith (
22+ expect . stringContaining ( template . name )
23+ ) ;
24+ expect ( consoleSpy ) . toHaveBeenCalledWith (
25+ expect . stringContaining ( template . id )
26+ ) ;
27+ expect ( consoleSpy ) . toHaveBeenCalledWith (
28+ expect . stringContaining ( template . description )
29+ ) ;
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments