Skip to content

Commit d660f5d

Browse files
committed
chore(structure): restructure project
1 parent 681f373 commit d660f5d

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

src/bin/index.ts renamed to index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
#!/usr/bin/env node
12
import { resolve, join } from "path";
23
import { promises } from "fs";
34
import * as ts from "typescript";
4-
5-
const userLibraryPrefixes = ["@custom"];
5+
import commander from "commander";
6+
7+
import * as packageJSON from "./package.json";
8+
9+
const collect = (value, previous) => previous.concat([value]);
10+
commander
11+
.version(packageJSON.version)
12+
.option("-s --source <string>", "path to the source files", "./src/*")
13+
.option(
14+
"-p --userLibPrefixes <value>",
15+
"the prefix of custom user libraries",
16+
collect,
17+
[]
18+
)
19+
.parse(process.argv);
620

721
interface ImportCategories {
822
thirdPartyImportPot: Map<string, string>;
@@ -76,7 +90,7 @@ function sortImportCategories(
7690

7791
function isCustomImport(literal: string): boolean {
7892
let isCustomImport = false;
79-
for (const userLibraryPrefix of userLibraryPrefixes) {
93+
for (const userLibraryPrefix of commander.userLibPrefixes) {
8094
if (literal.startsWith(`'${userLibraryPrefix}`)) {
8195
isCustomImport = true;
8296
break;
@@ -146,7 +160,7 @@ function getImportInformation(rootNode: ts.Node): ImportInformation {
146160
}
147161

148162
(async () => {
149-
for await (const p of walk(resolve(__dirname, "../../test"))) {
163+
for await (const p of walk(resolve(__dirname, commander.source))) {
150164
const fileContent = await promises.readFile(p);
151165
const rootNode = ts.createSourceFile(
152166
p,
@@ -171,10 +185,8 @@ function getImportInformation(rootNode: ts.Node): ImportInformation {
171185
fileContent.slice(importInformation.endPosition);
172186

173187
if (updatedContent !== fileContent.toString()) {
174-
// await promises.writeFile(p, updatedContent);
175-
console.log("New content", updatedContent);
188+
await promises.writeFile(p, updatedContent);
176189
}
177-
console.log("Done");
178190
}
179191
}
180192
})();

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
"description": "Automatically organize your Typescript import statements",
55
"main": "index.js",
66
"scripts": {
7+
"build": "tsc",
78
"format:check": "prettier --list-different 'src/**/*.ts'",
89
"format:write": "prettier --write 'src/**/*.ts'",
910
"test": "echo \"Error: no test specified\" && exit 1",
10-
"start": "ts-node ./src/bin/index.ts"
11+
"start": "ts-node ./index.ts -s './test' -p '@custom'"
1112
},
1213
"husky": {
1314
"hooks": {
1415
"pre-commit": "pretty-quick --staged"
1516
}
1617
},
18+
"bin": {
19+
"import-ant": "./index.js"
20+
},
1721
"repository": {
1822
"type": "git",
1923
"url": "git+https://github.com/kreuzerk/import-ant.git"
@@ -37,5 +41,8 @@
3741
"pretty-quick": "^2.0.1",
3842
"ts-node": "^8.10.2",
3943
"typescript": "^3.9.5"
44+
},
45+
"dependencies": {
46+
"commander": "^5.1.0"
4047
}
4148
}

tslint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": ["tslint:recommended"],
4+
"jsRules": {},
5+
"rules": {},
6+
"rulesDirectory": []
7+
}

0 commit comments

Comments
 (0)