Skip to content

Commit

Permalink
adding verbose flag for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
srozga committed Sep 10, 2018
1 parent 1a21a20 commit 12eedf6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions bin/luis-lu-export.js
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions bin/luis-version.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion 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": {
Expand Down
30 changes: 16 additions & 14 deletions src/updatemodel.js
Expand Up @@ -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) {
Expand All @@ -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} ...`));

Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.'));
}
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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

Expand All @@ -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;
Expand Down

0 comments on commit 12eedf6

Please sign in to comment.