Skip to content

Commit

Permalink
line-reader -> n-readlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok committed May 30, 2020
1 parent e4166c9 commit c9df537
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
33 changes: 13 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@
"dependencies": {
"@expo/spawn-async": "^1.5.0",
"@octokit/rest": "^17.9.2",
"@types/bluebird": "^3.5.32",
"@types/commander": "^2.12.2",
"@types/dot": "^1.1.4",
"@types/gapi.client.discovery": "^1.0.2",
"@types/line-reader": "0.0.29",
"@types/lodash": "^4.14.152",
"@types/mocha": "^7.0.2",
"@types/n-readlines": "^1.0.1",
"@types/node": "^12.12.42",
"@types/request": "2.48.5",
"bluebird": "^3.7.2",
"commander": "^5.1.0",
"deep-sort-object": "^1.0.2",
"dot": "^1.1.3",
"dtslint": "^3.6.9",
"get-proxy-settings": "^0.1.11",
"gts": "^2.0.2",
"line-reader": "^0.4.0",
"lodash": "^4.17.15",
"mocha": "^7.2.0",
"n-readlines": "^1.0.0",
"npm-run-all": "^4.1.5",
"parse-git-status": "^0.1.0",
"request": "^2.88.2",
Expand Down
45 changes: 17 additions & 28 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import _ from 'lodash';
import path, {basename, join, resolve} from 'path';
import request from 'request';
import sortObject from 'deep-sort-object';
import lineReader from 'line-reader';
import {promisify} from 'bluebird';
import LineByLine from 'n-readlines';
import {
ensureDirectoryExists,
getResourceTypeName,
Expand All @@ -24,12 +23,6 @@ export const typingsPrefix = 'gapi.client.';
export const tmpDirPath = resolve(__dirname, './../.tmp');
export const revisionPrefix = '// Revision: ';

const eachLine: (
...args: Parameters<LineReader['eachLine']>
) => Promise<ReturnType<LineReader['eachLine']>> = promisify(
lineReader.eachLine
);

const typesMap: {[key: string]: string} = {
integer: 'number',
object: 'any',
Expand Down Expand Up @@ -776,30 +769,26 @@ export class App {
);

ensureDirectoryExists(destinationDirectory);
const indexDTSPath = path.join(destinationDirectory, 'index.d.ts');

if (
newRevisionsOnly &&
fs.existsSync(path.join(destinationDirectory, 'index.d.ts'))
) {
let existingRevision;
await eachLine(
path.join(destinationDirectory, 'index.d.ts'),
{},
line => {
if (line.startsWith(revisionPrefix)) {
const match = line.match(new RegExp(`^${revisionPrefix}(\\d+)$`));
if (match !== null && match.length === 2) {
existingRevision = Number(match[1]);
return false;
}
}
return true;
}
);

if (newRevisionsOnly && fs.existsSync(indexDTSPath)) {
if (!api.revision) {
return console.error(`There's no revision in JSON: ${api.id}`);
}

let existingRevision, line;
const liner = new LineByLine(indexDTSPath);
while ((line = liner.next())) {
line = line.toString();
if (line.startsWith(revisionPrefix)) {
const match = line.match(new RegExp(`^${revisionPrefix}(\\d+)$`));
if (match !== null && match.length === 2) {
existingRevision = Number(match[1]);
break;
}
}
}

if (!existingRevision) {
return console.error(
`Can't find previous revision in index.d.ts: ${api.id}`
Expand Down

0 comments on commit c9df537

Please sign in to comment.