1
- const {
2
- promptForAccountDetails,
3
- promptForProjectName
4
- } = require ( './create-twilio-function/prompt' ) ;
1
+ const { promisify } = require ( 'util' ) ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ const ora = require ( 'ora' ) ;
5
+ const boxen = require ( 'boxen' ) ;
6
+ const rimraf = promisify ( require ( 'rimraf' ) ) ;
7
+ const { downloadTemplate } = require ( 'twilio-run/dist/templating/actions' ) ;
8
+
9
+ const { promptForAccountDetails, promptForProjectName } = require ( './create-twilio-function/prompt' ) ;
5
10
const validateProjectName = require ( './create-twilio-function/validate-project-name' ) ;
6
11
const {
7
12
createDirectory,
8
13
createEnvFile,
9
14
createExampleFromTemplates,
10
15
createPackageJSON,
11
- createNvmrcFile
16
+ createNvmrcFile,
12
17
} = require ( './create-twilio-function/create-files' ) ;
13
18
const createGitignore = require ( './create-twilio-function/create-gitignore' ) ;
14
19
const importCredentials = require ( './create-twilio-function/import-credentials' ) ;
15
- const {
16
- installDependencies
17
- } = require ( './create-twilio-function/install-dependencies' ) ;
20
+ const { installDependencies } = require ( './create-twilio-function/install-dependencies' ) ;
18
21
const successMessage = require ( './create-twilio-function/success-message' ) ;
19
- const ora = require ( 'ora' ) ;
20
- const boxen = require ( 'boxen' ) ;
21
- const { downloadTemplate } = require ( 'twilio-run/dist/templating/actions' ) ;
22
- const { promisify } = require ( 'util' ) ;
23
- const rimraf = promisify ( require ( 'rimraf' ) ) ;
24
- const path = require ( 'path' ) ;
25
22
26
23
async function cleanUpAndExit ( projectDir , spinner , errorMessage ) {
27
24
spinner . fail ( errorMessage ) ;
@@ -48,13 +45,11 @@ async function createTwilioFunction(config) {
48
45
switch ( e . code ) {
49
46
case 'EEXIST' :
50
47
spinner . fail (
51
- `A directory called '${ config . name } ' already exists. Please create your function in a new directory.`
48
+ `A directory called '${ config . name } ' already exists. Please create your function in a new directory.` ,
52
49
) ;
53
50
break ;
54
51
case 'EACCES' :
55
- spinner . fail (
56
- `You do not have permission to create files or directories in the path '${ config . path } '.`
57
- ) ;
52
+ spinner . fail ( `You do not have permission to create files or directories in the path '${ config . path } '.` ) ;
58
53
break ;
59
54
default :
60
55
spinner . fail ( e . message ) ;
@@ -68,14 +63,17 @@ async function createTwilioFunction(config) {
68
63
if ( Object . keys ( accountDetails ) . length === 0 ) {
69
64
accountDetails = await promptForAccountDetails ( config ) ;
70
65
}
71
- config = { ...accountDetails , ...config } ;
66
+ config = {
67
+ ...accountDetails ,
68
+ ...config ,
69
+ } ;
72
70
73
71
// Scaffold project
74
72
spinner . start ( 'Creating project directories and files' ) ;
75
73
76
74
await createEnvFile ( projectDir , {
77
75
accountSid : config . accountSid ,
78
- authToken : config . authToken
76
+ authToken : config . authToken ,
79
77
} ) ;
80
78
await createNvmrcFile ( projectDir ) ;
81
79
await createPackageJSON ( projectDir , config . name ) ;
@@ -88,11 +86,7 @@ async function createTwilioFunction(config) {
88
86
await downloadTemplate ( config . template , '' , projectDir ) ;
89
87
spinner . succeed ( ) ;
90
88
} catch ( err ) {
91
- await cleanUpAndExit (
92
- projectDir ,
93
- spinner ,
94
- `The template "${ config . template } " doesn't exist`
95
- ) ;
89
+ await cleanUpAndExit ( projectDir , spinner , `The template "${ config . template } " doesn't exist` ) ;
96
90
return ;
97
91
}
98
92
} else {
@@ -118,14 +112,17 @@ async function createTwilioFunction(config) {
118
112
} catch ( err ) {
119
113
spinner . fail ( ) ;
120
114
console . log (
121
- `There was an error installing the dependencies, but your project is otherwise complete in ./${ config . name } `
115
+ `There was an error installing the dependencies, but your project is otherwise complete in ./${ config . name } ` ,
122
116
) ;
123
117
}
124
118
125
119
// Success message
126
120
127
121
console . log (
128
- boxen ( await successMessage ( config ) , { padding : 1 , borderStyle : 'round' } )
122
+ boxen ( await successMessage ( config ) , {
123
+ padding : 1 ,
124
+ borderStyle : 'round' ,
125
+ } ) ,
129
126
) ;
130
127
}
131
128
0 commit comments