@nikovirtala/projen-constructs 0.1.7 → 0.2.0

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.
@@ -1,62 +1,55 @@
1
- import type { Property } from "@jsii/spec";
2
1
  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}`;
2
+ import * as projen from "projen";
3
+ import type { ProjectType } from "./project-type";
6
4
  /**
7
5
  * 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
6
  */
17
- interface ComponentConfig<T extends Component = Component> {
7
+ export interface Component {
8
+ /**
9
+ * Component class reference
10
+ *
11
+ * @jsii ignore
12
+ */
13
+ readonly componentClass: any;
18
14
  /**
19
- * Component class constructor
15
+ * Fully qualified name of the component class
16
+ *
17
+ * Optional - auto-detected by searching JSII manifests.
20
18
  */
21
- readonly component: new (project: never, options?: never) => T;
19
+ readonly fqn?: string;
22
20
  /**
23
21
  * Options property configuration for the generated options interface
24
22
  *
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
- };
23
+ * Optional - auto-detected from component constructor.
24
+ * Set to false to disable options property generation.
25
+ * Set to string or object to customize the property name.
26
+ */
27
+ readonly optionsProperty?: string | ComponentOptions | false;
28
+ }
29
+ /**
30
+ * Options property configuration
31
+ */
32
+ export interface ComponentOptions {
33
+ /**
34
+ * Name of the options property
35
+ */
36
+ readonly name: string;
37
+ /**
38
+ * Fully qualified type name (optional, auto-detected from component constructor)
39
+ */
40
+ readonly type?: string;
41
+ /**
42
+ * Documentation summary (optional, auto-detected from component constructor)
43
+ */
44
+ readonly docs?: string;
42
45
  }
43
46
  /**
44
47
  * Options for ProjectGenerator component
45
48
  *
46
49
  * Configures the generation of a TypeScript project class that extends a Projen base class
47
50
  * with standard configuration and component integration.
48
- *
49
- * @example
50
- * ```typescript
51
- * new ProjectGenerator(project, {
52
- * name: "TypeScriptProject",
53
- * baseClass: "typescript.TypeScriptProject",
54
- * filePath: "src/projects/typescript.generated.ts",
55
- * components: [{ component: Vitest, optionsProperty: "vitestOptions" }]
56
- * });
57
- * ```
58
51
  */
59
- export interface ProjectGeneratorOptions<M extends ProjenModule = ProjenModule> extends SourceCodeOptions {
52
+ export interface ProjectGeneratorOptions extends SourceCodeOptions {
60
53
  /**
61
54
  * Name of the generated class (e.g., "TypeScriptProject")
62
55
  *
@@ -64,15 +57,14 @@ export interface ProjectGeneratorOptions<M extends ProjenModule = ProjenModule>
64
57
  */
65
58
  readonly name: string;
66
59
  /**
67
- * Fully qualified base class to extend in format "module.ClassName"
60
+ * Project type identifier
68
61
  *
69
- * Must be a valid Projen class reference like "typescript.TypeScriptProject",
70
- * "cdk.JsiiProject", or "awscdk.AwsCdkTypeScriptApp".
62
+ * Specifies which Projen base class to extend and which default configuration to apply.
71
63
  *
72
- * @example "typescript.TypeScriptProject"
73
- * @example "cdk.JsiiProject"
64
+ * @example ProjectType.TYPESCRIPT
65
+ * @example ProjectType.JSII
74
66
  */
75
- readonly baseClass: ProjenBaseClass<M>;
67
+ readonly projectType: ProjectType;
76
68
  /**
77
69
  * Output file path for the generated class
78
70
  *
@@ -90,14 +82,16 @@ export interface ProjectGeneratorOptions<M extends ProjenModule = ProjenModule>
90
82
  *
91
83
  * @default [{ component: Mise }, { component: Vitest, optionsProperty: { name: "vitestOptions", type: "...", docs: "..." } }]
92
84
  */
93
- readonly components?: ComponentConfig[];
85
+ readonly components?: Component[];
94
86
  /**
95
87
  * Additional properties to add to the generated options interface
96
88
  *
97
89
  * Use this to extend the base options with custom properties specific to
98
90
  * your project type.
91
+ *
92
+ * @jsii ignore
99
93
  */
100
- readonly additionalOptions?: Property[];
94
+ readonly additionalOptions?: any[];
101
95
  /**
102
96
  * Property names to omit from the base options interface
103
97
  *
@@ -110,34 +104,17 @@ export interface ProjectGeneratorOptions<M extends ProjenModule = ProjenModule>
110
104
  * Projen component that generates TypeScript project classes with standard configuration
111
105
  *
112
106
  * 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 ProjectGenerator(project, {
126
- * name: "TypeScriptProject",
127
- * baseClass: "typescript.TypeScriptProject",
128
- * filePath: "src/projects/typescript.generated.ts",
129
- * components: [{ component: Vitest, optionsProperty: "vitestOptions" }]
130
- * });
131
- * ```
107
+ * with opinionated defaults and component integration.
132
108
  */
133
- export declare class ProjectGenerator extends Component {
109
+ export declare class ProjectGenerator extends projen.Component {
134
110
  private readonly options;
135
111
  private renderer;
112
+ private static enumGenerated;
136
113
  /**
137
114
  * @param project - Projen project instance
138
115
  * @param options - Generator configuration
139
116
  */
140
- constructor(project: Project, options: ProjectGeneratorOptions<ProjenModule>);
117
+ constructor(project: Project, options: ProjectGeneratorOptions);
141
118
  /**
142
119
  * Casts project to TypeScript project type
143
120
  *
@@ -169,5 +146,50 @@ export declare class ProjectGenerator extends Component {
169
146
  * The file is marked as readonly to prevent manual editing.
170
147
  */
171
148
  preSynthesize(): void;
149
+ /**
150
+ * Checks if an FQN is available in any JSII manifest
151
+ */
152
+ private isFqnAvailable;
153
+ /**
154
+ * Resolves component options type from JSII manifest
155
+ *
156
+ * Auto-detects options from JSII manifest when optionsProperty is undefined.
157
+ * Returns null only when optionsProperty is explicitly set to false.
158
+ */
159
+ private resolveComponentOptionsType;
160
+ /**
161
+ * Finds component FQN by searching all JSII manifests
162
+ */
163
+ private findComponentFqn;
164
+ /**
165
+ * Finds all JSII packages in node_modules
166
+ */
167
+ private findJsiiPackages;
168
+ /**
169
+ * Loads JSII manifest for a given FQN
170
+ *
171
+ * Extracts package name from FQN. For scoped packages like @scope/package.ClassName,
172
+ * the package name is everything before the first dot (i.e., @scope/package).
173
+ */
174
+ private loadManifestForFqn;
175
+ /**
176
+ * Loads JSII manifest from a package directory
177
+ */
178
+ private loadManifestFromPackage;
179
+ /**
180
+ * Loads this package's JSII manifest
181
+ */
182
+ private loadOwnManifest;
183
+ /**
184
+ * Generates ProjectType enum from Projen's JSII manifest
185
+ */
186
+ private generateProjectTypeEnum;
187
+ /**
188
+ * Discovers all project types that extend projen.Project
189
+ */
190
+ private discoverProjectTypes;
191
+ /**
192
+ * Checks if a class extends the base class
193
+ */
194
+ private extendsBase;
172
195
  }
173
- export {};