-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add api tables to all components (#2297)
* chore: add api tables to all components * chore: only use eleventyignore as ignore files for rocket
- Loading branch information
1 parent
b50b960
commit 8e45042
Showing
9 changed files
with
1,903 additions
and
340 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 @@ | ||
import fs from 'fs'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { globby } from 'globby'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { createModuleGraph } from '@thepassle/module-graph'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { create, ts } from '@custom-elements-manifest/analyzer'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { litPlugin } from '@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { generateCustomData } from 'cem-plugin-vs-code-custom-data-generator'; | ||
|
||
/** | ||
* Find all entrypoints for lion to create the CEM from | ||
*/ | ||
const globs = await globby('./exports/**/*.js'); | ||
|
||
/** | ||
* Based on the entrypoints, create a module graph including @lion/ui dependency | ||
* We'll feed these modules to the CEM analyzer | ||
*/ | ||
const moduleGraph = await createModuleGraph(globs, { | ||
exclude: [ | ||
/** Don't include translations in the CEM */ | ||
i => i.includes('/translations/'), | ||
/** Don't include SVGs in the CEM */ | ||
i => i.endsWith('.svg.js'), | ||
], | ||
}); | ||
|
||
/** | ||
* Create ts.sourceFiles from the modules in the module graph | ||
* to pass to the CEM analyzer | ||
*/ | ||
const modules = []; | ||
for (const [, module] of moduleGraph.modules) { | ||
modules.push(ts.createSourceFile(module.path, module.source, ts.ScriptTarget.ES2015, true)); | ||
} | ||
|
||
/** Exclude information inherited from these mixins, they're generally not useful for public api */ | ||
const inheritanceDenyList = [ | ||
'LocalizeMixin', | ||
'ScopedElementsMixin', | ||
'SlotMixin', | ||
'SyncUpdatableMixin', | ||
]; | ||
|
||
const cem = create({ | ||
modules, | ||
plugins: [ | ||
...litPlugin(), | ||
generateCustomData(), | ||
{ | ||
packageLinkPhase({ customElementsManifest }) { | ||
for (const definition of customElementsManifest.modules) { | ||
for (const declaration of definition.declarations) { | ||
if (declaration.kind === 'class' && declaration?.members?.length) { | ||
/** | ||
* Filter out unwanted information from the docs | ||
*/ | ||
declaration.members = declaration.members.filter( | ||
member => !inheritanceDenyList.includes(member.inheritedFrom?.name), | ||
); | ||
|
||
/** | ||
* Set privacy for members based on naming conventions | ||
*/ | ||
for (const m of declaration.members) { | ||
if (!m.privacy && !m.name.startsWith('_') && !m.name.startsWith('#')) { | ||
m.privacy = 'public'; | ||
} else if (!m.privacy && m.name.startsWith('_')) { | ||
m.privacy = 'protected'; | ||
} else if (m.name.startsWith('#') || m.name.startsWith('__')) { | ||
m.privacy = 'private'; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
fs.writeFileSync('./custom-elements.json', JSON.stringify(cem, null, 2)); |
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,89 @@ | ||
import fs from 'fs'; | ||
import { customElementsManifestToMarkdown } from '@custom-elements-manifest/to-markdown'; | ||
|
||
/** | ||
* @param {string} text | ||
*/ | ||
function toSplitAndUpperCase(text) { | ||
return text.replace(/(^\w|-\w)/g, clearAndUpper); | ||
} | ||
|
||
/** | ||
* @param {string} text | ||
*/ | ||
function clearAndUpper(text) { | ||
return text.replace(/-/, ' ').toUpperCase(); | ||
} | ||
|
||
const systemsTable = ['core', 'form-core', 'localize', 'overlays']; | ||
const mappingTable = [{ componentDir: 'validate-messages', portalDir: 'form' }]; | ||
|
||
const componentDirs = fs | ||
.readdirSync('./packages/ui/components') | ||
.filter(d => !d.startsWith('_') && !d.startsWith('form-integrations')); | ||
|
||
const customElementsJson = JSON.parse( | ||
fs.readFileSync('./packages/ui/custom-elements.json', 'utf8'), | ||
); | ||
|
||
for (let dir of componentDirs) { | ||
const isSystem = systemsTable.includes(dir); | ||
const classes = fs | ||
.readdirSync(`./packages/ui/components/${dir}/src/`) | ||
.filter(f => { | ||
if (isSystem) { | ||
return f.endsWith('.js') | ||
} | ||
return f.endsWith('.js') && !f.endsWith('Manager.js') && !f.endsWith('Mixin.js') | ||
}) | ||
.map(f => f.replace('.js', '')); | ||
|
||
for (const component of mappingTable) { | ||
if (dir === component.componentDir) { | ||
dir = component.portalDir; | ||
} | ||
} | ||
if (dir === 'form-core') { | ||
dir = 'form'; | ||
} | ||
|
||
const folderHeading = isSystem ? 'Systems >> ' : ''; | ||
let dirApiTableMd = `# ${folderHeading}${toSplitAndUpperCase(dir)} >> API Table ||90`; | ||
|
||
for (const c of classes) { | ||
for (const mod of customElementsJson.modules) { | ||
for (const declaration of mod.declarations) { | ||
if (declaration.name === c && declaration.kind === 'class') { | ||
const md = customElementsManifestToMarkdown( | ||
{ | ||
modules: [ | ||
{ | ||
declarations: [declaration], | ||
}, | ||
], | ||
}, | ||
{ | ||
private: 'hidden', | ||
headingOffset: 0, | ||
omitSections: [ | ||
'main-heading', | ||
'super-class', | ||
'static-fields', | ||
'static-methods', | ||
'mixins', | ||
], | ||
}, | ||
); | ||
dirApiTableMd = `${dirApiTableMd} \n\n${md}`; | ||
} | ||
} | ||
} | ||
} | ||
|
||
const folder = isSystem ? 'fundamentals/systems' : 'components'; | ||
try { | ||
fs.writeFileSync(`./docs/${folder}/${dir}/api-table.md`, dirApiTableMd); | ||
} catch (e) { | ||
console.error(`No api docs have been created, ${e}`); | ||
} | ||
} |