Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Update lg package in MSLG #1271

Merged
merged 1 commit into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,4 @@ packages/lubuild/bin/**
packages/lubuild/lib/**
packages/lubuild/typings/**

packages/MSLG/.vscode/launch.json
87 changes: 74 additions & 13 deletions packages/MSLG/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/MSLG/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"dependencies": {
"@types/fs-extra": "^5.0.5",
"botbuilder-lg": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/botbuilder-lg/-/4.5.1.tgz",
"@types/lru-cache": "^5.1.0",
"botbuilder-lg": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/botbuilder-lg/-/4.6.2.tgz",
"chalk": "^2.4.2",
"commander": "^2.19.0",
"fs-extra": "^7.0.1",
Expand Down
6 changes: 5 additions & 1 deletion packages/MSLG/src/Expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class Expander {

private parseFile(fileName: string, inlineExpression: any = undefined): string[] {
let fileContent: string = '';
let filePath: string = '';
if (fileName !== undefined) {
if (!fs.existsSync(path.resolve(fileName))) {
throw new Error('unable to open file: ' + fileName);
Expand All @@ -91,15 +92,18 @@ export class Expander {
if (!fileContent) {
throw new Error('unable to read file: ' + fileName);
}

filePath = path.resolve(fileName)
}

if (inlineExpression !== undefined) {
const fakeTemplateId: string = '__temp__';
const wrappedStr: string = `\n# ${fakeTemplateId} \r\n - ${inlineExpression}`;
fileContent += wrappedStr;
filePath = path.resolve('./');
}

const errors: string[] = this.tool.ValidateFile(fileContent);
const errors: string[] = this.tool.ValidateFile(fileContent, filePath);
if (errors.length > 0) {
errors.forEach(error => {
if (error.startsWith(ErrorType.Error)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/MSLG/src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Parser {

if (verbose) process.stdout.write(chalk.default.whiteBright('Parsing file: ' + fileName + '\n'));

const errors: string[] = this.tool.ValidateFile(fileContent);
const errors: string[] = this.tool.ValidateFile(fileContent, path.resolve(fileName));
if (errors.length > 0) {
errors.forEach(error => {
if (error.startsWith(ErrorType.Error)) {
Expand All @@ -159,7 +159,7 @@ export class Parser {
private parseStream(fileContent: string, verbose: boolean): string[] {
if (verbose) process.stdout.write(chalk.default.whiteBright('Parsing from stdin.\n'));

const errors: string[] = this.tool.ValidateFile(fileContent);
const errors: string[] = this.tool.ValidateFile(fileContent, path.resolve('./'));
if (errors.length > 0) {
errors.forEach(error => {
process.stderr.write(chalk.default.redBright(error + '\n'));
Expand Down
4 changes: 2 additions & 2 deletions packages/MSLG/test/mslg.cli.test.suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describe('The mslg cli tool', function () {
let filePath = resolvePath('examples/exceptionExamples/EmptyTemplate.lg');
exec(`node ${mslg} parse --in ${filePath}`, (error, stdout, stderr) => {
try {
assert.equal(stderr.includes('[Error] line 1:0 - line 1:2: There is no template body in template template'), true);
assert.equal(stderr.includes('[Error] line 2:0 - line 2:10:'), true);
assert.equal(stderr.includes('error message: There is no template body in template template'), true);
done();
} catch (err) {
done(err);
Expand Down Expand Up @@ -200,7 +201,6 @@ describe('The mslg cli tool', function () {
});

it('should expand inline expression successfully', function (done) {
let filePath = resolvePath('examples/validExamples/simple.lg');
exec(`node ${mslg} expand --inline '{1+1}'`, (error, stdout, stderr) => {
try {
assert.equal(stdout.includes('2'), true);
Expand Down