-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QOLOE-125 Add head meta elements which will include replaced version …
…details in dist, rejigged components to group like components together to make it easier to find things
- Loading branch information
Showing
19 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
import { execSync } from 'child_process'; | ||
import { fileURLToPath } from 'url'; | ||
import listFiles from "../helpers/listfiles.js"; | ||
import log from "../helpers/logger.js"; | ||
|
||
// Helper function to get git information | ||
const getGitInfo = () => { | ||
const getGitBranch = () => execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); | ||
const getGitTag = () => { | ||
try { | ||
return execSync('git describe --tags --exact-match 2>/dev/null').toString().trim(); | ||
} catch { | ||
return null; | ||
} | ||
}; | ||
const getGitCommit = () => execSync('git rev-parse HEAD').toString().trim(); | ||
const getGitCommitDate = () => execSync('git log -1 --format=%cI').toString().trim(); | ||
|
||
return { | ||
branch: getGitBranch(), | ||
tag: getGitTag(), | ||
commit: getGitCommit(), | ||
datetime: getGitCommitDate(), | ||
}; | ||
}; | ||
|
||
// Function to extract major version prefix from a tag | ||
const extractMajorVersion = (tag) => { | ||
if (tag.startsWith('v')) { | ||
// Format 'vX.Y.Z' -> 'vX' | ||
return tag.split('.')[0]; | ||
} else { | ||
// Split by non-alphanumeric characters and take the first part | ||
return tag.split(/[^a-zA-Z0-9]/)[0]; | ||
} | ||
}; | ||
|
||
// Helper function to get package.json info | ||
const getPackageJson = async () => { | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const packageJsonPath = path.resolve(__dirname, '../../package.json'); | ||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8')); | ||
return { | ||
project_id: packageJson.name, | ||
version: packageJson.version, | ||
}; | ||
}; | ||
|
||
// Create the plugin | ||
const versionPlugin = () => ({ | ||
name: 'version-plugin', | ||
setup(build) { | ||
// Get version details | ||
let versionDetails; | ||
build.onStart(async () => { | ||
const packageInfo = await getPackageJson(); | ||
const gitInfo = getGitInfo(); | ||
versionDetails = { | ||
...packageInfo, | ||
...gitInfo, | ||
majorVersion: extractMajorVersion(gitInfo.tag || 'v' + packageInfo.version), | ||
}; | ||
console.log(`version details collected: ${JSON.stringify(versionDetails)}`); | ||
}); | ||
|
||
// Replace placeholders in HTML, Mustache, and Handlebars files | ||
build.onEnd(async (result) => { | ||
console.log('version update starting'); | ||
|
||
//List new components | ||
const root = process.cwd(); | ||
const relativePath = "/dist/components/"; | ||
|
||
const newTemplateFiles = listFiles(root + relativePath); | ||
for (const file of newTemplateFiles) { | ||
if (/\.(html|mustache|hbs)$/.test(file)) { | ||
// const outputPath = path.resolve(process.cwd(), file); | ||
let source = await fs.readFile(file, 'utf8'); | ||
let newSource = source.replace(/###VERSION###/g, JSON.stringify(versionDetails)); | ||
|
||
// Replace major version placeholder if present | ||
newSource = newSource.replace(/###MAJOR_VERSION###/g, versionDetails.majorVersion); | ||
|
||
// Check if the content has changed | ||
if (source !== newSource) { | ||
console.log(`Placeholder replaced in: ${file}, ${newSource}`); | ||
await fs.writeFile(file, newSource); | ||
} | ||
} | ||
} | ||
|
||
}); | ||
|
||
}, | ||
}); | ||
|
||
export { versionPlugin }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Component from '../../../js/QGDSComponent.js' | ||
import template from "./head.hbs?raw"; | ||
|
||
export class Head { | ||
|
||
// Use the global Component class to create a new instance of the Loading Quickexit component. | ||
// A data object, containing the Handlebars placeholder replacement strings, should be provided as an argument. | ||
|
||
constructor(data = {}) { | ||
return new Component(template, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cdn": "{DEV|TEST|BETA|STAGING|PROD|/__data/assets/git_bridge/0026/471752/}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
<!-- VERSION_DETAILS=###VERSION### --> | ||
|
||
{{! Select environment, used verbatium if not using predefind key | ||
cdn := PROD|STAGING|BETA|TEST|DEV|??? | ||
}} | ||
|
||
<link rel="stylesheet" href="{{#if cdn }}{{#ifCond cdn '==' 'PROD'}}https://static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'STAGING'}}https://staging-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'BETA'}}https://beta-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'TEST'}}https://test-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'DEV'}}https://dev-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{cdn}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{else}}missing{{/if}}/assets/css/qld.bootstrap.css"> | ||
|
||
<script type="text/javascript" async src="{{#if cdn }}{{#ifCond cdn '==' 'PROD'}}https://static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'STAGING'}}https://staging-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'BETA'}}https://beta-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'TEST'}}https://test-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'DEV'}}https://dev-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{cdn}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{else}}missing{{/if}}/assets/js/bootstrap.min.js"></script> | ||
<script type="text/javascript" async src="{{#if cdn }}{{#ifCond cdn '==' 'PROD'}}https://static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'STAGING'}}https://staging-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'BETA'}}https://beta-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'TEST'}}https://test-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{#ifCond cdn '==' 'DEV'}}https://dev-static.qgov.net.au/qgds-bootstrap5/###MAJOR_VERSION###/###MAJOR_VERSION###.x.x-latest{{else}}{{cdn}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{/ifCond}}{{else}}missing{{/if}}/assets/js/qld.bootstrap.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import defaultdata from "./head.data.json"; | ||
import { Head } from "./Head.js"; | ||
|
||
export default { | ||
tags: ["autodocs"], | ||
title: "!Core/HeadMeta", | ||
render: (args) => { | ||
return new Head(args).html; | ||
}, | ||
|
||
argTypes: { | ||
cdn: { | ||
name: "CDN", | ||
description: `CDN prefix or provided text`, | ||
control: { type: 'radio' , | ||
labels: { 'DEV': 'DEV', 'TEST' : 'TEST','BETA':'BETA','STAGING':'STAGING','PROD':'PROD','/__data/assets/git_bridge/0026/471752/': 'SQUIZ Custom'}, | ||
}, | ||
options: [ | ||
"DEV", | ||
"TEST", | ||
"BETA", | ||
"STAGING", | ||
"PROD", | ||
"/__data/assets/git_bridge/0026/471752/", | ||
], | ||
} | ||
}, | ||
|
||
parameters: { | ||
docs: { | ||
controls: { | ||
|
||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* Default head metadata | ||
* | ||
*/ | ||
export const Default = { | ||
args: defaultdata, | ||
decorators: [ | ||
(Story) => { | ||
return ` | ||
${Story()} | ||
`; | ||
}, | ||
], | ||
}; | ||
|
||
|
||
export const DEV = { | ||
args: { | ||
cdn: "DEV" | ||
}, | ||
decorators:[Story => { | ||
return ` | ||
${Story()} | ||
`; | ||
}] | ||
}; | ||
|
||
export const SQUIZ = { | ||
args: { | ||
cdn: "/__data/assets/git_bridge/0026/471752/" | ||
}, | ||
decorators:[Story => { | ||
return ` | ||
${Story()} | ||
`; | ||
}] | ||
}; | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters