<commit_before>const fs = require('fs');

const commandName = "generate-ui";

const errorMessage = (message) => new Error(commandName + ": " + message);

class Scaffolding {
    constructor(embark, options){
        this.embark = embark;
        this.options = options;
        this.framework = options.framework;
        this.frameworkPlugin = null;
    }

    isContract(contractName){
        return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
    }

    generate(contractName){
        let frameworkPlugin;

        if(this.framework == 'react'){
            this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
            frameworkPlugin = this.embark.plugins.plugins.filter(x => x.name == "scaffolding-react")[0].pluginModule;
        } else {
            let plugins = this.embark.plugins.getPluginsFor(this.framework);
            if(plugins.length !== 1){
                throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
            }
            frameworkPlugin = plugins[0].pluginModule;
        }
        
        
        if(!this.isContract(contractName)){
            return errorMessage("contract '" + contractName + "' does not exist");
        }

        const contract = this.embark.config.contractsConfig.contracts[contractName];
        
        try {
            let uiFramework = new frameworkPlugin(this.embark, this.options);
            let result = uiFramework.build(contract);
            this.embark.logger.info(result);
        } catch(err){
            throw errorMessage(err);
        }
    }
}


module.exports = Scaffolding;<commit_msg>Adding base command logic for scaffolding generation<commit_after>const fs = require('fs');

const commandName = "generate-ui";

//const errorMessage = (message) => new Error(commandName + ": " + message);
const formatReplyMsg = (message) => commandName + ": " + message;

class Scaffolding {
    constructor(embark, options){
        this.embark = embark;
        this.options = options;
        this.framework = options.framework;
        this.frameworkPlugin = null;
    }

    createDirectories(contractName){
        const dir = './app/' + contractName;
        if (!fs.existsSync(dir)){
            fs.mkdirSync(dir);
        } else {
            throw formatReplyMsg("directory ./app/" + contractName + " already exists");
        }
    }

    isContract(contractName){
        return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
    }

    generate(contractName){
        let frameworkPlugin;

        if(this.framework == 'react'){
            this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
            frameworkPlugin = this.embark.plugins.plugins.filter(x => x.name == "scaffolding-react")[0].pluginModule;
        } else {
            let plugins = this.embark.plugins.getPluginsFor(this.framework);
            if(plugins.length !== 1){
                //throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
                return formatReplyMsg("Could not find plugin for framework '" + this.framework + "'");
            }
            frameworkPlugin = plugins[0].pluginModule;
        }
        
        try {
            if(!this.isContract(contractName)){
                return formatReplyMsg("contract '" + contractName + "' does not exist");
            }

            const contract = this.embark.config.contractsConfig.contracts[contractName];
            
            this.createDirectories(contractName);
            let uiFramework = new frameworkPlugin(this.embark, this.options);
            uiFramework.build(contract);
        } catch(err){
            return err;
        }

        return formatReplyMsg("done!");
    }
}


module.exports = Scaffolding;
{'fraction_non_alphanumeric': 0.12007308796658836, 'fraction_numerical': 0.0015661707126076742, 'mean_word_length': 2.323503902862099, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5086770', 'n_tokens_mistral': 1011, 'n_tokens_neox': 986, 'n_words': 193}