-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce plugin structure and generate documentation
- Loading branch information
Showing
19 changed files
with
833 additions
and
446 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,85 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
|
||
import { | ||
existsSync, | ||
mkdirSync, | ||
readFileSync, | ||
writeFileSync, | ||
} from 'fs'; | ||
import { rmSync } from 'node:fs'; | ||
import { join } from 'path'; | ||
|
||
import { default as htmlPlugin } from './src/rules/html'; | ||
import { default as tsPlugin } from './src/rules/ts'; | ||
|
||
const templates = new Map(); | ||
|
||
function lazyEJS(path: string, data: object) { | ||
if (!templates.has(path)) { | ||
templates.set(path, require('ejs').compile(readFileSync(path).toString())); | ||
} | ||
|
||
return templates.get(path)(data); | ||
} | ||
|
||
const docsDir = join('lint', 'docs'); | ||
const tsDir = join(docsDir, 'ts'); | ||
const htmlDir = join(docsDir, 'html'); | ||
|
||
if (existsSync(docsDir)) { | ||
rmSync(docsDir, { recursive: true }); | ||
} | ||
|
||
mkdirSync(join(tsDir, 'rules'), { recursive: true }); | ||
mkdirSync(join(htmlDir, 'rules'), { recursive: true }); | ||
|
||
function template(name: string): string { | ||
return join('lint', 'src', 'util', 'templates', name); | ||
} | ||
|
||
// TypeScript docs | ||
writeFileSync( | ||
join(tsDir, 'index.md'), | ||
lazyEJS(template('index.ejs'), { | ||
plugin: tsPlugin, | ||
rules: tsPlugin.index.map(rule => rule.info), | ||
}), | ||
); | ||
|
||
for (const rule of tsPlugin.index) { | ||
writeFileSync( | ||
join(tsDir, 'rules', rule.info.name + '.md'), | ||
lazyEJS(template('rule.ejs'), { | ||
plugin: tsPlugin, | ||
rule: rule.info, | ||
tests: rule.tests, | ||
}), | ||
); | ||
} | ||
|
||
// HTML docs | ||
writeFileSync( | ||
join(htmlDir, 'index.md'), | ||
lazyEJS(template('index.ejs'), { | ||
plugin: htmlPlugin, | ||
rules: htmlPlugin.index.map(rule => rule.info), | ||
}), | ||
); | ||
|
||
for (const rule of htmlPlugin.index) { | ||
writeFileSync( | ||
join(htmlDir, 'rules', rule.info.name + '.md'), | ||
lazyEJS(template('rule.ejs'), { | ||
plugin: htmlPlugin, | ||
rule: rule.info, | ||
tests: rule.tests, | ||
}), | ||
); | ||
} | ||
|
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import themedComponentSelectors from './themed-component-selectors'; | ||
import themedComponentUsages from './themed-component-usages'; | ||
import { | ||
bundle, | ||
RuleExports, | ||
} from '../../util/structure'; | ||
import * as themedComponentUsages from './themed-component-usages'; | ||
import * as themedComponentSelectors from './themed-component-selectors'; | ||
|
||
const index = [ | ||
themedComponentUsages, | ||
themedComponentSelectors, | ||
] as unknown as RuleExports[]; | ||
|
||
export = { | ||
rules: { | ||
'themed-component-selectors': themedComponentSelectors, | ||
'themed-component-usages': themedComponentUsages, | ||
}, | ||
...bundle('dspace-angular-ts', 'TypeScript', index), | ||
}; |
Oops, something went wrong.