@@ -17,12 +17,13 @@ const fetch = require('node-fetch');
17
17
const path = require ( 'path' ) ;
18
18
const semver = require ( 'semver' ) ;
19
19
20
- const { CLIENT_SECRET , ENV_NAME , IMS_USER_EMAIL , IMS_USER_ID , IMS_PASSWORD , IMS_ORG } = process . env ;
20
+ const { ENV_NAME , IMS_ORG } = process . env ;
21
21
22
22
const args = process . argv . slice ( 2 ) ;
23
23
24
24
const { ENVIRONMENTS } = require ( './constants' ) ;
25
25
const fetchAccessToken = require ( './fetch.access.token' ) ;
26
+ const fetchPlugin = require ( './fetch.plugin' ) ;
26
27
const readPluginJsonFromPackage = require ( './read.plugin.json.from.package' ) ;
27
28
28
29
const CREATE_QUERY = `
@@ -48,10 +49,11 @@ const UPDATE_QUERY = `
48
49
throw new Error ( 'You need to set IMS_ORG in your environment' ) ;
49
50
}
50
51
51
- const env = ENV_NAME || 'prod' ;
52
- const { GRAFFIAS_SERVER , IMS_HOST } = ENVIRONMENTS [ env ] ;
52
+ const environmentIndex = args . find ( arg => arg . startsWith ( '--environment=' ) ) ;
53
+ const env = environmentIndex ? environmentIndex . split ( '=' ) [ 1 ] : ENV_NAME || 'prod' ;
54
+ const { GRAFFIAS_SERVER } = ENVIRONMENTS [ env ] ;
53
55
54
- const zipFile = args [ 0 ] ;
56
+ const zipFile = args [ args . length - 1 ] ;
55
57
if ( ! zipFile ) {
56
58
throw new Error ( 'You must provide the zip plugin package as an argument.' ) ;
57
59
}
@@ -64,44 +66,9 @@ const UPDATE_QUERY = `
64
66
65
67
const { namespace, version } = descriptor ;
66
68
67
- const tokenResponseJson = await fetchAccessToken ( {
68
- CLIENT_SECRET ,
69
- IMS_PASSWORD ,
70
- IMS_HOST ,
71
- IMS_USER_EMAIL ,
72
- IMS_USER_ID
73
- } ) ;
74
-
75
- const queryPluginsResponse = await fetch ( GRAFFIAS_SERVER , {
76
- method : 'POST' ,
77
- headers : {
78
- 'x-gw-ims-org-id' : IMS_ORG ,
79
- 'x-gw-ims-user-id' : tokenResponseJson . userId ,
80
- 'x-api-key' : 'NovaTestToken' ,
81
- Authorization : `Bearer ${ tokenResponseJson . access_token } ` ,
82
- Accept : 'application/json' ,
83
- 'Content-Type' : 'application/json;charset=UTF-8'
84
- } ,
85
- body : JSON . stringify ( {
86
- query : `
87
- query queryPlugins($namespace: String){
88
- plugins (namespace:$namespace){
89
- uuid
90
- namespace
91
- version
92
- }
93
- }` ,
94
- variables : { namespace }
95
- } )
96
- } ) ;
97
-
98
- const plugins = await queryPluginsResponse . json ( ) ;
99
-
100
- if ( ! plugins || ! plugins . data || ! plugins . data . plugins ) {
101
- throw new Error ( 'There was a problem fetching plugins from the server.' ) ;
102
- }
69
+ const tokenResponseJson = await fetchAccessToken ( env ) ;
103
70
104
- const foundPlugin = plugins . data . plugins . find ( plugin => plugin . namespace === namespace ) ;
71
+ const foundPlugin = await fetchPlugin ( namespace , env ) ;
105
72
106
73
if ( foundPlugin ) {
107
74
if ( semver . lt ( version , foundPlugin . version ) ) {
@@ -134,8 +101,7 @@ const UPDATE_QUERY = `
134
101
} ) ;
135
102
136
103
const uploadedPlugin = await uploadPluginResponse . json ( ) ;
137
- const uuid = uploadedPlugin . data && uploadedPlugin . data [ field ]
138
- ? uploadedPlugin . data [ field ] . uuid : null ;
104
+ const uuid = uploadedPlugin . data ?. [ field ] ?. uuid || null ;
139
105
140
106
if ( uuid ) {
141
107
console . log ( `Uploaded plugin uuid: ${ uuid } ` ) ;
0 commit comments