Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 780bf2c

Browse files
author
Chris McConnell
authored
Cleanup dialog:verify and add intelligent import to dialog:merge (#1001)
* Fix missing -o exception. Clear ImportedDirectory on copy. Exclude csproj bin files. * Working on verify * Working tests. * Update verify to be more informative and enable tests. * Tests passing with new merge. * Intelligent merging. * Treat non-declarative files as unchanged. * Detect modified unchanged exports.
1 parent 028a4ec commit 780bf2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1622
-343
lines changed

.vscode/launch.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"999999",
3535
"--colors",
3636
"-g",
37-
".*"
37+
"dialog:merge.*"
3838
],
3939
"internalConsoleOptions": "openOnSessionStart",
4040
"outputCapture": "std",
@@ -164,6 +164,26 @@
164164
"internalConsoleOptions": "openOnSessionStart",
165165
"cwd": "${workspaceFolder}/../botbuilder-dotnet"
166166
},
167+
{
168+
"type": "node",
169+
"request": "launch",
170+
"name": "Adaptive Sample 08 project",
171+
"preLaunchTask": "${defaultBuildTask}",
172+
"program": "${workspaceFolder}/packages/dialog/bin/run",
173+
"outputCapture": "std",
174+
"outFiles": [
175+
"./packages/dialog/lib/**"
176+
],
177+
"args": [
178+
"dialog:merge",
179+
"*.csproj",
180+
"--verbose",
181+
"-o",
182+
"${env:TEMP}/app.schema",
183+
],
184+
"internalConsoleOptions": "openOnSessionStart",
185+
"cwd": "${workspaceFolder}/../botbuilder-samples/samples/csharp_dotnetcore/adaptive-dialog/08.todo-bot-luis-qnamaker"
186+
},
167187
{
168188
"type": "node",
169189
"request": "launch",

packages/dialog/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ ARGUMENTS
4646
PATTERNS Any number of glob regex patterns to match .csproj, .nuspec or package.json files.
4747
4848
OPTIONS
49+
-c, --checkOnly Check and do not write files.
4950
-h, --help show CLI help
5051
-o, --output=output Output path and filename for merged .schema and .uischema. Defaults to first project name.
5152
-s, --schema=schema Path to merged .schema file to use if merging .uischema only.
5253
-v, --verbose Show verbose logging of files as they are processed.
53-
--extension=extension [default: .dialog,.lg,.lu,.schema,.qna,.uischema] Extension to include as a resource for C#.
54+
--extension=extension [default: .dialog,.lg,.lu,.schema,.qna,.uischema] Extension to include as a resource.
5455
5556
--imports=imports Output path for imported assets. Defaults to the directory of --out with an ImportedAssets
5657
directory.
@@ -74,8 +75,9 @@ ARGUMENTS
7475
PATTERNS Any number of glob regex patterns to match .dialog files.
7576
7677
OPTIONS
77-
-h, --help show CLI help
78-
-v, --verbose Show verbose output
78+
-h, --help show CLI help
79+
-s, --schema=schema Default schema to use if no $schema in dialog file.
80+
-v, --verbose Show verbose output
7981
```
8082

8183
_See code: [src/commands/dialog/verify.ts](https://github.com/microsoft/botframework-cli/tree/master/packages/dialog/blob/v1.0.0/src/commands/dialog/verify.ts)_

packages/dialog/src/commands/dialog/merge.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import {Command, flags} from '@microsoft/bf-cli-command'
7-
import SchemaMerger from '../../library/schemaMerger'
7+
import { SchemaMerger } from '../../library/schemaMerger'
88

99
export default class DialogMerge extends Command {
1010
static description = 'Merge `<kind>.schema` and `<kind>[.<locale>].uischema` definitions from a project and its dependencies into a single .schema for describing .dialog files and a per locale .uischema for describing how Composer shows them. If a dependent package has an ExportedAssets directory it is copied to ImportedAssets/<package> in the --imports directory.'
@@ -16,8 +16,9 @@ export default class DialogMerge extends Command {
1616
static strict = false
1717

1818
static flags: flags.Input<any> = {
19+
checkOnly: flags.boolean({char: 'c', description: 'Check and do not write files.', default: false}),
1920
debug: flags.boolean({char: 'd', description: 'Generate debug files.', hidden: true, default: false}),
20-
extension: flags.string({description: 'Extension to include as a resource for C#.', required: false, multiple: true, default: ['.dialog', '.lg', '.lu', '.schema', '.qna', '.uischema']}),
21+
extension: flags.string({description: 'Extension to include as a resource.', required: false, multiple: true, default: ['.dialog', '.lg', '.lu', '.schema', '.qna', '.uischema']}),
2122
help: flags.help({char: 'h'}),
2223
nugetRoot: flags.string({description: 'Nuget root directory for debugging.', hidden: true}),
2324
imports: flags.string({description: 'Output path for imported assets. Defaults to the directory of --out with an ImportedAssets directory.', required: false}),
@@ -33,7 +34,7 @@ export default class DialogMerge extends Command {
3334

3435
async run() {
3536
const {argv, flags} = this.parse(DialogMerge)
36-
let merger = new SchemaMerger(argv, flags.output, flags.imports, flags.verbose, this.log, this.warn, this.error, flags.extension, flags.schema, flags.debug, flags.nugetRoot)
37+
let merger = new SchemaMerger(argv, flags.output, flags.imports, flags.checkOnly, flags.verbose, this.log, this.warn, this.error, flags.extension, flags.schema, flags.debug, flags.nugetRoot)
3738
await merger.merge()
3839
}
3940
}

packages/dialog/src/commands/dialog/verify.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { Command, flags } from '@microsoft/bf-cli-command';
6+
import {Command, flags} from '@microsoft/bf-cli-command';
77
import * as chalk from 'chalk';
8-
import { Definition, DialogTracker, SchemaTracker } from '../../library/dialogTracker';
8+
import {Definition, DialogTracker, SchemaTracker} from '../../library/dialogTracker';
99

1010
export default class DialogVerify extends Command {
1111
static description = 'Verify .dialog files match their app.schema.'
12-
12+
1313
static args = [
14-
{ name: 'patterns', required: true, description: 'Any number of glob regex patterns to match .dialog files.' },
14+
{name: 'patterns', required: true, description: 'Any number of glob regex patterns to match .dialog files.'}
1515
]
1616

1717
static strict = false
1818

1919
static flags: flags.Input<any> = {
20-
help: flags.help({ char: 'h' }),
21-
verbose: flags.boolean({ char: 'v', description: 'Show verbose output', default: false }),
20+
help: flags.help({char: 'h'}),
21+
schema: flags.string({char: 's', description: 'Default schema to use if no $schema in dialog file.'}),
22+
verbose: flags.boolean({char: 'v', description: 'Show verbose output', default: false}),
2223
}
2324

2425
private currentFile = ''
@@ -27,13 +28,13 @@ export default class DialogVerify extends Command {
2728
private warnings = 0
2829

2930
async run() {
30-
const { argv, flags } = this.parse(DialogVerify)
31-
await this.execute(argv, flags.verbose)
31+
const {argv, flags} = this.parse(DialogVerify)
32+
await this.execute(argv, flags.verbose, flags.schema)
3233
}
3334

34-
async execute(dialogFiles: string[], verbose?: boolean): Promise<void> {
35+
async execute(dialogFiles: string[], verbose?: boolean, schemaPath?: string): Promise<void> {
3536
const schema = new SchemaTracker()
36-
const tracker = new DialogTracker(schema)
37+
const tracker = new DialogTracker(schema, undefined, schemaPath)
3738

3839
await tracker.addDialogFiles(dialogFiles)
3940

@@ -49,10 +50,11 @@ export default class DialogVerify extends Command {
4950
}
5051
} else {
5152
for (let error of dialog.errors) {
52-
this.consoleError(`${error.message.trim()}`, 'DLG001')
53+
this.consoleError(`${error.message}`, 'DLG001')
5354
}
5455
}
5556
}
57+
this.currentFile = ''
5658

5759
for (let defs of tracker.multipleDefinitions()) {
5860
let def = (defs as Definition[])[0]
@@ -66,8 +68,10 @@ export default class DialogVerify extends Command {
6668
this.consoleError(`Missing definition for ${def} ${def.usedByString()}`, 'DLG003')
6769
}
6870

69-
for (let def of tracker.missingTypes) {
70-
this.consoleError(`Missing $kind for ${def}`, 'DLG004')
71+
for (let def of tracker.typeMismatches()) {
72+
for (let use of def.typeMismatches()) {
73+
this.consoleError(`Type mismatch ${def} does not match ${use}`, 'DLG004')
74+
}
7175
}
7276

7377
for (let def of tracker.unusedIDs()) {
@@ -84,9 +88,11 @@ export default class DialogVerify extends Command {
8488
}
8589

8690
this.log(`${this.files} files processed.`)
87-
this.error(`${this.warnings} found.`)
91+
if (this.warnings > 0) {
92+
this.warn(`Warnings: ${this.warnings} found.`)
93+
}
8894
if (this.errors > 0) {
89-
this.error(`Error: ${this.errors} found.`)
95+
this.error(`Errors: ${this.errors} found.`)
9096
}
9197
}
9298
}
@@ -101,11 +107,11 @@ export default class DialogVerify extends Command {
101107

102108
consoleWarn(msg: string, code: string): void {
103109
this.warnings++
104-
this.warn(`${this.currentFile} - warning ${code || ''}: ${msg}`)
110+
this.warn(`${this.currentFile ? `${this.currentFile} - ` : ''}Warning ${code || ''}: ${msg}`)
105111
}
106112

107113
consoleError(msg: string, code: string): void {
108114
this.errors++
109-
this.error(`${this.currentFile} - error ${code || ''}: ${msg}`)
115+
this.error(`${this.currentFile ? `${this.currentFile} - ` : ''}Error ${code || ''}: ${msg}`)
110116
}
111117
}

0 commit comments

Comments
 (0)