Skip to content

Commit

Permalink
fix: ensure resources dir, reduce deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Dec 11, 2021
1 parent ad0345b commit b662bd1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file added resources/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion src/bin/run-ktlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
29 changes: 19 additions & 10 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)

Expand All @@ -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`
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit b662bd1

Please sign in to comment.