-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.projenrc.ts
110 lines (86 loc) · 3.3 KB
/
.projenrc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { FileBase, Project, TextFile } from "projen";
import { TypeScriptProject } from "projen/lib/typescript";
import { VariableDeclarationKind } from "ts-morph";
import { TypescriptMorpher } from "./src";
const project = new TypeScriptProject({
defaultReleaseBranch: "main",
name: "projen-ts-morph",
authorName: "Mark McCulloh",
authorEmail: "Mark.McCulloh@gmail.com",
releaseToNpm: true,
projenrcTs: true,
peerDeps: ["projen@0.27.6", "ts-morph"],
projenDevDependency: false,
typescriptVersion: "~4.2.4",
docgen: true,
gitignore: ["test/test_project/"],
eslintOptions: {
dirs: ["src", "test"],
prettier: true,
},
jestOptions: {
jestConfig: {
testPathIgnorePatterns: ["/node_modules/", "test/test_project"],
},
},
antitamper: false,
});
const morpher = new TypescriptMorpher(project);
const exampleUsage = morpher.createTemporaryTypescriptFile("basic_create.ts");
exampleUsage.addImportDeclaration({
moduleSpecifier: "projen-ts-morph",
namedImports: ["TypescriptMorpher"],
});
exampleUsage.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [
{ name: "morpher", initializer: "new TypescriptMorpher(project)" },
],
});
exampleUsage.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [
{
name: "source",
initializer: "morpher.createTypescriptFile('src/cool_generated.ts')",
},
],
});
exampleUsage.addStatements([
`source.addClass({
name: 'CoolGenerated',
isDefaultExport: true,
});`,
]);
const readmeText = `\
![release](https://github.com/MarkMcCulloh/projen-ts-morph/actions/workflows/release.yml/badge.svg)
![npm version](https://badge.fury.io/js/projen-ts-morph.svg)
# ${project.name}
Generate and navigate typescript files with a [Projen](https://github.com/projen/projen) component.
## Implementation
The sole exported class of this project, \`TypescriptMorpher\`, acts as a wrapper around the excellent [ts-morph](https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph).
A few convenience methods are added to that class to aid in codegen, and during the synth() phase of your project all creations/updates/deletes will be saved to disk.
See https://github.com/dsherret/ts-morph and https://ts-morph.com for more details on the API. I take no credit for that amazing project.
## Gettings Started
Make sure to add \`ts-morph\` as a dependency and make sure it's actually installed before attempting to use this component. See examples below to get started.
## Stability
Consider this library unstable.
## Examples
### Create an example snippet for your README
See [this project's .projenrc.ts](./.projenrc.ts#L31) for usage of \`createTemporaryTypescriptFile\` and \`renderFencedTypescript\`
### Create a simple empty class
${morpher.renderFencedTypescript(exampleUsage)}
## [Typedocs](https://markmcculloh.github.io/projen-ts-morph/)
<!---
${FileBase.PROJEN_MARKER}
It is so unnecessary to use projen for this readme, but here I go anyways :)
-->
`;
new TextFile(project as Project, "README.md", {
lines: readmeText.split("\n"),
});
project.eslint!.addIgnorePattern("test/test_project/");
project.testTask.prependExec("mkdir test/test_project");
project.testTask.prependExec("rm -rf test/test_project");
project.addExcludeFromCleanup("docs/**");
project.synth();