#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const console_1 = require("console");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const prompts_1 = __importDefault(require("prompts"));
const customtypes_1 = require("./customtypes");
(async () => {
    const banner = chalk_1.default `
                _|_|                                        _|    _|                
    _|_|_|    _|        _|_|_|    _|_|_|                _|_|_|  _|_|_|_|    _|_|_|  
  _|_|      _|_|_|_|  _|        _|        _|_|_|_|_|  _|    _|    _|      _|_|      
      _|_|    _|      _|        _|                    _|    _|    _|          _|_|  
  _|_|_|      _|        _|_|_|    _|_|_|                _|_|_|      _|_|  _|_|_|    
                                                                                    
                                                                    `;
    console_1.log(chalk_1.default.hex('ed26f3')(banner));
    console_1.log(`Welcome to ${chalk_1.default.magentaBright('sfcc-dts')} custom attributes definition generator.\n`);
    let defaultpath = './sites/site_template/meta/';
    let defaultdest = './cartridges/app_project/cartridge/scripts/';
    let extensions;
    if (fs_1.default.existsSync(path_1.default.join(defaultpath, 'system-objecttype-extensions.xml'))) {
        console_1.log(`system-objecttype-extensions.xml detected at ${defaultpath}`);
        extensions = path_1.default.join(defaultpath, 'system-objecttype-extensions.xml');
    }
    else {
        const response = await prompts_1.default([
            {
                type: 'text',
                name: 'meta',
                message: 'Directory containing system-objecttype-extensions.xml?',
                initial: defaultpath,
                validate: value => !fs_1.default.existsSync(path_1.default.join(value, 'system-objecttype-extensions.xml')) ? `system-objecttype-extensions.xml not found in ${path_1.default.join(value, 'system-objecttype-extensions.xml')}` : true
            }
        ]);
        extensions = path_1.default.join(response.meta, 'system-objecttype-extensions.xml');
    }
    const destresponse = await prompts_1.default([
        {
            type: 'text',
            name: 'path',
            message: 'Folder for generated constant file?',
            initial: defaultdest,
            validate: value => !fs_1.default.existsSync(value) ? `Folder ${value} not found` : true
        }
    ]);
    let destination = path_1.default.join(destresponse.path, 'preferences.js');
    console_1.log(`Generating constants for organization and site preferences`);
    if (extensions) {
        await customtypes_1.generateConstants(extensions, destination);
    }
    console_1.log(`\nDone!`);
})();
