private async getExecutionModel()

in tools/botskills/src/functionality/connectSkill.ts [37:152]


    private async getExecutionModel(
        luisApp: string,
        culture: string,
        intentName: string,
        dispatchName: string): Promise<Map<string, string>> {

        if (!existsSync(this.configuration.luisFolder)) {
            throw new Error(`Path to the LUIS folder (${ this.configuration.luisFolder }) leads to a nonexistent folder.${
                EOL }Remember to use the argument '--luisFolder' for your Skill's LUIS folder.`);
        }

        let luFile = '';
        let luisFile = '';
        let luFilePath = '';
        let luisFolderPath: string = join(this.configuration.luisFolder, culture);
        let luisFilePath = '';
        let dispatchFolderPath = '';
        let dispatchFilePath = '';
        let useAllIntents = false;

        dispatchFolderPath = join(this.configuration.dispatchFolder, culture);
        dispatchFilePath = join(dispatchFolderPath, `${ dispatchName }.dispatch`);

        // Validate 'dispatch add' arguments
        if (!existsSync(dispatchFolderPath)) {
            throw new Error(
                `Path to the Dispatch folder (${ dispatchFolderPath }) leads to a nonexistent folder.${
                    EOL }Remember to use the argument '--dispatchFolder' for your Assistant's Dispatch folder.`);
        } else if (!existsSync(dispatchFilePath)) {
            throw new Error(`Path to the ${ dispatchName }.dispatch file leads to a nonexistent file.`);
        }

        luFile = `${ luisApp }.lu`;
        luisFile = `${ luisApp }.luis`;
        luFilePath = join(this.configuration.luisFolder, culture, luFile);
        luisFilePath = join(luisFolderPath, luisFile);

        if (!existsSync(luFilePath)) {
            if (this.manifest !== undefined && this.manifest.entries !== undefined) {

                const model: IModel = {id: '', name: '', contentType: '', url: '', description: ''};
                const currentLocaleApps = this.manifest.entries.find((entry: [string, IModel[]]): boolean => entry[0] === culture) || [model];
                const localeApps: IModel[] = currentLocaleApps[1];
                const currentApp: IModel = localeApps.find((model: IModel): boolean => model.id === luisApp) || model;

                if (currentApp.url.startsWith('file')) {
                    luFilePath = currentApp.url.split('file://')[1];
                    if(!existsSync(luFilePath)) {
                        luFile = luFilePath;
                        luisFile = `${ parse(luFilePath).name }.luis`;
                        luFilePath = join(this.configuration.luisFolder, culture, luFile);
                    }
                }
                else if (currentApp.url.startsWith('http')) {
                    try {
                        const remoteLuFile = await this.getRemoteLu(currentApp.url);
                        let luisAppName: string = currentApp.url.split('/').reverse()[0];

                        const luPath = join(this.configuration.luisFolder, culture, luisAppName.endsWith('.lu') ? luisAppName : luisAppName + '.lu');
                        this.verifyLuisFolder(culture);
                        writeFileSync(luPath, remoteLuFile);
                        luFilePath = luPath;
                    } catch (error) {
                        console.log(error);
                    }
                }
                else {
                    luFilePath = currentApp.url;
                }
                
                if(!existsSync(luFilePath)) {
                    throw new Error(`Path to the LU file (${ luFilePath }) leads to a nonexistent file.`);
                }

                if (luFile.trim().length === 0) {
                    luisFile = `${ parse(luFilePath).name }.luis`;
                }
                luisFilePath = join(luisFolderPath, luisFile);
            }
        }

        // Validate 'bf luis:convert' arguments
        if (!existsSync(luFilePath)) {
            throw new Error(`Path to the ${ luFile } file leads to a nonexistent file.${
                EOL }Make sure your Skill's .lu file's name matches your Skill's manifest id`);
        }

        const executionModelMap: Map<string, string> = new Map();
        executionModelMap.set('luisApp', luisApp);
        executionModelMap.set('luisFile', luisFile);
        executionModelMap.set('luisFilePath', luisFilePath);
        executionModelMap.set('--in', luFilePath);
        executionModelMap.set('--culture', culture);
        executionModelMap.set('--out', luisFilePath);
        executionModelMap.set('--type', 'file');
        executionModelMap.set('--name', intentName);
        executionModelMap.set('--filePath', luisFilePath);
        executionModelMap.set('--intentName', intentName);
        executionModelMap.set('--dataFolder', dispatchFolderPath);
        executionModelMap.set('--dispatch', dispatchFilePath);

        // Validation of filtered intents
        if (this.manifest !== undefined) {
            useAllIntents = this.manifest.allowedIntents.some(e => e === '*');

            if (useAllIntents && this.manifest.allowedIntents.length > 1) {
                this.logger.warning('Found intent with name \'*\'. Adding all intents.');
            }
            
            if (!useAllIntents && this.manifest.allowedIntents.length > 0) {
                executionModelMap.set('--includedIntents', this.manifest.allowedIntents.join(','));
            }
        }
        
        return executionModelMap;
    }