Skip to content

Commit

Permalink
fix: Move search scripts to assets
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Oct 23, 2024
1 parent f9b923f commit 4bd36c0
Show file tree
Hide file tree
Showing 9 changed files with 2,376 additions and 1,224 deletions.
3,416 changes: 2,201 additions & 1,215 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
},
"dependencies": {
"@diplodoc/client": "^3.1.3",
"@diplodoc/search-extension": "^1.1.4",
"@diplodoc/translation": "^1.4.3",
"katex": "^0.16.9",
"shelljs": "0.8.5",
Expand All @@ -68,6 +67,7 @@
"@diplodoc/mermaid-extension": "^1.3.1",
"@diplodoc/openapi-extension": "^2.4.1",
"@diplodoc/prettier-config": "^2.0.0",
"@diplodoc/search-extension": "^1.1.4",
"@diplodoc/transform": "^4.32.3",
"@diplodoc/tsconfig": "^1.0.2",
"@octokit/core": "4.2.4",
Expand Down
13 changes: 12 additions & 1 deletion scripts/build.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ const esbuild = require('esbuild');
const tsPaths = require('./ts-paths');
const shell = require('shelljs');

const SEARCH_API = require.resolve('@diplodoc/search-extension/worker');
const SEARCH_LANGS = require.resolve('@diplodoc/search-extension/worker/langs');
const CLIENT_PATH = dirname(require.resolve('@diplodoc/client/manifest'));
const ASSETS_PATH = resolve(__dirname, '..', 'assets');

const SEARCH_API_OUTPUT = join(ASSETS_PATH, 'search', 'index.js');
const SEARCH_LANGS_OUTPUT = join(ASSETS_PATH, 'search', 'langs');

const clientManifest = require('@diplodoc/client/manifest');
const assets = [
...clientManifest.app.js,
Expand Down Expand Up @@ -33,6 +38,8 @@ const commonConfig = {
],
define: {
VERSION: JSON.stringify(version),
SEARCH_API: JSON.stringify(SEARCH_API_OUTPUT),
SEARCH_LANGS: JSON.stringify(SEARCH_LANGS_OUTPUT),
},
};

Expand Down Expand Up @@ -61,8 +68,12 @@ Promise.all(builds.map(([entries, outfile]) => {

return esbuild.build(currentConfig);
})).then(() => {
shell.mkdir('-p', ASSETS_PATH);
for (const file of assets) {
shell.mkdir('-p', ASSETS_PATH);
shell.cp('-f', join(CLIENT_PATH, file), join(ASSETS_PATH, file));
}

shell.mkdir('-p', SEARCH_LANGS_OUTPUT);
shell.cp('-f', SEARCH_API, SEARCH_API_OUTPUT);
shell.cp('-f', join(dirname(SEARCH_LANGS), '*'), SEARCH_LANGS_OUTPUT);
});
2 changes: 2 additions & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
declare const VERSION: string;
declare const SEARCH_API: string;
declare const SEARCH_LANGS: string;

type Hash<T = any> = Record<string, T>;
9 changes: 3 additions & 6 deletions src/services/search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {DocInnerProps, DocPageData} from '@diplodoc/client';
import type {Lang} from '../constants';

import {dirname, join} from 'node:path';
import {join} from 'node:path';
import {mkdirSync, writeFileSync} from 'node:fs';

import {Indexer} from '@diplodoc/search-extension/indexer';
Expand All @@ -11,9 +11,6 @@ import {ArgvService} from '.';
import {generateStaticSearch} from '../pages';
import {copyFileSync} from 'fs';

const apiPath = require.resolve('@diplodoc/search-extension/worker');
const langsPath = require.resolve('@diplodoc/search-extension/worker/langs');

let indexer: Indexer;

function init() {
Expand Down Expand Up @@ -59,7 +56,7 @@ async function release() {

if (isLocalSearchEnabled()) {
mkdirSync(bundleDir(), {recursive: true});
copyFileSync(apiPath, apiLink());
copyFileSync(SEARCH_API, apiLink());
}

for (const lang of indexer.langs) {
Expand All @@ -72,7 +69,7 @@ async function release() {
writeFileSync(pageLink(lang), generateStaticSearch(lang as Lang), 'utf8');

if (isLocalSearchEnabled() && langs.includes(lang)) {
copyFileSync(join(dirname(langsPath), lang + '.js'), languageLink(lang));
copyFileSync(join(SEARCH_LANGS, lang + '.js'), languageLink(lang));
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ exports[`Allow load custom resources md2html single page with custom resources 1
"_bundle/search-css-2",
"_bundle/search-js-0",
"_bundle/search-js-1",
"_bundle/search/index.js",
"_bundle/search/langs/ar.js",
"_bundle/search/langs/da.js",
"_bundle/search/langs/de.js",
"_bundle/search/langs/du.js",
"_bundle/search/langs/el.js",
"_bundle/search/langs/es.js",
"_bundle/search/langs/fi.js",
"_bundle/search/langs/fr.js",
"_bundle/search/langs/he.js",
"_bundle/search/langs/hi.js",
"_bundle/search/langs/hu.js",
"_bundle/search/langs/hy.js",
"_bundle/search/langs/index.js",
"_bundle/search/langs/it.js",
"_bundle/search/langs/ja.js",
"_bundle/search/langs/jp.js",
"_bundle/search/langs/kn.js",
"_bundle/search/langs/ko.js",
"_bundle/search/langs/nl.js",
"_bundle/search/langs/no.js",
"_bundle/search/langs/pt.js",
"_bundle/search/langs/ro.js",
"_bundle/search/langs/ru.js",
"_bundle/search/langs/sa.js",
"_bundle/search/langs/sv.js",
"_bundle/search/langs/ta.js",
"_bundle/search/langs/te.js",
"_bundle/search/langs/th.js",
"_bundle/search/langs/tr.js",
"_bundle/search/langs/vi.js",
"_bundle/search-css-0",
"_bundle/search-js-2",
"_bundle/search-css-1",
Expand Down Expand Up @@ -283,6 +314,37 @@ exports[`Allow load custom resources md2html with custom resources 1`] = `
"_bundle/search-css-2",
"_bundle/search-js-0",
"_bundle/search-js-1",
"_bundle/search/index.js",
"_bundle/search/langs/ar.js",
"_bundle/search/langs/da.js",
"_bundle/search/langs/de.js",
"_bundle/search/langs/du.js",
"_bundle/search/langs/el.js",
"_bundle/search/langs/es.js",
"_bundle/search/langs/fi.js",
"_bundle/search/langs/fr.js",
"_bundle/search/langs/he.js",
"_bundle/search/langs/hi.js",
"_bundle/search/langs/hu.js",
"_bundle/search/langs/hy.js",
"_bundle/search/langs/index.js",
"_bundle/search/langs/it.js",
"_bundle/search/langs/ja.js",
"_bundle/search/langs/jp.js",
"_bundle/search/langs/kn.js",
"_bundle/search/langs/ko.js",
"_bundle/search/langs/nl.js",
"_bundle/search/langs/no.js",
"_bundle/search/langs/pt.js",
"_bundle/search/langs/ro.js",
"_bundle/search/langs/ru.js",
"_bundle/search/langs/sa.js",
"_bundle/search/langs/sv.js",
"_bundle/search/langs/ta.js",
"_bundle/search/langs/te.js",
"_bundle/search/langs/th.js",
"_bundle/search/langs/tr.js",
"_bundle/search/langs/vi.js",
"_bundle/search-css-0",
"_bundle/search-js-2",
"_bundle/search-css-1",
Expand Down
31 changes: 31 additions & 0 deletions tests/e2e/__snapshots__/metadata.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@ exports[`Allow load custom resources md2html with metadata 1`] = `
"_bundle/search-css-2",
"_bundle/search-js-0",
"_bundle/search-js-1",
"_bundle/search/index.js",
"_bundle/search/langs/ar.js",
"_bundle/search/langs/da.js",
"_bundle/search/langs/de.js",
"_bundle/search/langs/du.js",
"_bundle/search/langs/el.js",
"_bundle/search/langs/es.js",
"_bundle/search/langs/fi.js",
"_bundle/search/langs/fr.js",
"_bundle/search/langs/he.js",
"_bundle/search/langs/hi.js",
"_bundle/search/langs/hu.js",
"_bundle/search/langs/hy.js",
"_bundle/search/langs/index.js",
"_bundle/search/langs/it.js",
"_bundle/search/langs/ja.js",
"_bundle/search/langs/jp.js",
"_bundle/search/langs/kn.js",
"_bundle/search/langs/ko.js",
"_bundle/search/langs/nl.js",
"_bundle/search/langs/no.js",
"_bundle/search/langs/pt.js",
"_bundle/search/langs/ro.js",
"_bundle/search/langs/ru.js",
"_bundle/search/langs/sa.js",
"_bundle/search/langs/sv.js",
"_bundle/search/langs/ta.js",
"_bundle/search/langs/te.js",
"_bundle/search/langs/th.js",
"_bundle/search/langs/tr.js",
"_bundle/search/langs/vi.js",
"_bundle/search-css-0",
"_bundle/search-js-2",
"_bundle/search-css-1",
Expand Down
62 changes: 62 additions & 0 deletions tests/e2e/__snapshots__/rtl.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@ exports[`Generate html document with correct lang and dir attributes. Load corre
"_bundle/search-css-2",
"_bundle/search-js-0",
"_bundle/search-js-1",
"_bundle/search/index.js",
"_bundle/search/langs/ar.js",
"_bundle/search/langs/da.js",
"_bundle/search/langs/de.js",
"_bundle/search/langs/du.js",
"_bundle/search/langs/el.js",
"_bundle/search/langs/es.js",
"_bundle/search/langs/fi.js",
"_bundle/search/langs/fr.js",
"_bundle/search/langs/he.js",
"_bundle/search/langs/hi.js",
"_bundle/search/langs/hu.js",
"_bundle/search/langs/hy.js",
"_bundle/search/langs/index.js",
"_bundle/search/langs/it.js",
"_bundle/search/langs/ja.js",
"_bundle/search/langs/jp.js",
"_bundle/search/langs/kn.js",
"_bundle/search/langs/ko.js",
"_bundle/search/langs/nl.js",
"_bundle/search/langs/no.js",
"_bundle/search/langs/pt.js",
"_bundle/search/langs/ro.js",
"_bundle/search/langs/ru.js",
"_bundle/search/langs/sa.js",
"_bundle/search/langs/sv.js",
"_bundle/search/langs/ta.js",
"_bundle/search/langs/te.js",
"_bundle/search/langs/th.js",
"_bundle/search/langs/tr.js",
"_bundle/search/langs/vi.js",
"_bundle/search-css-0",
"_bundle/search-js-2",
"_bundle/search-css-1",
Expand Down Expand Up @@ -128,6 +159,37 @@ exports[`Generate html document with correct lang and dir attributes. Load corre
"_bundle/search-css-2",
"_bundle/search-js-0",
"_bundle/search-js-1",
"_bundle/search/index.js",
"_bundle/search/langs/ar.js",
"_bundle/search/langs/da.js",
"_bundle/search/langs/de.js",
"_bundle/search/langs/du.js",
"_bundle/search/langs/el.js",
"_bundle/search/langs/es.js",
"_bundle/search/langs/fi.js",
"_bundle/search/langs/fr.js",
"_bundle/search/langs/he.js",
"_bundle/search/langs/hi.js",
"_bundle/search/langs/hu.js",
"_bundle/search/langs/hy.js",
"_bundle/search/langs/index.js",
"_bundle/search/langs/it.js",
"_bundle/search/langs/ja.js",
"_bundle/search/langs/jp.js",
"_bundle/search/langs/kn.js",
"_bundle/search/langs/ko.js",
"_bundle/search/langs/nl.js",
"_bundle/search/langs/no.js",
"_bundle/search/langs/pt.js",
"_bundle/search/langs/ro.js",
"_bundle/search/langs/ru.js",
"_bundle/search/langs/sa.js",
"_bundle/search/langs/sv.js",
"_bundle/search/langs/ta.js",
"_bundle/search/langs/te.js",
"_bundle/search/langs/th.js",
"_bundle/search/langs/tr.js",
"_bundle/search/langs/vi.js",
"_bundle/search-css-0",
"_bundle/search-js-2",
"_bundle/search-css-1",
Expand Down
3 changes: 2 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"~/*": ["../src/*"]
},
"types": ["node", "jest"]
}
},
"include": ["../src/globals.d.ts"]
}

0 comments on commit 4bd36c0

Please sign in to comment.