import BaseApplicationGenerator from '../../../base-application/index.js';
export default class HuskyGenerator extends BaseApplicationGenerator {
    constructor(args, options, features) {
        super(args, options, { queueCommandTasks: true, ...features });
    }
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnJHipster('begcode:javascript:prettier');
        }
    }
    get configuring() {
        return this.asConfiguringTaskGroup({
            configureNodeOptions() {
                if (this.jhipsterConfig.skipCommitHook) {
                    this.cancelCancellableTasks();
                }
            },
        });
    }
    get [BaseApplicationGenerator.CONFIGURING]() {
        return this.delegateTasksToBlueprint(() => this.configuring);
    }
    get writing() {
        return this.asWritingTaskGroup({
            async writing({ application }) {
                await this.writeFiles({
                    blocks: [{ templates: ['.lintstagedrc.cjs', '.husky/pre-commit'] }],
                    context: application,
                });
            },
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            addCommitHookDependencies({ application }) {
                this.packageJson.merge({
                    scripts: {
                        prepare: 'husky',
                    },
                    devDependencies: {
                        husky: application.nodeDependencies.husky,
                        'lint-staged': application.nodeDependencies['lint-staged'],
                    },
                });
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.delegateTasksToBlueprint(() => this.postWriting);
    }
}
