Skip to content

Commit

Permalink
feat: first version
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Dec 11, 2021
0 parents commit ad0345b
Show file tree
Hide file tree
Showing 18 changed files with 4,616 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# DO NOT MODIFY, WILL BE OVERWRITTEN BY @naturalcycles/dev-lib
#
# http://editorconfig.org
#

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[**.md]
trim_trailing_whitespace = false
indent_size = 4

[**.html]
indent_size = 2

[**.{css,scss}]
indent_size = 2

[**.{js,ts}]
indent_size = 2

[**.json]
indent_size = 2

[**.xml]
indent_size = 2

[**.java]
indent_size = 4

[**.sql]
indent_size = 2

[.eslintrc]
indent_size = 2

[**.min.*]
indent_style = ignore
trim_trailing_whitespace = false
insert_final_newline = ignore
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: release

on:
push:
branches: [master, next, act]

jobs:
release-job:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v2, with: { persist-credentials: true } }
- { uses: actions/setup-node@v2, with: { node-version: 16 } }

# Cache for npm/npx in ~/.npm
- uses: actions/cache@v2
with:
path: ~/.npm
key: npm-v1-${{ runner.os }}

- name: yarn
run: yarn --frozen-lockfile

- name: build
run: yarn build-prod

- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx @naturalcycles/semantic-release
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# DO NOT MODIFY, WILL BE OVERWRITTEN BY @naturalcycles/dev-lib
#
# You can put more .gitignore files in your respective subfolders (e.g `src`) to ignore additional things.
# Or PR to @naturalcycles/dev-lib if you want to ignore something generic.
#

#
# Global (all dirs)
#
*.iml
.idea
.DS_Store
node_modules
.env
.npmrc
.classpath
.project
.settings
.externalToolBuilders
.cache
.stencil
.gitconfig
.lighthouseci

#
# Root dir
#
/target
/*.log
/log.txt
/.sass-cache
/.sourcemaps
/docs/.vuepress/dist

/coverage
/report

/dist
/dist-cjs
/dist-esm
/tmp

# All secrets are ignored, except encrypted
/secret/**/*.*
!/secret/**/*.enc

/scripts/try.*
/logs
/platforms
/plugins
/www/*
!/www/.gitkeep
6 changes: 6 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"

node_modules/.bin/commitlint-def $1
# exit 1 # uncomment to debug
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"

node_modules/.bin/lint-staged-def
49 changes: 49 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@naturalcycles/ktlint",
"scripts": {
"prepare": "husky install",
"_postinstall": "node dist/install.js",
"prepublishOnly": "pinst --enable",
"postpublish": "pinst --disable"
},
"dependencies": {
"@naturalcycles/js-lib": "^14.78.0",
"@naturalcycles/nodejs-lib": "^12.62.1"
},
"devDependencies": {
"@naturalcycles/dev-lib": "^12.14.2",
"@types/node": "^16.11.12",
"pinst": "^2.1.6"
},
"files": [
"dist",
"resources",
"!src/test",
"!src/**/*.test.ts",
"!src/**/__snapshots__",
"!src/**/__exclude"
],
"bin": {
"run-ktlint": "dist/bin/run-ktlint.js"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/NaturalCycles/ktlint"
},
"engines": {
"node": ">=14.15.0"
},
"version": "0.0.0",
"description": "ktlint, conveniently published to npm registry",
"keywords": [
"ktlint",
"npm",
"published",
"lint"
],
"author": "Natural Cycles Team",
"license": "MIT"
}
47 changes: 47 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## @naturalcycles/ktlint

> [ktlint](https://github.com/pinterest/ktlint), conveniently published to npm registry
[![npm](https://img.shields.io/npm/v/@naturalcycles/ktlint/latest.svg)](https://www.npmjs.com/package/@naturalcycles/ktlint)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)

Current ktlint version: `0.43.2`

# Features

## ktlint binary

Hosts `ktlint` binary in the npm registry.

So, you can install it as:

```shell
yarn add -D @naturalcycles/ktlint

# or with npm
npm i --save-dev @naturalcycles/ktlint
```

And access it as `node_modules/@naturalcycles/ktlint/resources/ktlint`.

E.g:

```shell
node_modules/@naturalcycles/ktlint/resources/ktlint --version
```

## run-ktlint

It exposes a `run-ktlint` CLI command, so you can run it like this (passing the arguments that you
would pass to ktlint):

```shell
yarn run-ktlint -F

# or

yarn run-ktlint "someFile.kt"
```

Test it with `yarn run-ktlint --version`
1 change: 1 addition & 0 deletions resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ktlint
1 change: 1 addition & 0 deletions scripts/empty.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
11 changes: 11 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// tsconfig.json for /scripts
//
{
"extends": "@naturalcycles/dev-lib/scripts/tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "../dist"
},
"exclude": ["**/__exclude"]
}
32 changes: 32 additions & 0 deletions src/bin/run-ktlint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

/*
yarn tsn ./src/bin/run-ktlint.ts --version
*/

import { spawn } from 'child_process'
import { ktlintPath } from '../paths'

// argv[0] is /usr/local/bin/node
// argv[1] is ./src/bin/run-ktlint.ts (when ran with `yarn tsn`)
const args = process.argv.slice(2)
// console.log({argv, argv0, args})

console.log(['ktlint', ...args].join(' '))

const p = spawn(ktlintPath, [...args], {
stdio: 'inherit',
shell: true,
// env : { FORCE_COLOR: 'true' }
})

// out.on('error', (error) => {
// console.log(`error: ${error.message}`);
// });

p.on('close', code => {
// console.log(`child process exited with code ${code}`);
process.exit(code || 0)
})
46 changes: 46 additions & 0 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
yarn tsn src/install
*/

import * as fs from 'fs'
import { _hb } from '@naturalcycles/js-lib'
import { _pipeline, getGot, runScript } from '@naturalcycles/nodejs-lib'
import { ktlintPath } from './paths'

runScript(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`

await _pipeline([got.stream.get(url), fs.createWriteStream(ktlintPath)])

console.log(`ktlint downloaded to ${ktlintPath}`)

if (!fs.existsSync(ktlintPath)) {
console.log(`something went wrong, ktlint not found at path: ${ktlintPath}`)
return process.exit(15)
}

const { size } = fs.statSync(ktlintPath)
console.log(`ktlint size: ${_hb(size)}`)

chmod()
})

function chmod() {
fs.chmodSync(ktlintPath, '775')
}
5 changes: 5 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as path from 'path'

export const projectDir = path.join(__dirname, '..')
export const resourcesDir = `${projectDir}/resources`
export const ktlintPath = `${resourcesDir}/ktlint`
4 changes: 4 additions & 0 deletions src/test/hello.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

fun main() {
println("hello.kt")
}
2 changes: 2 additions & 0 deletions src/test/hello.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

println("hello.kts")
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@naturalcycles/dev-lib/cfg/tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"outDir": "dist"
},
"include": ["src"],
"exclude": ["**/__exclude"]
}
8 changes: 8 additions & 0 deletions tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"sourceMap": false
},
"exclude": ["**/__exclude", "src/test", "src/**/*.test.*"]
}
Loading

0 comments on commit ad0345b

Please sign in to comment.