Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 14 additions & 28 deletions packages/cli/bin/download-connector-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const https = require('https');
const fs = require('fs');
const path = require('path');
const util = require('util');
const request = require('request-promise-native');

const readFileAsync = util.promisify(fs.readFile);
const writeFileAsync = util.promisify(fs.writeFile);

const DEST = path.resolve('generators/datasource/connectors.json');
Expand All @@ -15,36 +15,20 @@ const URL =
* so the list only has to be maintained in one place.
*/
async function download() {
var file = fs.createWriteStream(DEST);
var request = https
.get(URL, function(response) {
response.pipe(file);
file.on('finish', async function() {
file.close();
await transformConnectorJSON();
});
})
.on('error', function(err) {
fs.unlink(DEST);
return err;
});
}

/**
* This function transforms the array of Connector objects from
* loopback-workspace as follows:
*
* - Transforms the array into an object / map
* - Transforms display:password to type:password so it can be used by CLI directly
* - Transforms description to message so it can be used by CLI directly
*/
async function transformConnectorJSON() {
let data = await readFileAsync(DEST, 'utf-8');
data = JSON.parse(data);
const data = await request(URL, {json: true});
const out = {};

/**
* This transforms the array of Connector objects from
* loopback-workspace as follows:
*
* - Transforms the array into an object / map
* - Transforms display:password to type:password so it can be used by CLI directly
* - Transforms description to message so it can be used by CLI directly
*/
data.forEach(item => {
if (item.settings) {
Object.entries(item.settings).forEach(([key, value]) => {
Object.values(item.settings).forEach(value => {
if (value.display === 'password') {
value.type = 'password';
delete value.display;
Expand All @@ -58,6 +42,8 @@ async function transformConnectorJSON() {
}
out[item.name] = item;
});

// Write data to file
await writeFileAsync(DEST, JSON.stringify(out, null, 2));
}

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"mem-fs": "^1.1.3",
"mem-fs-editor": "^4.0.0",
"nsp": "^3.2.1",
"request": "^2.87.0",
"request-promise-native": "^1.0.5",
"rimraf": "^2.6.2",
"sinon": "^4.5.0",
"yeoman-assert": "^3.1.1",
Expand Down