forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.ts
More file actions
99 lines (89 loc) · 3.46 KB
/
commands.ts
File metadata and controls
99 lines (89 loc) · 3.46 KB
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
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as fs from 'fs-extra';
import { parse } from 'yaml';
import { CommandText, CommandOption } from '../base/command';
import { ClusterVersion, FunctionContent } from './types';
export class Utils {
static async getFuncYamlContent(dir: string): Promise<FunctionContent> {
let funcData: FunctionContent;
try {
const funcYaml: string = await fs.readFile(path.join(dir, 'func.yaml'), 'utf-8');
funcData = parse(funcYaml) as FunctionContent;
} catch (error) {
// ignore
}
return funcData;
}
}
export class ServerlessCommand {
static createFunction(language: string, template: string, location: string): CommandText {
return new CommandText(`func create ${location}`, undefined, [
new CommandOption('-l', language),
new CommandOption('-t', template)
]);
}
static buildFunction(location: string, image: string, clusterVersion: ClusterVersion | null): CommandText {
const commandText = new CommandText('func', 'build', [
new CommandOption('-p', location),
new CommandOption('-i', image),
new CommandOption('-v')
]);
if (clusterVersion) {
commandText.addOption(new CommandOption('-r', ''))
}
return commandText
}
static runFunction(location: string, runBuild: boolean): CommandText {
const commandText = new CommandText('func', 'run', [
new CommandOption('-p', location),
new CommandOption('-b', runBuild.toString())
]);
return commandText;
}
static deployFunction(location: string,
image: string,
namespace: string,
clusterVersion: ClusterVersion | null): CommandText {
const commandText = new CommandText('func', 'deploy', [
new CommandOption('-p', location),
new CommandOption('-i', image),
new CommandOption('-v')
]);
if (namespace){
commandText.addOption(new CommandOption('-n', namespace))
}
if (clusterVersion) {
commandText.addOption(new CommandOption('-r', ''))
}
return commandText;
}
static undeployFunction(name: string): CommandText {
const commandText = new CommandText('func', `delete ${name}`);
return commandText
}
static getClusterVersion(): CommandText {
return new CommandText('oc get clusterversion', undefined, [
new CommandOption('-o', 'josn')
]);
}
static config(functionPath: string, mode: string, isAdd: boolean): CommandText {
const commandText = new CommandText('func', 'config', [
new CommandOption(mode),
new CommandOption('-p', functionPath)
]);
if (isAdd) {
if (mode === 'git') {
commandText.addOption(new CommandOption('set'));
} else {
commandText.addOption(new CommandOption('add'));
}
} else {
commandText.addOption(new CommandOption('remove'));
}
return commandText;
}
}