Skip to content

Commit

Permalink
Chore: Clean up server implementation and update test docs (#2316)
Browse files Browse the repository at this point in the history
- Replace live-server with existing Browsersync dependency as web server
- Remove duplicate `index.html` file
- Add `build:html` script to generate `/docs/preview.html`
  • Loading branch information
jhildenbiddle committed Dec 11, 2023
1 parent cf61192 commit 1c5a701
Show file tree
Hide file tree
Showing 23 changed files with 898 additions and 2,918 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,9 +3,9 @@
*.log
/_playwright-report
/_playwright-results
/docs/preview.html
/lib
/node_modules
/themes

# exceptions
!.gitkeep
42 changes: 42 additions & 0 deletions build/html.js
@@ -0,0 +1,42 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as url from 'node:url';
import prettier from 'prettier';
import stripIndent from 'common-tags/lib/stripIndent/index.js';

const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const prettierConfig = prettier.resolveConfig.sync(__dirname);

// Preview
// =============================================================================
function generatePreview() {
const comment = stripIndent`
<!--
This file is generated by the build/html.js script.
Do not edit this file directly.
-->
`;
const srcFile = 'index.html';
const srcPath = path.resolve(__dirname, '..', 'docs');
const srcHTML = fs.readFileSync(path.resolve(srcPath, srcFile), 'utf8');
const outFile = 'preview.html';
const outPath = path.resolve(__dirname, '..', 'docs');
const outHTML = srcHTML
// Append comment
.replace(/(<!DOCTYPE html>)/, `${comment}\n$1`)
// Modify title
.replace(/(<\/title>)/, ' (Preview)$1')
// Replace CDN URLs with local paths
.replace(/\/\/cdn.jsdelivr.net\/npm\/docsify@4\//g, '/');
const formattedHTML = prettier.format(outHTML, {
...prettierConfig,
filepath: outFile,
});

console.log(`\nBuilding ${outFile} in ${outPath}`);

fs.writeFileSync(path.resolve(outPath, outFile), formattedHTML);
}

generatePreview();
34 changes: 15 additions & 19 deletions docs/index.html
Expand Up @@ -56,19 +56,22 @@
width: auto !important;
}
</style>
<script>
(function () {
const lang = location.hash.match(/#\/(de-de|es|ru-ru|zh-cn)\//);

// Set html "lang" attribute based on URL
if (lang) {
document.documentElement.setAttribute('lang', lang[1]);
}
})();
</script>
</head>

<body>
<div id="app">Loading ...</div>
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1"></script>
<script>
// Set html "lang" attribute based on URL
const lang = location.hash.match(/#\/(de-de|es|ru-ru|zh-cn)\//);

if (lang) {
document.documentElement.setAttribute('lang', lang[1]);
}

// Docsify configuration
window.$docsify = {
alias: {
Expand Down Expand Up @@ -184,7 +187,9 @@
},
},
plugins: [
DocsifyCarbon.create('CEBI6KQE', 'docsifyjsorg'),
function () {
DocsifyCarbon.create('CEBI6KQE', 'docsifyjsorg');
},
function (hook, vm) {
hook.beforeEach(html => {
if (/githubusercontent\.com/.test(vm.route.file)) {
Expand Down Expand Up @@ -214,21 +219,12 @@
</script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-markdown.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-nginx.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
<script>
// Public site only
if (/docsify/.test(location.host)) {
document.write(
'<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/ga.min.js"><\/script>'
);
document.write(
'<script src="//cdn.jsdelivr.net/npm/docsify@4/lib/plugins/matomo.min.js"><\/script>'
);
}
</script>
<script src="//cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
<!-- <script src="//cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script> -->
</body>
Expand Down
190 changes: 0 additions & 190 deletions index.html

This file was deleted.

6 changes: 5 additions & 1 deletion jest.config.js
@@ -1,5 +1,7 @@
import { TEST_HOST } from './test/config/server.js';
import serverConfig from './server.config.js';

const { hostname, port } = serverConfig.test;
const TEST_HOST = `http://${hostname}:${port}`;
const sharedConfig = {
errorOnDeprecated: true,
globalSetup: './test/config/jest.setup.js',
Expand All @@ -11,6 +13,8 @@ const sharedConfig = {
testURL: `${TEST_HOST}/_blank.html`,
};

process.env.TEST_HOST = TEST_HOST;

export default {
transform: {},
projects: [
Expand Down

1 comment on commit 1c5a701

@vercel
Copy link

@vercel vercel bot commented on 1c5a701 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.