@@ -5,20 +5,20 @@ import prompts from 'prompts';
5
5
import { Merge } from 'type-fest' ;
6
6
import { Arguments , Argv } from 'yargs' ;
7
7
import checkProjectStructure from '../checks/project-structure' ;
8
+ import { downloadTemplate , fetchListOfTemplates } from '../templating/actions' ;
8
9
import { CliInfo } from './types' ;
9
10
import { getFullCommand } from './utils' ;
10
- import { downloadTemplate , fetchListOfTemplates } from '../templating/actions' ;
11
11
12
12
export type NewCliFlags = Arguments < {
13
- filename ?: string ;
13
+ namespace ?: string ;
14
14
template ?: string ;
15
15
list ?: string ;
16
16
} > ;
17
17
18
18
export type NewConfig = Merge <
19
19
NewCliFlags ,
20
20
{
21
- filename ?: string ;
21
+ namespace ?: string ;
22
22
template ?: string ;
23
23
}
24
24
> ;
@@ -62,11 +62,12 @@ async function getMissingInfo(flags: NewCliFlags): Promise<NewConfig> {
62
62
} ) ;
63
63
}
64
64
65
- if ( ! flags . filename ) {
65
+ if ( ! flags . namespace ) {
66
66
questions . push ( {
67
67
type : 'text' ,
68
- name : 'filename' ,
69
- message : 'What should be the name of your function?' ,
68
+ name : 'namespace' ,
69
+ message :
70
+ 'What should be the namespace your function(s) are placed under?' ,
70
71
validate : ( input : string ) => {
71
72
if ( input . length < 1 || input . includes ( ' ' ) ) {
72
73
return 'Your name cannot include whitespace' ;
@@ -79,7 +80,7 @@ async function getMissingInfo(flags: NewCliFlags): Promise<NewConfig> {
79
80
if ( questions . length === 0 ) {
80
81
return {
81
82
...flags ,
82
- filename : flags . filename ,
83
+ namespace : flags . namespace ,
83
84
template : flags . template ,
84
85
} ;
85
86
}
@@ -88,7 +89,7 @@ async function getMissingInfo(flags: NewCliFlags): Promise<NewConfig> {
88
89
return {
89
90
...flags ,
90
91
template : flags . template || answers . template ,
91
- filename : flags . filename || answers . filename ,
92
+ namespace : flags . namespace || answers . namespace ,
92
93
} ;
93
94
}
94
95
@@ -120,17 +121,17 @@ export async function handler(flagsInput: NewCliFlags): Promise<void> {
120
121
const flags = await getMissingInfo ( flagsInput ) ;
121
122
122
123
if (
123
- typeof flags . filename === 'undefined' ||
124
- flags . filename . length === 0 ||
124
+ typeof flags . namespace === 'undefined' ||
125
+ flags . namespace . length === 0 ||
125
126
typeof flags . template === 'undefined' ||
126
- flags . filename . length === 0
127
+ flags . namespace . length === 0
127
128
) {
128
129
return ;
129
130
}
130
131
131
- const bundleName = flags . filename . replace ( / \. j s $ / , '' ) ;
132
+ const sanitizedNamespace = flags . namespace . replace ( / \. j s $ / , '' ) ;
132
133
133
- downloadTemplate ( flags . template , bundleName , targetDirectory ) ;
134
+ downloadTemplate ( flags . template , sanitizedNamespace , targetDirectory ) ;
134
135
}
135
136
136
137
export const cliInfo : CliInfo = {
@@ -162,7 +163,7 @@ function optionBuilder(yargs: Argv<any>): Argv<NewCliFlags> {
162
163
return yargs ;
163
164
}
164
165
165
- export const command = [ 'new [filename ]' , 'template [filename ]' ] ;
166
+ export const command = [ 'new [namespace ]' , 'template [namespace ]' ] ;
166
167
export const describe =
167
168
'Creates a new Twilio Function based on an existing template' ;
168
169
export const builder = optionBuilder ;
0 commit comments