Skip to content

Commit

Permalink
chore: created task packages
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 30, 2023
1 parent 206e4af commit 23085da
Show file tree
Hide file tree
Showing 45 changed files with 2,607 additions and 6,064 deletions.
23 changes: 23 additions & 0 deletions internal-packages/code-tools/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env ts-node

import { program } from 'commander';
import { prepareOptions } from './tasks/plugin-options';
import { prepareResources } from './tasks/theme-resources';

program.option('--prepare-options').option('--theme-resources');

program.parse();

const options = program.opts();

main();

async function main() {
if (options.pluginOptions) {
await prepareOptions();
}

if (options.themeResources) {
await prepareResources();
}
}
12 changes: 12 additions & 0 deletions internal-packages/code-tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "code-tools",
"version": "0.0.0",
"private": true,
"files": [
"/"
],
"bin": {
"code-tools": "cli.ts"
},
"author": "Tom Grey"
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
import { consola } from 'consola';
import * as fs from 'fs';
import * as path from 'path';
import * as prettier from 'prettier';
import { DeclarationOption, ParameterType } from 'typedoc';
import * as optionsConfig from '../../src/plugin/options/config';

export function prepareOptions() {
/**
* Creates models for plugin options
*/

export async function prepareOptions() {
consola.start('Preparing options...');

const optionsConfig = await import(
`${process.cwd()}/src/plugin/options/declarations`
);

const optionsModelFile = path.join(
process.cwd(),
'src',
'plugin',
'options',
'models.ts',
);

const optionsOutput = `
// THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.
declare module 'typedoc' {
export interface TypeDocOptionMap {
${Object.entries(optionsConfig)
.map(([key, option], i) => {
return `${option.name}: ${getType(option)};`;
.map(([name, option], i) => {
return `${name}: ${getType(option as any)};`;
})
.join('\n')}
}
}
export interface PluginOptions {
${Object.entries(optionsConfig)
.map(([key, option], i) => {
return `${option.name}: ${getType(option)};`;
.map(([name, option], i) => {
return `${name}: ${getType(option as any)};`;
})
.join('\n')}
}`;

const optionsModelFile = path.join(
__dirname,
'..',
'..',
'src',
'plugin',
'options',
'models.ts',
);
const formatted = await prettier.format(optionsOutput, {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
});

prettier
.format(optionsOutput, {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
})
.then((formatted) => {
fs.writeFileSync(optionsModelFile, formatted);
});
fs.writeFileSync(optionsModelFile, formatted);
consola.success(
`Option models written to ${path.relative(
process.cwd(),
optionsModelFile,
)}`,
);
}

function getType(option: Partial<DeclarationOption>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { consola } from 'consola';
import * as fs from 'fs';
import * as path from 'path';
import * as prettier from 'prettier';
Expand All @@ -7,16 +8,10 @@ const project = new Project({
tsConfigFilePath: 'tsconfig.json',
});

const resourcesPath = path.join(
__dirname,
'..',
'..',
'src',
'theme',
'resources',
);
const resourcesPath = path.join(process.cwd(), 'src', 'theme', 'resources');

export function prepareResources() {
export async function prepareResources() {
consola.start('Preparing preparing resources...');
const templateFiles = getFiles('templates').filter(
(file) => file !== 'index',
);
Expand All @@ -31,16 +26,12 @@ export function prepareResources() {
const partialsSymbols = getSymbols(partialsFiles, 'partials');

const themeRenderContextFile = path.join(
__dirname,
'..',
'..',
process.cwd(),
'src',
'theme',
'render-context.ts',
);

//const partialsBarrelFile = path.join(resourcesPath, 'partials', 'index.ts');

const importsOut: string[] = [];
const exportsOut: string[] = [];

Expand Down Expand Up @@ -93,15 +84,20 @@ export function prepareResources() {
/* end_resources */`,
);

prettier
.format(data, {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
})
.then((formatted) => {
fs.writeFileSync(themeRenderContextFile, formatted);
});
const formatted = await prettier.format(data, {
parser: 'typescript',
singleQuote: true,
trailingComma: 'all',
});

fs.writeFileSync(themeRenderContextFile, formatted);

consola.success(
`Option models written to ${path.relative(
process.cwd(),
themeRenderContextFile,
)}`,
);
}

function getFiles(type: string) {
Expand Down
22 changes: 22 additions & 0 deletions internal-packages/doc-tools/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

import { consola } from 'consola';
import { remark } from 'remark';
import remarkGfm from 'remark-gfm';
import remarkToc from 'remark-toc';
import { read, writeSync } from 'to-vfile';
import remarkDocumentOptions from './remark/remark-document-options.mjs';

main();

async function main() {
consola.start('Updating Readme');
const file = await read('./README.md');
const vfile = await remark()
.use(remarkGfm)
.use(remarkToc, { maxDepth: 2, tight: true })
.use(remarkDocumentOptions)
.process(file);
writeSync(vfile);
consola.success('Finished updating readme');
}
12 changes: 12 additions & 0 deletions internal-packages/doc-tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "doc-tools",
"version": "0.0.0",
"private": true,
"files": [
"/"
],
"bin": {
"doc-tools": "cli.mjs"
},
"author": "Tom Grey"
}
Loading

0 comments on commit 23085da

Please sign in to comment.