-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: cli healthcheck * fix: ensuring prompt works
- Loading branch information
1 parent
1aba2fa
commit 61f701b
Showing
24 changed files
with
672 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/app/src/app/pages/(documentation)/documentation/(ui)/health-checks.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { RouteMeta } from '@analogjs/router'; | ||
import { Component } from '@angular/core'; | ||
import { MainSectionDirective } from '@spartan-ng/app/app/shared/layout/main-section.directive'; | ||
import { PageBottomNavLinkComponent } from '@spartan-ng/app/app/shared/layout/page-bottom-nav/page-bottom-nav-link.component'; | ||
import { PageBottomNavComponent } from '@spartan-ng/app/app/shared/layout/page-bottom-nav/page-bottom-nav.component'; | ||
import { PageNavComponent } from '@spartan-ng/app/app/shared/layout/page-nav/page-nav.component'; | ||
import { SectionIntroComponent } from '@spartan-ng/app/app/shared/layout/section-intro.component'; | ||
import { metaWith } from '@spartan-ng/app/app/shared/meta/meta.util'; | ||
import { hlmP } from '@spartan-ng/ui-typography-helm'; | ||
import { TabsCliComponent } from '../../../../shared/layout/tabs-cli.component'; | ||
|
||
export const routeMeta: RouteMeta = { | ||
data: { breadcrumb: 'Figma' }, | ||
meta: metaWith('spartan - Health Checks', 'Ensure your project is up to date with the latest best practices.'), | ||
title: 'spartan - Health Checks', | ||
}; | ||
|
||
@Component({ | ||
selector: 'spartan-health-checks', | ||
standalone: true, | ||
imports: [ | ||
MainSectionDirective, | ||
SectionIntroComponent, | ||
PageBottomNavComponent, | ||
PageBottomNavLinkComponent, | ||
PageNavComponent, | ||
TabsCliComponent, | ||
], | ||
template: ` | ||
<section spartanMainSection> | ||
<spartan-section-intro | ||
name="Health Checks" | ||
lead="Ensure your project is up to date with the latest best practices." | ||
/> | ||
<section> | ||
<p class="${hlmP}"> | ||
Spartan CLI comes with a health check tool that will scan your project and provide you with a report of any | ||
issues that need to be addressed, and guidance on how to resolve them. | ||
</p> | ||
<p class="${hlmP}"> | ||
Additionally, while Spartan is still in its alpha stage we are working hard to make sure our components and | ||
tooling is built with the latest best practices and is structure in a way that will serve us well into the | ||
future. As a result we have been making some changes that may result in breaking changes to your project. | ||
</p> | ||
<p class="${hlmP}"> | ||
To help minimize the impact of such changes, in most cases the health check tool will be automatically be able | ||
to fix the issues for you. To run the health check tool simply run the following command: | ||
</p> | ||
<spartan-cli-tabs | ||
class="mb-6 mt-4" | ||
nxCode="npx nx g @spartan-ng/cli:healthcheck" | ||
ngCode="ng g @spartan-ng/cli:healthcheck" | ||
/> | ||
</section> | ||
<spartan-page-bottom-nav> | ||
<spartan-page-bottom-nav-link href="/components" label="Components" /> | ||
<spartan-page-bottom-nav-link direction="previous" href="figma" label="Figma" /> | ||
</spartan-page-bottom-nav> | ||
</section> | ||
<spartan-page-nav /> | ||
`, | ||
}) | ||
export default class HealthChecksPageComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { convertNxGenerator } from '@nx/devkit'; | ||
import { healthcheckGenerator } from './generator'; | ||
|
||
export default convertNxGenerator(healthcheckGenerator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { readJson, Tree, writeJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { healthcheckGenerator } from './generator'; | ||
|
||
describe('healthcheck generator', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
|
||
writeJson(tree, 'package.json', { | ||
dependencies: { | ||
'@spartan-ng/brain': '0.0.1-alpha.300', | ||
'@spartan-ng/ui-checkbox-brain': '0.0.1-alpha.300', | ||
}, | ||
devDependencies: { | ||
'@spartan-ng/cli': '0.0.1-alpha.300', | ||
}, | ||
}); | ||
|
||
// add a file with legacy imports | ||
tree.write( | ||
'libs/my-lib/src/index.ts', | ||
` | ||
import { BrnCheckbox } from '@spartan-ng/ui-checkbox-brain'; | ||
import { hlm } from '@spartan-ng/ui-core'; | ||
`, | ||
); | ||
|
||
// add a file with a helm icon | ||
tree.write( | ||
'libs/my-lib/src/app.component.html', | ||
` | ||
<hlm-icon /> | ||
<hlm-scroll-area /> | ||
`, | ||
); | ||
|
||
await healthcheckGenerator(tree, { skipFormat: true, autoFix: true }); | ||
}); | ||
|
||
it('should update to latest dependencies', () => { | ||
const packageJson = readJson(tree, 'package.json'); | ||
|
||
expect(packageJson.dependencies['@spartan-ng/brain']).not.toEqual('0.0.1-alpha.300'); | ||
expect(packageJson.devDependencies['@spartan-ng/cli']).not.toEqual('0.0.1-alpha.300'); | ||
}); | ||
|
||
it('should update brain imports', () => { | ||
const contents = tree.read('libs/my-lib/src/index.ts', 'utf-8'); | ||
|
||
expect(contents).not.toContain('@spartan-ng/ui-checkbox-brain'); | ||
expect(contents).toContain('@spartan-ng/brain/checkbox'); | ||
|
||
// check if package.json was updated | ||
const packageJson = readJson(tree, 'package.json'); | ||
expect(packageJson.dependencies['@spartan-ng/ui-checkbox-brain']).toBeUndefined(); | ||
}); | ||
|
||
it('should update core imports', () => { | ||
const contents = tree.read('libs/my-lib/src/index.ts', 'utf-8'); | ||
|
||
expect(contents).not.toContain('@spartan-ng/ui-core'); | ||
expect(contents).toContain('@spartan-ng/brain/core'); | ||
}); | ||
|
||
it('should update helm icons', () => { | ||
const contents = tree.read('libs/my-lib/src/app.component.html', 'utf-8'); | ||
|
||
expect(contents).not.toContain('<hlm-icon'); | ||
expect(contents).toContain('<ng-icon hlm'); | ||
}); | ||
|
||
it('should update helm scroll areas', () => { | ||
const contents = tree.read('libs/my-lib/src/app.component.html', 'utf-8'); | ||
|
||
expect(contents).not.toContain('<hlm-scroll-area'); | ||
expect(contents).toContain('<ng-scrollbar hlm'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { formatFiles, logger, Tree } from '@nx/devkit'; | ||
import { Healthcheck, HealthcheckReport, HealthcheckStatus, isHealthcheckFixable } from './healthchecks'; | ||
import { brainImportsHealthcheck } from './healthchecks/brain-imports'; | ||
import { coreImportsHealthcheck } from './healthchecks/core-imports'; | ||
import { helmIconHealthcheck } from './healthchecks/hlm-icon'; | ||
import { scrollAreaHealthcheck } from './healthchecks/hlm-scroll-area'; | ||
import { versionHealthcheck } from './healthchecks/version'; | ||
import { HealthcheckGeneratorSchema } from './schema'; | ||
import { promptUser } from './utils/prompt'; | ||
import { printReport } from './utils/reporter'; | ||
import { runHealthcheck } from './utils/runner'; | ||
|
||
export async function healthcheckGenerator(tree: Tree, options: HealthcheckGeneratorSchema) { | ||
logger.info('Running healthchecks...'); | ||
|
||
const healthchecks: Healthcheck[] = [ | ||
versionHealthcheck, | ||
brainImportsHealthcheck, | ||
coreImportsHealthcheck, | ||
helmIconHealthcheck, | ||
scrollAreaHealthcheck, | ||
]; | ||
|
||
// store all the failed healthchecks that can be fixed | ||
const failedReports: HealthcheckReport[] = []; | ||
|
||
for (const healthcheck of healthchecks) { | ||
const report = await runHealthcheck(tree, healthcheck); | ||
printReport(report); | ||
|
||
if (report.status === HealthcheckStatus.Failure) { | ||
failedReports.push(report); | ||
} | ||
} | ||
|
||
// if there are some failed healthchecks that can be fixed, ask the user if they want to fix them | ||
for (const report of failedReports) { | ||
if (report.fixable && isHealthcheckFixable(report.healthcheck)) { | ||
const fix = options.autoFix || (await promptUser(report.healthcheck.prompt)); | ||
|
||
if (fix) { | ||
await report.healthcheck.fix(tree); | ||
} | ||
} | ||
} | ||
|
||
if (!options.skipFormat) { | ||
await formatFiles(tree); | ||
} | ||
} | ||
|
||
export default healthcheckGenerator; |
Oops, something went wrong.