Skip to content

Commit 1bdbb00

Browse files
authored
Merge from tsco cli (#106)
1 parent 36b4fef commit 1bdbb00

19 files changed

Lines changed: 349 additions & 111 deletions

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,10 @@ See [TypeScript Code Organizer Command Line Interface](https://www.npmjs.com/pac
211211

212212
- fix issue with removing empty lines in code expressions
213213
- fix issue with using typed imports
214+
215+
### 2.0.10
216+
217+
- add setting for expanding/collapsing imports
218+
- fix issue with declaring modules
219+
- add support for exported enums, exported interfaces, exported classes and exported types (courtesy of [Carlos Jesús Huchim Ahumada](https://github.com/huchim))
220+
- add improved import statement grouping

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tsco",
33
"displayName": "TypeScript Code Organizer",
44
"description": "TypeScript Code Organizer for VS Code",
5-
"version": "2.0.9",
5+
"version": "2.0.10",
66
"publisher": "aljazsim",
77
"author": {
88
"name": "aljazsim",

src/tsco-cli/configuration/configuration.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ImportSourceFilePathQuoteType } from "../enums/Import-source-file-path-quote-type";
21
import { ClassMemberType } from "../enums/class-member-type";
2+
import { ImportExpand } from "../enums/import-expand";
3+
import { ImportSourceFilePathQuoteType } from "../enums/import-source-file-path-quote-type";
34
import { InterfaceMemberType } from "../enums/interface-member-type";
45
import { ModuleMemberType } from "../enums/module-member-type";
56
import { TypeMemberType } from "../enums/type-member-type";
@@ -78,7 +79,8 @@ export class Configuration
7879
configuration.imports?.sortImportsByName ?? defaultConfiguration.imports.sortImportsByName,
7980
configuration.imports?.groupImportsBySource ?? defaultConfiguration.imports.groupImportsBySource,
8081
configuration.imports?.separateImportGroups ?? defaultConfiguration.imports.separateImportGroups,
81-
this.parseImportSourceFilePathQuoteType(configuration.imports?.quote) ?? defaultConfiguration.imports.quote
82+
this.parseImportSourceFilePathQuoteType(configuration.imports?.quote) ?? defaultConfiguration.imports.quote,
83+
this.parseImportExpand(configuration.imports?.expand) ?? defaultConfiguration.imports.expand
8284
),
8385
new ModuleConfiguration
8486
(
@@ -159,7 +161,8 @@ export class Configuration
159161
defaultConfiguration.imports.sortImportsByName,
160162
defaultConfiguration.imports.groupImportsBySource,
161163
defaultConfiguration.imports.separateImportGroups,
162-
this.parseImportSourceFilePathQuoteType(defaultConfiguration.imports.quote) ?? ImportSourceFilePathQuoteType.Double
164+
this.parseImportSourceFilePathQuoteType(defaultConfiguration.imports.quote) ?? ImportSourceFilePathQuoteType.Double,
165+
this.parseImportExpand(defaultConfiguration.imports.expand) ?? ImportExpand.Never
163166
),
164167
new ModuleConfiguration
165168
(
@@ -228,7 +231,7 @@ export class Configuration
228231

229232
// #endregion Public Static Methods
230233

231-
// #region Private Static Methods (9)
234+
// #region Private Static Methods (10)
232235

233236
private static fixClassMemberMemberGroup(defaultMemberTypeOrder: ClassMemberGroupConfiguration[], memberTypeOrder: ClassMemberGroupConfiguration[]): ClassMemberGroupConfiguration[]
234237
{
@@ -339,6 +342,26 @@ export class Configuration
339342
return new ClassMemberGroupConfiguration(sortDirection, caption, memberTypes, memberTypesGrouped, placeAbove, placeBelow);
340343
}
341344

345+
private static parseImportExpand(importExpand: string)
346+
{
347+
if (importExpand === ImportExpand.Never)
348+
{
349+
return ImportExpand.Never;
350+
}
351+
else if (importExpand === ImportExpand.Always)
352+
{
353+
return ImportExpand.Always;
354+
}
355+
else if (importExpand === ImportExpand.WhenMoreThanOneNamedImport)
356+
{
357+
return ImportExpand.WhenMoreThanOneNamedImport;
358+
}
359+
else
360+
{
361+
return null;
362+
}
363+
}
364+
342365
private static parseImportSourceFilePathQuoteType(quoteType: string)
343366
{
344367
if (quoteType === ImportSourceFilePathQuoteType.Double)

src/tsco-cli/configuration/default-configuration.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ImportSourceFilePathQuoteType } from "../enums/Import-source-file-path-quote-type";
21
import { ClassMemberType } from "../enums/class-member-type";
2+
import { ImportExpand } from "../enums/import-expand";
3+
import { ImportSourceFilePathQuoteType } from "../enums/import-source-file-path-quote-type";
34
import { InterfaceMemberType } from "../enums/interface-member-type";
45
import { ModuleMemberType } from "../enums/module-member-type";
56
import { TypeMemberType } from "../enums/type-member-type";
@@ -19,7 +20,8 @@ export const defaultConfiguration: Configuration =
1920
sortImportsByName: true,
2021
groupImportsBySource: true,
2122
separateImportGroups: true,
22-
quote: ImportSourceFilePathQuoteType.Double
23+
quote: ImportSourceFilePathQuoteType.Double,
24+
expand: ImportExpand.Never,
2325
},
2426
modules: {
2527
regions: {
@@ -35,31 +37,31 @@ export const defaultConfiguration: Configuration =
3537
{
3638
sortDirection: "asc",
3739
caption: "Enums",
38-
memberTypes: [ModuleMemberType.enums],
40+
memberTypes: [ModuleMemberType.enums, ModuleMemberType.exportedEnums],
3941
memberTypesGrouped: true,
4042
placeAbove: [],
4143
placeBelow: []
4244
},
4345
{
4446
sortDirection: "asc",
4547
caption: "Interfaces",
46-
memberTypes: [ModuleMemberType.interfaces],
48+
memberTypes: [ModuleMemberType.interfaces, ModuleMemberType.exportedInterfaces],
4749
memberTypesGrouped: true,
4850
placeAbove: [],
4951
placeBelow: []
5052
},
5153
{
5254
sortDirection: "asc",
5355
caption: "Classes",
54-
memberTypes: [ModuleMemberType.classes],
56+
memberTypes: [ModuleMemberType.classes, ModuleMemberType.exportedClasses],
5557
memberTypesGrouped: true,
5658
placeAbove: [],
5759
placeBelow: []
5860
},
5961
{
6062
sortDirection: "asc",
6163
caption: "Types",
62-
memberTypes: [ModuleMemberType.types],
64+
memberTypes: [ModuleMemberType.types, ModuleMemberType.exportedTypes],
6365
memberTypesGrouped: true,
6466
placeAbove: [],
6567
placeBelow: []

src/tsco-cli/configuration/import-configuration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ImportSourceFilePathQuoteType } from "../enums/Import-source-file-path-quote-type";
1+
import { ImportExpand } from "../enums/import-expand";
2+
import { ImportSourceFilePathQuoteType } from "../enums/import-source-file-path-quote-type";
23

34
export class ImportConfiguration
45
{
@@ -10,7 +11,9 @@ export class ImportConfiguration
1011
public readonly sortImportsByName: boolean,
1112
public readonly groupImportsBySource: boolean,
1213
public readonly separateImportGroups: boolean,
13-
public readonly quote: ImportSourceFilePathQuoteType)
14+
public readonly quote: ImportSourceFilePathQuoteType,
15+
public readonly expand: ImportExpand
16+
)
1417
{
1518
}
1619

src/tsco-cli/elements/class-node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ts from "typescript";
33
import { ClassConfiguration } from "../configuration/class-configuration";
44
import { ClassMemberType } from "../enums/class-member-type";
55
import { WriteModifier } from "../enums/write-modifier";
6-
import { getDecorators, getDependencies, getIsAbstract, getIsStatic, isPrivate, isProtected, isPublic, isReadOnly, isWritable, order } from "../helpers/node-helper";
6+
import { getDecorators, getDependencies, getIsAbstract, getIsExport, getIsStatic, isPrivate, isProtected, isPublic, isReadOnly, isWritable, order } from "../helpers/node-helper";
77
import { AccessorNode } from "./accessor-node";
88
import { ConstructorNode } from "./constructor-node";
99
import { ElementNode } from "./element-node";
@@ -16,14 +16,15 @@ import { StaticBlockDeclarationNode } from "./static-block-declaration-node";
1616

1717
export class ClassNode extends ElementNode
1818
{
19-
// #region Properties (14)
19+
// #region Properties (15)
2020

2121
public readonly accessors: AccessorNode[] = [];
2222
public readonly constructors: ConstructorNode[] = [];
2323
public readonly decorators: string[];
2424
public readonly dependencies: string[] = [];
2525
public readonly getters: GetterNode[] = [];
2626
public readonly isAbstract: boolean;
27+
public readonly isExport: boolean;
2728
public readonly isStatic: boolean;
2829
public readonly membersEnd: number = 0;
2930
public readonly membersStart: number = 0;
@@ -108,6 +109,8 @@ export class ClassNode extends ElementNode
108109
}
109110
}
110111
}
112+
113+
this.isExport = getIsExport(classDeclaration);
111114
}
112115

113116
// #endregion Constructors

src/tsco-cli/elements/enum-node.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import ts from "typescript";
22

3+
import { getIsExport } from "../helpers/node-helper";
34
import { ElementNode } from "./element-node";
45

56
export class EnumNode extends ElementNode
67
{
7-
// #region Properties (1)
8+
// #region Properties (2)
89

10+
public readonly isExport: boolean;
911
public readonly name: string;
1012

1113
// #endregion Properties
@@ -17,6 +19,8 @@ export class EnumNode extends ElementNode
1719
super(sourceFile, enumDeclaration);
1820

1921
this.name = (<ts.Identifier>enumDeclaration.name).escapedText?.toString() ?? sourceFile.getFullText().substring(enumDeclaration.name.pos, enumDeclaration.name.end).trim();
22+
23+
this.isExport = getIsExport(enumDeclaration);
2024
}
2125

2226
// #endregion Constructors

src/tsco-cli/elements/interface-node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as ts from "typescript";
22

33
import { InterfaceConfiguration } from "../configuration/interface-configuration";
44
import { InterfaceMemberType } from "../enums/interface-member-type";
5-
import { isReadOnly, isWritable, order } from "../helpers/node-helper";
5+
import { getIsExport, isReadOnly, isWritable, order } from "../helpers/node-helper";
66
import { ElementNode } from "./element-node";
77
import { ElementNodeGroup } from "./element-node-group";
88
import { GetterSignatureNode } from "./getter-signature-node";
@@ -13,10 +13,11 @@ import { SetterSignatureNode } from "./setter-signature-node";
1313

1414
export class InterfaceNode extends ElementNode
1515
{
16-
// #region Properties (8)
16+
// #region Properties (9)
1717

1818
public readonly getters: GetterSignatureNode[] = [];
1919
public readonly indexes: IndexSignatureNode[] = [];
20+
public readonly isExport: boolean;
2021
public readonly membersEnd: number = 0;
2122
public readonly membersStart: number = 0;
2223
public readonly methods: (MethodSignatureNode | PropertySignatureNode)[] = [];
@@ -73,6 +74,8 @@ export class InterfaceNode extends ElementNode
7374
this.methods.push(new MethodSignatureNode(sourceFile, member));
7475
}
7576
}
77+
78+
this.isExport = getIsExport(interfaceDeclaration);
7679
}
7780

7881
// #endregion Constructors

src/tsco-cli/elements/type-alias-node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as ts from "typescript";
22

33
import { TypeConfiguration } from "../configuration/type-configuration";
44
import { TypeMemberType } from "../enums/type-member-type";
5-
import { order } from "../helpers/node-helper";
5+
import { getIsExport, order } from "../helpers/node-helper";
66
import { ElementNode } from "./element-node";
77
import { ElementNodeGroup } from "./element-node-group";
88
import { IndexSignatureNode } from "./index-signature-node";
@@ -11,9 +11,10 @@ import { PropertySignatureNode } from "./property-signature-node";
1111

1212
export class TypeAliasNode extends ElementNode
1313
{
14-
// #region Properties (6)
14+
// #region Properties (7)
1515

1616
public readonly indexes: IndexSignatureNode[] = [];
17+
public readonly isExport: boolean;
1718
public readonly membersEnd: number = 0;
1819
public readonly membersStart: number = 0;
1920
public readonly methods: MethodSignatureNode[] = [];
@@ -69,6 +70,8 @@ export class TypeAliasNode extends ElementNode
6970
}
7071
}
7172
}
73+
74+
this.isExport = getIsExport(typeAliasDeclaration);
7275
}
7376

7477
// #endregion Constructors

src/tsco-cli/elements/variable-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class VariableNode extends ElementNode
1515

1616
// #region Constructors (1)
1717

18-
constructor(sourceFile: ts.SourceFile, variableDeclaration: ts.VariableDeclaration, public readonly isExport: boolean, public readonly isConst: boolean, leadingComment: string | null, trailingComment: string | null)
18+
constructor(sourceFile: ts.SourceFile, variableDeclaration: ts.VariableDeclaration, public readonly isExport: boolean, public readonly isConst: boolean, public readonly isDeclaration: boolean, leadingComment: string | null, trailingComment: string | null)
1919
{
2020
super(sourceFile, variableDeclaration, leadingComment, trailingComment);
2121

0 commit comments

Comments
 (0)