@vismaux/ngx-vud
Advanced tools
Comparing version 12.0.0-next.4 to 12.0.0-next.5
{ | ||
"name": "@vismaux/ngx-vud", | ||
"version": "12.0.0-next.4", | ||
"version": "12.0.0-next.5", | ||
"peerDependencies": { | ||
@@ -5,0 +5,0 @@ "@angular/cdk": "^16.0.0", |
@@ -31,3 +31,2 @@ "use strict"; | ||
const angularCoreVersion = (0, package_config_1.getPackageVersionFromPackageJson)(tree, '@angular/core'); | ||
const angularLocalizeVersion = (0, package_config_1.getPackageVersionFromPackageJson)(tree, '@angular/localize'); | ||
const angularCdkVersion = (0, package_config_1.getPackageVersionFromPackageJson)(tree, '@angular/cdk'); | ||
@@ -37,5 +36,2 @@ const pkg = require('../../package.json'); | ||
if (angularCoreVersion !== null) { | ||
if (angularLocalizeVersion === null) { | ||
(0, package_config_1.addPackageToPackageJson)(tree, '@angular/localize', angularCoreVersion); | ||
} | ||
if (angularCdkVersion === null) { | ||
@@ -42,0 +38,0 @@ (0, package_config_1.addPackageToPackageJson)(tree, '@angular/cdk', pkg.peerDependencies['@angular/cdk']); |
import { Rule } from '@angular-devkit/schematics'; | ||
export declare function ngAddSetupProject(options: any): Rule; | ||
import { Schema } from './schema'; | ||
export declare function ngAddSetupProject(options: Schema): Rule; |
@@ -14,45 +14,45 @@ "use strict"; | ||
const schematics_1 = require("@angular-devkit/schematics"); | ||
const ast_utils_1 = require("@schematics/angular/utility/ast-utils"); | ||
const change_1 = require("@schematics/angular/utility/change"); | ||
const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils"); | ||
const schematics_2 = require("@angular/cdk/schematics"); | ||
const workspace_1 = require("@schematics/angular/utility/workspace"); | ||
const path = require("path"); | ||
const ts = require("typescript"); | ||
const project_1 = require("../utils/project"); | ||
const messages_1 = require("./messages"); | ||
function ngAddSetupProject(options) { | ||
return (0, schematics_1.chain)([ | ||
updateAppModule(options), | ||
addStyles(options), | ||
(0, schematics_1.externalSchematic)('@angular/localize', 'ng-add', options.project ? { project: options.project } : {}), | ||
]); | ||
return (0, schematics_1.chain)([updateAppModule(options), addStyles(options)]); | ||
} | ||
exports.ngAddSetupProject = ngAddSetupProject; | ||
const ANIMATION_MODULE_NAME = 'BrowserAnimationsModule'; | ||
const NO_ANIMATION_MODULE_NAME = 'NoopAnimationsModule'; | ||
const ANIMATION_MODULE_PACKAGE_NAME = '@angular/platform-browser/animations'; | ||
function updateAppModule(options) { | ||
return (host) => __awaiter(this, void 0, void 0, function* () { | ||
return (host, context) => __awaiter(this, void 0, void 0, function* () { | ||
const workspace = yield (0, workspace_1.getWorkspace)(host); | ||
const projectName = options.project || workspace.extensions.defaultProject; | ||
const project = workspace.projects.get(projectName); | ||
if (!project) { | ||
throw new schematics_1.SchematicsException((0, messages_1.noProject)(projectName)); | ||
const project = (0, schematics_2.getProjectFromWorkspace)(workspace, options.project); | ||
const mainFilePath = (0, schematics_2.getProjectMainFile)(project); | ||
if ((0, schematics_2.isStandaloneApp)(host, mainFilePath)) { | ||
// TODO: print warning message | ||
return; | ||
} | ||
const buildOptions = (0, project_1.getProjectTargetOptions)(project, 'build'); | ||
const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, buildOptions.main); | ||
const text = host.read(modulePath); | ||
if (text === null) { | ||
throw new schematics_1.SchematicsException(`File '${modulePath}' does not exist.`); | ||
addAnimationsToNonStandaloneApp(host, project, mainFilePath, context, options); | ||
}); | ||
} | ||
function addAnimationsToNonStandaloneApp(host, project, mainFile, context, options) { | ||
const browserAnimationsModuleName = 'BrowserAnimationsModule'; | ||
const noopAnimationsModuleName = 'NoopAnimationsModule'; | ||
const appModulePath = (0, schematics_2.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_2.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.`); | ||
} | ||
const source = ts.createSourceFile(modulePath, text.toString('utf-8'), ts.ScriptTarget.Latest, true); | ||
const changes = (0, ast_utils_1.addImportToModule)(source, modulePath, options.animations ? ANIMATION_MODULE_NAME : NO_ANIMATION_MODULE_NAME, ANIMATION_MODULE_PACKAGE_NAME); | ||
const recorder = host.beginUpdate(modulePath); | ||
for (const change of changes) { | ||
if (change instanceof change_1.InsertChange) { | ||
recorder.insertLeft(change.pos, change.toAdd); | ||
} | ||
else { | ||
(0, schematics_2.addModuleImportToRootModule)(host, browserAnimationsModuleName, '@angular/platform-browser/animations', project); | ||
} | ||
host.commitUpdate(recorder); | ||
}); | ||
} | ||
else if (!options.animations && | ||
!(0, schematics_2.hasNgModuleImport)(host, appModulePath, browserAnimationsModuleName)) { | ||
// Do not add the NoopAnimationsModule module if the project already explicitly uses | ||
// the BrowserAnimationsModule. | ||
(0, schematics_2.addModuleImportToRootModule)(host, noopAnimationsModuleName, '@angular/platform-browser/animations', project); | ||
} | ||
} | ||
@@ -64,11 +64,10 @@ const SUPPORTED_BOOTSTRAP_STYLE_IMPORTS = { | ||
function addStyles(options) { | ||
return (host) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return (host, context) => __awaiter(this, void 0, void 0, function* () { | ||
const workspace = yield (0, workspace_1.getWorkspace)(host); | ||
const projectName = options.project || ((_a = workspace.extensions.defaultProject) === null || _a === void 0 ? void 0 : _a.toString()); | ||
const project = workspace.projects.get(projectName); | ||
if (!project) { | ||
throw new schematics_1.SchematicsException((0, messages_1.noProject)(projectName)); | ||
const project = (0, schematics_2.getProjectFromWorkspace)(workspace, options.project); | ||
const styleFilePath = (0, schematics_2.getProjectStyleFile)(project); | ||
if (!styleFilePath) { | ||
context.logger.error(`Could not find the default style file for this project.`); | ||
return; | ||
} | ||
const styleFilePath = (0, project_1.getProjectStyleFile)(project) || ''; | ||
const styleFileExtension = path.extname(styleFilePath); | ||
@@ -75,0 +74,0 @@ const styleFilePatch = SUPPORTED_BOOTSTRAP_STYLE_IMPORTS[styleFileExtension]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2489841
331
20999