-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import { typescript } from 'projen'; | ||
const project = new typescript.TypeScriptProject({ | ||
defaultReleaseBranch: 'main', | ||
name: 'l2-projen', | ||
projenrcTs: true, | ||
import { L2ConstructProject } from './projenrc/L2ConstructProject'; | ||
// import * as meta from './projenrc/meta/'; | ||
|
||
// deps: [], /* Runtime dependencies of this module. */ | ||
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */ | ||
// devDeps: [], /* Build dependencies for this module. */ | ||
// packageName: undefined, /* The "name" in package.json. */ | ||
const project = new L2ConstructProject({ | ||
moduleName: 'aws-kinesis', | ||
}); | ||
project.synth(); | ||
project.synth(); | ||
// project.addImplementation(new meta.StreamImplementation()); | ||
// project.addImplementation(new meta.StreamConsumerImplementation()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface BaseImplementationOptions { | ||
|
||
} | ||
|
||
export interface IImplementation { | ||
readonly resourceName: string; | ||
} | ||
|
||
export abstract class BaseImplementation implements IImplementation { | ||
public readonly resourceName: string = ''; | ||
protected readonly options: BaseImplementationOptions; | ||
|
||
public constructor(options: BaseImplementationOptions) { | ||
this.options = options; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { TextFile } from 'projen'; | ||
import { TypeScriptProject, TypeScriptProjectOptions } from 'projen/lib/typescript'; | ||
import { StructureKind } from 'ts-morph'; | ||
import { IImplementation } from './Implementation'; | ||
import { TSSourceCode } from './TSSourceCode'; | ||
|
||
|
||
export interface L2ConstructProjectOptions extends Omit<TypeScriptProjectOptions, 'name' | 'defaultReleaseBranch'> { | ||
moduleName: string; | ||
defaultReleaseBranch?: string; | ||
} | ||
|
||
|
||
export class L2ConstructProject extends TypeScriptProject { | ||
public constructor(options: L2ConstructProjectOptions) { | ||
super({ | ||
name: '@aws-cdk/' + options.moduleName, | ||
defaultReleaseBranch: 'main', | ||
projenrcTs: true, | ||
...options, | ||
devDeps: (options.devDeps ?? []).concat('aws-cdk-lib', 'constructs@^10', 'ts-morph'), | ||
}); | ||
|
||
const cfnResources = Object.keys(cdk[options.moduleName.replace('-', '_') as keyof typeof cdk]) | ||
.filter(resource => resource.startsWith('Cfn')); | ||
|
||
const exportFile = new TextFile(this, 'projenrc/meta/index.ts', {}); | ||
|
||
for (const resource of cfnResources) { | ||
const className = `${resource.substring(3)}Implementation`; | ||
const optionsName = `${className}Options`; | ||
|
||
exportFile.addLine(`export * from './${className}';`); | ||
new TSSourceCode(this, `projenrc/meta/${className}.ts`, { | ||
kind: StructureKind.SourceFile, | ||
statements: [{ | ||
kind: StructureKind.ImportDeclaration, | ||
namedImports: [ | ||
{ name: 'BaseImplementation' }, | ||
{ name: 'BaseImplementationOptions' }, | ||
], | ||
moduleSpecifier: '../Implementation', | ||
}, | ||
{ | ||
kind: StructureKind.Interface, | ||
name: optionsName, | ||
extends: ['BaseImplementationOptions'], | ||
}, | ||
{ | ||
kind: StructureKind.Class, | ||
isAbstract: false, | ||
isExported: true, | ||
extends: 'BaseImplementation', | ||
name: className, | ||
ctors: [{ | ||
kind: StructureKind.Constructor, | ||
parameters: [{ | ||
name: 'options', | ||
type: optionsName, | ||
}], | ||
statements: 'super(options);', | ||
}], | ||
typeParameters: [], | ||
properties: [{ | ||
name: 'resourceName', | ||
initializer: `'${resource}'`, | ||
type: 'string', | ||
isReadonly: true, | ||
isStatic: false, | ||
}], | ||
methods: [], | ||
}], | ||
}); | ||
} | ||
} | ||
|
||
public addImplementation(implementation: IImplementation) { | ||
console.log(implementation.resourceName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { tmpdir } from 'os'; | ||
import { join } from 'path'; | ||
import { FileBase, Project } from 'projen'; | ||
import { SourceFileStructure, Project as TSProject, SourceFile, IndentationText, QuoteKind } from 'ts-morph'; | ||
|
||
export class TSSourceCode extends FileBase { | ||
|
||
public readonly filePath: string; | ||
protected ts: TSProject; | ||
protected file: SourceFile; | ||
|
||
public constructor(project: Project, filePath: string, structure: SourceFileStructure) { | ||
super(project, filePath); | ||
this.ts = new TSProject({ | ||
manipulationSettings: { | ||
indentationText: IndentationText.TwoSpaces, | ||
quoteKind: QuoteKind.Single, | ||
}, | ||
}); | ||
|
||
this.filePath = filePath; | ||
this.file = this.ts.createSourceFile(join(tmpdir(), filePath)); | ||
this.file.set(structure); | ||
} | ||
|
||
protected synthesizeContent(): string { | ||
return this.file.getFullText(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.