themekit-js 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/bin/themekit.js +2 -0
- package/client.d.ts +5 -0
- package/dist/client/app/components/ClientOnly.js +10 -0
- package/dist/client/app/components/Content.js +23 -0
- package/dist/client/app/composables/codeGroups.js +40 -0
- package/dist/client/app/composables/copyCode.js +73 -0
- package/dist/client/app/composables/head.js +81 -0
- package/dist/client/app/composables/preFetch.js +99 -0
- package/dist/client/app/data.js +59 -0
- package/dist/client/app/devtools.js +29 -0
- package/dist/client/app/index.js +140 -0
- package/dist/client/app/router.js +233 -0
- package/dist/client/app/ssr.js +10 -0
- package/dist/client/app/theme.js +1 -0
- package/dist/client/app/utils.js +119 -0
- package/dist/client/index.d.ts +1446 -0
- package/dist/client/index.js +9 -0
- package/dist/client/shared.js +139 -0
- package/dist/client/theme-default/Layout.vue +94 -0
- package/dist/client/theme-default/NotFound.vue +109 -0
- package/dist/client/theme-default/components/VPAlgoliaSearchBox.vue +99 -0
- package/dist/client/theme-default/components/VPBackdrop.vue +41 -0
- package/dist/client/theme-default/components/VPBadge.vue +86 -0
- package/dist/client/theme-default/components/VPButton.vue +123 -0
- package/dist/client/theme-default/components/VPCarbonAds.vue +109 -0
- package/dist/client/theme-default/components/VPContent.vue +98 -0
- package/dist/client/theme-default/components/VPDoc.vue +193 -0
- package/dist/client/theme-default/components/VPDocAside.vue +46 -0
- package/dist/client/theme-default/components/VPDocAsideCarbonAds.vue +18 -0
- package/dist/client/theme-default/components/VPDocAsideOutline.vue +87 -0
- package/dist/client/theme-default/components/VPDocAsideSponsors.vue +17 -0
- package/dist/client/theme-default/components/VPDocFooter.vue +145 -0
- package/dist/client/theme-default/components/VPDocFooterLastUpdated.vue +50 -0
- package/dist/client/theme-default/components/VPDocOutlineItem.vue +59 -0
- package/dist/client/theme-default/components/VPFeature.vue +123 -0
- package/dist/client/theme-default/components/VPFeatures.vue +121 -0
- package/dist/client/theme-default/components/VPFlyout.vue +136 -0
- package/dist/client/theme-default/components/VPFooter.vue +60 -0
- package/dist/client/theme-default/components/VPHero.vue +336 -0
- package/dist/client/theme-default/components/VPHome.vue +43 -0
- package/dist/client/theme-default/components/VPHomeContent.vue +52 -0
- package/dist/client/theme-default/components/VPHomeFeatures.vue +14 -0
- package/dist/client/theme-default/components/VPHomeHero.vue +24 -0
- package/dist/client/theme-default/components/VPHomeSponsors.vue +116 -0
- package/dist/client/theme-default/components/VPImage.vue +46 -0
- package/dist/client/theme-default/components/VPLink.vue +33 -0
- package/dist/client/theme-default/components/VPLocalNav.vue +171 -0
- package/dist/client/theme-default/components/VPLocalNavOutlineDropdown.vue +190 -0
- package/dist/client/theme-default/components/VPLocalSearchBox.vue +856 -0
- package/dist/client/theme-default/components/VPMenu.vue +72 -0
- package/dist/client/theme-default/components/VPMenuGroup.vue +47 -0
- package/dist/client/theme-default/components/VPMenuLink.vue +54 -0
- package/dist/client/theme-default/components/VPNav.vue +57 -0
- package/dist/client/theme-default/components/VPNavBar.vue +267 -0
- package/dist/client/theme-default/components/VPNavBarAppearance.vue +25 -0
- package/dist/client/theme-default/components/VPNavBarExtra.vue +94 -0
- package/dist/client/theme-default/components/VPNavBarHamburger.vue +79 -0
- package/dist/client/theme-default/components/VPNavBarMenu.vue +29 -0
- package/dist/client/theme-default/components/VPNavBarMenuGroup.vue +42 -0
- package/dist/client/theme-default/components/VPNavBarMenuLink.vue +53 -0
- package/dist/client/theme-default/components/VPNavBarSearch.vue +194 -0
- package/dist/client/theme-default/components/VPNavBarSearchButton.vue +208 -0
- package/dist/client/theme-default/components/VPNavBarSocialLinks.vue +27 -0
- package/dist/client/theme-default/components/VPNavBarTitle.vue +76 -0
- package/dist/client/theme-default/components/VPNavBarTranslations.vue +47 -0
- package/dist/client/theme-default/components/VPNavScreen.vue +99 -0
- package/dist/client/theme-default/components/VPNavScreenAppearance.vue +33 -0
- package/dist/client/theme-default/components/VPNavScreenMenu.vue +23 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroup.vue +111 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroupLink.vue +39 -0
- package/dist/client/theme-default/components/VPNavScreenMenuGroupSection.vue +34 -0
- package/dist/client/theme-default/components/VPNavScreenMenuLink.vue +39 -0
- package/dist/client/theme-default/components/VPNavScreenSocialLinks.vue +14 -0
- package/dist/client/theme-default/components/VPNavScreenTranslations.vue +73 -0
- package/dist/client/theme-default/components/VPPage.vue +7 -0
- package/dist/client/theme-default/components/VPSidebar.vue +137 -0
- package/dist/client/theme-default/components/VPSidebarItem.vue +250 -0
- package/dist/client/theme-default/components/VPSkipLink.vue +68 -0
- package/dist/client/theme-default/components/VPSocialLink.vue +50 -0
- package/dist/client/theme-default/components/VPSocialLinks.vue +27 -0
- package/dist/client/theme-default/components/VPSponsors.vue +48 -0
- package/dist/client/theme-default/components/VPSponsorsGrid.vue +48 -0
- package/dist/client/theme-default/components/VPSwitch.vue +63 -0
- package/dist/client/theme-default/components/VPSwitchAppearance.vue +52 -0
- package/dist/client/theme-default/components/VPTeamMembers.vue +66 -0
- package/dist/client/theme-default/components/VPTeamMembersItem.vue +225 -0
- package/dist/client/theme-default/components/VPTeamPage.vue +58 -0
- package/dist/client/theme-default/components/VPTeamPageSection.vue +77 -0
- package/dist/client/theme-default/components/VPTeamPageTitle.vue +63 -0
- package/dist/client/theme-default/components/icons/VPIconAlignJustify.vue +8 -0
- package/dist/client/theme-default/components/icons/VPIconAlignLeft.vue +8 -0
- package/dist/client/theme-default/components/icons/VPIconAlignRight.vue +8 -0
- package/dist/client/theme-default/components/icons/VPIconArrowLeft.vue +7 -0
- package/dist/client/theme-default/components/icons/VPIconArrowRight.vue +7 -0
- package/dist/client/theme-default/components/icons/VPIconChevronDown.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronLeft.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronRight.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconChevronUp.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconEdit.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconHeart.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconLanguages.vue +9 -0
- package/dist/client/theme-default/components/icons/VPIconMinus.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconMinusSquare.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconMoon.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconMoreHorizontal.vue +7 -0
- package/dist/client/theme-default/components/icons/VPIconPlus.vue +5 -0
- package/dist/client/theme-default/components/icons/VPIconPlusSquare.vue +6 -0
- package/dist/client/theme-default/components/icons/VPIconSun.vue +13 -0
- package/dist/client/theme-default/composables/aside.js +17 -0
- package/dist/client/theme-default/composables/data.js +2 -0
- package/dist/client/theme-default/composables/edit-link.js +16 -0
- package/dist/client/theme-default/composables/flyout.js +41 -0
- package/dist/client/theme-default/composables/langs.js +26 -0
- package/dist/client/theme-default/composables/local-nav.js +18 -0
- package/dist/client/theme-default/composables/nav.js +30 -0
- package/dist/client/theme-default/composables/outline.js +178 -0
- package/dist/client/theme-default/composables/prev-next.js +57 -0
- package/dist/client/theme-default/composables/sidebar.js +136 -0
- package/dist/client/theme-default/composables/sponsor-grid.js +94 -0
- package/dist/client/theme-default/fonts/inter-italic-cyrillic-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-cyrillic.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-greek-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-greek.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-latin-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-latin.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-italic-vietnamese.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-cyrillic-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-cyrillic.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-greek-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-greek.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-latin-ext.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-latin.woff2 +0 -0
- package/dist/client/theme-default/fonts/inter-roman-vietnamese.woff2 +0 -0
- package/dist/client/theme-default/index.js +3 -0
- package/dist/client/theme-default/styles/base.css +252 -0
- package/dist/client/theme-default/styles/components/custom-block.css +208 -0
- package/dist/client/theme-default/styles/components/vp-code-group.css +85 -0
- package/dist/client/theme-default/styles/components/vp-code.css +7 -0
- package/dist/client/theme-default/styles/components/vp-doc.css +570 -0
- package/dist/client/theme-default/styles/components/vp-sponsor.css +155 -0
- package/dist/client/theme-default/styles/fonts.css +157 -0
- package/dist/client/theme-default/styles/icons.css +123 -0
- package/dist/client/theme-default/styles/utils.css +9 -0
- package/dist/client/theme-default/styles/vars.css +563 -0
- package/dist/client/theme-default/support/lru.js +33 -0
- package/dist/client/theme-default/support/sidebar.js +89 -0
- package/dist/client/theme-default/support/translation.js +49 -0
- package/dist/client/theme-default/support/utils.js +33 -0
- package/dist/client/theme-default/without-fonts.js +32 -0
- package/dist/node/cli.js +444 -0
- package/dist/node/index.d.ts +4588 -0
- package/dist/node/index.js +198 -0
- package/dist/node/serve-BjvG349_.js +50301 -0
- package/lib/vue-demi.mjs +34 -0
- package/package.json +223 -0
- package/template/.vitepress/config.js +28 -0
- package/template/.vitepress/theme/Layout.vue +21 -0
- package/template/.vitepress/theme/index.js +29 -0
- package/template/.vitepress/theme/style.css +143 -0
- package/template/api-examples.md +49 -0
- package/template/index.md +28 -0
- package/template/markdown-examples.md +85 -0
- package/theme-without-fonts.d.ts +2 -0
- package/theme.d.ts +30 -0
- package/types/default-theme.d.ts +533 -0
- package/types/docsearch.d.ts +144 -0
- package/types/index.d.ts +3 -0
- package/types/local-search.d.ts +33 -0
- package/types/shared.d.ts +199 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useData } from '../composables/data';
|
|
2
|
+
/**
|
|
3
|
+
* @param themeObject Can be an object with `translations` and `locales` properties
|
|
4
|
+
*/
|
|
5
|
+
export function createSearchTranslate(defaultTranslations) {
|
|
6
|
+
const { localeIndex, theme } = useData();
|
|
7
|
+
function translate(key) {
|
|
8
|
+
const keyPath = key.split('.');
|
|
9
|
+
const themeObject = theme.value.search?.options;
|
|
10
|
+
const isObject = themeObject && typeof themeObject === 'object';
|
|
11
|
+
const locales = (isObject && themeObject.locales?.[localeIndex.value]?.translations) ||
|
|
12
|
+
null;
|
|
13
|
+
const translations = (isObject && themeObject.translations) || null;
|
|
14
|
+
let localeResult = locales;
|
|
15
|
+
let translationResult = translations;
|
|
16
|
+
let defaultResult = defaultTranslations;
|
|
17
|
+
const lastKey = keyPath.pop();
|
|
18
|
+
for (const k of keyPath) {
|
|
19
|
+
let fallbackResult = null;
|
|
20
|
+
const foundInFallback = defaultResult?.[k];
|
|
21
|
+
if (foundInFallback) {
|
|
22
|
+
fallbackResult = defaultResult = foundInFallback;
|
|
23
|
+
}
|
|
24
|
+
const foundInTranslation = translationResult?.[k];
|
|
25
|
+
if (foundInTranslation) {
|
|
26
|
+
fallbackResult = translationResult = foundInTranslation;
|
|
27
|
+
}
|
|
28
|
+
const foundInLocale = localeResult?.[k];
|
|
29
|
+
if (foundInLocale) {
|
|
30
|
+
fallbackResult = localeResult = foundInLocale;
|
|
31
|
+
}
|
|
32
|
+
// Put fallback into unresolved results
|
|
33
|
+
if (!foundInFallback) {
|
|
34
|
+
defaultResult = fallbackResult;
|
|
35
|
+
}
|
|
36
|
+
if (!foundInTranslation) {
|
|
37
|
+
translationResult = fallbackResult;
|
|
38
|
+
}
|
|
39
|
+
if (!foundInLocale) {
|
|
40
|
+
localeResult = fallbackResult;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return (localeResult?.[lastKey] ??
|
|
44
|
+
translationResult?.[lastKey] ??
|
|
45
|
+
defaultResult?.[lastKey] ??
|
|
46
|
+
'');
|
|
47
|
+
}
|
|
48
|
+
return translate;
|
|
49
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { withBase } from 'vitepress';
|
|
2
|
+
import { useData } from '../composables/data';
|
|
3
|
+
import { isExternal, treatAsHtml } from '../../shared';
|
|
4
|
+
export function throttleAndDebounce(fn, delay) {
|
|
5
|
+
let timeoutId;
|
|
6
|
+
let called = false;
|
|
7
|
+
return () => {
|
|
8
|
+
if (timeoutId)
|
|
9
|
+
clearTimeout(timeoutId);
|
|
10
|
+
if (!called) {
|
|
11
|
+
fn();
|
|
12
|
+
(called = true) && setTimeout(() => (called = false), delay);
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
timeoutId = setTimeout(fn, delay);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function ensureStartingSlash(path) {
|
|
19
|
+
return /^\//.test(path) ? path : `/${path}`;
|
|
20
|
+
}
|
|
21
|
+
export function normalizeLink(url) {
|
|
22
|
+
const { pathname, search, hash, protocol } = new URL(url, 'http://a.com');
|
|
23
|
+
if (isExternal(url) ||
|
|
24
|
+
url.startsWith('#') ||
|
|
25
|
+
!protocol.startsWith('http') ||
|
|
26
|
+
!treatAsHtml(pathname))
|
|
27
|
+
return url;
|
|
28
|
+
const { site } = useData();
|
|
29
|
+
const normalizedPath = pathname.endsWith('/') || pathname.endsWith('.html')
|
|
30
|
+
? url
|
|
31
|
+
: url.replace(/(?:(^\.+)\/)?.*$/, `$1${pathname.replace(/(\.md)?$/, site.value.cleanUrls ? '' : '.html')}${search}${hash}`);
|
|
32
|
+
return withBase(normalizedPath);
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import './styles/vars.css';
|
|
2
|
+
import './styles/base.css';
|
|
3
|
+
import './styles/icons.css';
|
|
4
|
+
import './styles/utils.css';
|
|
5
|
+
import './styles/components/custom-block.css';
|
|
6
|
+
import './styles/components/vp-code.css';
|
|
7
|
+
import './styles/components/vp-code-group.css';
|
|
8
|
+
import './styles/components/vp-doc.css';
|
|
9
|
+
import './styles/components/vp-sponsor.css';
|
|
10
|
+
import VPBadge from './components/VPBadge.vue';
|
|
11
|
+
import Layout from './Layout.vue';
|
|
12
|
+
export { default as VPBadge } from './components/VPBadge.vue';
|
|
13
|
+
export { default as VPImage } from './components/VPImage.vue';
|
|
14
|
+
export { default as VPButton } from './components/VPButton.vue';
|
|
15
|
+
export { default as VPHomeHero } from './components/VPHomeHero.vue';
|
|
16
|
+
export { default as VPHomeFeatures } from './components/VPHomeFeatures.vue';
|
|
17
|
+
export { default as VPHomeSponsors } from './components/VPHomeSponsors.vue';
|
|
18
|
+
export { default as VPDocAsideSponsors } from './components/VPDocAsideSponsors.vue';
|
|
19
|
+
export { default as VPSponsors } from './components/VPSponsors.vue';
|
|
20
|
+
export { default as VPTeamPage } from './components/VPTeamPage.vue';
|
|
21
|
+
export { default as VPTeamPageTitle } from './components/VPTeamPageTitle.vue';
|
|
22
|
+
export { default as VPTeamPageSection } from './components/VPTeamPageSection.vue';
|
|
23
|
+
export { default as VPTeamMembers } from './components/VPTeamMembers.vue';
|
|
24
|
+
export { useSidebar } from './composables/sidebar';
|
|
25
|
+
export { useLocalNav } from './composables/local-nav';
|
|
26
|
+
const theme = {
|
|
27
|
+
Layout,
|
|
28
|
+
enhanceApp: ({ app }) => {
|
|
29
|
+
app.component('Badge', VPBadge);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export default theme;
|
package/dist/node/cli.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import { a as getDefaultExportFromCjs, q as c, t as clearCache, n as init, b as build, o as serve, v as version, p as createServer } from './serve-BjvG349_.js';
|
|
2
|
+
import { createLogger } from 'vite';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'shiki';
|
|
5
|
+
import '@shikijs/transformers';
|
|
6
|
+
import 'url';
|
|
7
|
+
import 'crypto';
|
|
8
|
+
import 'module';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import 'node:process';
|
|
11
|
+
import 'node:fs/promises';
|
|
12
|
+
import 'node:url';
|
|
13
|
+
import 'node:fs';
|
|
14
|
+
import 'fs';
|
|
15
|
+
import 'node:events';
|
|
16
|
+
import 'node:stream';
|
|
17
|
+
import 'node:string_decoder';
|
|
18
|
+
import 'util';
|
|
19
|
+
import 'os';
|
|
20
|
+
import 'assert';
|
|
21
|
+
import 'events';
|
|
22
|
+
import 'stream';
|
|
23
|
+
import 'readline';
|
|
24
|
+
import 'child_process';
|
|
25
|
+
import 'string_decoder';
|
|
26
|
+
import 'zlib';
|
|
27
|
+
import 'node:readline';
|
|
28
|
+
import 'node:tty';
|
|
29
|
+
import 'http';
|
|
30
|
+
import 'querystring';
|
|
31
|
+
import 'tty';
|
|
32
|
+
import 'constants';
|
|
33
|
+
import 'node:crypto';
|
|
34
|
+
import 'minisearch';
|
|
35
|
+
|
|
36
|
+
function hasKey(obj, keys) {
|
|
37
|
+
var o = obj;
|
|
38
|
+
keys.slice(0, -1).forEach(function (key) {
|
|
39
|
+
o = o[key] || {};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
var key = keys[keys.length - 1];
|
|
43
|
+
return key in o;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isNumber(x) {
|
|
47
|
+
if (typeof x === 'number') { return true; }
|
|
48
|
+
if ((/^0x[0-9a-f]+$/i).test(x)) { return true; }
|
|
49
|
+
return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isConstructorOrProto(obj, key) {
|
|
53
|
+
return (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var minimist = function (args, opts) {
|
|
57
|
+
if (!opts) { opts = {}; }
|
|
58
|
+
|
|
59
|
+
var flags = {
|
|
60
|
+
bools: {},
|
|
61
|
+
strings: {},
|
|
62
|
+
unknownFn: null,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (typeof opts.unknown === 'function') {
|
|
66
|
+
flags.unknownFn = opts.unknown;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof opts.boolean === 'boolean' && opts.boolean) {
|
|
70
|
+
flags.allBools = true;
|
|
71
|
+
} else {
|
|
72
|
+
[].concat(opts.boolean).filter(Boolean).forEach(function (key) {
|
|
73
|
+
flags.bools[key] = true;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var aliases = {};
|
|
78
|
+
|
|
79
|
+
function aliasIsBoolean(key) {
|
|
80
|
+
return aliases[key].some(function (x) {
|
|
81
|
+
return flags.bools[x];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Object.keys(opts.alias || {}).forEach(function (key) {
|
|
86
|
+
aliases[key] = [].concat(opts.alias[key]);
|
|
87
|
+
aliases[key].forEach(function (x) {
|
|
88
|
+
aliases[x] = [key].concat(aliases[key].filter(function (y) {
|
|
89
|
+
return x !== y;
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
[].concat(opts.string).filter(Boolean).forEach(function (key) {
|
|
95
|
+
flags.strings[key] = true;
|
|
96
|
+
if (aliases[key]) {
|
|
97
|
+
[].concat(aliases[key]).forEach(function (k) {
|
|
98
|
+
flags.strings[k] = true;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
var defaults = opts.default || {};
|
|
104
|
+
|
|
105
|
+
var argv = { _: [] };
|
|
106
|
+
|
|
107
|
+
function argDefined(key, arg) {
|
|
108
|
+
return (flags.allBools && (/^--[^=]+$/).test(arg))
|
|
109
|
+
|| flags.strings[key]
|
|
110
|
+
|| flags.bools[key]
|
|
111
|
+
|| aliases[key];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function setKey(obj, keys, value) {
|
|
115
|
+
var o = obj;
|
|
116
|
+
for (var i = 0; i < keys.length - 1; i++) {
|
|
117
|
+
var key = keys[i];
|
|
118
|
+
if (isConstructorOrProto(o, key)) { return; }
|
|
119
|
+
if (o[key] === undefined) { o[key] = {}; }
|
|
120
|
+
if (
|
|
121
|
+
o[key] === Object.prototype
|
|
122
|
+
|| o[key] === Number.prototype
|
|
123
|
+
|| o[key] === String.prototype
|
|
124
|
+
) {
|
|
125
|
+
o[key] = {};
|
|
126
|
+
}
|
|
127
|
+
if (o[key] === Array.prototype) { o[key] = []; }
|
|
128
|
+
o = o[key];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var lastKey = keys[keys.length - 1];
|
|
132
|
+
if (isConstructorOrProto(o, lastKey)) { return; }
|
|
133
|
+
if (
|
|
134
|
+
o === Object.prototype
|
|
135
|
+
|| o === Number.prototype
|
|
136
|
+
|| o === String.prototype
|
|
137
|
+
) {
|
|
138
|
+
o = {};
|
|
139
|
+
}
|
|
140
|
+
if (o === Array.prototype) { o = []; }
|
|
141
|
+
if (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {
|
|
142
|
+
o[lastKey] = value;
|
|
143
|
+
} else if (Array.isArray(o[lastKey])) {
|
|
144
|
+
o[lastKey].push(value);
|
|
145
|
+
} else {
|
|
146
|
+
o[lastKey] = [o[lastKey], value];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function setArg(key, val, arg) {
|
|
151
|
+
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
152
|
+
if (flags.unknownFn(arg) === false) { return; }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var value = !flags.strings[key] && isNumber(val)
|
|
156
|
+
? Number(val)
|
|
157
|
+
: val;
|
|
158
|
+
setKey(argv, key.split('.'), value);
|
|
159
|
+
|
|
160
|
+
(aliases[key] || []).forEach(function (x) {
|
|
161
|
+
setKey(argv, x.split('.'), value);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Object.keys(flags.bools).forEach(function (key) {
|
|
166
|
+
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
var notFlags = [];
|
|
170
|
+
|
|
171
|
+
if (args.indexOf('--') !== -1) {
|
|
172
|
+
notFlags = args.slice(args.indexOf('--') + 1);
|
|
173
|
+
args = args.slice(0, args.indexOf('--'));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (var i = 0; i < args.length; i++) {
|
|
177
|
+
var arg = args[i];
|
|
178
|
+
var key;
|
|
179
|
+
var next;
|
|
180
|
+
|
|
181
|
+
if ((/^--.+=/).test(arg)) {
|
|
182
|
+
// Using [\s\S] instead of . because js doesn't support the
|
|
183
|
+
// 'dotall' regex modifier. See:
|
|
184
|
+
// http://stackoverflow.com/a/1068308/13216
|
|
185
|
+
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
|
186
|
+
key = m[1];
|
|
187
|
+
var value = m[2];
|
|
188
|
+
if (flags.bools[key]) {
|
|
189
|
+
value = value !== 'false';
|
|
190
|
+
}
|
|
191
|
+
setArg(key, value, arg);
|
|
192
|
+
} else if ((/^--no-.+/).test(arg)) {
|
|
193
|
+
key = arg.match(/^--no-(.+)/)[1];
|
|
194
|
+
setArg(key, false, arg);
|
|
195
|
+
} else if ((/^--.+/).test(arg)) {
|
|
196
|
+
key = arg.match(/^--(.+)/)[1];
|
|
197
|
+
next = args[i + 1];
|
|
198
|
+
if (
|
|
199
|
+
next !== undefined
|
|
200
|
+
&& !(/^(-|--)[^-]/).test(next)
|
|
201
|
+
&& !flags.bools[key]
|
|
202
|
+
&& !flags.allBools
|
|
203
|
+
&& (aliases[key] ? !aliasIsBoolean(key) : true)
|
|
204
|
+
) {
|
|
205
|
+
setArg(key, next, arg);
|
|
206
|
+
i += 1;
|
|
207
|
+
} else if ((/^(true|false)$/).test(next)) {
|
|
208
|
+
setArg(key, next === 'true', arg);
|
|
209
|
+
i += 1;
|
|
210
|
+
} else {
|
|
211
|
+
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
212
|
+
}
|
|
213
|
+
} else if ((/^-[^-]+/).test(arg)) {
|
|
214
|
+
var letters = arg.slice(1, -1).split('');
|
|
215
|
+
|
|
216
|
+
var broken = false;
|
|
217
|
+
for (var j = 0; j < letters.length; j++) {
|
|
218
|
+
next = arg.slice(j + 2);
|
|
219
|
+
|
|
220
|
+
if (next === '-') {
|
|
221
|
+
setArg(letters[j], next, arg);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
|
|
226
|
+
setArg(letters[j], next.slice(1), arg);
|
|
227
|
+
broken = true;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (
|
|
232
|
+
(/[A-Za-z]/).test(letters[j])
|
|
233
|
+
&& (/-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
|
|
234
|
+
) {
|
|
235
|
+
setArg(letters[j], next, arg);
|
|
236
|
+
broken = true;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
|
241
|
+
setArg(letters[j], arg.slice(j + 2), arg);
|
|
242
|
+
broken = true;
|
|
243
|
+
break;
|
|
244
|
+
} else {
|
|
245
|
+
setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
key = arg.slice(-1)[0];
|
|
250
|
+
if (!broken && key !== '-') {
|
|
251
|
+
if (
|
|
252
|
+
args[i + 1]
|
|
253
|
+
&& !(/^(-|--)[^-]/).test(args[i + 1])
|
|
254
|
+
&& !flags.bools[key]
|
|
255
|
+
&& (aliases[key] ? !aliasIsBoolean(key) : true)
|
|
256
|
+
) {
|
|
257
|
+
setArg(key, args[i + 1], arg);
|
|
258
|
+
i += 1;
|
|
259
|
+
} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {
|
|
260
|
+
setArg(key, args[i + 1] === 'true', arg);
|
|
261
|
+
i += 1;
|
|
262
|
+
} else {
|
|
263
|
+
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
268
|
+
argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
|
|
269
|
+
}
|
|
270
|
+
if (opts.stopEarly) {
|
|
271
|
+
argv._.push.apply(argv._, args.slice(i + 1));
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
Object.keys(defaults).forEach(function (k) {
|
|
278
|
+
if (!hasKey(argv, k.split('.'))) {
|
|
279
|
+
setKey(argv, k.split('.'), defaults[k]);
|
|
280
|
+
|
|
281
|
+
(aliases[k] || []).forEach(function (x) {
|
|
282
|
+
setKey(argv, x.split('.'), defaults[k]);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
if (opts['--']) {
|
|
288
|
+
argv['--'] = notFlags.slice();
|
|
289
|
+
} else {
|
|
290
|
+
notFlags.forEach(function (k) {
|
|
291
|
+
argv._.push(k);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return argv;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
var minimist$1 = /*@__PURE__*/getDefaultExportFromCjs(minimist);
|
|
299
|
+
|
|
300
|
+
function bindShortcuts(server, createDevServer) {
|
|
301
|
+
if (!server.httpServer || !process.stdin.isTTY || process.env.CI) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
server.config.logger.info(
|
|
305
|
+
c.dim(c.green(" \u279C")) + c.dim(" press ") + c.bold("h") + c.dim(" to show help")
|
|
306
|
+
);
|
|
307
|
+
let actionRunning = false;
|
|
308
|
+
const onInput = async (input) => {
|
|
309
|
+
if (input === "" || input === "") {
|
|
310
|
+
await server.close().finally(() => process.exit(1));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (actionRunning)
|
|
314
|
+
return;
|
|
315
|
+
if (input === "h") {
|
|
316
|
+
server.config.logger.info(
|
|
317
|
+
[
|
|
318
|
+
"",
|
|
319
|
+
c.bold(" Shortcuts"),
|
|
320
|
+
...SHORTCUTS.map(
|
|
321
|
+
(shortcut2) => c.dim(" press ") + c.bold(shortcut2.key) + c.dim(` to ${shortcut2.description}`)
|
|
322
|
+
)
|
|
323
|
+
].join("\n")
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
const shortcut = SHORTCUTS.find((shortcut2) => shortcut2.key === input);
|
|
327
|
+
if (!shortcut)
|
|
328
|
+
return;
|
|
329
|
+
actionRunning = true;
|
|
330
|
+
await shortcut.action(server, createDevServer);
|
|
331
|
+
actionRunning = false;
|
|
332
|
+
};
|
|
333
|
+
process.stdin.setRawMode(true);
|
|
334
|
+
process.stdin.on("data", onInput).setEncoding("utf8").resume();
|
|
335
|
+
server.httpServer.on("close", () => {
|
|
336
|
+
process.stdin.off("data", onInput).pause();
|
|
337
|
+
process.stdin.setRawMode(false);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
const SHORTCUTS = [
|
|
341
|
+
{
|
|
342
|
+
key: "r",
|
|
343
|
+
description: "restart the server",
|
|
344
|
+
async action(server, createDevServer) {
|
|
345
|
+
server.config.logger.info(c.green(`restarting server...
|
|
346
|
+
`), {
|
|
347
|
+
clear: true,
|
|
348
|
+
timestamp: true
|
|
349
|
+
});
|
|
350
|
+
clearCache();
|
|
351
|
+
await server.close();
|
|
352
|
+
await createDevServer();
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
key: "u",
|
|
357
|
+
description: "show server url",
|
|
358
|
+
action(server) {
|
|
359
|
+
server.config.logger.info("");
|
|
360
|
+
server.printUrls();
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
key: "o",
|
|
365
|
+
description: "open in browser",
|
|
366
|
+
action(server) {
|
|
367
|
+
server.openBrowser();
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
key: "c",
|
|
372
|
+
description: "clear console",
|
|
373
|
+
action(server) {
|
|
374
|
+
server.config.logger.clearScreen("error");
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
key: "q",
|
|
379
|
+
description: "quit",
|
|
380
|
+
async action(server) {
|
|
381
|
+
await server.close().finally(() => process.exit());
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
];
|
|
385
|
+
|
|
386
|
+
const argv = minimist$1(process.argv.slice(2));
|
|
387
|
+
const logVersion = (logger = createLogger()) => {
|
|
388
|
+
logger.info(`
|
|
389
|
+
${c.green(`${c.bold("vitepress")} v${version}`)}
|
|
390
|
+
`, {
|
|
391
|
+
clear: !logger.hasWarned
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
const command = argv._[0];
|
|
395
|
+
const root = argv._[command ? 1 : 0];
|
|
396
|
+
if (root) {
|
|
397
|
+
argv.root = root;
|
|
398
|
+
}
|
|
399
|
+
if (!command || command === "dev") {
|
|
400
|
+
if (argv.force) {
|
|
401
|
+
delete argv.force;
|
|
402
|
+
argv.optimizeDeps = { force: true };
|
|
403
|
+
}
|
|
404
|
+
const createDevServer = async () => {
|
|
405
|
+
const server = await createServer(root, argv, async () => {
|
|
406
|
+
await server.close();
|
|
407
|
+
await createDevServer();
|
|
408
|
+
});
|
|
409
|
+
await server.listen();
|
|
410
|
+
logVersion(server.config.logger);
|
|
411
|
+
server.printUrls();
|
|
412
|
+
bindShortcuts(server, createDevServer);
|
|
413
|
+
};
|
|
414
|
+
createDevServer().catch((err) => {
|
|
415
|
+
createLogger().error(
|
|
416
|
+
`${c.red(`failed to start server. error:`)}
|
|
417
|
+
${err.stack}`
|
|
418
|
+
);
|
|
419
|
+
process.exit(1);
|
|
420
|
+
});
|
|
421
|
+
} else if (command === "init") {
|
|
422
|
+
createLogger().info("", { clear: true });
|
|
423
|
+
init();
|
|
424
|
+
} else {
|
|
425
|
+
logVersion();
|
|
426
|
+
if (command === "build") {
|
|
427
|
+
build(root, argv).catch((err) => {
|
|
428
|
+
createLogger().error(`${c.red(`build error:`)}
|
|
429
|
+
${err.stack}`);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
});
|
|
432
|
+
} else if (command === "serve" || command === "preview") {
|
|
433
|
+
serve(argv).catch((err) => {
|
|
434
|
+
createLogger().error(
|
|
435
|
+
`${c.red(`failed to start server. error:`)}
|
|
436
|
+
${err.stack}`
|
|
437
|
+
);
|
|
438
|
+
process.exit(1);
|
|
439
|
+
});
|
|
440
|
+
} else {
|
|
441
|
+
createLogger().error(c.red(`unknown command "${command}".`));
|
|
442
|
+
process.exit(1);
|
|
443
|
+
}
|
|
444
|
+
}
|