This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
add-cx-server.ts
76 lines (65 loc) · 2.22 KB
/
add-cx-server.ts
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
/*!
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
import { Command, flags } from '@oclif/command';
import * as Listr from 'listr';
import * as path from 'path';
import { CopyDescriptor, copyFiles, findConflicts } from '../utils/';
export default class AddCxServer extends Command {
static description = 'Add the scripts to set up a Jenkins master for CI/CD of your project';
static examples = ['$ sap-cloud-sdk add-cx-server'];
static flags = {
force: flags.boolean({
description: 'Do not fail if a file already exist and overwrite it.'
}),
platform: flags.string({
hidden: true,
default: process.platform,
description: 'The currently running OS.'
}),
help: flags.help({
char: 'h',
description: 'Show help for the add-cx-server command.'
})
};
static args = [
{
name: 'projectDir',
description: 'Path to the project directory to which the cx-server should be added.'
}
];
async run() {
const { flags, args } = this.parse(AddCxServer);
const projectDir = args.projectDir || '.';
const options = await this.getOptions();
try {
const files = [this.copyDescriptorForGithub('cx-server', projectDir), this.copyDescriptorForGithub('server.cfg', projectDir)];
if (flags.platform === 'win32') {
files.push(this.copyDescriptorForGithub('cx-server.bat', projectDir));
}
const tasks = new Listr([
{
title: 'Finding potential conflicts',
task: async () => findConflicts(files, flags.force).catch(e => this.error(e, { exit: 11 }))
},
{
title: 'Creating files',
task: async () => copyFiles(files, options)
}
]);
await tasks.run();
} catch (error) {
this.error(error, { exit: 1 });
}
}
private copyDescriptorForGithub(fileName: string, projectDir: string): CopyDescriptor {
const githubPrefix = 'https://raw.githubusercontent.com/SAP/devops-docker-cx-server/master/cx-server-companion/life-cycle-scripts/';
return {
sourcePath: new URL(fileName, githubPrefix),
fileName: path.resolve(projectDir, 'cx-server', fileName)
};
}
private async getOptions() {
return {};
}
}