@@ -2,8 +2,8 @@ const https = require('https');
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
44const util = require ( 'util' ) ;
5+ const request = require ( 'request-promise-native' ) ;
56
6- const readFileAsync = util . promisify ( fs . readFile ) ;
77const writeFileAsync = util . promisify ( fs . writeFile ) ;
88
99const DEST = path . resolve ( 'generators/datasource/connectors.json' ) ;
@@ -15,36 +15,20 @@ const URL =
1515 * so the list only has to be maintained in one place.
1616 */
1717async function download ( ) {
18- var file = fs . createWriteStream ( DEST ) ;
19- var request = https
20- . get ( URL , function ( response ) {
21- response . pipe ( file ) ;
22- file . on ( 'finish' , async function ( ) {
23- file . close ( ) ;
24- await transformConnectorJSON ( ) ;
25- } ) ;
26- } )
27- . on ( 'error' , function ( err ) {
28- fs . unlink ( DEST ) ;
29- return err ;
30- } ) ;
31- }
32-
33- /**
34- * This function transforms the array of Connector objects from
35- * loopback-workspace as follows:
36- *
37- * - Transforms the array into an object / map
38- * - Transforms display:password to type:password so it can be used by CLI directly
39- * - Transforms description to message so it can be used by CLI directly
40- */
41- async function transformConnectorJSON ( ) {
42- let data = await readFileAsync ( DEST , 'utf-8' ) ;
43- data = JSON . parse ( data ) ;
18+ const data = await request ( URL , { json : true } ) ;
4419 const out = { } ;
20+
21+ /**
22+ * This transforms the array of Connector objects from
23+ * loopback-workspace as follows:
24+ *
25+ * - Transforms the array into an object / map
26+ * - Transforms display:password to type:password so it can be used by CLI directly
27+ * - Transforms description to message so it can be used by CLI directly
28+ */
4529 data . forEach ( item => {
4630 if ( item . settings ) {
47- Object . entries ( item . settings ) . forEach ( ( [ key , value ] ) => {
31+ Object . values ( item . settings ) . forEach ( value => {
4832 if ( value . display === 'password' ) {
4933 value . type = 'password' ;
5034 delete value . display ;
@@ -58,6 +42,8 @@ async function transformConnectorJSON() {
5842 }
5943 out [ item . name ] = item ;
6044 } ) ;
45+
46+ // Write data to file
6147 await writeFileAsync ( DEST , JSON . stringify ( out , null , 2 ) ) ;
6248}
6349
0 commit comments