Replace 'read-last-lines' with 'n-readlines'
read-last-lines had trouble reading lines
This commit is contained in:
parent
877811bf50
commit
d14b966ef1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -33,12 +33,13 @@
|
|||
"@actions/core": "^1.2.6",
|
||||
"async": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"read-last-lines": "^1.7.2"
|
||||
"n-readlines": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node12": "^1.0.7",
|
||||
"@types/async": "^3.2.4",
|
||||
"@types/fs-extra": "^9.0.4",
|
||||
"@types/n-readlines": "^1.0.1",
|
||||
"@types/node": "~12.19.6",
|
||||
"@vercel/ncc": "^0.25.1",
|
||||
"ts-node": "^9.0.0",
|
||||
|
|
|
@ -30,6 +30,15 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/n-readlines": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/n-readlines/-/n-readlines-1.0.1.tgz",
|
||||
"integrity": "sha512-n1ND4k+9hgtil2HnHK+1tIj1UWchsD+RwoH7eVQqLbUe8AxwLuqDEnx3Riq+twHoMTjP80Q/ilB3LGdyXKfTEg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.19.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.6.tgz",
|
||||
|
@ -42,11 +51,6 @@
|
|||
"integrity": "sha512-dGecC5+1wLof1MQpey4+6i2KZv4Sfs6WfXkl9KfO32GED4ZPiKxRfvtGPjbjZv0IbqMl6CxtcV1RotXYfd5SSA==",
|
||||
"dev": true
|
||||
},
|
||||
"any-promise": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
|
||||
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
|
||||
},
|
||||
"arg": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||
|
@ -113,28 +117,10 @@
|
|||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||
"dev": true
|
||||
},
|
||||
"mz": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
|
||||
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
|
||||
"requires": {
|
||||
"any-promise": "^1.0.0",
|
||||
"object-assign": "^4.0.1",
|
||||
"thenify-all": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"read-last-lines": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/read-last-lines/-/read-last-lines-1.7.2.tgz",
|
||||
"integrity": "sha512-K0yUvTYAYn6qpyLJufaJ7yC6BeL23qpgZ8SKM7/fA1R1rHotCDxB/zDp9i1I2JHvexWBW6/35jkt07iiIKKp4g==",
|
||||
"requires": {
|
||||
"mz": "^2.7.0"
|
||||
}
|
||||
"n-readlines": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/n-readlines/-/n-readlines-1.0.1.tgz",
|
||||
"integrity": "sha512-z4SyAIVgMy7CkgsoNw7YVz40v0g4+WWvvqy8+ZdHrCtgevcEO758WQyrYcw3XPxcLxF+//RszTz/rO48nzD0wQ=="
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
|
@ -152,22 +138,6 @@
|
|||
"source-map": "^0.6.0"
|
||||
}
|
||||
},
|
||||
"thenify": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
||||
"integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
|
||||
"requires": {
|
||||
"any-promise": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"thenify-all": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
|
||||
"integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
|
||||
"requires": {
|
||||
"thenify": ">= 3.1.0 < 4"
|
||||
}
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz",
|
||||
|
|
|
@ -33,12 +33,13 @@
|
|||
"@actions/core": "^1.2.6",
|
||||
"async": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"read-last-lines": "^1.7.2"
|
||||
"n-readlines": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node12": "^1.0.7",
|
||||
"@types/async": "^3.2.4",
|
||||
"@types/fs-extra": "^9.0.4",
|
||||
"@types/n-readlines": "^1.0.1",
|
||||
"@types/node": "~12.19.6",
|
||||
"@vercel/ncc": "^0.25.1",
|
||||
"ts-node": "^9.0.0",
|
||||
|
|
16
src/index.ts
16
src/index.ts
|
@ -4,9 +4,7 @@ import { copy } from 'fs-extra';
|
|||
import { rmdirSync } from 'fs';
|
||||
import { parallelLimit } from 'async';
|
||||
|
||||
import { cpuCount, downloadFile, exit, fixArgArr, isNumeric, resetWorkingDir, runCmd } from './utils';
|
||||
|
||||
const rll = require('read-last-lines');
|
||||
import { cpuCount, downloadFile, exit, fixArgArr, isNumeric, readLastLines, resetWorkingDir, runCmd } from './utils';
|
||||
|
||||
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
|
||||
spraxdev: {
|
||||
|
@ -66,7 +64,7 @@ async function run(): Promise<{ code: number, msg?: string }> {
|
|||
console.error(err);
|
||||
|
||||
console.error(`\nPrinting last 25 lines from '${resolvePath(appLogFile)}':`);
|
||||
for (const line of (await rll.read(appLogFile, 25))) {
|
||||
for (const line of readLastLines(appLogFile, 25)) {
|
||||
console.error(line);
|
||||
}
|
||||
|
||||
|
@ -122,14 +120,12 @@ async function run(): Promise<{ code: number, msg?: string }> {
|
|||
console.error(err);
|
||||
|
||||
console.error(`\nPrinting last 25 lines from '${resolvePath(logFile)}':`);
|
||||
rll.read(logFile, 25)
|
||||
.then((lines: string[]) => {
|
||||
for (const line of lines) {
|
||||
|
||||
for (const line of readLastLines(logFile, 25)) {
|
||||
console.error(line);
|
||||
}
|
||||
})
|
||||
.catch(console.error)
|
||||
.finally(() => rejectTask(err));
|
||||
|
||||
rejectTask(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
18
src/utils.ts
18
src/utils.ts
|
@ -4,6 +4,7 @@ import { get as httpGet } from 'http';
|
|||
import { get as httpsGet } from 'https';
|
||||
import { cpus, tmpdir } from 'os';
|
||||
import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs';
|
||||
import readLines from 'n-readlines';
|
||||
|
||||
const packageJson = JSON.parse(readFileSync(joinPath(__dirname, '..', 'package.json'), 'utf-8'));
|
||||
const userAgent = `${packageJson.name || 'Action-SpigotMC'}/${packageJson.version || 'UNKNOWN_VERSION'} (+${packageJson.homepage || 'https://github.com/SpraxDev/'})`;
|
||||
|
@ -127,6 +128,23 @@ export async function downloadFile(url: string, dest: string, currRedirectDepth:
|
|||
});
|
||||
}
|
||||
|
||||
export function readLastLines(file: string, lineCount: number, encoding: string = 'utf-8'): string[] {
|
||||
const result = [];
|
||||
|
||||
const reader = new readLines(file);
|
||||
|
||||
let line;
|
||||
while (line = reader.next()) {
|
||||
result.push(line.toString(encoding));
|
||||
|
||||
if (result.length > lineCount) {
|
||||
result.shift();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function resetWorkingDir(): { base: string, cache: string, logs: string } {
|
||||
const baseDir = joinPath(tmpdir(), 'SpraxDev-Action-SpigotMC');
|
||||
const cacheDir = joinPath(baseDir, 'cache');
|
||||
|
|
Loading…
Reference in New Issue