diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f635576..80a2a8a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,13 +28,15 @@ jobs: with: node-version: 18.x - name: Prepare generator - run: cd ../generator && yarn && yarn build && cd ../cli + run: cd ../generator && yarn && yarn build && yarn link && cd ../cli - name: Prepare definition run: cd ../definition && yarn && yarn build && cd ../cli - name: Install dependencies run: yarn - name: Build run: yarn lint + - name: yarn link generator + run: yarn link "@recognizebv/sc3000-generator" - name: Build run: yarn build - name: Test diff --git a/README.md b/README.md index 99c005a..8e00d00 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,17 @@ export default createDefinition() ``` +## Development +In order to develop the tool, you will need to have Node.js and Yarn installed. After cloning the repository, you can build generator project by running the following command: +```yarn build ``` in the generator project directory. + +In case you make changes to the generator project, you need to link the generator project to the cli project. You can do this by running the following command in the generator project directory: +```yarn link ``` in the generator project directory and ```yarn link @recognizegroup/sc3000-generator``` in the cli project directory. + +To run or debug the cli project create a nodeJS configuration and select the cli/bin/dev file and add generate as parameter. You should have a `sc3000.definition.ts` file in the root of the cli project. + +![img.png](img.png) + ## 👋 About The Project diff --git a/cli/src/commands/generate/index.ts b/cli/src/commands/generate/index.ts index 1c561c3..0e239db 100644 --- a/cli/src/commands/generate/index.ts +++ b/cli/src/commands/generate/index.ts @@ -108,10 +108,14 @@ $ sc3000 generate --force await loader.update(`Generating entity ${entity.name} with ${metaData.name}`) await entityCodeProvider?.render(entityContext) + entityCodeProvider?.reset() lockFile = await lockFileManager.addGeneratedEntity(generator, entity) entityCodeProviderInvocations++ } } + + await projectCodeProvider?.postProcessing() + projectCodeProvider?.reset() } catch (error) { await loader.stop() diff --git a/generator/src/enums/render-hook-type.ts b/generator/src/enums/render-hook-type.ts index f19ad0d..3ecaf60 100644 --- a/generator/src/enums/render-hook-type.ts +++ b/generator/src/enums/render-hook-type.ts @@ -1,4 +1,5 @@ export enum RenderHookType { beforeRender = 'beforeRender', afterRender = 'afterRender', + finalize = 'finalize', } diff --git a/generator/src/providers/code-provider.ts b/generator/src/providers/code-provider.ts index c542b1b..de77e07 100644 --- a/generator/src/providers/code-provider.ts +++ b/generator/src/providers/code-provider.ts @@ -1,6 +1,7 @@ import {Context} from '../context/context' import {Generator} from '../models/generator' import {Renderer} from '../rendering/renderer' +import {RenderHookType} from '../enums/render-hook-type' export abstract class CodeProvider { public renderer: Renderer; @@ -15,6 +16,13 @@ export abstract class CodeProvider { this.renderer.setContext(context) await this.generate(context) await this.renderer.render() - await this.renderer.reset() + } + + public reset() { + this.renderer.reset() + } + + public async postProcessing() { + await this.renderer.executeHook(RenderHookType.finalize) } } diff --git a/generator/test/providers/code-provider.test.ts b/generator/test/providers/code-provider.test.ts index e6a3216..bd1e152 100644 --- a/generator/test/providers/code-provider.test.ts +++ b/generator/test/providers/code-provider.test.ts @@ -86,7 +86,7 @@ describe('code provider', () => { expect(setContextSpy.calledOnce).to.be.true expect(renderSpy.calledOnce).to.be.true - expect(resetSpy.calledOnce).to.be.true + expect(resetSpy.calledOnce).to.be.false expect(setContextSpy.calledBefore(renderSpy)).to.be.true expect(renderSpy.calledBefore(resetSpy)).to.be.true }) diff --git a/img.png b/img.png new file mode 100644 index 0000000..8a300b7 Binary files /dev/null and b/img.png differ