-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (58 loc) · 2.42 KB
/
index.js
File metadata and controls
66 lines (58 loc) · 2.42 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
const core = require('@actions/core');
const fs = require('fs');
const path = process.cwd();
const sfdxJson = require(path + '/sfdx-project.json');
async function run() {
try {
// Reading the content of the README file
let readmeContent = fs.readFileSync(path + '/README.md', 'utf8');
// We need all package directories
const packageDirectories = sfdxJson.packageDirectories;
packageDirectories.forEach((dir) => {
const packageName = dir.package;
const packageKey = packageName + '@';
const packageVersionKeys = [];
const packageVersionIds = [];
Object.keys(sfdxJson.packageAliases).forEach((packageVersion) => {
if (packageVersion.startsWith(packageKey)) {
packageVersionKeys.push(packageVersion);
packageVersionIds.push(
sfdxJson.packageAliases[packageVersion]
);
}
});
// Only update package version if there's a new release
if (packageVersionIds.length > 1) {
const newPackageVersionId =
packageVersionIds[packageVersionIds.length - 1];
// Lets pop things so that we know what to delete
packageVersionKeys.pop();
packageVersionIds.pop();
// Removing all no longer needed package version keys
packageVersionKeys.forEach((version) => {
delete sfdxJson.packageAliases[version];
});
// And we need now all IDs to replace them in the README
packageVersionIds.forEach((id) => {
// If you want to use Regex to identify package version id => /04t(.*)\)/
readmeContent = readmeContent.replace(
id,
newPackageVersionId
);
});
}
});
// Writing back potential changes to the sfdx-project.json file...
fs.writeFileSync(
'./sfdx-project.json',
JSON.stringify(sfdxJson, null, 4).concat('\n'),
'utf8'
);
// And finally we're updating the README.
fs.writeFileSync(path + '/README.md', readmeContent, 'utf8');
core.setOutput('isSuccess', true);
} catch (error) {
core.setFailed(error.message);
}
}
run();