Skip to content

Commit

Permalink
feat: new client integration
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Jun 29, 2023
1 parent a8d096d commit c1fb398
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 91 deletions.
147 changes: 76 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@diplodoc/client": "0.0.6",
"@diplodoc/client": "0.0.7",
"@diplodoc/markdown-translation": "^0.12.0",
"@diplodoc/mermaid-extension": "0.0.5",
"@diplodoc/openapi-extension": "^1.2.7",
Expand Down
12 changes: 11 additions & 1 deletion scripts/build.cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
const esbuild = require('esbuild');
const shell = require('shelljs');

const client = require('./client');
const {version, dependencies} = require('../package.json');
const {target} = require('../tsconfig.json').compilerOptions;
const {compilerOptions: {target}} = require('../tsconfig.json');

const diplodocExtensions = Object.keys(dependencies).filter((name) => name.startsWith('@diplodoc'));

for (const [type, path] of Object.entries(client.src)) {
const dst = client.dst[type];

shell.cp('-f', path, dst);
}

const commonConfig = {
tsconfig: './tsconfig.json',
packages: 'external',
Expand Down
21 changes: 21 additions & 0 deletions scripts/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');

const CLIENT_PATH = path.dirname(require.resolve('@diplodoc/client'));
const BUILD_PATH = 'build';
const BUNDLE_JS_FILENAME = 'app.client.js';
const BUNDLE_CSS_FILENAME = 'app.client.css';

const src = (target) => path.resolve(CLIENT_PATH, target);
const dst = (target) => path.resolve(BUILD_PATH, target);


module.exports = {
dst: {
js: dst(BUNDLE_JS_FILENAME),
css: dst(BUNDLE_CSS_FILENAME),
},
src: {
js: src(BUNDLE_JS_FILENAME),
css: src(BUNDLE_CSS_FILENAME),
},
};
12 changes: 5 additions & 7 deletions src/steps/processAssets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import walkSync from 'walk-sync';
import {resolve} from 'path';
import shell from 'shelljs';

import {BUNDLE_JS_FILENAME, BUNDLE_CSS_FILENAME, BUILD_FOLDER_PATH} from '../constants';
import client from '../../scripts/client';
import {ArgvService} from '../services';
import {copyFiles} from '../utils';

Expand All @@ -28,11 +27,10 @@ export function processAssets(outputBundlePath: string) {

copyFiles(inputFolderPath, outputFolderPath, assetFilePath);

const src = (file: string) => resolve(BUILD_FOLDER_PATH, file);
const dst = (file: string) => resolve(outputBundlePath, file);

/* Copy js bundle to user' output folder */
shell.mkdir('-p', outputBundlePath);
shell.cp(src(BUNDLE_JS_FILENAME), dst(BUNDLE_JS_FILENAME));
shell.cp(src(BUNDLE_CSS_FILENAME), dst(BUNDLE_CSS_FILENAME));

for (const path of Object.values(client.dst)) {
shell.cp(path, outputBundlePath);
}
}
10 changes: 3 additions & 7 deletions src/steps/processPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function processPages(outputBundlePath: string): Promise<void> {
}));

if (singlePage) {
await saveSinglePages(outputBundlePath);
await saveSinglePages();
}
}

Expand Down Expand Up @@ -97,10 +97,9 @@ function getPathData(
return pathData;
}

async function saveSinglePages(outputBundlePath: string) {
async function saveSinglePages() {
const {
input: inputFolderPath,
output: outputFolderPath,
lang,
resources,
} = ArgvService.getConfig();
Expand Down Expand Up @@ -133,13 +132,10 @@ async function saveSinglePages(outputBundlePath: string) {
lang: lang || Lang.RU,
};

const outputTocDir = resolve(outputFolderPath, relative(inputFolderPath, tocDir));
const relativeOutputBundlePath = relative(outputTocDir, outputBundlePath);

// Save the full single page for viewing locally
const singlePageFn = join(tocDir, SINGLE_PAGE_FILENAME);
const singlePageDataFn = join(tocDir, SINGLE_PAGE_DATA_FILENAME);
const singlePageContent = generateStaticMarkup(pageData, relativeOutputBundlePath);
const singlePageContent = generateStaticMarkup(pageData);

writeFileSync(singlePageFn, singlePageContent);
writeFileSync(singlePageDataFn, JSON.stringify(pageData));
Expand Down
9 changes: 5 additions & 4 deletions src/utils/markup.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {platform} from 'process';

import {BUNDLE_JS_FILENAME, BUNDLE_CSS_FILENAME, CUSTOM_STYLE, Platforms, ResourceType} from '../constants';
import {CUSTOM_STYLE, Platforms, ResourceType} from '../constants';
import {SinglePageResult, Resources} from '../models';
import {ArgvService, PluginService} from '../services';
import {preprocessPageHtmlForSinglePage} from './singlePage';
import {render, DocInnerProps, DocPageData} from '@diplodoc/client';
import client from '../../scripts/client';

export interface TitleMeta {
title?: string;
}
export type Meta = TitleMeta & Resources;

export function generateStaticMarkup(props: DocInnerProps<DocPageData>, pathToBundle: string): string {
export function generateStaticMarkup(props: DocInnerProps<DocPageData>): string {
const {title: metaTitle, style, script} = props.data.meta as Meta || {};
const {title: tocTitle} = props.data.toc;
const {title: pageTitle} = props.data;
Expand Down Expand Up @@ -40,7 +41,7 @@ export function generateStaticMarkup(props: DocInnerProps<DocPageData>, pathToBu
height: 100vh;
}
</style>
<link type="text/css" rel="stylesheet" href="${pathToBundle}/${BUNDLE_CSS_FILENAME}" />
<link type="text/css" rel="stylesheet" href="${client.dst.css}" />
${PluginService.getHeadContent()}
${resources}
</head>
Expand All @@ -50,7 +51,7 @@ export function generateStaticMarkup(props: DocInnerProps<DocPageData>, pathToBu
window.STATIC_CONTENT = ${staticContent}
window.__DATA__ = ${JSON.stringify(props)};
</script>
<script type="application/javascript" src="${pathToBundle}/${BUNDLE_JS_FILENAME}"></script>
<script type="application/javascript" src="${client.dst.js}"></script>
</body>
</html>
`;
Expand Down

0 comments on commit c1fb398

Please sign in to comment.