Skip to content

Commit

Permalink
Merge pull request #20 from FotonTech/feat/multiple-files
Browse files Browse the repository at this point in the history
Feat/multiple files
  • Loading branch information
renanmav authored Dec 14, 2019
2 parents 3545d09 + 931f574 commit 1261361
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ yarn add @fotoncompany/sort-object

Use the cli with the `--src` flag as follows:
```
sort-object --src ./**/*.ts
sort-object --src ./packages
```

You can filter which files will be formated through the `--regex` flag, as shown below. The Regex must be a string that can be parsed.
```
sort-object --src ./packages --regex '.input.ts'
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fotoncompany/sort-object",
"version": "0.0.1",
"version": "0.2.2",
"description": "Sort an object's key within source code automatically as part of linting",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
8 changes: 6 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ export const run = () => {
const argv = yargs(process.argv)
.usage('Sort an object’s key within source code automatically as part of linting')
.describe('src', 'The source to sort object’s keys')
.default('src', process.cwd()).argv
.default('src', process.cwd())
.describe('regex', 'Regex to match files')
.default('regex', /./g).argv

const jsFiles = shell.find(argv.src).filter(path => /\.(js|ts|tsx)$/.test(path))

generateResources(jsFiles)
const regex = new RegExp(argv.regex)

generateResources(jsFiles.filter(file => regex.test(file)))
}
10 changes: 10 additions & 0 deletions test/fixtures/WithTypes.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const coolThings = {
Star: 'Wars',
TheBigBang: 'Theory',
The: 'Office',
Breaking: 'Bad',
}

export default coolThings

export type Keys = keyof typeof coolThings
10 changes: 10 additions & 0 deletions test/fixtures/WithTypes.output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const coolThings = {
Breaking: 'Bad',
The: 'Office',
TheBigBang: 'Theory',
Star: 'Wars',
}

export default coolThings

export type Keys = keyof typeof coolThings

0 comments on commit 1261361

Please sign in to comment.