-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
96 lines (88 loc) · 3.77 KB
/
index.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
const core = require('@actions/core');
const fs = require('fs');
const toml = require('toml');
var json2toml = require('json2toml');
var enums = require('./enums');
try {
const componentType = core.getInput('componentType');
const subPath = core.getInput('subPath');
const type = core.getInput('type');
const config = toml.parse(fs.readFileSync(`${subPath}/Ballerina.toml`, 'utf-8'));
switch (type) {
case 'edit':
const name = core.getInput('name').replace(/[^\w-_]+/g, "").replace(/[^\w]+/g, "_");
const org = core.getInput('org').replace(/[^\w-_]+/g, "").replace(/[^\w]+/g, "_");
const template = core.getInput('template');
var package = new Object();
if (config.package) {
package = config.package;
}
if (componentType === enums.ChoreoRepository.USER_MANAGE_NON_EMPTY || componentType === enums.ChoreoRepository.USER_MANAGE_BUILDPACKS) {
!package.name ? package.name = name : null;
!package.org ? package.org = org : null;
} else {
package.name = name;
package.org = org;
if (enums.ChoreoBasicTemplates.indexOf(template) === -1) {
package.export = [name]
// Hack for breaking changes of ballerina 2201.1.1 update
fs.readFile(`${subPath}/Dependencies.toml`, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/choreo/g, org);
result = result.replace(/proj/g, name);
fs.writeFile(`${subPath}/Dependencies.toml`, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
}
}
config.package = package;
const isCloudTomlExists = fs.existsSync(`${subPath}/Cloud.toml`);
let cloudToml = {};
if (isCloudTomlExists) {
cloudToml = toml.parse(fs.readFileSync(`${subPath}/Cloud.toml`, 'utf-8'));
if (cloudToml.settings) {
cloudToml.settings.buildImage = false
} else {
cloudToml.settings = {
buildImage: false
};
}
} else {
cloudToml = {
settings: {
buildImage: false
}
};
}
fs.writeFileSync(`${subPath}/Ballerina.toml`, json2toml(config, { indent: 2, newlineAfterSection: true }));
fs.writeFileSync(`${subPath}/Cloud.toml`, json2toml(cloudToml, { indent: 2, newlineAfterSection: true }));
break;
case 'read':
const contex = '\
[ballerina]\n\
[ballerina.observe]\n\
enabled = true\n\
provider = "choreo"\n\
[ballerinax]\n\
[ballerinax.choreo]\n\
reporterHostname = "periscope.preview-dv.choreo.dev"\n\
reporterPort = 443';
var workspace = 'workspace';
if (config.package) {
// Replace default workspace name
if (config.package.name) {
workspace = config.package.name
}
}
fs.writeFileSync(`${subPath}/Config.toml`, contex, 'utf-8');
fs.writeFileSync(`${subPath}/workspace.txt`, workspace, 'utf-8');
break;
default:
break;
}
} catch (error) {
console.log(error, "Ballerinal.toml not found!");
}