Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/docs/assets/data/stable-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "0.0.0"
}
4 changes: 2 additions & 2 deletions apps/docs/components/layout/footer/app.footer.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import StableVersion from '@/assets/data/stable-version.json';
import { GITHUB_DISCUSSIONS_URL, GITHUB_REPO_URL } from '@/utils/constants';
import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';
Expand Down Expand Up @@ -29,6 +30,5 @@ export class AppFooterComponent {

readonly licenseUrl = `${GITHUB_REPO_URL}/blob/main/LICENSE.md`;

// eslint-disable-next-line @typescript-eslint/no-var-requires
readonly version = require('@/package.json').version;
readonly version = StableVersion.version;
}
3 changes: 2 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"build:sitemap": "node scripts/build-sitemap.mjs",
"build:llm-docs": "node scripts/build-llm-docs.mjs",
"build:democode": "node scripts/build-demo-code.mjs",
"build:docs": "npm run build:apidoc && npm run build:democode && npm run build:llm-docs && npm run build:routes && npm run build:sitemap && npm run test:democode && npm run test:stackblitz",
"build:stable-version": "node scripts/build-stable-version.mjs",
"build:docs": "npm run build:apidoc && npm run build:democode && npm run build:llm-docs && npm run build:routes && npm run build:sitemap && npm run build:stable-version && npm run test:democode && npm run test:stackblitz",
"test:democode": "node scripts/test-demo-code.mjs",
"test:stackblitz": "node scripts/test-stackblitz-e2e.mjs --all"
},
Expand Down
41 changes: 41 additions & 0 deletions apps/docs/scripts/build-stable-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Fetches the "latest" (stable) dist-tag for @openng/optimus-ui from the npm
* registry and writes it to assets/data/stable-version.json.
*
* The footer must not read the monorepo's root package.json version directly —
* that value tracks the in-progress release (often an -rc.x pre-release) and is
* not necessarily what's actually published as stable.
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '..');
const OUTPUT = path.join(ROOT, 'assets/data/stable-version.json');

const PACKAGE_NAME = '@openng/optimus-ui';
const FALLBACK_VERSION = JSON.parse(fs.readFileSync(path.join(ROOT, '../../package.json'), 'utf-8')).version.split('-')[0];

async function fetchStableVersion() {
const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}`);
if (!response.ok) throw new Error(`npm registry responded with ${response.status}`);

const data = await response.json();
const version = data['dist-tags']?.latest;
if (!version) throw new Error('no "latest" dist-tag found in registry response');

return version;
}

let version;

try {
version = await fetchStableVersion();
} catch (error) {
console.warn(`⚠ Could not fetch stable version from npm, falling back to ${FALLBACK_VERSION}: ${error.message}`);
version = FALLBACK_VERSION;
}

fs.writeFileSync(OUTPUT, JSON.stringify({ version }, null, 4) + '\n', 'utf-8');
console.log(`✓ Generated ${path.relative(ROOT, OUTPUT)} with version ${version}`);