Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): collect analytics option usage from workspace config and prompts #18982

Merged
merged 1 commit into from
Oct 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/angular/cli/commands/build-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,4 @@ export class BuildCommand extends ArchitectCommand<BuildCommandSchema> {
public async run(options: ArchitectCommandOptions & Arguments) {
return this.runArchitectTarget(options);
}

async reportAnalytics(
paths: string[],
options: BuildCommandSchema & Arguments,
dimensions: (boolean | number | string)[] = [],
metrics: (boolean | number | string)[] = [],
): Promise<void> {
return super.reportAnalytics(paths, options, dimensions, metrics);
}
}
9 changes: 0 additions & 9 deletions packages/angular/cli/commands/deploy-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,4 @@ export class DeployCommand extends ArchitectCommand<DeployCommandSchema> {
return super.initialize(options);
}
}

async reportAnalytics(
paths: string[],
options: DeployCommandSchema & Arguments,
dimensions: (boolean | number | string)[] = [],
metrics: (boolean | number | string)[] = [],
): Promise<void> {
return super.reportAnalytics(paths, options, dimensions, metrics);
}
}
12 changes: 4 additions & 8 deletions packages/angular/cli/commands/generate-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,18 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
paths: string[],
options: GenerateCommandSchema & Arguments,
): Promise<void> {
const [collectionName, schematicName] = await this.parseSchematicInfo(options);

if (!schematicName || !collectionName) {
if (!this.collectionName || !this.schematicName) {
return;
}
const escapedSchematicName = (this.longSchematicName || schematicName).replace(/\//g, '_');
const escapedSchematicName = (this.longSchematicName || this.schematicName).replace(/\//g, '_');

return super.reportAnalytics(
['generate', collectionName.replace(/\//g, '_'), escapedSchematicName],
['generate', this.collectionName.replace(/\//g, '_'), escapedSchematicName],
options,
);
}

private async parseSchematicInfo(options: {
schematic?: string;
}): Promise<[string, string | undefined]> {
private async parseSchematicInfo(options: GenerateCommandSchema): Promise<[string, string | undefined]> {
let collectionName = await this.getDefaultSchematicCollection();

let schematicName = options.schematic;
Expand Down
10 changes: 0 additions & 10 deletions packages/angular/cli/commands/serve-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
import { Arguments } from '../models/interface';
import { Schema as BuildCommandSchema } from './build';
import { Schema as ServeCommandSchema } from './serve';

export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
Expand All @@ -20,13 +19,4 @@ export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
public async run(options: ArchitectCommandOptions & Arguments) {
return this.runArchitectTarget(options);
}

async reportAnalytics(
paths: string[],
options: BuildCommandSchema & Arguments,
dimensions: (boolean | number | string)[] = [],
metrics: (boolean | number | string)[] = [],
): Promise<void> {
return super.reportAnalytics(paths, options, dimensions, metrics);
}
}
10 changes: 7 additions & 3 deletions packages/angular/cli/models/architect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export abstract class ArchitectCommand<
protected _architect!: Architect;
protected _architectHost!: WorkspaceNodeModulesArchitectHost;
protected _registry!: json.schema.SchemaRegistry;
protected readonly useReportAnalytics = false;

// If this command supports running multiple targets.
protected multiTarget = false;
Expand Down Expand Up @@ -192,7 +193,6 @@ export abstract class ArchitectCommand<
protected async runSingleTarget(
target: Target,
targetOptions: string[],
commandOptions: ArchitectCommandOptions & Arguments,
) {
// We need to build the builderSpec twice because architect does not understand
// overrides separately (getting the configuration builds the whole project, including
Expand All @@ -216,6 +216,11 @@ export abstract class ArchitectCommand<
return 1;
}

await this.reportAnalytics([this.description.name], {
...await this._architectHost.getOptionsForTarget(target) as unknown as T,
...overrides,
});

const run = await this._architect.scheduleTarget(target, overrides as json.JsonObject, {
logger: this.logger,
analytics: isPackageNameSafeForAnalytics(builderConf) ? this.analytics : undefined,
Expand Down Expand Up @@ -246,13 +251,12 @@ export abstract class ArchitectCommand<
result |= await this.runSingleTarget(
{ ...targetSpec, project } as Target,
extra,
options,
);
}

return result;
} else {
return await this.runSingleTarget(targetSpec, extra, options);
return await this.runSingleTarget(targetSpec, extra);
}
} catch (e) {
if (e instanceof schema.SchemaValidationException) {
Expand Down
9 changes: 6 additions & 3 deletions packages/angular/cli/models/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface BaseCommandOptions {
}

export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions> {
public allowMissingWorkspace = false;
protected allowMissingWorkspace = false;
protected useReportAnalytics = true;
readonly workspace?: AngularWorkspace;
readonly analytics: analytics.Analytics;

Expand Down Expand Up @@ -143,7 +144,7 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>

async reportAnalytics(
paths: string[],
options: T & Arguments,
options: Arguments,
dimensions: (boolean | number | string)[] = [],
metrics: (boolean | number | string)[] = [],
): Promise<void> {
Expand Down Expand Up @@ -173,7 +174,9 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
return this.printJsonHelp(options);
} else {
const startTime = +new Date();
await this.reportAnalytics([this.description.name], options);
alan-agius4 marked this conversation as resolved.
Show resolved Hide resolved
if (this.useReportAnalytics) {
await this.reportAnalytics([this.description.name], options);
}
const result = await this.run(options);
const endTime = +new Date();

Expand Down
6 changes: 5 additions & 1 deletion packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class UnknownCollectionError extends Error {
export abstract class SchematicCommand<
T extends BaseSchematicSchema & BaseCommandOptions
> extends Command<T> {
readonly allowPrivateSchematics: boolean = false;
protected readonly allowPrivateSchematics: boolean = false;
protected readonly useReportAnalytics = false;
protected _workflow!: NodeWorkflow;

protected defaultCollectionName = '@schematics/angular';
Expand Down Expand Up @@ -482,6 +483,9 @@ export abstract class SchematicCommand<
...options.additionalOptions,
};

const transformOptions = await workflow.engine.transformOptions(schematic, input).toPromise();
await this.reportAnalytics([this.description.name], transformOptions as Arguments);

workflow.reporter.subscribe((event: DryRunEvent) => {
nothingDone = false;

Expand Down