diff --git a/bin/luis-lu-export.js b/bin/luis-lu-export.js index 27bfafd..19badf7 100644 --- a/bin/luis-lu-export.js +++ b/bin/luis-lu-export.js @@ -18,6 +18,7 @@ program .option('--model [model file]', 'The destination .lu file') .option('--versionId [versionId]', 'The version id to export') .option('--luisrc [luisrc file]', 'The .luisrc file we want to use, perhaps if we want to use a different LUIS app if you have an app per environment setup.') + .option('--verbose') .parse(process.argv); if(!program.model) { diff --git a/bin/luis-version.js b/bin/luis-version.js index db58a5a..727577d 100644 --- a/bin/luis-version.js +++ b/bin/luis-version.js @@ -19,6 +19,7 @@ program .option('--publish', 'Publishes the new version of the application') .option('--model [model file]', 'The .lu file supporting the application') .option('--luisrc [luisrc file]', 'The .luisrc file we want to use, perhaps if we want to use a different LUIS app if you have an app per environment setup.') + .option('--verbose') .parse(process.argv); if(!program.model) { diff --git a/package.json b/package.json index 316db0b..3895154 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "luis-version-tools", - "version": "0.0.7", + "version": "0.0.8", "description": "An opinionated LUIS versioning tool", "main": "luis-version.js", "bin": { diff --git a/src/updatemodel.js b/src/updatemodel.js index 69ef8f3..320f3d9 100644 --- a/src/updatemodel.js +++ b/src/updatemodel.js @@ -9,9 +9,11 @@ const replaceExt = require('replace-ext'); const VersionFile = '.luis-app-version'; const LuisRcFile = '.luisrc'; -function npmrunExecSync(cmd) { - console.log(chalk.default.white(`exec: ${cmd}`)); - return npmrun.execSync(cmd); +function npmrunExecSync(cmd, options, program) { + if(program.verbose) { + console.log(chalk.default.white(`exec: ${cmd}`)); + } + return npmrun.execSync(cmd, options); } exports.exportlu = function (program) { @@ -25,17 +27,17 @@ exports.exportlu = function (program) { } else { console.log(chalk.default.green('Fetching versions ...')); const getVersions = `luis list versions --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey}`; - const getVersionsResult = JSON.parse(npmrunExecSync(getVersions)); + const getVersionsResult = JSON.parse(npmrunExecSync(getVersions, {}, program)); latestVersion = getVersionsResult[getVersionsResult.length - 1].version; } console.log(chalk.default.green(`Exporting version ${latestVersion} ...`)); const exportCmd = `luis export version --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey} --versionId ${latestVersion} > ${tempJson}`; - const exportCmdResult = npmrunExecSync(exportCmd); + const exportCmdResult = npmrunExecSync(exportCmd, {}, program); console.log(chalk.default.green(`Refreshing .lu ...`)); const ludownCmd = `ludown refresh -i ${tempJson} -n ${program.model} --skip_header`; - const ludownCmdResult = npmrunExecSync(ludownCmd); + const ludownCmdResult = npmrunExecSync(ludownCmd, {}, program); console.log(chalk.default.green(`Done! Created ${program.model} ...`)); @@ -62,7 +64,7 @@ exports.updateModel = function (program) { console.log(chalk.default.green(`Getting app id ${appConfig.appId}...`)); const appCmd = `luis get application --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey}`; - const appCmdResult = npmrunExecSync(appCmd); + const appCmdResult = npmrunExecSync(appCmd, {}, program); if (appCmdResult.indexOf('is not a valid value for appId') >= 0) { console.log(chalk.default.redBright(`Application ${appConfig.appId} not found.`)); process.exit(); @@ -98,7 +100,7 @@ exports.updateModel = function (program) { let versionExists = false; try { - getVersionResult = npmrunExecSync(getVersion, { stdio: 'ignore' }); + getVersionResult = npmrunExecSync(getVersion, { stdio: 'ignore' }, program); console.log(chalk.default.yellowBright(`Version ${version} exists...`)); versionExists = true; } catch (error) { @@ -137,7 +139,7 @@ exports.updateModel = function (program) { console.log(chalk.default.green('Publishing...')); const publishCmd = `luis publish version --appId ${appConfig.appId} --versionId ${version} --authoringKey ${appConfig.authoringKey} --endpointBasePath ${appConfig.endpointBasePath}`; - const publishResult = JSON.parse(npmrunExecSync(publishCmd)); + const publishResult = JSON.parse(npmrunExecSync(publishCmd, {}, program)); } else { console.log(chalk.default.yellowBright('Skipping publish. Use --publish option to include publish.')); } @@ -156,7 +158,7 @@ function runLudown(program, version, applicationJson) { console.log(chalk.default.green('Running ludown.')); const n = applicationJson.name; const ludownCmd = `ludown parse ToLuis --in ${program.model} --luis_name ${n} --luis_desc "${applicationJson.description}" --luis_versionId ${version} --luis_culture ${applicationJson.culture}`; - const ludownCmdResult = npmrunExecSync(ludownCmd); + const ludownCmdResult = npmrunExecSync(ludownCmd, {}, program); if (ludownCmdResult.toString().length > 0) { // there was an issue with ludown throw new Error('Issue with ludown: ' + ludownCmdResult); @@ -173,7 +175,7 @@ function runLudown(program, version, applicationJson) { function deleteVersion(program, version, appConfig) { console.log(chalk.default.green('Backing version up before delete')); const backupVersionCmd = `luis export version --versionId ${version} --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey}`; - const backupVersionCmdResult = npmrunExecSync(backupVersionCmd); + const backupVersionCmdResult = npmrunExecSync(backupVersionCmd, {}, program); const deleteVersionCmd = `luis delete version --versionId ${version} --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey}`; const deleteVersionCmdProcess = npmrun.exec(deleteVersionCmd, {}, function (err, stdout, stderr) { @@ -187,7 +189,7 @@ function deleteVersion(program, version, appConfig) { function importVersion(program, appConfig, version, jsonFilename) { console.log(chalk.green(`Importing version ${version}...`)); const updateCmd = `luis import version --appId ${appConfig.appId} --authoringKey ${appConfig.authoringKey} --in ${jsonFilename}`; - const updateCmdResult = npmrunExecSync(updateCmd); + const updateCmdResult = npmrunExecSync(updateCmd, {}, progam); fs.unlinkSync(jsonFilename); // get rid of the old file @@ -204,13 +206,13 @@ function trainVersion(version, appConfig) { if (retryCount > 0) { console.log(chalk.default.yellow(`Retry ${retryCount}: ${trainVersion}`)); } - npmrunExecSync(trainVersion); + npmrunExecSync(trainVersion, {}, program); utils.waitfor(5); var start = moment(); while (true) { const getStatus = `luis get status --appId ${appConfig.appId} --versionId ${version} --authoringKey ${appConfig.authoringKey}`; - const statusStr = npmrunExecSync(getStatus).toString(); + const statusStr = npmrunExecSync(getStatus, {}, program).toString(); let isDone = null; let needsRetrain = null;