From ee8b20906042f3c1b7cd953b205b6a214ccb0a6a Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:02:03 -0300 Subject: [PATCH 1/6] feat(multiple-files): add second fixture --- test/fixtures/WithTypes.input.ts | 10 ++++++++++ test/fixtures/WithTypes.output.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/fixtures/WithTypes.input.ts create mode 100644 test/fixtures/WithTypes.output.ts diff --git a/test/fixtures/WithTypes.input.ts b/test/fixtures/WithTypes.input.ts new file mode 100644 index 0000000..1d2835b --- /dev/null +++ b/test/fixtures/WithTypes.input.ts @@ -0,0 +1,10 @@ +const coolThings = { + Star: 'Wars', + TheBigBang: 'Theory', + The: 'Office', + Breaking: 'Bad', +} + +export default coolThings + +export type Keys = keyof typeof coolThings diff --git a/test/fixtures/WithTypes.output.ts b/test/fixtures/WithTypes.output.ts new file mode 100644 index 0000000..4791c30 --- /dev/null +++ b/test/fixtures/WithTypes.output.ts @@ -0,0 +1,10 @@ +const coolThings = { + Breaking: 'Bad', + The: 'Office', + TheBigBang: 'Theory', + Star: 'Wars', +} + +export default coolThings + +export type Keys = keyof typeof coolThings From 9fbb0676f8112af563b625d601f5fb711351996d Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:43:05 -0300 Subject: [PATCH 2/6] feat(multiple-files): add regex flag --- README.md | 7 ++++++- src/cli.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 65924e2..332d90e 100644 --- a/README.md +++ b/README.md @@ -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' +``` \ No newline at end of file diff --git a/src/cli.ts b/src/cli.ts index 95f57cf..bd80a9c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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))) } From 3e258e57a717ef08c721319fd202e5c64acefd8e Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:43:39 -0300 Subject: [PATCH 3/6] 0.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b97ea5f..fbc94ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fotoncompany/sort-object", - "version": "0.0.1", + "version": "0.1.0", "description": "Sort an object's key within source code automatically as part of linting", "main": "dist/index.js", "module": "dist/index.js", From 3c8b66914a6d4ffce762f365d439009eedbec7ed Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:46:05 -0300 Subject: [PATCH 4/6] 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fbc94ed..00d1933 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fotoncompany/sort-object", - "version": "0.1.0", + "version": "0.2.0", "description": "Sort an object's key within source code automatically as part of linting", "main": "dist/index.js", "module": "dist/index.js", From 3b70e1870ac75003d41d7c6ee05696f2b66dd06f Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:48:33 -0300 Subject: [PATCH 5/6] 0.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00d1933..fb411e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fotoncompany/sort-object", - "version": "0.2.0", + "version": "0.2.1", "description": "Sort an object's key within source code automatically as part of linting", "main": "dist/index.js", "module": "dist/index.js", From 931f574a32f21c2461395afabb224f199eb4a92c Mon Sep 17 00:00:00 2001 From: Renan Machado Date: Sat, 14 Dec 2019 10:48:57 -0300 Subject: [PATCH 6/6] 0.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb411e0..4a37c71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fotoncompany/sort-object", - "version": "0.2.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",