import BaseApplicationGenerator from '../../../base-application/index.js';
export default class NodeGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnBootstrapApplication();
            await this.dependsOnJHipster('begcode:java:build-tool');
        }
    }
    get initializing() {
        return this.asInitializingTaskGroup({
            async parseCommand() {
                await this.parseCurrentJHipsterCommand();
            },
        });
    }
    get [BaseApplicationGenerator.INITIALIZING]() {
        return this.delegateTasksToBlueprint(() => this.initializing);
    }
    get prompting() {
        return this.asPromptingTaskGroup({
            async promptCommand({ control }) {
                if (control.existingProject && this.options.askAnswered !== true)
                    return;
                await this.promptCurrentJHipsterCommand();
            },
        });
    }
    get [BaseApplicationGenerator.PROMPTING]() {
        return this.delegateTasksToBlueprint(() => this.prompting);
    }
    get composing() {
        return this.asComposingTaskGroup({
            async compose() {
                const { buildTool } = this.jhipsterConfigWithDefaults;
                if (buildTool === 'maven') {
                    await this.composeWithJHipster('begcode:maven:frontend-plugin');
                }
                else if (buildTool === 'gradle') {
                    await this.composeWithJHipster('begcode:gradle:node-gradle');
                }
            },
        });
    }
    get [BaseApplicationGenerator.COMPOSING]() {
        return this.delegateTasksToBlueprint(() => this.composing);
    }
    get loading() {
        return this.asLoadingTaskGroup({
            async loadConfig({ application }) {
                await this.loadCurrentJHipsterCommandConfig(application);
            },
        });
    }
    get [BaseApplicationGenerator.LOADING]() {
        return this.delegateTasksToBlueprint(() => this.loading);
    }
    get writing() {
        return this.asWritingTaskGroup({
            async writing({ application }) {
                await this.writeFiles({
                    blocks: [
                        {
                            condition: (ctx) => ctx.useNpmWrapper && ctx.applicationType !== 'commonmodule',
                            renameTo: (data, path) => path.replace('_pnpm', ''),
                            transform: false,
                            templates: ['npmw_pnpm', 'npmw_pnpm.cmd'],
                        },
                    ],
                    context: application,
                });
            },
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
}
