forked from eclipse-archived/codewind-appsody-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templatesProvider.js
executable file
·67 lines (50 loc) · 2.19 KB
/
templatesProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
*
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*
*******************************************************************************/
'use strict';
const { exec } = require('child_process');
const os = require('os');
module.exports = {
getRepositories: async function() {
return new Promise((resolve, reject) => {
// not support on k8s at the moment, return empty list
if (global.codewind && global.codewind.RUNNING_IN_K8S)
return resolve([]);
// list of repositories start on 3rd line
exec(`${__dirname}/appsody repo list | tail -n+3`, (err, stdout) => {
if (err)
return reject(err);
const repos = [];
stdout.split(os.EOL).forEach((line) => {
// split the line: <name> <url>
const pair = line.trim().split(/\s+/);
// appsody uses index.yaml, change that to index.json
if (pair.length >= 2) {
let name = pair[0];
// chop of the default repo indicator if present
if (name.startsWith('*'))
name = name.substring(1);
if (name != 'experimental' && pair[1].endsWith('index.yaml')) {
let url = pair[1];
url = url.substring(0, url.length - 10) + 'index.json';
repos.push({
description: `Appsody Stacks - ${name}`,
url: url
});
}
}
});
resolve(repos);
});
});
}
}