Hans Larsen 15032aa2e8 feat(@angular-devkit/schematics): add support for analytics
Schematics context now have an (optional) analytics field that, if set,
should be used to report usage. This can be set even in some cases where
analytics is disabled (to a noop analytics).
2019-03-20 15:08:07 -07:00

67 lines
1.9 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path, getSystemPath, virtualFs } from '@angular-devkit/core';
import {
workflow,
} from '@angular-devkit/schematics'; // tslint:disable-line:no-implicit-dependencies
import { BuiltinTaskExecutor } from '../../tasks/node';
import { FileSystemEngine } from '../description';
import { NodeModulesEngineHost } from '../node-module-engine-host';
import { validateOptionsWithSchema } from '../schema-option-transform';
/**
* A workflow specifically for Node tools.
*/
export class NodeWorkflow extends workflow.BaseWorkflow {
constructor(
host: virtualFs.Host,
options: {
force?: boolean;
dryRun?: boolean;
root?: Path,
packageManager?: string;
},
) {
const engineHost = new NodeModulesEngineHost();
super({
host,
engineHost,
force: options.force,
dryRun: options.dryRun,
});
engineHost.registerOptionsTransform(validateOptionsWithSchema(this._registry));
engineHost.registerTaskExecutor(
BuiltinTaskExecutor.NodePackage,
{
allowPackageManagerOverride: true,
packageManager: options.packageManager,
rootDirectory: options.root && getSystemPath(options.root),
},
);
engineHost.registerTaskExecutor(
BuiltinTaskExecutor.RepositoryInitializer,
{
rootDirectory: options.root && getSystemPath(options.root),
},
);
engineHost.registerTaskExecutor(BuiltinTaskExecutor.RunSchematic);
engineHost.registerTaskExecutor(BuiltinTaskExecutor.TslintFix);
this._context = [];
}
get engine(): FileSystemEngine {
return this._engine as {} as FileSystemEngine;
}
get engineHost(): NodeModulesEngineHost {
return this._engineHost as NodeModulesEngineHost;
}
}