Skip to content

Commit 3ff02c5

Browse files
committed
website: re-generate commons
1 parent 6a134c0 commit 3ff02c5

File tree

2 files changed

+93
-58
lines changed

2 files changed

+93
-58
lines changed

website/customFields.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// DO NOT EDIT!
2+
// Automatically generated from docusaurus-template-liquid/templates/docusaurus.
3+
4+
import { fileURLToPath } from 'node:url';
5+
import path from 'node:path';
6+
import fs from 'node:fs';
7+
8+
// ----------------------------------------------------------------------------
9+
10+
export function getCustomFields() {
11+
const pwd = fileURLToPath(import.meta.url);
12+
// console.log(pwd);
13+
14+
// First get the version from the top package.json.
15+
const topFilePath = path.join(path.dirname(path.dirname(pwd)), 'package.json');
16+
// console.log(filePath);
17+
const topFileContent = fs.readFileSync(topFilePath);
18+
19+
const topPackageJson = JSON.parse(topFileContent.toString());
20+
const releaseVersion = topPackageJson.version.replace(/[.-]pre/, '');
21+
22+
console.log(`package version: ${topPackageJson.version}`);
23+
24+
let versionFields;
25+
26+
if (topPackageJson.xpack && !releaseVersion.startsWith('0.0.0')) {
27+
// Remove the first part, up to the last dot.
28+
const npmSubversion = releaseVersion.replace(/^.*[.]/, '');
29+
30+
// Remove from the last dot to the end.
31+
const xpackVersion = releaseVersion.replace(/[.][0-9]*$/, '');
32+
33+
// Remove the pre-release.
34+
const xpackSemver = xpackVersion.replace(/[-].*$/, '');
35+
36+
// Remove the first part, up to the dash.
37+
const xpackSubversion = xpackVersion.replace(/^.*[-]/, '');
38+
39+
let upstreamVersion = xpackSemver;
40+
41+
versionFields = {
42+
releaseVersion,
43+
xpackVersion,
44+
xpackSemver,
45+
xpackSubversion,
46+
npmSubversion,
47+
upstreamVersion,
48+
}
49+
} else {
50+
versionFields = {
51+
releaseVersion
52+
}
53+
}
54+
55+
let engineVersionFields;
56+
57+
if (topPackageJson?.engines?.node) {
58+
const enginesNodeVersion = topPackageJson.engines.node.replace(/[^0-9]*/, '') || '';
59+
const enginesNodeVersionMajor = enginesNodeVersion.replace(/[.].*/, '');
60+
engineVersionFields = {
61+
enginesNodeVersion,
62+
enginesNodeVersionMajor
63+
}
64+
} else {
65+
engineVersionFields = {};
66+
}
67+
68+
const docusaurusFields = {
69+
docusaurusVersion: require('@docusaurus/core/package.json').version,
70+
buildTime: new Date().getTime(),
71+
}
72+
73+
let websiteFields = {};
74+
try {
75+
const websiteFilePath = path.join(path.dirname(path.dirname(pwd)), 'website', 'package.json');
76+
// console.log(filePath);
77+
const websiteFileContent = fs.readFileSync(websiteFilePath);
78+
const websitePackageJson = JSON.parse(websiteFileContent.toString());
79+
websiteFields = websitePackageJson?.websiteConfig?.customFields ?? {};
80+
} catch (error) {
81+
// Most probably there is no website/package.json.
82+
}
83+
84+
return {
85+
...versionFields,
86+
...engineVersionFields,
87+
...docusaurusFields,
88+
...websiteFields,
89+
}
90+
}
91+
92+
// ----------------------------------------------------------------------------

website/docusaurus.config.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,13 @@ import type * as Preset from '@docusaurus/preset-classic';
88
import util from 'node:util';
99

1010
import {redirects} from './docusaurus-config-redirects'
11+
import {getCustomFields} from './customFields'
1112

1213
// The node.js modules cannot be used in modules imported in browser code:
1314
// webpack < 5 used to include polyfills for node.js core modules by default.
1415
// so the entire initialisation code must be in this file, that is
1516
// not processed by webpack.
1617

17-
import {fileURLToPath} from 'node:url';
18-
import path from 'node:path';
19-
import fs from 'node:fs';
20-
21-
// ----------------------------------------------------------------------------
22-
23-
function getCustomFields() {
24-
const pwd = fileURLToPath(import.meta.url);
25-
// console.log(pwd);
26-
27-
// First get the version from the top package.json.
28-
const topFilePath = path.join(path.dirname(path.dirname(pwd)), 'package.json');
29-
// console.log(filePath);
30-
const topFileContent = fs.readFileSync(topFilePath);
31-
32-
const topPackageJson = JSON.parse(topFileContent.toString());
33-
const jsonVersion = topPackageJson.version.replace(/[.-]pre/, '');
34-
35-
console.log(`package version: ${topPackageJson.version}`);
36-
37-
// Remove the first part, up to the last dot.
38-
const npmSubversion = jsonVersion.replace(/^.*[.]/, '');
39-
40-
// Remove from the last dot to the end.
41-
const xpackVersion = jsonVersion.replace(/[.][0-9]*$/, '');
42-
43-
// Remove the pre-release.
44-
const xpackSemver = xpackVersion.replace(/[-].*$/, '');
45-
46-
// Remove the first part, up to the dash.
47-
const xpackSubversion = xpackVersion.replace(/^.*[-]/, '');
48-
49-
let websitePackageJson = {}
50-
try {
51-
const websiteFilePath = path.join(path.dirname(path.dirname(pwd)), 'website', 'package.json');
52-
// console.log(filePath);
53-
const websiteFileContent = fs.readFileSync(websiteFilePath);
54-
websitePackageJson = JSON.parse(websiteFileContent.toString());
55-
} catch (error) {
56-
}
57-
58-
const customFields = websitePackageJson?.websiteConfig?.customFields ?? {};
59-
60-
let upstreamVersion = xpackSemver;
61-
62-
return {
63-
version: jsonVersion,
64-
xpackVersion,
65-
xpackSemver,
66-
xpackSubversion,
67-
npmSubversion,
68-
upstreamVersion,
69-
docusaurusVersion: require('@docusaurus/core/package.json').version,
70-
buildTime: new Date().getTime(),
71-
...customFields,
72-
}
73-
}
74-
7518
// ----------------------------------------------------------------------------
7619

7720
const customFields = getCustomFields();

0 commit comments

Comments
 (0)