@@ -5,140 +5,25 @@ import {
5
5
import chalk from 'chalk' ;
6
6
import { stripIndent } from 'common-tags' ;
7
7
import debug from 'debug' ;
8
- import dotenv from 'dotenv' ;
9
8
import ora , { Ora } from 'ora' ;
10
9
import path from 'path' ;
11
- import { Arguments , Argv } from 'yargs' ;
10
+ import { Argv } from 'yargs' ;
12
11
import { checkConfigForCredentials } from '../checks/check-credentials' ;
13
12
import checkProjectStructure from '../checks/project-structure' ;
13
+ import { DeployCliFlags , getConfigFromFlags } from '../config/deploy' ;
14
14
import { printConfigInfo , printDeployedResources } from '../printers/deploy' ;
15
15
import { errorMessage } from '../printers/utils' ;
16
16
import {
17
17
ApiErrorResponse ,
18
- getFunctionServiceSid ,
19
18
HttpError ,
20
19
saveLatestDeploymentData ,
21
20
} from '../serverless-api/utils' ;
22
- import { EnvironmentVariablesWithAuth } from '../types/generic' ;
23
- import { fileExists , readFile } from '../utils/fs' ;
24
- import { sharedCliOptions , SharedFlags } from './shared' ;
21
+ import { sharedCliOptions } from './shared' ;
25
22
import { CliInfo } from './types' ;
26
- import { deprecateProjectName , getFullCommand } from './utils' ;
23
+ import { getFullCommand } from './utils' ;
27
24
28
25
const log = debug ( 'twilio-run:deploy' ) ;
29
26
30
- export type DeployCliFlags = Arguments <
31
- SharedFlags & {
32
- cwd ?: string ;
33
- serviceSid ?: string ;
34
- functionsEnv : string ;
35
- projectName ?: string ;
36
- serviceName ?: string ;
37
- accountSid ?: string ;
38
- authToken ?: string ;
39
- env ?: string ;
40
- overrideExistingProject : boolean ;
41
- force : boolean ;
42
- functions : boolean ;
43
- assets : boolean ;
44
- assetsFolder ?: string ;
45
- functionsFolder ?: string ;
46
- }
47
- > & {
48
- _cliDefault ?: {
49
- username : string ;
50
- password : string ;
51
- } ;
52
- } ;
53
-
54
- async function getConfigFromFlags (
55
- flags : DeployCliFlags
56
- ) : Promise < DeployLocalProjectConfig > {
57
- const cwd = flags . cwd ? path . resolve ( flags . cwd ) : process . cwd ( ) ;
58
-
59
- let accountSid = '' ;
60
- let authToken = '' ;
61
- let localEnv : EnvironmentVariablesWithAuth = { } ;
62
-
63
- const envPath = path . resolve ( cwd , flags . env || '.env' ) ;
64
-
65
- if ( await fileExists ( envPath ) ) {
66
- const contentEnvFile = await readFile ( envPath , 'utf8' ) ;
67
- localEnv = dotenv . parse ( contentEnvFile ) ;
68
-
69
- accountSid =
70
- flags . accountSid ||
71
- localEnv . ACCOUNT_SID ||
72
- ( flags . _cliDefault && flags . _cliDefault . username ) ||
73
- '' ;
74
- authToken =
75
- flags . authToken ||
76
- localEnv . AUTH_TOKEN ||
77
- ( flags . _cliDefault && flags . _cliDefault . password ) ||
78
- '' ;
79
- } else if ( flags . env ) {
80
- throw new Error ( `Failed to find .env file at "${ envPath } "` ) ;
81
- }
82
-
83
- const serviceSid =
84
- flags . serviceSid ||
85
- ( await getFunctionServiceSid ( cwd , flags . config , 'deployConfig' ) ) ;
86
-
87
- const pkgJsonPath = path . join ( cwd , 'package.json' ) ;
88
- if ( ! ( await fileExists ( pkgJsonPath ) ) ) {
89
- throw new Error ( 'Failed to find package.json file' ) ;
90
- }
91
-
92
- const pkgContent = await readFile ( pkgJsonPath , 'utf8' ) ;
93
- const pkgJson = JSON . parse ( pkgContent ) ;
94
-
95
- const env = {
96
- ...localEnv ,
97
- } ;
98
-
99
- for ( let key of Object . keys ( env ) ) {
100
- const val = env [ key ] ;
101
- if ( typeof val === 'string' && val . length === 0 ) {
102
- delete env [ key ] ;
103
- }
104
- }
105
-
106
- delete env . ACCOUNT_SID ;
107
- delete env . AUTH_TOKEN ;
108
-
109
- let serviceName : string | undefined = flags . serviceName || pkgJson . name ;
110
- if ( typeof flags . projectName !== 'undefined' ) {
111
- deprecateProjectName ( ) ;
112
- if ( ! serviceName ) {
113
- serviceName = flags . projectName ;
114
- }
115
- }
116
-
117
- if ( ! serviceName ) {
118
- throw new Error (
119
- 'Please pass --service-name or add a "name" field to your package.json'
120
- ) ;
121
- }
122
-
123
- return {
124
- cwd,
125
- envPath,
126
- accountSid,
127
- authToken,
128
- env,
129
- serviceSid,
130
- pkgJson,
131
- overrideExistingService : flags . overrideExistingProject ,
132
- force : flags . force ,
133
- serviceName,
134
- functionsEnv : flags . functionsEnv ,
135
- functionsFolderName : flags . functionsFolder ,
136
- assetsFolderName : flags . assetsFolder ,
137
- noAssets : ! flags . assets ,
138
- noFunctions : ! flags . functions ,
139
- } ;
140
- }
141
-
142
27
function logError ( msg : string ) {
143
28
console . error ( chalk `{red.bold ERROR} ${ msg } ` ) ;
144
29
}
@@ -246,7 +131,13 @@ export const cliInfo: CliInfo = {
246
131
} ,
247
132
'functions-env' : {
248
133
type : 'string' ,
249
- describe : 'The environment name you want to use' ,
134
+ describe : 'DEPRECATED: Use --environment instead' ,
135
+ hidden : true ,
136
+ } ,
137
+ environment : {
138
+ type : 'string' ,
139
+ describe :
140
+ 'The environment name and domain suffix you want to use for your deployment' ,
250
141
default : 'dev' ,
251
142
} ,
252
143
'service-name' : {
0 commit comments