@bitblit/ratchet-node-only 4.0.80-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/build/ratchet-node-only-info.js +18 -0
- package/dist/cjs/ci/apply-ci-env-variables-to-files.js +82 -0
- package/dist/cjs/ci/ci-run-information-util.js +47 -0
- package/dist/cjs/ci/ci-run-information.js +2 -0
- package/dist/cjs/cli/abstract-ratchet-cli-handler.js +32 -0
- package/dist/cjs/cli/cli-ratchet.js +33 -0
- package/dist/cjs/cli/ratchet-cli-handler.js +21 -0
- package/dist/cjs/csv/csv-ratchet.js +163 -0
- package/dist/cjs/files/files-to-static-class.js +61 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/third-party/git/git-ratchet.js +74 -0
- package/dist/cjs/third-party/slack/publish-ci-release-to-slack.js +64 -0
- package/dist/es/build/ratchet-node-only-info.js +14 -0
- package/dist/es/ci/apply-ci-env-variables-to-files.js +77 -0
- package/dist/es/ci/ci-run-information-util.js +43 -0
- package/dist/es/ci/ci-run-information.js +1 -0
- package/dist/es/cli/abstract-ratchet-cli-handler.js +28 -0
- package/dist/es/cli/cli-ratchet.js +28 -0
- package/dist/es/cli/ratchet-cli-handler.js +17 -0
- package/dist/es/csv/csv-ratchet.js +158 -0
- package/dist/es/files/files-to-static-class.js +56 -0
- package/dist/es/index.js +11 -0
- package/dist/es/third-party/git/git-ratchet.js +69 -0
- package/dist/es/third-party/slack/publish-ci-release-to-slack.js +59 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.es.tsbuildinfo +1 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/build/ratchet-node-only-info.d.ts +5 -0
- package/dist/types/ci/apply-ci-env-variables-to-files.d.ts +11 -0
- package/dist/types/ci/ci-run-information-util.d.ts +8 -0
- package/dist/types/ci/ci-run-information.d.ts +9 -0
- package/dist/types/cli/abstract-ratchet-cli-handler.d.ts +6 -0
- package/dist/types/cli/cli-ratchet.d.ts +6 -0
- package/dist/types/cli/ratchet-cli-handler.d.ts +6 -0
- package/dist/types/csv/csv-ratchet.d.ts +27 -0
- package/dist/types/files/files-to-static-class.d.ts +8 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/third-party/git/git-ratchet.d.ts +26 -0
- package/dist/types/third-party/slack/publish-ci-release-to-slack.d.ts +9 -0
- package/includes/cli.js +12 -0
- package/package.json +77 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RatchetNodeOnlyInfo = void 0;
|
|
4
|
+
class RatchetNodeOnlyInfo {
|
|
5
|
+
constructor() { }
|
|
6
|
+
static buildInformation() {
|
|
7
|
+
const val = {
|
|
8
|
+
version: '80',
|
|
9
|
+
hash: '10fcb761c2fa4186df89e527e948f5780a4e14ac',
|
|
10
|
+
branch: 'alpha-2023-03-12-2',
|
|
11
|
+
tag: 'alpha-2023-03-12-2',
|
|
12
|
+
timeBuiltISO: '2023-03-12T20:00:51-0700',
|
|
13
|
+
notes: '',
|
|
14
|
+
};
|
|
15
|
+
return val;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.RatchetNodeOnlyInfo = RatchetNodeOnlyInfo;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplyCiEnvVariablesToFiles = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
7
|
+
const ci_run_information_util_1 = require("./ci-run-information-util");
|
|
8
|
+
class ApplyCiEnvVariablesToFiles {
|
|
9
|
+
static async process(fileNames, cfg, buildFinder = 'LOCAL-SNAPSHOT', branchFinder = 'LOCAL-BRANCH', hashFinder = 'LOCAL-HASH', tagFinder = 'LOCAL-TAG', timeFinder = 'LOCAL-TIME') {
|
|
10
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(cfg, 'cfg');
|
|
11
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(cfg.buildNumber, 'cfg.buildNumber');
|
|
12
|
+
ratchet_common_1.RequireRatchet.notNullOrUndefined(cfg.localTime, 'cfg.localTime');
|
|
13
|
+
if (!fileNames) {
|
|
14
|
+
throw new Error('fileNames must be defined');
|
|
15
|
+
}
|
|
16
|
+
if (fileNames.length === 0) {
|
|
17
|
+
ratchet_common_1.Logger.warn('Warning - no files supplied to process');
|
|
18
|
+
}
|
|
19
|
+
if (!cfg.buildNumber) {
|
|
20
|
+
ratchet_common_1.ErrorRatchet.throwFormattedErr('%s env var not set - apparently not in a CI environment', cfg.buildNumber);
|
|
21
|
+
}
|
|
22
|
+
ratchet_common_1.Logger.info('Processing files %j with run info %j', cfg);
|
|
23
|
+
let foundCount = 0;
|
|
24
|
+
fileNames.forEach((f) => {
|
|
25
|
+
if (!fs_1.default.existsSync(f)) {
|
|
26
|
+
ratchet_common_1.Logger.error('Could not find file %s to process, continuing', f);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
try {
|
|
30
|
+
let contents = fs_1.default.readFileSync(f).toString();
|
|
31
|
+
contents = contents.split(buildFinder).join(cfg.buildNumber);
|
|
32
|
+
contents = contents.split(branchFinder).join(cfg.branch || '');
|
|
33
|
+
contents = contents.split(hashFinder).join(cfg.commitHash || '');
|
|
34
|
+
contents = contents.split(tagFinder).join(cfg.tag || '');
|
|
35
|
+
contents = contents.split(timeFinder).join(cfg.localTime || '');
|
|
36
|
+
fs_1.default.writeFileSync(f, contents);
|
|
37
|
+
foundCount++;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
ratchet_common_1.Logger.error('Error processing %s , continuing: %s', f, err, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return foundCount;
|
|
45
|
+
}
|
|
46
|
+
static extractFileNames() {
|
|
47
|
+
let rval = [];
|
|
48
|
+
if (process && process.argv && process.argv.length > 3) {
|
|
49
|
+
rval = process.argv.slice(3);
|
|
50
|
+
}
|
|
51
|
+
return rval;
|
|
52
|
+
}
|
|
53
|
+
static extractVariableConfig(inName) {
|
|
54
|
+
let rval = null;
|
|
55
|
+
const name = ratchet_common_1.StringRatchet.trimToEmpty(inName).toLowerCase();
|
|
56
|
+
switch (name) {
|
|
57
|
+
case 'circleci':
|
|
58
|
+
rval = ci_run_information_util_1.CiRunInformationUtil.createDefaultCircleCiRunInformation();
|
|
59
|
+
break;
|
|
60
|
+
case 'github':
|
|
61
|
+
rval = ci_run_information_util_1.CiRunInformationUtil.createDefaultGithubActionsRunInformation();
|
|
62
|
+
break;
|
|
63
|
+
case 'test':
|
|
64
|
+
rval = ci_run_information_util_1.CiRunInformationUtil.createTestingCiRunInformation();
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
ratchet_common_1.ErrorRatchet.throwFormattedErr('Unrecognized env var config type : %s', name);
|
|
68
|
+
}
|
|
69
|
+
ratchet_common_1.Logger.info('Using variable config : %j', rval);
|
|
70
|
+
return rval;
|
|
71
|
+
}
|
|
72
|
+
static async runFromCliArgs(args) {
|
|
73
|
+
if (args.length > 1) {
|
|
74
|
+
return ApplyCiEnvVariablesToFiles.process(args.slice(1), ApplyCiEnvVariablesToFiles.extractVariableConfig(args[0]));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
ratchet_common_1.Logger.infoP('Usage : apply-ci-env-variables-to-files {file1} {file2} ...');
|
|
78
|
+
return -1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ApplyCiEnvVariablesToFiles = ApplyCiEnvVariablesToFiles;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CiRunInformationUtil = void 0;
|
|
4
|
+
const luxon_1 = require("luxon");
|
|
5
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
6
|
+
class CiRunInformationUtil {
|
|
7
|
+
static createTestingCiRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
|
|
8
|
+
const now = new Date().toISOString();
|
|
9
|
+
const rval = {
|
|
10
|
+
buildNumber: 'Test_buildNumberVar_' + now,
|
|
11
|
+
localTime: luxon_1.DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
|
|
12
|
+
branch: 'Test_branchVar_' + now,
|
|
13
|
+
tag: 'Test_tagVar_' + now,
|
|
14
|
+
commitHash: 'Test_hashVar_' + now,
|
|
15
|
+
userName: 'Test_userNameVar_' + now,
|
|
16
|
+
projectName: 'Test_projectNameVar_' + now,
|
|
17
|
+
};
|
|
18
|
+
return rval;
|
|
19
|
+
}
|
|
20
|
+
static createDefaultCircleCiRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
|
|
21
|
+
const rval = {
|
|
22
|
+
buildNumber: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_BUILD_NUM'),
|
|
23
|
+
branch: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_BRANCH'),
|
|
24
|
+
tag: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_TAG'),
|
|
25
|
+
commitHash: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_SHA1'),
|
|
26
|
+
localTime: luxon_1.DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
|
|
27
|
+
userName: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_USERNAME'),
|
|
28
|
+
projectName: ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_PROJECT_REPONAME'),
|
|
29
|
+
};
|
|
30
|
+
return rval;
|
|
31
|
+
}
|
|
32
|
+
static createDefaultGithubActionsRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
|
|
33
|
+
const rval = {
|
|
34
|
+
buildNumber: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_RUN_NUMBER'),
|
|
35
|
+
branch: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_REF_NAME'),
|
|
36
|
+
tag: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_REF_NAME'),
|
|
37
|
+
commitHash: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_SHA'),
|
|
38
|
+
localTime: luxon_1.DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
|
|
39
|
+
userName: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_ACTOR'),
|
|
40
|
+
projectName: ratchet_common_1.GlobalRatchet.fetchGlobalVar('GITHUB_REPOSITORY'),
|
|
41
|
+
};
|
|
42
|
+
return rval;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CiRunInformationUtil = CiRunInformationUtil;
|
|
46
|
+
CiRunInformationUtil.DEFAULT_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss a z';
|
|
47
|
+
CiRunInformationUtil.DEFAULT_TIME_ZONE = 'America/Los_Angeles';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractRatchetCliHandler = void 0;
|
|
4
|
+
const cli_ratchet_1 = require("./cli-ratchet");
|
|
5
|
+
class AbstractRatchetCliHandler {
|
|
6
|
+
async findAndExecuteHandler() {
|
|
7
|
+
let handler = null;
|
|
8
|
+
if (cli_ratchet_1.CliRatchet.argsAfterCommand(['version'])) {
|
|
9
|
+
console.log('Version : ' + JSON.stringify(this.fetchVersionInfo()));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const handlerMap = this.fetchHandlerMap();
|
|
13
|
+
const keys = Object.keys(handlerMap);
|
|
14
|
+
let remainArgs = null;
|
|
15
|
+
for (let i = 0; i < keys.length && !handler; i++) {
|
|
16
|
+
remainArgs = cli_ratchet_1.CliRatchet.argsAfterCommand([keys[i], keys[i] + '.js']);
|
|
17
|
+
if (remainArgs) {
|
|
18
|
+
handler = handlerMap[keys[i]];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (handler) {
|
|
22
|
+
console.debug('Running command with args ' + JSON.stringify(remainArgs));
|
|
23
|
+
await handler(remainArgs);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.log('Unrecognized command : ', process.argv);
|
|
27
|
+
console.log('Valid commands are : ', Object.keys(handlerMap));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AbstractRatchetCliHandler = AbstractRatchetCliHandler;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliRatchet = void 0;
|
|
4
|
+
class CliRatchet {
|
|
5
|
+
static isCalledFromCLI(filenames) {
|
|
6
|
+
let rval = false;
|
|
7
|
+
for (let i = 0; filenames && i < filenames.length && !rval; i++) {
|
|
8
|
+
rval = CliRatchet.indexOfCommandArgument(filenames[i]) > -1;
|
|
9
|
+
}
|
|
10
|
+
return rval;
|
|
11
|
+
}
|
|
12
|
+
static argsAfterCommand(filenames) {
|
|
13
|
+
var _a;
|
|
14
|
+
let rval = null;
|
|
15
|
+
if (((_a = process === null || process === void 0 ? void 0 : process.argv) === null || _a === void 0 ? void 0 : _a.length) && (filenames === null || filenames === void 0 ? void 0 : filenames.length)) {
|
|
16
|
+
let idx = null;
|
|
17
|
+
for (let i = 0; i < filenames.length && idx === null; i++) {
|
|
18
|
+
idx = CliRatchet.indexOfCommandArgument(filenames[i]);
|
|
19
|
+
}
|
|
20
|
+
rval = idx !== null ? process.argv.slice(idx + 1, process.argv.length) : null;
|
|
21
|
+
}
|
|
22
|
+
return rval;
|
|
23
|
+
}
|
|
24
|
+
static isCalledFromCLISingle(filename) {
|
|
25
|
+
return CliRatchet.isCalledFromCLI([filename]);
|
|
26
|
+
}
|
|
27
|
+
static indexOfCommandArgument(filename) {
|
|
28
|
+
const contFileName = process.argv.map((arg) => arg.indexOf(filename) !== -1);
|
|
29
|
+
const idx = contFileName.indexOf(true);
|
|
30
|
+
return idx === -1 ? null : idx;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.CliRatchet = CliRatchet;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RatchetCliHandler = void 0;
|
|
4
|
+
const ratchet_node_only_info_1 = require("../build/ratchet-node-only-info");
|
|
5
|
+
const apply_ci_env_variables_to_files_1 = require("../ci/apply-ci-env-variables-to-files");
|
|
6
|
+
const files_to_static_class_1 = require("../files/files-to-static-class");
|
|
7
|
+
const publish_ci_release_to_slack_1 = require("../third-party/slack/publish-ci-release-to-slack");
|
|
8
|
+
const abstract_ratchet_cli_handler_1 = require("./abstract-ratchet-cli-handler");
|
|
9
|
+
class RatchetCliHandler extends abstract_ratchet_cli_handler_1.AbstractRatchetCliHandler {
|
|
10
|
+
fetchHandlerMap() {
|
|
11
|
+
return {
|
|
12
|
+
'apply-ci-env-variables-to-files': apply_ci_env_variables_to_files_1.ApplyCiEnvVariablesToFiles.runFromCliArgs,
|
|
13
|
+
'files-to-static-class': files_to_static_class_1.FilesToStaticClass.runFromCliArgs,
|
|
14
|
+
'publish-ci-release-to-slack': publish_ci_release_to_slack_1.PublishCiReleaseToSlack.runFromCliArgs,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
fetchVersionInfo() {
|
|
18
|
+
return ratchet_node_only_info_1.RatchetNodeOnlyInfo.buildInformation();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.RatchetCliHandler = RatchetCliHandler;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsvRatchet = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const csv_parse_1 = require("csv-parse");
|
|
7
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
8
|
+
const csv_stringify_1 = require("csv-stringify");
|
|
9
|
+
const ratchet_common_2 = require("@bitblit/ratchet-common");
|
|
10
|
+
const ratchet_common_3 = require("@bitblit/ratchet-common");
|
|
11
|
+
const stream_1 = require("stream");
|
|
12
|
+
class CsvRatchet {
|
|
13
|
+
static defaultParseOptions() {
|
|
14
|
+
const rval = {
|
|
15
|
+
delimiter: ',',
|
|
16
|
+
columns: true,
|
|
17
|
+
};
|
|
18
|
+
return rval;
|
|
19
|
+
}
|
|
20
|
+
static defaultStringifyOptions() {
|
|
21
|
+
const rval = {
|
|
22
|
+
header: true,
|
|
23
|
+
};
|
|
24
|
+
return rval;
|
|
25
|
+
}
|
|
26
|
+
static async stringParse(input, pf, opts = CsvRatchet.defaultParseOptions()) {
|
|
27
|
+
return CsvRatchet.streamParse(stream_1.Readable.from(input), pf, opts);
|
|
28
|
+
}
|
|
29
|
+
static async streamParse(readStream, pf, opts = CsvRatchet.defaultParseOptions()) {
|
|
30
|
+
return new Promise((res, rej) => {
|
|
31
|
+
const rval = [];
|
|
32
|
+
const p = (0, csv_parse_1.parse)(opts);
|
|
33
|
+
p.on('readable', () => {
|
|
34
|
+
let record = p.read();
|
|
35
|
+
while (record) {
|
|
36
|
+
const newVal = pf(record);
|
|
37
|
+
if (newVal) {
|
|
38
|
+
rval.push(newVal);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
}
|
|
42
|
+
record = p.read();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
p.on('error', (err) => {
|
|
46
|
+
rej(err);
|
|
47
|
+
});
|
|
48
|
+
p.on('end', () => {
|
|
49
|
+
res(rval);
|
|
50
|
+
});
|
|
51
|
+
readStream.pipe(p);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
static async fileParse(filename, pf) {
|
|
55
|
+
const readStream = fs_1.default.createReadStream(filename);
|
|
56
|
+
return CsvRatchet.streamParse(readStream, pf);
|
|
57
|
+
}
|
|
58
|
+
static async generateCsvData(objectsToConvert, opts = CsvRatchet.defaultStringifyOptions()) {
|
|
59
|
+
ratchet_common_1.Logger.silly('Converting %d items into csv file', objectsToConvert.length);
|
|
60
|
+
const genProm = new Promise((res, rej) => {
|
|
61
|
+
(0, csv_stringify_1.stringify)(objectsToConvert, opts, function (err, data) {
|
|
62
|
+
if (err) {
|
|
63
|
+
rej(err);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
res(data);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
return genProm;
|
|
71
|
+
}
|
|
72
|
+
static async generateComparison(file1, file2, keyField) {
|
|
73
|
+
ratchet_common_2.RequireRatchet.notNullOrUndefined(file1, 'file1');
|
|
74
|
+
ratchet_common_2.RequireRatchet.notNullOrUndefined(file2, 'file2');
|
|
75
|
+
ratchet_common_2.RequireRatchet.notNullOrUndefined(keyField, 'keyField');
|
|
76
|
+
ratchet_common_1.Logger.info('Created csv compare with files %s and %s keyed on %s', file1, file2, keyField);
|
|
77
|
+
let file1Parsed = await this.streamParse(fs_1.default.createReadStream(file1), (f) => {
|
|
78
|
+
f;
|
|
79
|
+
});
|
|
80
|
+
file1Parsed = file1Parsed.map((m) => {
|
|
81
|
+
const next = {};
|
|
82
|
+
Object.keys(m).forEach((k) => {
|
|
83
|
+
next[k.trim()] = m[k];
|
|
84
|
+
});
|
|
85
|
+
return next;
|
|
86
|
+
});
|
|
87
|
+
const file1Mapped = ratchet_common_3.MapRatchet.mapByUniqueProperty(file1Parsed, keyField);
|
|
88
|
+
let file2Parsed = await this.streamParse(fs_1.default.createReadStream(file2), (f) => {
|
|
89
|
+
f;
|
|
90
|
+
});
|
|
91
|
+
file2Parsed = file2Parsed.map((m) => {
|
|
92
|
+
const next = {};
|
|
93
|
+
Object.keys(m).forEach((k) => {
|
|
94
|
+
next[k.trim()] = m[k];
|
|
95
|
+
});
|
|
96
|
+
return next;
|
|
97
|
+
});
|
|
98
|
+
const file2Mapped = ratchet_common_3.MapRatchet.mapByUniqueProperty(file2Parsed, keyField);
|
|
99
|
+
const f1Only = [];
|
|
100
|
+
const f2Only = [];
|
|
101
|
+
const both = [];
|
|
102
|
+
Array.from(file1Mapped.keys()).forEach((f1k) => {
|
|
103
|
+
if (file2Mapped.has(f1k)) {
|
|
104
|
+
both.push(f1k);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
f1Only.push(f1k);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Array.from(file2Mapped.keys()).forEach((f1k) => {
|
|
111
|
+
if (!file1Mapped.has(f1k)) {
|
|
112
|
+
f2Only.push(f1k);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const rval = {
|
|
116
|
+
file1Data: file1Mapped,
|
|
117
|
+
file2Data: file2Mapped,
|
|
118
|
+
file1OnlyKeys: f1Only,
|
|
119
|
+
file2OnlyKeys: f2Only,
|
|
120
|
+
bothFilesKeys: both,
|
|
121
|
+
};
|
|
122
|
+
return rval;
|
|
123
|
+
}
|
|
124
|
+
static async streamObjectsToCsv(srcSubject, output, inOpts) {
|
|
125
|
+
ratchet_common_2.RequireRatchet.notNullOrUndefined(srcSubject, 'srcSubject');
|
|
126
|
+
ratchet_common_2.RequireRatchet.notNullOrUndefined(output, 'output');
|
|
127
|
+
const opts = inOpts || CsvRatchet.defaultStringifyOptions();
|
|
128
|
+
ratchet_common_1.Logger.silly('Running pipe to csv output : %j', opts);
|
|
129
|
+
let count = 0;
|
|
130
|
+
const genProm = new Promise((res, rej) => {
|
|
131
|
+
const stringifier = (0, csv_stringify_1.stringify)(opts);
|
|
132
|
+
stringifier.on('error', (err) => {
|
|
133
|
+
if (sub) {
|
|
134
|
+
sub.unsubscribe();
|
|
135
|
+
}
|
|
136
|
+
rej(err);
|
|
137
|
+
});
|
|
138
|
+
stringifier.on('finish', () => {
|
|
139
|
+
if (sub) {
|
|
140
|
+
sub.unsubscribe();
|
|
141
|
+
}
|
|
142
|
+
res(count);
|
|
143
|
+
});
|
|
144
|
+
stringifier.pipe(output);
|
|
145
|
+
const sub = srcSubject.subscribe((next) => {
|
|
146
|
+
ratchet_common_1.Logger.debug('Adding %j to csv', next);
|
|
147
|
+
count++;
|
|
148
|
+
stringifier.write(next);
|
|
149
|
+
}, (err) => {
|
|
150
|
+
ratchet_common_1.Logger.error('Error generating : %s', err);
|
|
151
|
+
rej(err);
|
|
152
|
+
}, () => {
|
|
153
|
+
ratchet_common_1.Logger.debug('Finished');
|
|
154
|
+
stringifier.end();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return genProm;
|
|
158
|
+
}
|
|
159
|
+
static defaultParseFunction(row) {
|
|
160
|
+
return row;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.CsvRatchet = CsvRatchet;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilesToStaticClass = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
6
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
+
const cli_ratchet_1 = require("../cli/cli-ratchet");
|
|
8
|
+
class FilesToStaticClass {
|
|
9
|
+
static async process(fileNames, outClassName, outFileName = null) {
|
|
10
|
+
if (!fileNames) {
|
|
11
|
+
throw new Error('fileNames must be defined');
|
|
12
|
+
}
|
|
13
|
+
if (!outClassName) {
|
|
14
|
+
throw new Error('outClassName must be defined');
|
|
15
|
+
}
|
|
16
|
+
if (fileNames.length === 0) {
|
|
17
|
+
ratchet_common_1.Logger.warn('Warning - no files supplied to process');
|
|
18
|
+
}
|
|
19
|
+
ratchet_common_1.Logger.info('Generating class %s from files %j (output file: %s)', outClassName, fileNames, outFileName);
|
|
20
|
+
let rval = '/** \n';
|
|
21
|
+
rval += '* Holder for the constants to be used by consumers \n';
|
|
22
|
+
rval += '* Moves it into code so that it can survive a trip through WebPack \n';
|
|
23
|
+
rval += '*/ \n\n';
|
|
24
|
+
rval += 'export class ' + outClassName + ' { \n';
|
|
25
|
+
rval += ' public static readonly VALUES:Record<string, string> = { \n';
|
|
26
|
+
for (let i = 0; i < fileNames.length; i++) {
|
|
27
|
+
let contents = 'NOT-FOUND';
|
|
28
|
+
if (fs_1.default.existsSync(fileNames[i])) {
|
|
29
|
+
const trimmed = fileNames[i].substring(fileNames[i].lastIndexOf('/') + 1);
|
|
30
|
+
contents = fs_1.default.readFileSync(fileNames[i]).toString();
|
|
31
|
+
rval += i > 0 ? ',' : '';
|
|
32
|
+
rval += '"' + trimmed + '":' + JSON.stringify(contents) + '\n';
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
ratchet_common_1.Logger.warn('Could not find file %s', fileNames[i]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
rval += '}; \n';
|
|
39
|
+
rval += '}';
|
|
40
|
+
if (!!outFileName) {
|
|
41
|
+
ratchet_common_1.Logger.info('Writing to %s', outFileName);
|
|
42
|
+
fs_1.default.writeFileSync(outFileName, rval);
|
|
43
|
+
}
|
|
44
|
+
return rval;
|
|
45
|
+
}
|
|
46
|
+
static async runFromCliArgs(args) {
|
|
47
|
+
if (args.length < 4) {
|
|
48
|
+
ratchet_common_1.Logger.infoP('Usage: ratchet-files-to-static-class {outFileName} {outClassName} {file0} ... {fileN}');
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const idx = cli_ratchet_1.CliRatchet.indexOfCommandArgument('files-to-static-class');
|
|
53
|
+
const outFileName = process.argv[idx + 1];
|
|
54
|
+
const outClassName = process.argv[idx + 2];
|
|
55
|
+
const files = process.argv.slice(idx + 3);
|
|
56
|
+
ratchet_common_1.Logger.info('Running FilesToStaticClass from command line arguments Target: %s TargetClass: %s InFiles: %j', outFileName, outClassName, files);
|
|
57
|
+
return FilesToStaticClass.process(files, outClassName, outFileName);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.FilesToStaticClass = FilesToStaticClass;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./build/ratchet-node-only-info"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./ci/apply-ci-env-variables-to-files"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./ci/ci-run-information-util"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./ci/ci-run-information"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./cli/abstract-ratchet-cli-handler"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./cli/cli-ratchet"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./cli/ratchet-cli-handler"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./csv/csv-ratchet"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./files/files-to-static-class"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./third-party/git/git-ratchet"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./third-party/slack/publish-ci-release-to-slack"), exports);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitRatchet = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
6
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
7
|
+
class GitRatchet {
|
|
8
|
+
static async executeCommand(command, options) {
|
|
9
|
+
let dst = __dirname;
|
|
10
|
+
if (!!options && !!options.dst) {
|
|
11
|
+
dst = options.dst;
|
|
12
|
+
}
|
|
13
|
+
return new Promise((res, rej) => {
|
|
14
|
+
child_process_1.default.exec(command, { cwd: dst }, (err, stdout, stderr) => {
|
|
15
|
+
if (stdout === '') {
|
|
16
|
+
rej('this does not look like a git repo');
|
|
17
|
+
}
|
|
18
|
+
if (!!stderr) {
|
|
19
|
+
rej(stderr);
|
|
20
|
+
}
|
|
21
|
+
res(stdout);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static getCommandString(splitChar) {
|
|
26
|
+
return ('git log -1 --pretty=format:"' +
|
|
27
|
+
GitRatchet.PRETTY_FORMAT.join(splitChar) +
|
|
28
|
+
'"' +
|
|
29
|
+
' && git rev-parse --abbrev-ref HEAD' +
|
|
30
|
+
' && git tag --contains HEAD');
|
|
31
|
+
}
|
|
32
|
+
static async getLastCommitSwallowException(options = {}) {
|
|
33
|
+
let rval = null;
|
|
34
|
+
try {
|
|
35
|
+
rval = await this.getLastCommit(options);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
ratchet_common_1.Logger.warn('Failed to fetch git data : %s', err, err);
|
|
39
|
+
}
|
|
40
|
+
return rval;
|
|
41
|
+
}
|
|
42
|
+
static async getLastCommit(options = {}) {
|
|
43
|
+
const command = GitRatchet.getCommandString(GitRatchet.SPLIT_CHARACTER);
|
|
44
|
+
const res = await GitRatchet.executeCommand(command, options);
|
|
45
|
+
const a = res.split(GitRatchet.SPLIT_CHARACTER);
|
|
46
|
+
const branchAndTags = a[a.length - 1].split('\n').filter((n) => n);
|
|
47
|
+
const branch = branchAndTags[0];
|
|
48
|
+
const tags = branchAndTags.slice(1);
|
|
49
|
+
const rval = {
|
|
50
|
+
shortHash: a[0],
|
|
51
|
+
hash: a[1],
|
|
52
|
+
subject: a[2],
|
|
53
|
+
sanitizedSubject: a[3],
|
|
54
|
+
body: a[4],
|
|
55
|
+
authoredOn: a[5],
|
|
56
|
+
committedOn: a[6],
|
|
57
|
+
author: {
|
|
58
|
+
name: a[7],
|
|
59
|
+
email: a[8],
|
|
60
|
+
},
|
|
61
|
+
committer: {
|
|
62
|
+
name: a[9],
|
|
63
|
+
email: a[10],
|
|
64
|
+
},
|
|
65
|
+
notes: a[11],
|
|
66
|
+
branch,
|
|
67
|
+
tags,
|
|
68
|
+
};
|
|
69
|
+
return rval;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.GitRatchet = GitRatchet;
|
|
73
|
+
GitRatchet.SPLIT_CHARACTER = '<##>';
|
|
74
|
+
GitRatchet.PRETTY_FORMAT = ['%h', '%H', '%s', '%f', '%b', '%at', '%ct', '%an', '%ae', '%cn', '%ce', '%N', ''];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublishCiReleaseToSlack = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const luxon_1 = require("luxon");
|
|
6
|
+
const ratchet_common_1 = require("@bitblit/ratchet-common");
|
|
7
|
+
const cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch"));
|
|
8
|
+
const util_1 = tslib_1.__importDefault(require("util"));
|
|
9
|
+
const git_ratchet_1 = require("../git/git-ratchet");
|
|
10
|
+
class PublishCiReleaseToSlack {
|
|
11
|
+
static async process(slackHookUrl, timezone = 'America/Los_Angeles') {
|
|
12
|
+
if (!slackHookUrl) {
|
|
13
|
+
throw new Error('slackHookUrl must be defined');
|
|
14
|
+
}
|
|
15
|
+
const buildNum = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_BUILD_NUM');
|
|
16
|
+
const userName = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_USERNAME');
|
|
17
|
+
const projectName = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_PROJECT_REPONAME');
|
|
18
|
+
const branch = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_BRANCH') || '';
|
|
19
|
+
const tag = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_TAG') || '';
|
|
20
|
+
const sha1 = ratchet_common_1.GlobalRatchet.fetchGlobalVar('CIRCLE_SHA1') || '';
|
|
21
|
+
const localTime = luxon_1.DateTime.local().setZone(timezone).toFormat('MMMM Do yyyy, h:mm:ss a z');
|
|
22
|
+
const gitData = await git_ratchet_1.GitRatchet.getLastCommitSwallowException();
|
|
23
|
+
if (!buildNum || !userName || !projectName) {
|
|
24
|
+
throw new Error('CIRCLE_BUILD_NUM, CIRCLE_USERNAME, CIRCLE_PROJECT_REPONAME env vars not set - apparently not in a CircleCI environment');
|
|
25
|
+
}
|
|
26
|
+
ratchet_common_1.Logger.info('Sending slack notification %j with build %s, branch %s, tag %s, sha %s, time: %s', buildNum, branch, tag, sha1, localTime);
|
|
27
|
+
let message = util_1.default.format('%s performed release %s on %s at %s', userName, tag + ' ' + branch, projectName, localTime);
|
|
28
|
+
if (!!gitData && !!gitData.subject) {
|
|
29
|
+
message += '\n\n' + gitData.subject;
|
|
30
|
+
}
|
|
31
|
+
const response = await (0, cross_fetch_1.default)(slackHookUrl, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
mode: 'cors',
|
|
34
|
+
cache: 'no-cache',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
},
|
|
38
|
+
redirect: 'follow',
|
|
39
|
+
body: JSON.stringify({ text: message }),
|
|
40
|
+
});
|
|
41
|
+
const bodyOut = await response.text();
|
|
42
|
+
ratchet_common_1.Logger.info('Slack returned : %s', bodyOut);
|
|
43
|
+
return bodyOut;
|
|
44
|
+
}
|
|
45
|
+
static extractHookUrl() {
|
|
46
|
+
let rval = null;
|
|
47
|
+
if (process && process.argv && process.argv.length > 2) {
|
|
48
|
+
rval = process.argv[2];
|
|
49
|
+
}
|
|
50
|
+
return rval;
|
|
51
|
+
}
|
|
52
|
+
static async runFromCliArgs(args) {
|
|
53
|
+
ratchet_common_1.Logger.info('Running PublishCiReleaseToSlack from command line arguments');
|
|
54
|
+
const hook = PublishCiReleaseToSlack.extractHookUrl();
|
|
55
|
+
if (!!hook) {
|
|
56
|
+
return PublishCiReleaseToSlack.process(hook);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
ratchet_common_1.Logger.infoP('Usage : ratchet-publish-circle-ci-release-to-slack {hookUrl} ...');
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.PublishCiReleaseToSlack = PublishCiReleaseToSlack;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class RatchetNodeOnlyInfo {
|
|
2
|
+
constructor() { }
|
|
3
|
+
static buildInformation() {
|
|
4
|
+
const val = {
|
|
5
|
+
version: '80',
|
|
6
|
+
hash: '10fcb761c2fa4186df89e527e948f5780a4e14ac',
|
|
7
|
+
branch: 'alpha-2023-03-12-2',
|
|
8
|
+
tag: 'alpha-2023-03-12-2',
|
|
9
|
+
timeBuiltISO: '2023-03-12T20:00:51-0700',
|
|
10
|
+
notes: '',
|
|
11
|
+
};
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
}
|