import BaseApplicationGenerator from '../../../base-application/index.js';
import { GRADLE_BUILD_SRC_MAIN_DIR } from '../../../generator-constants.js';
import { GENERATOR_GRADLE } from '../../../generator-list.js';
export default class NodeGradleGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnBootstrapApplication();
            await this.dependsOnJHipster(GENERATOR_GRADLE);
        }
    }
    get writing() {
        return this.asWritingTaskGroup({
            async writing({ application }) {
                await this.writeFiles({
                    blocks: [{ templates: [`${GRADLE_BUILD_SRC_MAIN_DIR}/jhipster.node-gradle-conventions.gradle`] }],
                    context: application,
                });
            },
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            customize({ application, source }) {
                source.addGradlePlugin({ id: 'jhipster.node-gradle-conventions' });
                source.addGradleBuildSrcDependencyCatalogLibraries([
                    {
                        libraryName: 'node-gradle',
                        module: 'com.github.node-gradle:gradle-node-plugin',
                        version: application.javaDependencies['node-gradle'],
                        scope: 'implementation',
                    },
                ]);
                source.addGradleProperty({ property: 'nodeInstall', comment: 'Install and use a local version of node and npm.' });
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.delegateTasksToBlueprint(() => this.postWriting);
    }
}
