-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
75 lines (64 loc) · 2.81 KB
/
utils.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
'use strict';
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const normalizeDirectoryPaths = originalPath => originalPath.replace(/\\/g, '/');
const buildBumpSummaryMessage = (numBumpedFiles, bumpType) => {
return `Bumped ${numBumpedFiles} task manifest file(s) using bump type ${bumpType}`;
};
const buildBumpedFileResultMessage = (oldVersion, newVersion, file) => {
return `Bumped ${oldVersion} to ${newVersion} in ${normalizeDirectoryPaths(file)}`;
};
const buildCliCommand = (args, options) => {
let command = 'azp-bump';
if (options) {
command = `${command} ${options}`;
}
return `${command} ${args}`;
};
const runAzpBumpCli = (args, options, isSilent = true) => {
const command = buildCliCommand(args, options);
return shell.exec(command, { silent: isSilent });
};
const runAzpBumpCliWithCallback = (args, options, isSilent = true, callback) => {
const command = buildCliCommand(args, options);
return shell.exec(command, { silent: isSilent }, callback);
};
const getFileContents = (filePath) => {
const file = fs.readFileSync(filePath, 'utf8');
return file;
};
const testContextRootDir = '.testcontext';
const libTestContextDir = 'lib';
const cliTestContextDir = 'cli';
const testContextRootDirPath = path.join(path.resolve('./'), testContextRootDir);
const libTestContextDirPath = path.join(testContextRootDirPath, libTestContextDir);
const cliTestContextDirPath = path.join(testContextRootDirPath, cliTestContextDir);
const libBaseErrorMessage = 'Fatal error occurred while attempting to bump file. Details:';
const cliBaseErrorMessage = `Fatal error encountered. ${libBaseErrorMessage}`;
const invalidTaskFileErrorDetails = 'Encountered one or more invalid tasks. Task must represent version as an object ' +
'under the \'version\' key with Major, Minor, and Patch fields (that start with Uppercase letters)';
module.exports = {
successfulReturnCode: 0,
testContextRootDir,
libTestContextRelativeDir: `${testContextRootDir}/${libTestContextDir}`,
cliTestContextRelativeDir: `${testContextRootDir}/${cliTestContextDir}`,
testContextRootDirPath,
libTestContextDirPath,
cliTestContextDirPath,
patchReleaseType: 'patch',
minorReleaseType: 'minor',
majorReleaseType: 'major',
defaultBumpType: 'patch',
buildBumpSummaryMessage,
buildBumpedFileResultMessage,
runAzpBumpCli,
runAzpBumpCliWithCallback,
getFileContents,
getTaskFromFile: (filePath) => JSON.parse(getFileContents(filePath)),
cliBaseErrorMessage,
invalidTaskFileErrorDetails,
buildExpectedCliErrorMessage: errorMessageDetails => `${cliBaseErrorMessage} ${errorMessageDetails}`,
buildExpectedLibErrorMessage: errorMessageDetails => `${libBaseErrorMessage} ${errorMessageDetails}`,
normalizeDirectoryPaths
};