Skip to content

Commit 2ec7596

Browse files
authored
Feat/log affected (#15)
* fix: change filter name * chore: up version * feat: add flag to log only affected files
1 parent a1db3e6 commit 2ec7596

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@jotforminc/zenith",
33
"packageManager": "pnpm@7.18.0",
4-
"version": "0.5.3",
4+
"version": "0.5.4",
55
"description": "",
66
"main": "./build/index.js",
77
"files": [

src/classes/BuildHelper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ export default class BuildHelper extends WorkerHelper {
2020
this.command = command;
2121
}
2222

23-
async init(debug, compareWith, compareHash) {
23+
async init({debug, compareWith, compareHash, logAffected}) {
2424
this.cacher = new Cacher().cacher;
2525
this.compareHash = compareHash;
26+
this.logAffected = logAffected;
2627
this.startTime = process.hrtime();
2728
if (debug) {
2829
this.debug = debug;
@@ -120,7 +121,7 @@ export default class BuildHelper extends WorkerHelper {
120121
for (const output of outputs) {
121122
// const outputPath = path.join(ROOT_PATH, root, output);
122123
Logger.log(3, 'Recovering from cache', buildProject, 'with hash => ', hash);
123-
const recoverResponse = await this.anotherJob(hash, root, output, script, this.compareHash);
124+
const recoverResponse = await this.anotherJob(hash, root, output, script, this.compareHash, this.logAffected);
124125
if (recoverResponse instanceof Error) {
125126
throw new Error(recoverResponse);
126127
}

src/classes/RemoteCacher.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class RemoteCacher {
185185
})
186186
}
187187

188-
async recoverFromCache(originalHash, root, output, target) {
188+
async recoverFromCache(originalHash, root, output, target, logAffected) {
189189
const isStdOut = isOutputTxt(output)
190190
const remotePath = `${target}/${originalHash}/${root}/${output}.${isStdOut ? 'txt' : 'zip'}`;
191191
try {
@@ -194,7 +194,11 @@ class RemoteCacher {
194194
Key: remotePath,
195195
});
196196
const outputPath = path.join(ROOT_PATH, root, output);
197-
if (isStdOut) return Logger.log(2, await this.txtPipeEnd(response.Body));
197+
if (isStdOut) {
198+
const stdout = await this.txtPipeEnd(response.Body);
199+
if (logAffected) return stdout
200+
return Logger.log(2, await this.txtPipeEnd(response.Body));
201+
}
198202
if (existsSync(outputPath)) {
199203
rmSync(outputPath, { recursive: true, force: true });
200204
mkdirSync(outputPath);

src/classes/Runner.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class Runner {
1111
.option('-d, --debug', 'Debug mode')
1212
.option('-c, --compareWith <compareWith>', 'Compare with')
1313
.option('-ch, --noCompareHash', 'default: false. If false, will compare remote folders\' and local folders\' hash and execute target if hashes are not the same.')
14+
.option('-la, --logAffected', 'default: false. If true, will log outputs of ONLY missed caches\' executes.')
1415
.addOption(
1516
new Option(
1617
'-l, --logLevel <logLevel>',
@@ -35,13 +36,21 @@ export default class Runner {
3536
if (options.noCompareHash) {
3637
this.compareHash = false;
3738
}
39+
if (options.logAffected) {
40+
this.logAffected = true;
41+
}
3842

3943
Logger.setLogLevel(Number(options.logLevel));
4044
}
4145

4246
async run() {
4347
const Builder = new BuildHelper(this.command);
44-
await Builder.init(this.debug, this.compareWith, this.compareHash);
48+
await Builder.init({
49+
debug: this.debug,
50+
compareWith: this.compareWith,
51+
compareHash: this.compareHash,
52+
logAffected: this.logAffected
53+
});
4554
Logger.log(2, `Zenith ${this.command} started.`)
4655
if (this.project === 'all') {
4756
Builder.buildAll();

src/classes/WorkerHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export default class WorkerHelper {
2121
}
2222
}
2323

24-
async anotherJob(hash, root, output, target, compareHashes) {
24+
async anotherJob(hash, root, output, target, compareHashes, logAffected) {
2525
try {
26-
return await this.pool.exec('anotherJob', [hash, root, output, target, compareHashes], {
26+
return await this.pool.exec('anotherJob', [hash, root, output, target, compareHashes, logAffected], {
2727
on: message => Logger.log(3, message)
2828
});
2929
} catch (error) {

src/worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const execute = async (buildPath, targetCommand, hash, root, outputs, projectNam
2121
}
2222
}
2323

24-
const anotherJob = async (hash, root, output, target, compareHash) => {
24+
const anotherJob = async (hash, root, output, target, compareHash, logAffected) => {
2525
try {
26-
const outputHash = await RemoteCacher.recoverFromCache(hash, root, output, target);
26+
const outputHash = await RemoteCacher.recoverFromCache(hash, root, output, target, logAffected);
2727
workerpool.workerEmit(`Cache recovered ${root}`);
2828
if (!compareHash) return true;
2929
const remoteHash = await RemoteCacher.checkHashes(hash, root, output, target);

0 commit comments

Comments
 (0)