ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
85 lines • 5.24 kB
JavaScript
;
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addAnimationsModule = void 0;
const schematics_1 = require("@angular/cdk/schematics");
const components_1 = require("@schematics/angular/private/components");
const workspace_1 = require("@schematics/angular/utility/workspace");
function addAnimationsModule(options) {
return (host, context) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, workspace_1.getWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
const mainFilePath = (0, schematics_1.getProjectMainFile)(project);
if ((0, schematics_1.isStandaloneApp)(host, mainFilePath)) {
addAnimationsToStandaloneApp(host, mainFilePath, context, options);
}
else {
addAnimationsToNonStandaloneApp(host, project, mainFilePath, context, options);
}
});
}
exports.addAnimationsModule = addAnimationsModule;
/** Adds the animations module to an app that is bootstrap using the standalone component APIs. */
function addAnimationsToStandaloneApp(host, mainFile, context, options) {
const animationsFunction = 'provideAnimations';
const noopAnimationsFunction = 'provideNoopAnimations';
if (options.animations) {
// In case the project explicitly uses provideNoopAnimations, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add provideAnimations while provideNoopAnimations
// is already configured, we would cause unexpected behavior and runtime exceptions.
if ((0, components_1.callsProvidersFunction)(host, mainFile, noopAnimationsFunction)) {
context.logger.error(`Could not add "${animationsFunction}" ` + `because "${noopAnimationsFunction}" is already provided.`);
context.logger.info(`Please manually set up browser animations.`);
}
else {
(0, components_1.addFunctionalProvidersToStandaloneBootstrap)(host, mainFile, animationsFunction, '@angular/platform-browser/animations');
}
}
else if (!options.animations && !(0, components_1.importsProvidersFrom)(host, mainFile, animationsFunction)) {
// Do not add the provideNoopAnimations if the project already explicitly uses
// the provideAnimations.
(0, components_1.addFunctionalProvidersToStandaloneBootstrap)(host, mainFile, noopAnimationsFunction, '@angular/platform-browser/animations');
}
}
/**
* Adds the animations module to an app that is bootstrap
* using the non-standalone component APIs.
*/
function addAnimationsToNonStandaloneApp(host, project, mainFile, context, options) {
const browserAnimationsModuleName = 'BrowserAnimationsModule';
const noopAnimationsModuleName = 'NoopAnimationsModule';
const appModulePath = (0, schematics_1.getAppModulePath)(host, mainFile);
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if ((0, schematics_1.hasNgModuleImport)(host, appModulePath, noopAnimationsModuleName)) {
context.logger.error(`Could not set up "${browserAnimationsModuleName}" ` +
`because "${noopAnimationsModuleName}" is already imported.`);
context.logger.info(`Please manually set up browser animations.`);
}
else {
(0, schematics_1.addModuleImportToRootModule)(host, browserAnimationsModuleName, '@angular/platform-browser/animations', project);
}
}
else if (!options.animations && !(0, schematics_1.hasNgModuleImport)(host, appModulePath, browserAnimationsModuleName)) {
// Do not add the NoopAnimationsModule module if the project already explicitly uses
// the BrowserAnimationsModule.
(0, schematics_1.addModuleImportToRootModule)(host, noopAnimationsModuleName, '@angular/platform-browser/animations', project);
}
}
//# sourceMappingURL=add-animations-module.js.map