-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(angular): fail build when an angular directive or component is not…
… exported (#561)
- Loading branch information
1 parent
0d22e56
commit d6583a6
Showing
4 changed files
with
58 additions
and
2 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
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,50 @@ | ||
import {glob} from 'glob'; | ||
import path from 'path'; | ||
import {fileURLToPath} from 'url'; | ||
import {readFile} from 'fs/promises'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const pathRegExp = /\\/g; | ||
function normalizePath(str) { | ||
return str.replace(pathRegExp, '/'); | ||
} | ||
|
||
const COMPONENTS_FOLDER = path.join(__dirname, '../src/components'); | ||
|
||
const files = ( | ||
await glob('**/*.component.ts', { | ||
cwd: COMPONENTS_FOLDER, | ||
nodir: true, | ||
}) | ||
).map((file) => normalizePath(path.join(COMPONENTS_FOLDER, file))); | ||
|
||
const stuffToExportRegex = /(@Directive|@Component)\({[\S\s]+?}\)\s*export class ([a-zA-Z]*)/g; | ||
|
||
const classesToExport = []; | ||
for (const file of files) { | ||
const content = await readFile(file, {encoding: 'utf-8'}); | ||
const matches = [...content.matchAll(stuffToExportRegex)]; | ||
for (const match of matches) { | ||
classesToExport.push(match[2]); | ||
} | ||
} | ||
|
||
const angularModuleContent = await readFile(normalizePath(path.join(__dirname, '../src/agnos-ui-angular.module.ts')), {encoding: 'utf-8'}); | ||
const componentsFromAngularModule = new Set( | ||
angularModuleContent | ||
.match(/const components = \[([^\]]+)\];/)[1] | ||
.split(',') | ||
.map((component) => component.trim()) | ||
.filter((component) => !!component), | ||
); | ||
|
||
const defaultSlotRegex = /^[a-zA-Z]*Default[a-zA-Z]*Slots?Component$/; | ||
const missingComponents = classesToExport.filter( | ||
(classToExport) => !componentsFromAngularModule.has(classToExport) && !classToExport.match(defaultSlotRegex), | ||
); | ||
|
||
if (missingComponents.length) { | ||
console.error(`ERROR ! The following Angular components / directives are not exported in the main angular module: ${missingComponents.join(', ')}`); | ||
process.exit(1); | ||
} |
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