diff --git a/package-lock.json b/package-lock.json index d1621b8..c81a7af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3303,9 +3303,9 @@ } }, "node_modules/@hug/ngx-schematics-utilities": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@hug/ngx-schematics-utilities/-/ngx-schematics-utilities-9.0.0.tgz", - "integrity": "sha512-d5bZ5AhOI+1eUTuEFLah8gp185ZpXnXW618TNKjy8/pRQsfynJi2+AwuD7MxIScE68vUCpIk1ePszZ8VutI5PQ==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@hug/ngx-schematics-utilities/-/ngx-schematics-utilities-9.0.1.tgz", + "integrity": "sha512-g+9Wq0rmSKLKDeP5JOW6jROWwb3VXAjXy2e2MqMyGiEQ8A0fxsVQmYmq4CCgmUCfENfCDfyAML5ROQEyBrlY7w==", "dependencies": { "@badisi/latest-version": "^7.0.3", "@colors/colors": "^1.6.0", @@ -19012,7 +19012,7 @@ "version": "6.0.1", "license": "GPL-3.0-only", "dependencies": { - "@hug/ngx-schematics-utilities": "^9.0.0", + "@hug/ngx-schematics-utilities": "^9.0.1", "@sentry/angular-ivy": "^7.110.0", "@sentry/cli": "2.31.0", "tslib": "^2.6.2" diff --git a/projects/lib/package.json b/projects/lib/package.json index 6162bec..b11aad5 100644 --- a/projects/lib/package.json +++ b/projects/lib/package.json @@ -47,7 +47,7 @@ "@angular/router": ">= 15" }, "dependencies": { - "@hug/ngx-schematics-utilities": "^9.0.0", + "@hug/ngx-schematics-utilities": "^9.0.1", "@sentry/angular-ivy": "^7.110.0", "@sentry/cli": "2.31.0", "tslib": "^2.6.2" diff --git a/projects/lib/schematics/ng-add/index.ts b/projects/lib/schematics/ng-add/index.ts index a9a0f3a..8c30f6a 100644 --- a/projects/lib/schematics/ng-add/index.ts +++ b/projects/lib/schematics/ng-add/index.ts @@ -1,15 +1,14 @@ import { tags } from '@angular-devkit/core'; import { chain, Rule } from '@angular-devkit/schematics'; import { - addImportToFile, addImportToNgModule, addProviderToBootstrapApplication, application, - ChainableProjectContext, createOrUpdateFile, getProjectMainPath, isProjectStandalone, logAction, schematic, workspace + addImportToFile, addImportToNgModule, addProviderToBootstrapApplication, application, ChainableApplicationContext, + createOrUpdateFile, logAction, schematic, workspace } from '@hug/ngx-schematics-utilities'; import { NgAddOptions } from './ng-add-options'; -export const initSentry = (context: ChainableProjectContext, options: NgAddOptions): Rule => { - const mainTsPath = getProjectMainPath(context.tree, context.project.name); - const mainTsContent = context.tree.read(mainTsPath)?.toString('utf-8') ?? ''; +export const initSentry = ({ tree, project }: ChainableApplicationContext, options: NgAddOptions): Rule => { + const mainTsContent = tree.read(project.mainFilePath)?.toString('utf-8') ?? ''; const rules: Rule[] = []; // Initialize Sentry in main.ts @@ -33,21 +32,21 @@ export const initSentry = (context: ChainableProjectContext, options: NgAddOptio newContent += mainTsContent.substring(insertAtPosition); rules.push( - createOrUpdateFile(mainTsPath, newContent), + createOrUpdateFile(project.mainFilePath, newContent), logAction('Have a look at `main.ts` file and update Sentry configuration according to your needs') ); } rules.push( - addImportToFile(mainTsPath, 'isDevMode', '@angular/core'), - addImportToFile(mainTsPath, 'packageJson', '../package.json', true) + addImportToFile(project.mainFilePath, 'isDevMode', '@angular/core'), + addImportToFile(project.mainFilePath, 'packageJson', '../package.json', true) ); // Provide library - rules.push(addImportToFile(mainTsPath, 'initSentry', '@hug/ngx-sentry')); - if (isProjectStandalone(context.tree, context.project.name)) { - rules.push(addProviderToBootstrapApplication(mainTsPath, 'provideSentry()', '@hug/ngx-sentry')); + rules.push(addImportToFile(project.mainFilePath, 'initSentry', '@hug/ngx-sentry')); + if (project.isStandalone) { + rules.push(addProviderToBootstrapApplication(project.mainFilePath, 'provideSentry()', '@hug/ngx-sentry')); } else { - const appModulePath = context.project.pathFromSourceRoot('app/app.module.ts'); + const appModulePath = project.pathFromSourceRoot('app/app.module.ts'); rules.push(addImportToNgModule(appModulePath, 'NgxSentryModule.forRoot()', '@hug/ngx-sentry')); } diff --git a/projects/lib/schematics/ng-add/ng-add.spec.ts b/projects/lib/schematics/ng-add/ng-add.spec.ts index fc1942d..3ff6f5c 100644 --- a/projects/lib/schematics/ng-add/ng-add.spec.ts +++ b/projects/lib/schematics/ng-add/ng-add.spec.ts @@ -1,5 +1,5 @@ import { UnitTestTree } from '@angular-devkit/schematics/testing'; -import { getProjectFromWorkspace, ProjectDefinition } from '@hug/ngx-schematics-utilities'; +import { ApplicationDefinition, getProjectFromWorkspace } from '@hug/ngx-schematics-utilities'; import { appTest1, appTest2, getCleanAppTree, runner } from '../schematics.spec'; import { NgAddOptions } from './ng-add-options'; @@ -12,7 +12,7 @@ const joc = jasmine.objectContaining; let defaultOptions: NgAddOptions; let tree: UnitTestTree; let nbFiles: number; - let project: ProjectDefinition; + let project: ApplicationDefinition; beforeEach(async () => { tree = await getCleanAppTree(useWorkspace, useStandalone);