This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
templatesProvider.js
executable file
·111 lines (86 loc) · 3.44 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
*
* 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 { promisify } = require('util');
const exec = promisify(require('child_process').exec);
module.exports = {
canHandle: function(repository) {
return repository.id &&
Array.isArray(repository.projectStyles) &&
repository.projectStyles.includes('Appsody');
},
addRepository: async function(repository) {
// no-op
if (!repository.url.endsWith('index.json'))
return;
let url = repository.url;
url = url.substring(0, url.length - 10) + 'index.yaml';
await exec(`${__dirname}/appsody repo add ${repository.id} ${url}`);
},
removeRepository: async function(repository) {
await exec(`${__dirname}/appsody repo remove ${repository.id}`);
},
getRepositories: async function() {
const repos = [];
try {
const result = await exec(`${__dirname}/appsody repo list -o json`);
const json = JSON.parse(result.stdout);
for (const repo of json.repositories) {
const name = repo.name;
let url = repo.url;
if (name != 'experimental' && url.endsWith('index.yaml')) {
url = url.substring(0, url.length - 10) + 'index.json';
repos.push({
id: name,
name: `Appsody Stacks - ${name}`,
description: 'Use Appsody in Codewind to develop applications with sharable technology stacks.',
url
});
}
}
}
catch (err) {
console.error('Appsody extension: failed to retrieve repositories');
console.error(err.message);
}
return repos;
},
getProjectTypes: async function(id) {
const projectTypes = [];
try {
const result = await exec(`${__dirname}/appsody list ${id} -o json`);
const json = JSON.parse(result.stdout);
for (const repo of json.repositories) {
for (const stack of repo.stacks) {
projectTypes.push({
projectType: 'appsodyExtension',
projectSubtypes: {
label: 'Appsody stack',
items: [{
id: `${repo.repositoryName}/${stack.id}`,
version: stack.version,
label: `Appsody ${stack.id}`,
description: stack.description
}]
}
});
}
}
}
catch (err) {
console.error('Appsody extension: failed to retrieve project types');
console.error(err.message);
}
return projectTypes;
}
}