Skip to content

Commit 0eac822

Browse files
authored
Merge branch 'next' into 1348-refactor-mersenne
2 parents eb5749f + 97ebd29 commit 0eac822

File tree

17 files changed

+698
-341
lines changed

17 files changed

+698
-341
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
steps:
3232
- name: Checkout
3333
uses: actions/checkout@v3
34+
with:
35+
# Required for docs/versions tests
36+
fetch-depth: 0
3437

3538
- name: Install pnpm
3639
uses: pnpm/[email protected]

docs/.vitepress/components/Banner.vue

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script setup lang="ts">
2+
import { useElementSize } from '@vueuse/core';
3+
import { ref, watchEffect } from 'vue';
4+
5+
defineProps<{
6+
version: string;
7+
}>();
8+
9+
const el = ref<HTMLElement>();
10+
const { height } = useElementSize(el);
11+
12+
watchEffect(() => {
13+
if (height.value) {
14+
document.documentElement.style.setProperty(
15+
'--vp-layout-top-height',
16+
`${height.value + 16}px`
17+
);
18+
}
19+
});
20+
21+
const dismiss = () => {
22+
localStorage.setItem(
23+
'faker-version-banner',
24+
(Date.now() + 8.64e7 * 1).toString() // current time + 1 day
25+
);
26+
document.documentElement.classList.add('banner-dismissed');
27+
};
28+
</script>
29+
30+
<template>
31+
<div ref="el" class="banner">
32+
<div class="text">
33+
These docs are of {{ version }}. For docs of the current version visit:
34+
<a href="https://fakerjs.dev/">fakerjs.dev</a>
35+
</div>
36+
37+
<button type="button" @click="dismiss">
38+
<svg
39+
xmlns="http://www.w3.org/2000/svg"
40+
viewBox="0 0 20 20"
41+
fill="currentColor"
42+
>
43+
<path
44+
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
45+
/>
46+
</svg>
47+
</button>
48+
</div>
49+
</template>
50+
51+
<style>
52+
.banner-dismissed {
53+
--vp-layout-top-height: 0px !important;
54+
}
55+
56+
html {
57+
--vp-layout-top-height: 88px;
58+
}
59+
60+
@media (min-width: 375px) {
61+
html {
62+
--vp-layout-top-height: 64px;
63+
}
64+
}
65+
66+
@media (min-width: 768px) {
67+
html {
68+
--vp-layout-top-height: 40px;
69+
}
70+
}
71+
</style>
72+
73+
<style scoped>
74+
.banner-dismissed .banner {
75+
display: none;
76+
}
77+
78+
.banner {
79+
position: fixed;
80+
top: 0;
81+
right: 0;
82+
left: 0;
83+
z-index: var(--vp-z-index-layout-top);
84+
85+
padding: 8px;
86+
text-align: center;
87+
88+
background: #383636;
89+
color: #fff;
90+
91+
display: flex;
92+
justify-content: space-between;
93+
}
94+
95+
.text {
96+
flex: 1;
97+
}
98+
99+
a {
100+
text-decoration: underline;
101+
}
102+
103+
svg {
104+
width: 20px;
105+
height: 20px;
106+
margin-left: 8px;
107+
}
108+
</style>

docs/.vitepress/components/shims.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare const __BANNER__: string | false;
2+
3+
declare module '*.vue' {
4+
import type { DefineComponent } from 'vue';
5+
const component: DefineComponent;
6+
export default component;
7+
}

docs/.vitepress/config.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from 'vitepress';
22
import { DefaultTheme } from 'vitepress/theme';
33
import { apiPages } from './api-pages';
4-
import { currentVersion, oldVersions } from './versions';
4+
import { currentVersion, oldVersions, versionBannerInfix } from './versions';
55

66
type SidebarGroup = DefaultTheme.SidebarGroup;
77

@@ -51,7 +51,7 @@ function extendSideNav(current: SidebarGroup): SidebarGroup[] {
5151
return links;
5252
}
5353

54-
export default defineConfig({
54+
const config = defineConfig({
5555
title: 'Faker',
5656
description,
5757

@@ -229,4 +229,29 @@ export default defineConfig({
229229
}),
230230
},
231231
},
232+
233+
vite: {
234+
define: {
235+
__BANNER__: versionBannerInfix ?? false,
236+
},
237+
},
232238
});
239+
240+
if (versionBannerInfix) {
241+
config.head?.push([
242+
'script',
243+
{ id: 'restore-banner-preference' },
244+
`
245+
(() => {
246+
const restore = (key, cls, def = false) => {
247+
const saved = localStorage.getItem(key);
248+
if (saved ? saved !== 'false' && new Date() < saved : def) {
249+
document.documentElement.classList.add(cls);
250+
}
251+
};
252+
restore('faker-version-banner', 'banner-dismissed');
253+
})();`,
254+
]);
255+
}
256+
257+
export default config;

docs/.vitepress/theme/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
import DefaultTheme from 'vitepress/theme';
2+
import { defineAsyncComponent, h } from 'vue';
23
import './index.css';
34

4-
export default DefaultTheme;
5+
export default {
6+
...DefaultTheme,
7+
Layout() {
8+
return h(
9+
DefaultTheme.Layout,
10+
null,
11+
__BANNER__
12+
? {
13+
'layout-top': () =>
14+
h(
15+
defineAsyncComponent(() => import('../components/Banner.vue')),
16+
{ version: __BANNER__ }
17+
),
18+
}
19+
: null
20+
);
21+
},
22+
};

docs/.vitepress/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ES2020",
4+
"module": "ES2020",
45
"moduleResolution": "Node",
56
"resolveJsonModule": true
67
}

docs/.vitepress/versions.ts

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,71 @@
1+
import { execSync } from 'node:child_process';
2+
import * as semver from 'semver';
13
import { version } from '../../package.json';
24

3-
export const currentVersion = `v${version}`;
5+
function readBranchName(): string {
6+
return (
7+
execSync('git branch --show-current').toString('utf8').trim() || 'unknown'
8+
);
9+
}
410

11+
function readOtherLatestReleaseTagNames(): string[] {
12+
const currentMajorVersion = semver.major(version);
13+
const latestReleaseTagNames = execSync('git tag -l')
14+
.toString('utf8')
15+
.split('\n')
16+
.filter((tag) => semver.valid(tag))
17+
.reduce<Record<number, string[]>>((acc, tag) => {
18+
const majorVersion = semver.major(tag);
19+
// Only consider tags for our deployed website versions,
20+
// excluding the current major version.
21+
if (majorVersion >= 6 && majorVersion !== currentMajorVersion) {
22+
(acc[majorVersion] = acc[majorVersion] ?? []).push(tag);
23+
}
24+
return acc;
25+
}, {});
26+
return Object.entries(latestReleaseTagNames)
27+
.map(([major, tags]) => semver.maxSatisfying(tags, `^${major}`))
28+
.sort(semver.rcompare);
29+
}
30+
31+
// Set by netlify
32+
const {
33+
CONTEXT: deployContext = 'local',
34+
BRANCH: branchName = readBranchName(),
35+
} = process.env;
36+
37+
const hiddenLink =
38+
deployContext === 'production'
39+
? 'https://fakerjs.dev/'
40+
: `https://${branchName}.fakerjs.dev/`;
41+
const otherVersions = readOtherLatestReleaseTagNames();
42+
const isReleaseBranch = /^v\d+$/.test(branchName);
43+
44+
export const versionBannerInfix: string | null = (() => {
45+
if (deployContext === 'production') {
46+
return null;
47+
}
48+
if (isReleaseBranch) {
49+
return '"an old version"';
50+
}
51+
if (branchName === 'next') {
52+
return '"the next (unreleased) version"';
53+
}
54+
return '"a development version"';
55+
})();
56+
57+
export const currentVersion = isReleaseBranch ? `v${version}` : branchName;
558
export const oldVersions = [
6-
{ version: 'v6.3.1', link: 'https://v6.fakerjs.dev/' },
7-
];
59+
{
60+
version: 'latest',
61+
link: 'https://fakerjs.dev/',
62+
},
63+
{
64+
version: 'next',
65+
link: 'https://next.fakerjs.dev/',
66+
},
67+
...otherVersions.map((version) => ({
68+
version,
69+
link: `https://v${semver.major(version)}.fakerjs.dev/`,
70+
})),
71+
].filter(({ link }) => link !== hiddenLink);

docs/guide/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const randomName = faker.person.fullName(); // Rowan Nikolaus
1111
const randomEmail = faker.internet.email(); // [email protected]
1212
```
1313

14-
Or if you using CommonJS
14+
Or if you're using CommonJS:
1515

1616
```js
1717
const { faker } = require('@faker-js/faker');

package.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,24 @@
9999
"@types/markdown-it": "~12.2.3",
100100
"@types/node": "~18.8.4",
101101
"@types/prettier": "~2.7.1",
102-
"@types/react": "~18.0.21",
102+
"@types/react": "~18.0.22",
103103
"@types/sanitize-html": "~2.6.2",
104-
"@types/validator": "~13.7.8",
105-
"@typescript-eslint/eslint-plugin": "~5.40.0",
106-
"@typescript-eslint/parser": "~5.40.0",
104+
"@types/semver": "~7.3.12",
105+
"@types/validator": "~13.7.9",
106+
"@typescript-eslint/eslint-plugin": "~5.40.1",
107+
"@typescript-eslint/parser": "~5.40.1",
107108
"@vitest/coverage-c8": "~0.24.3",
108109
"@vitest/ui": "~0.24.3",
110+
"@vueuse/core": "~9.4.0",
109111
"c8": "~7.12.0",
110112
"conventional-changelog-cli": "~2.2.2",
111113
"cypress": "~10.10.0",
112-
"esbuild": "~0.15.11",
113-
"eslint": "~8.25.0",
114+
"esbuild": "~0.15.12",
115+
"eslint": "~8.26.0",
114116
"eslint-config-prettier": "~8.5.0",
115-
"eslint-define-config": "~1.7.0",
117+
"eslint-define-config": "~1.8.0",
116118
"eslint-gitignore": "~0.1.0",
117-
"eslint-plugin-jsdoc": "~39.3.6",
119+
"eslint-plugin-jsdoc": "~39.3.23",
118120
"eslint-plugin-prettier": "~4.2.1",
119121
"glob": "~8.0.3",
120122
"lint-staged": "~13.0.3",
@@ -127,18 +129,20 @@
127129
"react-dom": "~18.2.0",
128130
"rimraf": "~3.0.2",
129131
"sanitize-html": "~2.7.2",
130-
"simple-git-hooks": "~2.8.0",
132+
"semver": "~7.3.8",
133+
"simple-git-hooks": "~2.8.1",
131134
"standard-version": "~9.5.0",
132-
"tsx": "~3.10.1",
133-
"typedoc": "~0.23.16",
135+
"tsx": "~3.11.0",
136+
"typedoc": "~0.23.18",
134137
"typedoc-plugin-missing-exports": "~1.0.0",
135138
"typescript": "~4.8.4",
136139
"validator": "~13.7.0",
137140
"vite": "~3.1.8",
138-
"vitepress": "1.0.0-alpha.21",
139-
"vitest": "~0.24.3"
141+
"vitepress": "1.0.0-alpha.26",
142+
"vitest": "~0.24.3",
143+
"vue": "~3.2.41"
140144
},
141-
"packageManager": "pnpm@7.13.5",
145+
"packageManager": "pnpm@7.14.0",
142146
"engines": {
143147
"node": ">=14.0.0",
144148
"npm": ">=6.0.0"

0 commit comments

Comments
 (0)