@nikovirtala/projen-constructs 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +54 -34
- package/API.md +52 -28
- package/lib/components/mise.js +4 -2
- package/lib/components/vitest.js +1 -1
- package/lib/config.d.ts +20 -7
- package/lib/config.js +28 -16
- package/lib/errors.d.ts +20 -0
- package/lib/errors.js +36 -0
- package/lib/projects/awscdk-construct-library-options.generated.d.ts +7 -7
- package/lib/projects/awscdk-construct-library-options.generated.js +1 -1
- package/lib/projects/awscdk-construct-library.generated.d.ts +8 -0
- package/lib/projects/awscdk-construct-library.generated.js +17 -4
- package/lib/projects/awscdk-typescript-app-options.generated.d.ts +7 -7
- package/lib/projects/awscdk-typescript-app-options.generated.js +1 -1
- package/lib/projects/awscdk-typescript-app.generated.d.ts +8 -0
- package/lib/projects/awscdk-typescript-app.generated.js +17 -4
- package/lib/projects/jsii-options.generated.d.ts +7 -7
- package/lib/projects/jsii-options.generated.js +1 -1
- package/lib/projects/jsii.generated.d.ts +8 -0
- package/lib/projects/jsii.generated.js +17 -4
- package/lib/projects/typescript-options.generated.d.ts +7 -7
- package/lib/projects/typescript-options.generated.js +1 -1
- package/lib/projects/typescript.generated.d.ts +8 -0
- package/lib/projects/typescript.generated.js +17 -4
- package/lib/projen-project-generator.d.ts +173 -0
- package/lib/projen-project-generator.js +509 -0
- package/package.json +1 -1
- package/lib/projen-project-class.d.ts +0 -44
- package/lib/projen-project-class.js +0 -137
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { Property } from "@jsii/spec";
|
|
2
|
+
import type { Project, SourceCodeOptions } from "projen";
|
|
3
|
+
import { Component } from "projen";
|
|
4
|
+
type ProjenModule = "typescript" | "cdk" | "awscdk";
|
|
5
|
+
type ProjenBaseClass<M extends ProjenModule> = `${M}.${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for a component to be integrated into a generated project
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const config: ComponentConfig = {
|
|
12
|
+
* component: Vitest,
|
|
13
|
+
* optionsProperty: "vitestOptions"
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
interface ComponentConfig<T extends Component = Component> {
|
|
18
|
+
/**
|
|
19
|
+
* Component class constructor
|
|
20
|
+
*/
|
|
21
|
+
readonly component: new (project: never, options?: never) => T;
|
|
22
|
+
/**
|
|
23
|
+
* Options property configuration for the generated options interface
|
|
24
|
+
*
|
|
25
|
+
* When specified, adds an options property to the interface allowing
|
|
26
|
+
* users to configure the component.
|
|
27
|
+
*/
|
|
28
|
+
readonly optionsProperty?: {
|
|
29
|
+
/**
|
|
30
|
+
* Name of the options property (e.g., "vitestOptions")
|
|
31
|
+
*/
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/**
|
|
34
|
+
* Fully qualified type name (e.g., "@nikovirtala/projen-constructs.VitestOptions")
|
|
35
|
+
*/
|
|
36
|
+
readonly type: string;
|
|
37
|
+
/**
|
|
38
|
+
* Documentation summary
|
|
39
|
+
*/
|
|
40
|
+
readonly docs?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for ProjenProjectGenerator component
|
|
45
|
+
*
|
|
46
|
+
* Configures the generation of a TypeScript project class that extends a Projen base class
|
|
47
|
+
* with standard configuration and component integration.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* new ProjenProjectGenerator(project, {
|
|
52
|
+
* name: "TypeScriptProject",
|
|
53
|
+
* baseClass: "typescript.TypeScriptProject",
|
|
54
|
+
* filePath: "src/projects/typescript.generated.ts",
|
|
55
|
+
* components: [{ component: Vitest, optionsProperty: "vitestOptions" }]
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export interface ProjenProjectGeneratorOptions<M extends ProjenModule = ProjenModule> extends SourceCodeOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Name of the generated class (e.g., "TypeScriptProject")
|
|
62
|
+
*
|
|
63
|
+
* The options interface will be named `${name}Options`.
|
|
64
|
+
*/
|
|
65
|
+
readonly name: string;
|
|
66
|
+
/**
|
|
67
|
+
* Fully qualified base class to extend in format "module.ClassName"
|
|
68
|
+
*
|
|
69
|
+
* Must be a valid Projen class reference like "typescript.TypeScriptProject",
|
|
70
|
+
* "cdk.JsiiProject", or "awscdk.AwsCdkTypeScriptApp".
|
|
71
|
+
*
|
|
72
|
+
* @example "typescript.TypeScriptProject"
|
|
73
|
+
* @example "cdk.JsiiProject"
|
|
74
|
+
*/
|
|
75
|
+
readonly baseClass: ProjenBaseClass<M>;
|
|
76
|
+
/**
|
|
77
|
+
* Output file path for the generated class
|
|
78
|
+
*
|
|
79
|
+
* Must contain a directory separator. The options interface will be generated
|
|
80
|
+
* in the same directory with a ".generated.ts" suffix.
|
|
81
|
+
*
|
|
82
|
+
* @example "src/projects/typescript.generated.ts"
|
|
83
|
+
*/
|
|
84
|
+
readonly filePath: string;
|
|
85
|
+
/**
|
|
86
|
+
* Components to integrate into the project
|
|
87
|
+
*
|
|
88
|
+
* Each component will be instantiated during project construction and can be
|
|
89
|
+
* configured via an optional options property in the generated interface.
|
|
90
|
+
*
|
|
91
|
+
* @default [{ component: Mise }, { component: Vitest, optionsProperty: { name: "vitestOptions", type: "...", docs: "..." } }]
|
|
92
|
+
*/
|
|
93
|
+
readonly components?: ComponentConfig[];
|
|
94
|
+
/**
|
|
95
|
+
* Additional properties to add to the generated options interface
|
|
96
|
+
*
|
|
97
|
+
* Use this to extend the base options with custom properties specific to
|
|
98
|
+
* your project type.
|
|
99
|
+
*/
|
|
100
|
+
readonly additionalOptions?: Property[];
|
|
101
|
+
/**
|
|
102
|
+
* Property names to omit from the base options interface
|
|
103
|
+
*
|
|
104
|
+
* Use this to hide base class options that should not be configurable
|
|
105
|
+
* in the generated project type.
|
|
106
|
+
*/
|
|
107
|
+
readonly omitOptions?: string[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Projen component that generates TypeScript project classes with standard configuration
|
|
111
|
+
*
|
|
112
|
+
* This component automates the creation of project classes that extend Projen base classes
|
|
113
|
+
* with opinionated defaults and component integration. It generates both:
|
|
114
|
+
* 1. An options interface (via ProjenStruct) that extends the base Projen options
|
|
115
|
+
* 2. A project class that applies default configuration and instantiates components
|
|
116
|
+
*
|
|
117
|
+
* The generated code follows a consistent pattern:
|
|
118
|
+
* - Imports required modules and components
|
|
119
|
+
* - Re-exports the generated options interface
|
|
120
|
+
* - Defines a class extending the Projen base class
|
|
121
|
+
* - Constructor merges defaults with user options and applies components
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* new ProjenProjectGenerator(project, {
|
|
126
|
+
* name: "TypeScriptProject",
|
|
127
|
+
* baseClass: "typescript.TypeScriptProject",
|
|
128
|
+
* filePath: "src/projects/typescript.generated.ts",
|
|
129
|
+
* components: [{ component: Vitest, optionsProperty: "vitestOptions" }]
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare class ProjenProjectGenerator extends Component {
|
|
134
|
+
private readonly options;
|
|
135
|
+
private renderer;
|
|
136
|
+
/**
|
|
137
|
+
* @param project - Projen project instance
|
|
138
|
+
* @param options - Generator configuration
|
|
139
|
+
*/
|
|
140
|
+
constructor(project: Project, options: ProjenProjectGeneratorOptions<ProjenModule>);
|
|
141
|
+
/**
|
|
142
|
+
* Casts project to TypeScript project type
|
|
143
|
+
*
|
|
144
|
+
* ProjenStruct requires a TypeScriptProject instance. This generator is only used
|
|
145
|
+
* within TypeScript projects, so the cast is safe in practice.
|
|
146
|
+
*
|
|
147
|
+
* Note: Type assertion is necessary here because Projen's type system doesn't provide
|
|
148
|
+
* a runtime type guard for TypeScriptProject.
|
|
149
|
+
*
|
|
150
|
+
* @param project - Projen project instance
|
|
151
|
+
* @returns TypeScript project instance
|
|
152
|
+
*/
|
|
153
|
+
private asTypeScriptProject;
|
|
154
|
+
/**
|
|
155
|
+
* Derives the file path for the generated options interface
|
|
156
|
+
*
|
|
157
|
+
* Places the options interface file in the same directory as the class file
|
|
158
|
+
* with a ".generated.ts" suffix.
|
|
159
|
+
*
|
|
160
|
+
* @param optionsInterface - Name of the options interface
|
|
161
|
+
* @returns File path for the options interface
|
|
162
|
+
* @throws {InvalidFilePathError} When filePath doesn't contain a directory separator
|
|
163
|
+
*/
|
|
164
|
+
private getOptionsFilePath;
|
|
165
|
+
/**
|
|
166
|
+
* Generates the TypeScript class file during Projen synthesis
|
|
167
|
+
*
|
|
168
|
+
* Called by Projen during the synthesis phase to generate the project class file.
|
|
169
|
+
* The file is marked as readonly to prevent manual editing.
|
|
170
|
+
*/
|
|
171
|
+
preSynthesize(): void;
|
|
172
|
+
}
|
|
173
|
+
export {};
|