Skip to content

Commit

Permalink
website: re-generate commons
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Jan 20, 2025
1 parent 30ae550 commit c8619f6
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 35 deletions.
92 changes: 92 additions & 0 deletions website/customFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// DO NOT EDIT!
// Automatically generated from docusaurus-template-liquid/templates/docusaurus.

import { fileURLToPath } from 'node:url';
import path from 'node:path';
import fs from 'node:fs';

// ----------------------------------------------------------------------------

export function getCustomFields() {
const pwd = fileURLToPath(import.meta.url);
// console.log(pwd);

// First get the version from the top package.json.
const topFilePath = path.join(path.dirname(path.dirname(pwd)), 'package.json');
// console.log(filePath);
const topFileContent = fs.readFileSync(topFilePath);

const topPackageJson = JSON.parse(topFileContent.toString());
const releaseVersion = topPackageJson.version.replace(/[.-]pre/, '');

console.log(`package version: ${topPackageJson.version}`);

let versionFields;

if (topPackageJson.xpack && !releaseVersion.startsWith('0.0.0')) {
// Remove the first part, up to the last dot.
const npmSubversion = releaseVersion.replace(/^.*[.]/, '');

// Remove from the last dot to the end.
const xpackVersion = releaseVersion.replace(/[.][0-9]*$/, '');

// Remove the pre-release.
const xpackSemver = xpackVersion.replace(/[-].*$/, '');

// Remove the first part, up to the dash.
const xpackSubversion = xpackVersion.replace(/^.*[-]/, '');

let upstreamVersion = xpackSemver;

versionFields = {
releaseVersion,
xpackVersion,
xpackSemver,
xpackSubversion,
npmSubversion,
upstreamVersion,
}
} else {
versionFields = {
releaseVersion
}
}

let engineVersionFields;

if (topPackageJson?.engines?.node) {
const enginesNodeVersion = topPackageJson.engines.node.replace(/[^0-9]*/, '') || '';
const enginesNodeVersionMajor = enginesNodeVersion.replace(/[.].*/, '');
engineVersionFields = {
enginesNodeVersion,
enginesNodeVersionMajor
}
} else {
engineVersionFields = {};
}

const docusaurusFields = {
docusaurusVersion: require('@docusaurus/core/package.json').version,
buildTime: new Date().getTime(),
}

let websiteFields = {};
try {
const websiteFilePath = path.join(path.dirname(path.dirname(pwd)), 'website', 'package.json');
// console.log(filePath);
const websiteFileContent = fs.readFileSync(websiteFilePath);
const websitePackageJson = JSON.parse(websiteFileContent.toString());
websiteFields = websitePackageJson?.websiteConfig?.customFields ?? {};
} catch (error) {
// Most probably there is no website/package.json.
}

return {
...versionFields,
...engineVersionFields,
...docusaurusFields,
...websiteFields,
}
}

// ----------------------------------------------------------------------------
36 changes: 1 addition & 35 deletions website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,13 @@ import {customDocsNavbarItem} from './navbar-docs-items'


import {redirects} from './docusaurus-config-redirects'
import {getCustomFields} from './customFields'

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

import { fileURLToPath } from 'node:url';
import path from 'node:path';
import fs from 'node:fs';

// ----------------------------------------------------------------------------

function getCustomFields() {
const pwd = fileURLToPath(import.meta.url);
// console.log(pwd);

// First get the version from the top package.json.
const topFilePath = path.join(path.dirname(path.dirname(pwd)), 'package.json');
// console.log(filePath);
const topFileContent = fs.readFileSync(topFilePath);

const topPackageJson = JSON.parse(topFileContent.toString());
const releaseVersion = topPackageJson.version.replace(/[.-]pre/, '');

console.log(`package version: ${topPackageJson.version}`);

const enginesNodeVersion = topPackageJson.engines.node.replace(/[^0-9]*/, '') || '';
const enginesNodeVersionMajor = enginesNodeVersion.replace(/[.].*/, '');
const customFields = {
enginesNodeVersion,
enginesNodeVersionMajor
}

return {
releaseVersion,
docusaurusVersion: require('@docusaurus/core/package.json').version,
buildTime: new Date().getTime(),
...customFields,
}
}

// ----------------------------------------------------------------------------

const customFields = getCustomFields();
Expand Down

0 comments on commit c8619f6

Please sign in to comment.