@bitblit/ratchet-node-only 4.0.115-alpha → 4.0.119-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitblit/ratchet-node-only",
3
- "version": "4.0.115-alpha",
3
+ "version": "4.0.119-alpha",
4
4
  "description": "Ratchet tools for use on node-only",
5
5
  "note-on-side-effects": "Technically the entries in 'bin' below might be side effects, but they are called explicitly",
6
6
  "sideEffects": false,
@@ -8,11 +8,16 @@
8
8
  "ratchet-cli": "./bin/cli.js"
9
9
  },
10
10
  "type": "module",
11
- "module": "index.js",
12
11
  "files": [
13
12
  "lib/*",
14
13
  "bin/*"
15
14
  ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/index.d.ts",
18
+ "import": "./lib/index.mjs"
19
+ }
20
+ },
16
21
  "contributors": [
17
22
  "Christopher Weiss <bitblit@gmail.com>",
18
23
  "William Weiss <npm@codification.org>",
@@ -39,9 +44,8 @@
39
44
  "docs": "typedoc",
40
45
  "lint": "eslint src/**/*.ts",
41
46
  "lint-fix": "eslint --fix src/**/*.ts",
42
- "__generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts",
43
- "__build": "yarn run generate-barrels && tsc",
44
- "build": "tsc",
47
+ "generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts && sed -i 's/\\x27;/.js\\x27;/' src/index.ts",
48
+ "build": "yarn clean && yarn generate-barrels && rollup -c rollup.config.js",
45
49
  "force-build": "tsc --build --force"
46
50
  },
47
51
  "repository": {
@@ -61,13 +65,11 @@
61
65
  },
62
66
  "license": "Apache-2.0",
63
67
  "dependencies": {
64
- "@bitblit/ratchet-common": "4.0.115-alpha",
65
- "csv": "6.2.12",
68
+ "@bitblit/ratchet-common": "4.0.119-alpha",
69
+ "csv": "6.3.0",
66
70
  "rxjs": "7.8.1"
67
71
  },
68
72
  "peerDependencies": {
69
- "csv": "^6.2.12",
70
- "rxjs": "^7.8.1"
71
73
  },
72
74
  "peerDependenciesMeta": {
73
75
  "csv": {
@@ -1,14 +0,0 @@
1
- export class RatchetNodeOnlyInfo {
2
- constructor() { }
3
- static buildInformation() {
4
- const val = {
5
- version: 'LOCAL-SNAPSHOT',
6
- hash: 'LOCAL-HASH',
7
- branch: 'LOCAL-BRANCH',
8
- tag: 'LOCAL-TAG',
9
- timeBuiltISO: 'LOCAL-TIME-ISO',
10
- notes: 'LOCAL-NOTES',
11
- };
12
- return val;
13
- }
14
- }
@@ -1,80 +0,0 @@
1
- import fs from 'fs';
2
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
3
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
4
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
5
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
6
- import { CiRunInformationUtil } from './ci-run-information-util.js';
7
- export class ApplyCiEnvVariablesToFiles {
8
- static async process(fileNames, cfg, buildFinder = 'LOCAL-SNAPSHOT', branchFinder = 'LOCAL-BRANCH', hashFinder = 'LOCAL-HASH', tagFinder = 'LOCAL-TAG', timeFinder = 'LOCAL-TIME') {
9
- RequireRatchet.notNullOrUndefined(cfg, 'cfg');
10
- RequireRatchet.notNullOrUndefined(cfg.buildNumber, 'cfg.buildNumber');
11
- RequireRatchet.notNullOrUndefined(cfg.localTime, 'cfg.localTime');
12
- if (!fileNames) {
13
- throw new Error('fileNames must be defined');
14
- }
15
- if (fileNames.length === 0) {
16
- Logger.warn('Warning - no files supplied to process');
17
- }
18
- if (!cfg.buildNumber) {
19
- ErrorRatchet.throwFormattedErr('%s env var not set - apparently not in a CI environment', cfg.buildNumber);
20
- }
21
- Logger.info('Processing files %j with run info %j', cfg);
22
- let foundCount = 0;
23
- fileNames.forEach((f) => {
24
- if (!fs.existsSync(f)) {
25
- Logger.error('Could not find file %s to process, continuing', f);
26
- }
27
- else {
28
- try {
29
- let contents = fs.readFileSync(f).toString();
30
- contents = contents.split(buildFinder).join(cfg.buildNumber);
31
- contents = contents.split(branchFinder).join(cfg.branch || '');
32
- contents = contents.split(hashFinder).join(cfg.commitHash || '');
33
- contents = contents.split(tagFinder).join(cfg.tag || '');
34
- contents = contents.split(timeFinder).join(cfg.localTime || '');
35
- fs.writeFileSync(f, contents);
36
- foundCount++;
37
- }
38
- catch (err) {
39
- Logger.error('Error processing %s , continuing: %s', f, err, err);
40
- }
41
- }
42
- });
43
- return foundCount;
44
- }
45
- static extractFileNames() {
46
- let rval = [];
47
- if (process && process.argv && process.argv.length > 3) {
48
- rval = process.argv.slice(3);
49
- }
50
- return rval;
51
- }
52
- static extractVariableConfig(inName) {
53
- let rval = null;
54
- const name = StringRatchet.trimToEmpty(inName).toLowerCase();
55
- switch (name) {
56
- case 'circleci':
57
- rval = CiRunInformationUtil.createDefaultCircleCiRunInformation();
58
- break;
59
- case 'github':
60
- rval = CiRunInformationUtil.createDefaultGithubActionsRunInformation();
61
- break;
62
- case 'test':
63
- rval = CiRunInformationUtil.createTestingCiRunInformation();
64
- break;
65
- default:
66
- ErrorRatchet.throwFormattedErr('Unrecognized env var config type : %s', name);
67
- }
68
- Logger.info('Using variable config : %j', rval);
69
- return rval;
70
- }
71
- static async runFromCliArgs(args) {
72
- if (args.length > 1) {
73
- return ApplyCiEnvVariablesToFiles.process(args.slice(1), ApplyCiEnvVariablesToFiles.extractVariableConfig(args[0]));
74
- }
75
- else {
76
- Logger.infoP('Usage : apply-ci-env-variables-to-files {file1} {file2} ...');
77
- return -1;
78
- }
79
- }
80
- }
@@ -1,23 +0,0 @@
1
- import { ApplyCiEnvVariablesToFiles } from './apply-ci-env-variables-to-files.js';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- import { GlobalRatchet } from '@bitblit/ratchet-common/lib/lang/global-ratchet.js';
4
- import { CiRunInformationUtil } from './ci-run-information-util.js';
5
- describe('#applyCiEnvVariablesToFiles', function () {
6
- xit('should fail if not in a ci environment', async () => {
7
- try {
8
- const result = await ApplyCiEnvVariablesToFiles.process(['test1.txt'], CiRunInformationUtil.createDefaultCircleCiRunInformation());
9
- this.bail();
10
- }
11
- catch (err) {
12
- Logger.debug('Caught expected error : %s', err['message']);
13
- }
14
- });
15
- it('should not fail if in a ci environment', async () => {
16
- GlobalRatchet.setGlobalVar('CIRCLE_BUILD_NUM', '1');
17
- GlobalRatchet.setGlobalVar('CIRCLE_BRANCH', 'B');
18
- GlobalRatchet.setGlobalVar('CIRCLE_TAG', 'T');
19
- GlobalRatchet.setGlobalVar('CIRCLE_SHA1', 'S');
20
- const result = await ApplyCiEnvVariablesToFiles.process([], CiRunInformationUtil.createDefaultCircleCiRunInformation());
21
- expect(result).toEqual(0);
22
- });
23
- });
@@ -1,43 +0,0 @@
1
- import { DateTime } from 'luxon';
2
- import { GlobalRatchet } from '@bitblit/ratchet-common/lib/lang/global-ratchet.js';
3
- export class CiRunInformationUtil {
4
- static DEFAULT_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss a z';
5
- static DEFAULT_TIME_ZONE = 'America/Los_Angeles';
6
- static createTestingCiRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
7
- const now = new Date().toISOString();
8
- const rval = {
9
- buildNumber: 'Test_buildNumberVar_' + now,
10
- localTime: DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
11
- branch: 'Test_branchVar_' + now,
12
- tag: 'Test_tagVar_' + now,
13
- commitHash: 'Test_hashVar_' + now,
14
- userName: 'Test_userNameVar_' + now,
15
- projectName: 'Test_projectNameVar_' + now,
16
- };
17
- return rval;
18
- }
19
- static createDefaultCircleCiRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
20
- const rval = {
21
- buildNumber: GlobalRatchet.fetchGlobalVar('CIRCLE_BUILD_NUM'),
22
- branch: GlobalRatchet.fetchGlobalVar('CIRCLE_BRANCH'),
23
- tag: GlobalRatchet.fetchGlobalVar('CIRCLE_TAG'),
24
- commitHash: GlobalRatchet.fetchGlobalVar('CIRCLE_SHA1'),
25
- localTime: DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
26
- userName: GlobalRatchet.fetchGlobalVar('CIRCLE_USERNAME'),
27
- projectName: GlobalRatchet.fetchGlobalVar('CIRCLE_PROJECT_REPONAME'),
28
- };
29
- return rval;
30
- }
31
- static createDefaultGithubActionsRunInformation(timezone = CiRunInformationUtil.DEFAULT_TIME_ZONE) {
32
- const rval = {
33
- buildNumber: GlobalRatchet.fetchGlobalVar('GITHUB_RUN_NUMBER'),
34
- branch: GlobalRatchet.fetchGlobalVar('GITHUB_REF_NAME'),
35
- tag: GlobalRatchet.fetchGlobalVar('GITHUB_REF_NAME'),
36
- commitHash: GlobalRatchet.fetchGlobalVar('GITHUB_SHA'),
37
- localTime: DateTime.local().setZone(timezone).toFormat(CiRunInformationUtil.DEFAULT_TIME_FORMAT),
38
- userName: GlobalRatchet.fetchGlobalVar('GITHUB_ACTOR'),
39
- projectName: GlobalRatchet.fetchGlobalVar('GITHUB_REPOSITORY'),
40
- };
41
- return rval;
42
- }
43
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import { CliRatchet } from './cli-ratchet.js';
2
- export class AbstractRatchetCliHandler {
3
- async findAndExecuteHandler() {
4
- let handler = null;
5
- if (CliRatchet.argsAfterCommand(['version'])) {
6
- console.log('Version : ' + JSON.stringify(this.fetchVersionInfo()));
7
- }
8
- else {
9
- const handlerMap = this.fetchHandlerMap();
10
- const keys = Object.keys(handlerMap);
11
- let remainArgs = null;
12
- for (let i = 0; i < keys.length && !handler; i++) {
13
- remainArgs = CliRatchet.argsAfterCommand([keys[i], keys[i] + '.js']);
14
- if (remainArgs) {
15
- handler = handlerMap[keys[i]];
16
- }
17
- }
18
- if (handler) {
19
- console.debug('Running command with args ' + JSON.stringify(remainArgs));
20
- await handler(remainArgs);
21
- }
22
- else {
23
- console.log('Unrecognized command : ', process.argv);
24
- console.log('Valid commands are : ', Object.keys(handlerMap));
25
- }
26
- }
27
- }
28
- }
@@ -1,28 +0,0 @@
1
- export class CliRatchet {
2
- static isCalledFromCLI(filenames) {
3
- let rval = false;
4
- for (let i = 0; filenames && i < filenames.length && !rval; i++) {
5
- rval = CliRatchet.indexOfCommandArgument(filenames[i]) > -1;
6
- }
7
- return rval;
8
- }
9
- static argsAfterCommand(filenames) {
10
- let rval = null;
11
- if (process?.argv?.length && filenames?.length) {
12
- let idx = null;
13
- for (let i = 0; i < filenames.length && idx === null; i++) {
14
- idx = CliRatchet.indexOfCommandArgument(filenames[i]);
15
- }
16
- rval = idx !== null ? process.argv.slice(idx + 1, process.argv.length) : null;
17
- }
18
- return rval;
19
- }
20
- static isCalledFromCLISingle(filename) {
21
- return CliRatchet.isCalledFromCLI([filename]);
22
- }
23
- static indexOfCommandArgument(filename) {
24
- const contFileName = process.argv.map((arg) => arg.indexOf(filename) !== -1);
25
- const idx = contFileName.indexOf(true);
26
- return idx === -1 ? null : idx;
27
- }
28
- }
@@ -1,17 +0,0 @@
1
- import { RatchetNodeOnlyInfo } from '../build/ratchet-node-only-info.js';
2
- import { ApplyCiEnvVariablesToFiles } from '../ci/apply-ci-env-variables-to-files.js';
3
- import { FilesToStaticClass } from '../files/files-to-static-class.js';
4
- import { PublishCiReleaseToSlack } from '../third-party/slack/publish-ci-release-to-slack.js';
5
- import { AbstractRatchetCliHandler } from './abstract-ratchet-cli-handler.js';
6
- export class RatchetCliHandler extends AbstractRatchetCliHandler {
7
- fetchHandlerMap() {
8
- return {
9
- 'apply-ci-env-variables-to-files': ApplyCiEnvVariablesToFiles.runFromCliArgs,
10
- 'files-to-static-class': FilesToStaticClass.runFromCliArgs,
11
- 'publish-ci-release-to-slack': PublishCiReleaseToSlack.runFromCliArgs,
12
- };
13
- }
14
- fetchVersionInfo() {
15
- return RatchetNodeOnlyInfo.buildInformation();
16
- }
17
- }
@@ -1,158 +0,0 @@
1
- import fs from 'fs';
2
- import { parse } from 'csv-parse';
3
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
4
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
5
- import { MapRatchet } from '@bitblit/ratchet-common/lib/lang/map-ratchet.js';
6
- import { stringify } from 'csv-stringify';
7
- import { Readable } from 'stream';
8
- export class CsvRatchet {
9
- static defaultParseOptions() {
10
- const rval = {
11
- delimiter: ',',
12
- columns: true,
13
- };
14
- return rval;
15
- }
16
- static defaultStringifyOptions() {
17
- const rval = {
18
- header: true,
19
- };
20
- return rval;
21
- }
22
- static async stringParse(input, pf, opts = CsvRatchet.defaultParseOptions()) {
23
- return CsvRatchet.streamParse(Readable.from(input), pf, opts);
24
- }
25
- static async streamParse(readStream, pf, opts = CsvRatchet.defaultParseOptions()) {
26
- return new Promise((res, rej) => {
27
- const rval = [];
28
- const p = parse(opts);
29
- p.on('readable', () => {
30
- let record = p.read();
31
- while (record) {
32
- const newVal = pf(record);
33
- if (newVal) {
34
- rval.push(newVal);
35
- }
36
- else {
37
- }
38
- record = p.read();
39
- }
40
- });
41
- p.on('error', (err) => {
42
- rej(err);
43
- });
44
- p.on('end', () => {
45
- res(rval);
46
- });
47
- readStream.pipe(p);
48
- });
49
- }
50
- static async fileParse(filename, pf) {
51
- const readStream = fs.createReadStream(filename);
52
- return CsvRatchet.streamParse(readStream, pf);
53
- }
54
- static async generateCsvData(objectsToConvert, opts = CsvRatchet.defaultStringifyOptions()) {
55
- Logger.silly('Converting %d items into csv file', objectsToConvert.length);
56
- const genProm = new Promise((res, rej) => {
57
- stringify(objectsToConvert, opts, function (err, data) {
58
- if (err) {
59
- rej(err);
60
- }
61
- else {
62
- res(data);
63
- }
64
- });
65
- });
66
- return genProm;
67
- }
68
- static async generateComparison(file1, file2, keyField) {
69
- RequireRatchet.notNullOrUndefined(file1, 'file1');
70
- RequireRatchet.notNullOrUndefined(file2, 'file2');
71
- RequireRatchet.notNullOrUndefined(keyField, 'keyField');
72
- Logger.info('Created csv compare with files %s and %s keyed on %s', file1, file2, keyField);
73
- let file1Parsed = await this.streamParse(fs.createReadStream(file1), (f) => {
74
- f;
75
- });
76
- file1Parsed = file1Parsed.map((m) => {
77
- const next = {};
78
- Object.keys(m).forEach((k) => {
79
- next[k.trim()] = m[k];
80
- });
81
- return next;
82
- });
83
- const file1Mapped = MapRatchet.mapByUniqueProperty(file1Parsed, keyField);
84
- let file2Parsed = await this.streamParse(fs.createReadStream(file2), (f) => {
85
- f;
86
- });
87
- file2Parsed = file2Parsed.map((m) => {
88
- const next = {};
89
- Object.keys(m).forEach((k) => {
90
- next[k.trim()] = m[k];
91
- });
92
- return next;
93
- });
94
- const file2Mapped = MapRatchet.mapByUniqueProperty(file2Parsed, keyField);
95
- const f1Only = [];
96
- const f2Only = [];
97
- const both = [];
98
- Array.from(file1Mapped.keys()).forEach((f1k) => {
99
- if (file2Mapped.has(f1k)) {
100
- both.push(f1k);
101
- }
102
- else {
103
- f1Only.push(f1k);
104
- }
105
- });
106
- Array.from(file2Mapped.keys()).forEach((f1k) => {
107
- if (!file1Mapped.has(f1k)) {
108
- f2Only.push(f1k);
109
- }
110
- });
111
- const rval = {
112
- file1Data: file1Mapped,
113
- file2Data: file2Mapped,
114
- file1OnlyKeys: f1Only,
115
- file2OnlyKeys: f2Only,
116
- bothFilesKeys: both,
117
- };
118
- return rval;
119
- }
120
- static async streamObjectsToCsv(srcSubject, output, inOpts) {
121
- RequireRatchet.notNullOrUndefined(srcSubject, 'srcSubject');
122
- RequireRatchet.notNullOrUndefined(output, 'output');
123
- const opts = inOpts || CsvRatchet.defaultStringifyOptions();
124
- Logger.silly('Running pipe to csv output : %j', opts);
125
- let count = 0;
126
- const genProm = new Promise((res, rej) => {
127
- const stringifier = stringify(opts);
128
- stringifier.on('error', (err) => {
129
- if (sub) {
130
- sub.unsubscribe();
131
- }
132
- rej(err);
133
- });
134
- stringifier.on('finish', () => {
135
- if (sub) {
136
- sub.unsubscribe();
137
- }
138
- res(count);
139
- });
140
- stringifier.pipe(output);
141
- const sub = srcSubject.subscribe((next) => {
142
- Logger.debug('Adding %j to csv', next);
143
- count++;
144
- stringifier.write(next);
145
- }, (err) => {
146
- Logger.error('Error generating : %s', err);
147
- rej(err);
148
- }, () => {
149
- Logger.debug('Finished');
150
- stringifier.end();
151
- });
152
- });
153
- return genProm;
154
- }
155
- static defaultParseFunction(row) {
156
- return row;
157
- }
158
- }
@@ -1,41 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- import { StringWritable } from '@bitblit/ratchet-common/lib/stream/string-writable.js';
3
- import { CsvRatchet } from './csv-ratchet.js';
4
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
5
- import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
6
- describe('#streamObjectsToCsv', function () {
7
- it('should parse a string', async () => {
8
- const testString = 'a,b\n1,2\n3,4\n';
9
- const out = await CsvRatchet.stringParse(testString, (CsvRatchet.defaultParseFunction));
10
- expect(out).toBeTruthy();
11
- expect(out.length).toEqual(2);
12
- expect(out[0].a).toEqual('1');
13
- expect(out[1].a).toEqual('3');
14
- });
15
- it('should generate csv data', async () => {
16
- const output = [
17
- { a: 1, b: '2' },
18
- { a: 3, b: '4' },
19
- ];
20
- const testString = await CsvRatchet.generateCsvData(output);
21
- expect(testString).toBeTruthy();
22
- expect(testString.length).toBeGreaterThan(10);
23
- });
24
- it('should stream objects to a csv', async () => {
25
- const sub = new Subject();
26
- const out = new StringWritable();
27
- const prom = CsvRatchet.streamObjectsToCsv(sub, out);
28
- for (let i = 1; i < 6; i++) {
29
- Logger.debug('Proc : %d', i);
30
- sub.next({ a: i, b: 'test ' + i + ' ,,' });
31
- await PromiseRatchet.wait(10);
32
- }
33
- sub.complete();
34
- Logger.debug('Waiting on write');
35
- const result = await prom;
36
- Logger.debug('Write complete');
37
- const val = out.value;
38
- expect(result).toEqual(5);
39
- Logger.debug('Have res : %d and val : \n%s', result, val);
40
- });
41
- });
@@ -1,56 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- import fs from 'fs';
3
- import { CliRatchet } from '../cli/cli-ratchet.js';
4
- export class FilesToStaticClass {
5
- static async process(fileNames, outClassName, outFileName = null) {
6
- if (!fileNames) {
7
- throw new Error('fileNames must be defined');
8
- }
9
- if (!outClassName) {
10
- throw new Error('outClassName must be defined');
11
- }
12
- if (fileNames.length === 0) {
13
- Logger.warn('Warning - no files supplied to process');
14
- }
15
- Logger.info('Generating class %s from files %j (output file: %s)', outClassName, fileNames, outFileName);
16
- let rval = '/** \n';
17
- rval += '* Holder for the constants to be used by consumers \n';
18
- rval += '* Moves it into code so that it can survive a trip through WebPack \n';
19
- rval += '*/ \n\n';
20
- rval += 'export class ' + outClassName + ' { \n';
21
- rval += ' public static readonly VALUES:Record<string, string> = { \n';
22
- for (let i = 0; i < fileNames.length; i++) {
23
- let contents = 'NOT-FOUND';
24
- if (fs.existsSync(fileNames[i])) {
25
- const trimmed = fileNames[i].substring(fileNames[i].lastIndexOf('/') + 1);
26
- contents = fs.readFileSync(fileNames[i]).toString();
27
- rval += i > 0 ? ',' : '';
28
- rval += '"' + trimmed + '":' + JSON.stringify(contents) + '\n';
29
- }
30
- else {
31
- Logger.warn('Could not find file %s', fileNames[i]);
32
- }
33
- }
34
- rval += '}; \n';
35
- rval += '}';
36
- if (!!outFileName) {
37
- Logger.info('Writing to %s', outFileName);
38
- fs.writeFileSync(outFileName, rval);
39
- }
40
- return rval;
41
- }
42
- static async runFromCliArgs(args) {
43
- if (args.length < 4) {
44
- Logger.infoP('Usage: ratchet-files-to-static-class {outFileName} {outClassName} {file0} ... {fileN}');
45
- return null;
46
- }
47
- else {
48
- const idx = CliRatchet.indexOfCommandArgument('files-to-static-class');
49
- const outFileName = process.argv[idx + 1];
50
- const outClassName = process.argv[idx + 2];
51
- const files = process.argv.slice(idx + 3);
52
- Logger.info('Running FilesToStaticClass from command line arguments Target: %s TargetClass: %s InFiles: %j', outFileName, outClassName, files);
53
- return FilesToStaticClass.process(files, outClassName, outFileName);
54
- }
55
- }
56
- }
@@ -1,11 +0,0 @@
1
- import path from 'path';
2
- import { FilesToStaticClass } from './files-to-static-class.js';
3
- import { EsmRatchet } from '@bitblit/ratchet-common/lib/lang/esm-ratchet.js';
4
- const testDirname = EsmRatchet.fetchDirName(import.meta.url);
5
- describe('#filesToStaticClass', function () {
6
- it('should convert files to a static class', async () => {
7
- const out = await FilesToStaticClass.process([path.join(testDirname, 'files-to-static-class.ts'), path.join(testDirname, 'cli-ratchet.ts')], 'Test');
8
- expect(out).not.toBeNull();
9
- expect(out.length).toBeGreaterThan(0);
10
- });
11
- });
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,70 +0,0 @@
1
- import process from 'child_process';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- import { EsmRatchet } from '@bitblit/ratchet-common/lib/lang/esm-ratchet.js';
4
- export class GitRatchet {
5
- static SPLIT_CHARACTER = '<##>';
6
- static PRETTY_FORMAT = ['%h', '%H', '%s', '%f', '%b', '%at', '%ct', '%an', '%ae', '%cn', '%ce', '%N', ''];
7
- static async executeCommand(command, options) {
8
- let dst = EsmRatchet.fetchDirName(import.meta.url);
9
- if (!!options && !!options.dst) {
10
- dst = options.dst;
11
- }
12
- return new Promise((res, rej) => {
13
- process.exec(command, { cwd: dst }, (err, stdout, stderr) => {
14
- if (stdout === '') {
15
- rej('this does not look like a git repo');
16
- }
17
- if (!!stderr) {
18
- rej(stderr);
19
- }
20
- res(stdout);
21
- });
22
- });
23
- }
24
- static getCommandString(splitChar) {
25
- return ('git log -1 --pretty=format:"' +
26
- GitRatchet.PRETTY_FORMAT.join(splitChar) +
27
- '"' +
28
- ' && git rev-parse --abbrev-ref HEAD' +
29
- ' && git tag --contains HEAD');
30
- }
31
- static async getLastCommitSwallowException(options = {}) {
32
- let rval = null;
33
- try {
34
- rval = await this.getLastCommit(options);
35
- }
36
- catch (err) {
37
- Logger.warn('Failed to fetch git data : %s', err, err);
38
- }
39
- return rval;
40
- }
41
- static async getLastCommit(options = {}) {
42
- const command = GitRatchet.getCommandString(GitRatchet.SPLIT_CHARACTER);
43
- const res = await GitRatchet.executeCommand(command, options);
44
- const a = res.split(GitRatchet.SPLIT_CHARACTER);
45
- const branchAndTags = a[a.length - 1].split('\n').filter((n) => n);
46
- const branch = branchAndTags[0];
47
- const tags = branchAndTags.slice(1);
48
- const rval = {
49
- shortHash: a[0],
50
- hash: a[1],
51
- subject: a[2],
52
- sanitizedSubject: a[3],
53
- body: a[4],
54
- authoredOn: a[5],
55
- committedOn: a[6],
56
- author: {
57
- name: a[7],
58
- email: a[8],
59
- },
60
- committer: {
61
- name: a[9],
62
- email: a[10],
63
- },
64
- notes: a[11],
65
- branch,
66
- tags,
67
- };
68
- return rval;
69
- }
70
- }
@@ -1,9 +0,0 @@
1
- import { GitRatchet } from './git-ratchet.js';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- describe('#gitRatchet', function () {
4
- it('should fetch last commit data', async () => {
5
- const res = await GitRatchet.getLastCommitSwallowException();
6
- expect(res).toBeTruthy();
7
- Logger.info('Got: %j', res);
8
- }, 10_000);
9
- });