From b662bd180b3678cacd43ec7cfb022fc65adafcaa Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Sat, 11 Dec 2021 19:30:46 +0100 Subject: [PATCH] fix: ensure `resources` dir, reduce deps --- package.json | 3 +-- resources/.gitkeep | 0 src/bin/run-ktlint.ts | 1 - src/install.ts | 29 +++++++++++++++++++---------- yarn.lock | 6 +++--- 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 resources/.gitkeep diff --git a/package.json b/package.json index fcd3434..4fcaf3f 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ "postpublish": "pinst --disable" }, "dependencies": { - "@naturalcycles/js-lib": "^14.78.0", - "@naturalcycles/nodejs-lib": "^12.62.1" + "got": "^11.0.0" }, "devDependencies": { "@naturalcycles/dev-lib": "^12.14.2", diff --git a/resources/.gitkeep b/resources/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/bin/run-ktlint.ts b/src/bin/run-ktlint.ts index c678c73..80b10cb 100755 --- a/src/bin/run-ktlint.ts +++ b/src/bin/run-ktlint.ts @@ -19,7 +19,6 @@ console.log(['ktlint', ...args].join(' ')) const p = spawn(ktlintPath, [...args], { stdio: 'inherit', shell: true, - // env : { FORCE_COLOR: 'true' } }) // out.on('error', (error) => { diff --git a/src/install.ts b/src/install.ts index a5a7c6a..2395f57 100644 --- a/src/install.ts +++ b/src/install.ts @@ -5,28 +5,27 @@ yarn tsn src/install */ import * as fs from 'fs' -import { _hb } from '@naturalcycles/js-lib' -import { _pipeline, getGot, runScript } from '@naturalcycles/nodejs-lib' +import { pipeline } from 'stream' +import { promisify } from 'util' +import got from 'got' import { ktlintPath } from './paths' -runScript(async () => { +const _pipeline = promisify(pipeline) as any + +void (async () => { if (fs.existsSync(ktlintPath)) { // const {size, mode} = fs.statSync(ktlintPath) // return console.log(`ktlint exists, size: ${_hb(size)} mode ${mode}`) return } - const got = getGot({ - debug: true, - logWithSearchParams: false, - }) - const ktlintVersion = '0.43.2' console.log(`downloading ktlint ${ktlintVersion} from github, may take some time...`) const url = `https://github.com/pinterest/ktlint/releases/download/${ktlintVersion}/ktlint` + console.log(url) - await _pipeline([got.stream.get(url), fs.createWriteStream(ktlintPath)]) + await _pipeline(got.stream.get(url), fs.createWriteStream(ktlintPath)) console.log(`ktlint downloaded to ${ktlintPath}`) @@ -39,8 +38,18 @@ runScript(async () => { console.log(`ktlint size: ${_hb(size)}`) chmod() -}) +})() function chmod() { fs.chmodSync(ktlintPath, '775') } + +// from js-lib +function _hb(b = 0): string { + if (b < 1024) return `${Math.round(b)} byte` + if (b < 1024 ** 2) return `${(b / 1024).toPrecision(3)} Kb` + if (b < 1024 ** 3) return `${(b / 1024 ** 2).toPrecision(3)} Mb` + if (b < 1024 ** 4) return `${(b / 1024 ** 3).toPrecision(3)} Gb` + if (b < 1024 ** 5) return `${(b / 1024 ** 4).toPrecision(3)} Tb` + return `${Math.round(b / 1024 ** 4)} Tb` +} diff --git a/yarn.lock b/yarn.lock index 5c7fcdc..c8bde09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -488,14 +488,14 @@ typescript "^4.0.2" yargs "^17.0.0" -"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.6.1", "@naturalcycles/js-lib@^14.78.0": +"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.6.1": version "14.78.0" resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.78.0.tgz#5271ccbbc10fc9efc627bb26992cfc8843a0744c" integrity sha512-c8TeDjy8xNUUr1DB6aqG6OyvSACXZBOgZ7C9kqNBRGaUXIXUrM7psnd0G+cET1dqB6s/hajQZO09CSLo7Re8+A== dependencies: tslib "^2.0.0" -"@naturalcycles/nodejs-lib@^12.0.0", "@naturalcycles/nodejs-lib@^12.62.1", "@naturalcycles/nodejs-lib@^12.8.0": +"@naturalcycles/nodejs-lib@^12.0.0", "@naturalcycles/nodejs-lib@^12.8.0": version "12.62.1" resolved "https://registry.yarnpkg.com/@naturalcycles/nodejs-lib/-/nodejs-lib-12.62.1.tgz#1e1cba550380622de023486a1f5fb447446c929a" integrity sha512-4SQJMwfrnB1UutHJycT+EC3QTyp3d4pG060aWjsiMnl1Y87sAMJLFjKqUcM0LBvmkK5ZbYkVeW0v9bZWbJf6mw== @@ -2191,7 +2191,7 @@ globjoin@^0.1.4: resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43" integrity sha1-L0SUrIkZ43Z8XLtpHp9GMyQoXUM= -got@^11.0.1: +got@^11.0.0, got@^11.0.1: version "11.8.3" resolved "https://registry.yarnpkg.com/got/-/got-11.8.3.tgz#f496c8fdda5d729a90b4905d2b07dbd148170770" integrity sha512-7gtQ5KiPh1RtGS9/Jbv1ofDpBFuq42gyfEib+ejaRBJuj/3tQFeR5+gw57e4ipaU8c/rCjvX6fkQz2lyDlGAOg==