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 69d9503 commit 71d62f8
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 73 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,
}
}

// ----------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions website/docs/developer/_common/_platform-docker-section.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ or, for more verbosity, run the similar development build:
archive and its SHA signature, created in
the <code>build-assets/build/{props.platform}/deploy</code> folder:

* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>

To rerun the build, invoke the **deep-clean** action and repeat from install:

Expand Down
4 changes: 2 additions & 2 deletions website/docs/developer/_common/_platform-native-section.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ or, for more verbosity, run the similar development build:
archive and its SHA signature, created in
the <code>build-assets/build/{props.platform}/deploy</code> folder:

* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>

To rerun the build, invoke the **deep-clean** action and repeat from install:

Expand Down
2 changes: 1 addition & 1 deletion website/docs/install/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ The command to install the **latest** available version of **ninja-build** is:
To install a **specific version**, specify it explicitly:

<CodeBlock language="sh"> {
`xpm install @xpack-dev-tools/ninja-build@${customField('version')} --verbose
`xpm install @xpack-dev-tools/ninja-build@${customField('releaseVersion')} --verbose
`} </CodeBlock>

<Tabs groupId="operating-systems">
Expand Down
4 changes: 2 additions & 2 deletions website/docs/maintainer/_common/_platform-docker-build.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ xpm run docker-build-development --config ${props.platform} -C ~/Work/xpack-dev-
archive and its SHA signature, created in
the <code>build-assets/build/{props.platform}/deploy</code> folder:

* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.{props.platform === 'win32-x64' ? 'zip' : 'tar.gz'}</code>
* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.{props.platform === 'win32-x64' ? 'zip' : 'tar.gz'}.sha</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.{props.platform === 'win32-x64' ? 'zip' : 'tar.gz'}</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.{props.platform === 'win32-x64' ? 'zip' : 'tar.gz'}.sha</code>

To update the build scripts and build the release binaries:

Expand Down
4 changes: 2 additions & 2 deletions website/docs/maintainer/_common/_platform-native-build.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ xpm run build-development --config ${props.platform} -C ~/Work/xpack-dev-tools/n
archive and its SHA signature, created in
the <code>build-assets/build/{props.platform}/deploy</code> folder:

* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
* <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz</code>
- <code>xpack-ninja-build-{customField('xpackVersion')}-{props.platform}.tar.gz.sha</code>

To update the build scripts and build the release binaries:

Expand Down
4 changes: 2 additions & 2 deletions website/docs/user/_common/_arm-toolchain-versioning.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ upstream **Arm GNU Toolchain** project is a bit unusual and unstable in time,
(like <code>{versionMajor()}.{versionMinor()}.Rel1</code>)
therefore the upstream GCC version is preferred, which
is a three number string
like <code>{customField('xpackVersion')}</code>;
like <code>{customField('xpackSemver')}</code>;
to this string the xPack distribution adds a fourth number that represents
the Arm release with the same GCC release, and a fifth number
that represents the xPack release of the same Arm release;
since [SemVer](https://semver.org) allows only three numbers,
all additional ones can
be added only as pre-release strings, separated by a dash,
like <code>{customField('xpackVersion')}-<b>{customField('xpackSubversion')}</b></code>. When
like <code>{customField('xpackSemver')}-<b>{customField('xpackSubversion')}</b></code>. When
published as a npm package, the version gets
a sixth number,
like <code>{customField('xpackVersion')}.<b>{customField('npmSubversion')}</b></code>.
Expand Down
6 changes: 3 additions & 3 deletions website/docs/user/_common/_versioning.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import LinksVsForwarders from '@site/src/components/LinksVsForwarders'
The version string used by the
upstream {props.upstreamName ? props.upstreamName : 'Ninja Build'} project
is a three number string
like <code>{customField('xpackVersion')}</code>;
like <code>{customField('xpackSemver')}</code>;
to this string the xPack distribution adds a fourth number,
but since [SemVer](https://semver.org) allows only three numbers,
all additional ones can
be added only as pre-release strings, separated by a dash,
like <code>{customField('xpackVersion')}</code>. When
like <code>{customField('xpackSemver')}-<b>{customField('xpackSubversion')}</b></code>. When
published as a npm package, the version gets
a fifth number,
like <code>{customField('xpackVersion')}.{customField('npmSubversion')}</code>.
like <code>{customField('xpackVersion')}.<b>{customField('npmSubversion')}</b></code>.

Since adherence of third party packages to SemVer is not guaranteed,
it is recommended to avoid referring to the xPack Ninja Build dependency via
Expand Down
59 changes: 1 addition & 58 deletions website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,13 @@ import type * as Preset from '@docusaurus/preset-classic';
import util from 'node:util';

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 jsonVersion = topPackageJson.version.replace(/[.-]pre/, '');

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

// Remove the first part, up to the last dot.
const npmSubversion = jsonVersion.replace(/^.*[.]/, '');

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

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

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

let websitePackageJson = {}
try {
const websiteFilePath = path.join(path.dirname(path.dirname(pwd)), 'website', 'package.json');
// console.log(filePath);
const websiteFileContent = fs.readFileSync(websiteFilePath);
websitePackageJson = JSON.parse(websiteFileContent.toString());
} catch (error) {
}

const customFields = websitePackageJson?.websiteConfig?.customFields ?? {};

let upstreamVersion = xpackSemver;

return {
version: jsonVersion,
xpackVersion,
xpackSemver,
xpackSubversion,
npmSubversion,
upstreamVersion,
docusaurusVersion: require('@docusaurus/core/package.json').version,
buildTime: new Date().getTime(),
...customFields,
}
}

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

const customFields = getCustomFields();
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function HomepageHeader() {
<p className="hero__subtitle">{siteConfig.tagline}</p>

<div className={styles.installWithCopy}>
<InstallWithCopy>xpm install @xpack-dev-tools/ninja-build@{customField('version')} --verbose</InstallWithCopy>
<InstallWithCopy>xpm install @xpack-dev-tools/ninja-build@{customField('releaseVersion')} --verbose</InstallWithCopy>
</div>

</div>
Expand Down

0 comments on commit 71d62f8

Please sign in to comment.