Skip to content

Commit

Permalink
chore(all): convert to esm / TypeDoc 0.27 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 14, 2024
1 parent 8e17932 commit 78f246b
Show file tree
Hide file tree
Showing 214 changed files with 4,750 additions and 7,694 deletions.
3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit ${1}
6 changes: 3 additions & 3 deletions devtools/examples/docusaurus/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const sidebars = {
},
items: require('./docs/api/typedoc-sidebar.cjs'),
},
/*{
{
type: 'category',
label: 'DOCS 2',
link: {
type: 'doc',
id: 'api-2/index',
},
items: require('./docs/api-2/typedoc-sidebar.cjs'),
},
} /*
{
type: 'category',
label: 'DOCS 3',
Expand All @@ -41,7 +41,7 @@ const sidebars = {
id: 'api-3/index',
},
items: require('./docs/api-3/typedoc-sidebar.cjs'),
},*/
},*/,
],
};

Expand Down
21 changes: 15 additions & 6 deletions devtools/packages/fixtures/cli.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx

import { getPackageName } from '@devtools/helpers';
/* eslint-disable @typescript-eslint/no-unused-vars */

import { getPackageName } from '@devtools/helpers/index.js';
import { spawn } from 'child_process';
import { consola } from 'consola';
import * as fs from 'fs-extra';
import fs from 'fs-extra';
import * as path from 'path';
import { Fixture } from './models';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { Fixture } from './models.js';

export const __filename = fileURLToPath(import.meta.url);
export const __dirname = dirname(__filename);

const timeStart = new Date().getTime();

main();

async function main() {
fs.removeSync(path.join(process.cwd(), 'test', 'fixtures', 'out'));
const outPath = path.join(process.cwd(), 'test', 'fixtures', 'out');

fs.removeSync(outPath);

const config: Record<string, Fixture> = await import(
path.join(process.cwd(), process.argv[3])
Expand Down Expand Up @@ -41,7 +50,7 @@ async function main() {
const outputFileStrategies: ('members' | 'modules')[] =
config.outputFileStrategies || ['members', 'modules'];

//writeHtml(key, config.entryPoints);
writeHtml(key, config.entryPoints);
outputFileStrategies.forEach((outputFileStrategy) => {
config.options.forEach((optionGroup, index: number) => {
const options = {
Expand Down
1 change: 1 addition & 0 deletions devtools/packages/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@devtools/fixtures",
"version": "0.0.0",
"private": true,
"type": "module",
"files": [
"/"
],
Expand Down
10 changes: 10 additions & 0 deletions devtools/packages/fixtures/typedoc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ module.exports = {
URL: 'https://developer.mozilla.org/en-US/docs/Web/API/URL',
},
},
/*outputs: [
{
name: 'html',
path: './docs-html',
},
{
name: 'markdown',
path: './docs-markdown',
},
],*/
locales: {
en: {
theme_defined_in: 'Source',
Expand Down
2 changes: 1 addition & 1 deletion devtools/packages/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DocsConfig } from './models';
import { DocsConfig } from './models.js';

export const SRC_PATH = `${process.cwd()}/src`;
export const PRESETS_PATH = `${process.cwd()}/src/options/presets.ts`;
Expand Down
6 changes: 3 additions & 3 deletions devtools/packages/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './constants';
export * from './methods';
export * from './models';
export * from './constants.js';
export * from './methods.js';
export * from './models.js';
1 change: 1 addition & 0 deletions devtools/packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@devtools/helpers",
"version": "0.0.0",
"private": true,
"type": "module",
"main": "index.ts",
"files": [
"/"
Expand Down
6 changes: 3 additions & 3 deletions devtools/packages/prebuild-options/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx

import { DOCS_CONFIG, DocsConfig, getPackageName } from '@devtools/helpers';
import { consola } from 'consola';
import { generateOptionsDocs } from './tasks/generate-docs';
import { generateOptionsModels } from './tasks/generate-models';
import { generateOptionsDocs } from './tasks/generate-docs.js';
import { generateOptionsModels } from './tasks/generate-models.js';

main();

Expand Down
1 change: 1 addition & 0 deletions devtools/packages/prebuild-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@devtools/prebuild-options",
"version": "0.0.0",
"private": true,
"type": "module",
"files": [
"/"
],
Expand Down
49 changes: 30 additions & 19 deletions devtools/packages/prebuild-options/tasks/generate-docs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-empty */
import { DocsConfig } from '@devtools/helpers';
import * as fs from 'fs';
import * as path from 'path';
import { dirname } from 'path';
import * as prettier from 'prettier';
import { Project, VariableStatement } from 'ts-morph';
import { ParameterType } from 'typedoc';
import { fileURLToPath } from 'url';

export const __filename = fileURLToPath(import.meta.url);
export const __dirname = dirname(__filename);

export async function generateOptionsDocs(docsConfig: DocsConfig) {
const project = new Project({
Expand Down Expand Up @@ -53,9 +60,14 @@ ${presetsJson}
const optionsVariableStatements =
configFileTs?.getVariableStatements() as VariableStatement[];

const parsedConfig = Object.entries(declarationsConfig)
.map(([name, option]: any, i) => {
const docs = optionsVariableStatements[i].getJsDocs().map((doc) => {
const parsedConfig = optionsVariableStatements
.map((variableStatement) => {
const name = (
variableStatement.compilerNode.declarationList.declarations[0]
.name as any
).escapedText;
const option = declarationsConfig[name];
const docs = variableStatement.getJsDocs().map((doc) => {
return {
comments: (doc.getComment() as string)
?.replace(/\\\//g, '/')
Expand Down Expand Up @@ -125,7 +137,7 @@ ${presetsJson}
: '',
];
const optionLevel =
categories.length === 1 && !Boolean(docsConfig.presets) ? '##' : '##';
categories.length === 1 && !docsConfig.presets ? '##' : '##';
if (categories.length > 1) {
out.push(`# ${getDocsTitle(categoryName)}`);
if (Object.keys(categoryDescriptions)?.length) {
Expand All @@ -142,19 +154,15 @@ ${presetsJson}
options.forEach((option) => {
optionsLi.push(
`- [${
Boolean(option.deprecated)
? `~--${option.name}~`
: `--${option.name}`
option.deprecated ? `~--${option.name}~` : `--${option.name}`
}](./options/${categoryName.toLowerCase()}-options.mdx#--${option.name.toLowerCase()})`,
);
out.push(
`${optionLevel} ${
Boolean(option.deprecated)
? `~--${option.name}~`
: `--${option.name}`
option.deprecated ? `~--${option.name}~` : `--${option.name}`
}`,
);
if (Boolean(option.deprecated)) {
if (option.deprecated) {
out.push(
`<Callout type="warning">Deprecated: ${option.deprecated}</Callout>`,
);
Expand Down Expand Up @@ -195,15 +203,18 @@ ${presetsJson}
//out.push('Below is the full list of keys and default values:');
}
}

let exampleJson = {};

try {
exampleJson = JSON.parse(`{
"${option.name}": ${getExampleValue(option)}
}`);
} catch (e) {}

out.push(`
\`\`\`json filename="typedoc.json"
${JSON.stringify(
JSON.parse(`{
"${option.name}": ${getExampleValue(option)}
}`),
null,
2,
)}
${JSON.stringify(exampleJson, null, 2)}
\`\`\``);
});
if (categories.length > 1) {
Expand Down Expand Up @@ -303,7 +314,7 @@ function getType(option: any) {
}

function getDefaultValue(option) {
if (Boolean(option.default)) {
if (option.default) {
return option.default;
}

Expand Down
5 changes: 4 additions & 1 deletion devtools/packages/prebuild-options/tasks/generate-models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { DocsConfig, SRC_PATH } from '@devtools/helpers';
import * as fs from 'fs';
import * as path from 'path';
Expand Down Expand Up @@ -45,7 +46,7 @@ import { ManuallyValidatedOption } from 'typedoc'`);
if (
!ignoreTypes.map((t) => t.toLowerCase()).includes(option.toLowerCase())
) {
out.push(`import { ${option} } from './types/options';`);
out.push(`import { ${option} } from './types/options.js';`);
}
});
}
Expand All @@ -66,6 +67,8 @@ import { ManuallyValidatedOption } from 'typedoc'`);
theme_default_type: [];
theme_description: [];
theme_event: [];
theme_re_exports: [];
theme_renames_and_re_exports: [];
theme_extends: [];
theme_extended_by: [];
theme_globals: [];
Expand Down
1 change: 0 additions & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
module.exports = {
transform: {
'^.+\\.tsx?$': [
Expand Down
Loading

0 comments on commit 78f246b

Please sign in to comment.