Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated and fixed converters & added cli options for globbing & filtering #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.DS_Store
dist
node_modules
work
.idea
*.tgz
yarn-error.log
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,57 @@ npm install flow-to-typescript --save

### CLI

*Only `-i` is required*

```sh
# Install globally
yarn global add flow-to-typescript

# Compile a file (all of these are equivalent)
flow2ts my/file.js.flow
flow2ts my/file.js.flow my/file.ts
flow2ts my/file.js.flow > my/file.ts
flow2ts -i my/file.js.flow -o my/file.ts
flow2ts --input my/file.js.flow --output my/file.ts
flow2ts \
-i other-dir/my-flow-src-dir \
-o other-dir/my-ts-src-dir \
-e '\.js.flow$' \
-p other-dir/prettier.config.js \
-f "include-regex-filter"

flow2ts [args]

Options:
--help Show help [boolean]
--version Show version number [boolean]
-i, --input Input file or directory [string] [required]
-e, --ext Regex to match the file ext [string] [default: "\.js$"]
-f, --filter Input regex filter for excluding files [string]
-o, --output Output directory [string]
-p, --pretty-config Prettier config [string]


```

### Programmatic

```typescript
import { compile, CompileResult } from 'flow-to-typescript'
import { readFileSync, writeFileSync } from 'fs'

const path = 'path/to/file.js.flow'
const file = readFileSync(path, 'utf-8')

compile(file, path).then(({code}: CompileResult) =>
writeFileSync('path/to/file.ts', code)
)
```

```js
import { compile } from 'flow-to-typescript'
import { readFileSync, writeFileSync } from 'fs'

let path = 'path/to/file.js.flow'
let file = readFileSync(path, 'utf-8')

compile(file, path).then(ts =>
writeFileSync('path/to/file.ts', ts)
compile(file, path).then(({code}) =>
writeFileSync('path/to/file.ts', code)
)
```

Expand Down
9 changes: 9 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-syntax-dynamic-import'
]
};
62 changes: 51 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"scripts": {
"build": "tsc",
"build:watch": "tsc -w",
"build:watch": "tsc -p tsconfig.json -w",
"clean": "rm -rf ./dist",
"lint": "tslint src/**/*.ts && npm run prettier:check",
"prettier": "prettier 'src/**/*.[tj]s'",
Expand All @@ -21,29 +21,69 @@
"prepublishOnly": "npm run clean && npm run lint && npm run build -- -d",
"pretest": "npm run build",
"tdd": "concurrently -k 'npm run build:watch' 'npm run test:watch'",
"test": "ava --verbose",
"test:debug": "node --inspect-brk ./node_modules/ava/profile.js ./dist/test/test.js",
"test:watch": "ava -w"
"test": "jest",
"test:watch": "jest --watchAll",
"test:ava": "ava --verbose",
"test:ava:debug": "node --inspect-brk ./node_modules/ava/profile.js ./dist/test/test.js",
"test:ava:watch": "ava -w"
},
"jest": {
"testEnvironment": "node",
"watchPathIgnorePatterns": [
"dist\\/results"
],
"testMatch": [
"<rootDir>/dist/test/test.js"
],
"watchPlugins": [
"<rootDir>/dist/test/rule-watcher-plugin"
],
"moduleFileExtensions": [
"ts",
"tsx",
"txt",
"js",
"json"
]
},
"dependencies": {
"@babel/generator": "7.0.0-beta.38",
"@babel/traverse": "7.0.0-beta.38",
"@babel/types": "7.0.0-beta.38",
"@babel/generator": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"glob": "^7.1.2",
"lodash": "^4.17.4",
"mz": "^2.7.0"
"lodash": "^4.17.11",
"mz": "^2.7.0",
"typeguard": "^0.0.13",
"yargs": "^13.2.2"
},
"devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.4",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@types/babel__generator": "^7.0.2",
"@types/babel__traverse": "^7.0.6",
"@types/glob": "^5.0.33",
"@types/jest": "^24.0.12",
"@types/lodash": "^4.14.86",
"@types/minimist": "^1.2.0",
"@types/mz": "^0.0.32",
"@types/prettier": "^1.16.3",
"@types/shelljs": "^0.8.5",
"@typescript-eslint/typescript-estree": "^1.7.0",
"ansicolor": "^1.1.83",
"ava": "^0.24.0",
"concurrently": "^3.5.1",
"flow-bin": "^0.59.0",
"prettier": "^1.15.3",
"jest": "^24.8.0",
"jest-diff": "^24.8.0",
"jest-matcher-utils": "^24.8.0",
"jest-watcher": "^24.8.0",
"prettier": "^1.17.0",
"shelljs": "^0.8.3",
"ts-jest": "^24.0.2",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
"typescript": "^3.4.5"
},
"ava": {
"files": [
Expand Down
9 changes: 6 additions & 3 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
printWidth: 80,
printWidth: 120,
semi: false,
singleQuote: true,
trailingComma: 'none',
singleQuote: false,
useTabs: false,
tabWidth: 2,
trailingComma: "none",
parser: "typescript"
}
Loading