Skip to content

Commit

Permalink
fix: restore bundle path
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Jun 29, 2023
1 parent 75d6c58 commit ffd29ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 6 additions & 4 deletions scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ const path = require('path');

const CLIENT_PATH = path.dirname(require.resolve('@diplodoc/client'));
const BUILD_PATH = 'build';
const BUNDLE_PATH = '_bundle';
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);
const bundle = (target) => path.join('../', BUNDLE_PATH, target);


module.exports = {
Expand All @@ -21,7 +19,11 @@ module.exports = {
css: src(BUNDLE_CSS_FILENAME),
},
bundle: {
js: bundle(BUNDLE_JS_FILENAME),
css: bundle(BUNDLE_CSS_FILENAME),
js(bundlePath) {
return path.join(bundlePath, BUNDLE_JS_FILENAME);
},
css(bundlePath) {
return path.join(bundlePath, BUNDLE_CSS_FILENAME);
},
},
};
10 changes: 7 additions & 3 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();
await saveSinglePages(outputBundlePath);
}
}

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

async function saveSinglePages() {
async function saveSinglePages(outputBundlePath: string) {
const {
input: inputFolderPath,
output: outputFolderPath,
lang,
resources,
} = ArgvService.getConfig();
Expand Down Expand Up @@ -132,10 +133,13 @@ async function saveSinglePages() {
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);
const singlePageContent = generateStaticMarkup(pageData, relativeOutputBundlePath);

writeFileSync(singlePageFn, singlePageContent);
writeFileSync(singlePageDataFn, JSON.stringify(pageData));
Expand Down
6 changes: 3 additions & 3 deletions src/utils/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface TitleMeta {
}
export type Meta = TitleMeta & Resources;

export function generateStaticMarkup(props: DocInnerProps<DocPageData>): string {
export function generateStaticMarkup(props: DocInnerProps<DocPageData>, pathToBundle: string): 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 @@ -41,7 +41,7 @@ export function generateStaticMarkup(props: DocInnerProps<DocPageData>): string
height: 100vh;
}
</style>
<link type="text/css" rel="stylesheet" href="${client.bundle.css}" />
<link type="text/css" rel="stylesheet" href="${client.bundle.css(pathToBundle)}" />
${PluginService.getHeadContent()}
${resources}
</head>
Expand All @@ -51,7 +51,7 @@ export function generateStaticMarkup(props: DocInnerProps<DocPageData>): string
window.STATIC_CONTENT = ${staticContent}
window.__DATA__ = ${JSON.stringify(props)};
</script>
<script type="application/javascript" src="${client.bundle.js}"></script>
<script type="application/javascript" src="${client.bundle.js(pathToBundle)}"></script>
</body>
</html>
`;
Expand Down

0 comments on commit ffd29ba

Please sign in to comment.