-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
33 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
20 changes: 20 additions & 0 deletions
20
packages/skeleton-cli/src/utility/ts-morph/add-named-import.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SourceFile } from "ts-morph"; | ||
|
||
function addNamedImport(file: SourceFile, specifier: string, name: string) { | ||
const existingImportDeclaration = file.getImportDeclaration((importDeclaration) => { | ||
const moduleSpecifier = importDeclaration.getModuleSpecifier().getLiteralText(); | ||
return moduleSpecifier === specifier; | ||
}); | ||
if (existingImportDeclaration) { | ||
if (!existingImportDeclaration.getNamedImports().some((namedImport) => namedImport.getName() === name)) { | ||
existingImportDeclaration.addNamedImport(name); | ||
} | ||
} else { | ||
file.addImportDeclaration({ | ||
moduleSpecifier: specifier, | ||
namedImports: [name] | ||
}); | ||
} | ||
} | ||
|
||
export { addNamedImport }; |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ton-cli/src/utility/create-source-file.ts → ...src/utility/ts-morph/parse-source-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Project } from 'ts-morph'; | ||
|
||
function createSourceFile(code: string) { | ||
function parseSourceFile(code: string) { | ||
const project = new Project({ | ||
useInMemoryFileSystem: true | ||
}); | ||
return project.createSourceFile('virtual.ts', code); | ||
} | ||
|
||
export { createSourceFile }; | ||
export { parseSourceFile }; |