Skip to content

Commit

Permalink
update to latest typedoc
Browse files Browse the repository at this point in the history
fixes #158
  • Loading branch information
nolimits4web committed Jul 5, 2021
1 parent 7e2efc2 commit 4a11d94
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ src/types.json
src/demos.json
src/shared/sponsors-list.js

tsconfig.json
23 changes: 18 additions & 5 deletions build/api/build-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ const fs = require('fs-extra');
const path = require('path');
const description = require('./description');

const plainDescription = (item) => {
if (item.comment && item.comment.shortText)
return item.comment.shortText || '';
if (
item.type &&
item.type.declaration &&
item.type.declaration.signatures &&
item.type.declaration.signatures[0] &&
item.type.declaration.signatures[0].comment &&
item.type.declaration.signatures[0].comment.shortText
)
return item.type.declaration.signatures[0].comment.shortText || '';
return '';
};

const buildEvents = async (typesName, typesData, ignoreEvents = []) => {
items =
(typesData[typesName] || [])
.filter((item) =>
item.comment && item.comment.shortText
? !item.comment.shortText.toLowerCase().includes('internal')
: true
.filter(
(item) => !plainDescription(item).toLowerCase().includes('internal')
)
.filter((item) => !ignoreEvents.includes(item.name)) || [];

Expand Down Expand Up @@ -63,7 +76,7 @@ export const ${typesName} = () => {
<td className="w-1/4 text-red-700 font-mono font-semibold">
${args(item)}
</td>
<td className="w-1/2 space-y-2">${description(item)}</td>
<td className="w-1/2 space-y-2">${description(item, true)}</td>
</tr>
`
)
Expand Down
9 changes: 7 additions & 2 deletions build/api/build-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ const buildOptions = async (

const type = (item = {}) => {
const typeObj = item.type || {};
if (typeObj.type === 'array' && typeObj.elementType) {
return `${typeObj.elementType.name}[]`;
}
if (typeObj.type === 'union') {
const types = [];
typeObj.types.forEach(({ name, value }) => {
typeObj.types.forEach(({ name, value, type, elementType }) => {
if (value) types.push(`'${value}'`);
else types.push(name);
else if (name) types.push(name);
else if (type === 'array' && elementType)
types.push(`${elementType.name}[]`);
});
return types.join(`{' | '}`);
}
Expand Down
11 changes: 8 additions & 3 deletions build/api/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ const processDescription = (text) => {
});
};

module.exports = (typesItem) => {
const { shortText, text, tags = [] } =
!typesItem.comment && typesItem.signatures && typesItem.signatures[0]
module.exports = (typesItem, isEvent) => {
const getProps = (item) => {
if (isEvent) {
return typesItem.type.declaration.signatures[0].comment || {};
}
return !typesItem.comment && typesItem.signatures && typesItem.signatures[0]
? typesItem.signatures[0].comment || {}
: typesItem.comment || {};
};
const { shortText, text, tags = [] } = getProps(typesItem);

const textContent = [shortText, text].filter((el) => !!el).join('\n\n');

Expand Down
20 changes: 17 additions & 3 deletions build/build-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ const components = [

(async () => {
elapsed.start('Typedoc');
await exec(
`npx typedoc --json ./src/types.json ./node_modules/swiper/types --includeDeclarations --excludeExternals`
fs.writeFileSync(
'./tsconfig.json',
fs.readFileSync('./tsconfig.json.typedoc', 'utf-8')
);
await exec(`npx typedoc --json ./src/types.json`);
elapsed.end('Typedoc');
elapsed.start('Generate all types');
const typesPath = path.join(__dirname, '../src/types.json');
const { children } = await fs.readJSON(typesPath);
const types = {};

children.forEach(async ({ name, children, flags, originalName }) => {
const _name = name.replace(/^\"(.*).d\"$/, '$1');
if (_name === 'public-api' || _name === 'shared' || !flags.isExported) {
if (
_name === 'public-api' ||
_name.includes('public-api') ||
_name === 'shared' ||
_name.includes('shared')
) {
return;
}
children.forEach((v) => {
Expand Down Expand Up @@ -76,8 +84,13 @@ const components = [
});
});

if (types.default) {
types.Swiper = types.default;
}

const componentsEventsList = [];
const componentsOptionsList = [];

components.forEach((component) => {
buildOptions(`${component}Options`, types, [], [], types.SwiperOptions);
buildEvents(`${component}Events`, types);
Expand Down Expand Up @@ -110,4 +123,5 @@ const components = [
await fs.writeFile(typesPath, `${JSON.stringify(types, null, 4)}`);
elapsed.end('Generate all types');
console.log(chalk.green(`Types generation finished`));
fs.unlinkSync('./tsconfig.json');
})();
16 changes: 11 additions & 5 deletions build/build-types.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const fs = require('fs-extra');
const { promise: exec } = require('exec-sh');
const dir = './public/types';
fs.removeSync(dir);
fs.ensureDirSync(dir);
exec(
'npx typedoc --out ./public/types ./node_modules/swiper --includeDeclarations --excludeExternals'
);

(async () => {
fs.removeSync(dir);
fs.ensureDirSync(dir);
fs.writeFileSync(
'./tsconfig.json',
fs.readFileSync('./tsconfig.json.typedoc', 'utf-8')
);
await exec('npx typedoc');
fs.unlinkSync('./tsconfig.json');
})();
Loading

0 comments on commit 4a11d94

Please sign in to comment.