From acc70e813b0ec20d71113409e8fcecec87611ed5 Mon Sep 17 00:00:00 2001 From: William Dutton Date: Tue, 3 Sep 2024 07:20:51 +1000 Subject: [PATCH] QOLOE-514 Expand readme, add watch ability as well as manifest namespace replacement for releases --- README.md | 53 ++++++++- esbuild.js | 46 ++++++-- package-lock.json | 195 +++++++++++++++++++++++++++++++++- package.json | 12 ++- src/accordion/manifest.json | 4 +- src/blockquote/manifest.json | 2 +- src/callout/manifest.json | 2 +- src/inpageAlert/manifest.json | 2 +- src/table/manifest.json | 2 +- src/video/manifest.json | 2 +- 10 files changed, 294 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 1e2623f..a592bc1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,52 @@ +## QGDS Bootstrap 5 - Squiz DXP Component System +This library is for dxp.squiz.cloud to generate the required html structure to use the QGDS Bootstrap5 css/javascript. -Squiz DXP Compoint System Restrictions +### Quick start + +Use namespace and version on each component. + +```bash +npm install +npm run serve +``` +Go to http://localhost:3000 + + +### Dev Deployment + + +```bash +npm run build +``` + +#### What does it do +* Overrides namespace to qgds-bs5-dev + +* Use package.json version + date/current time appended to end of version for per min to allow unique deployments into DXP CS + + +### Release Deployment + +```bash +npm run release +``` + +#### What does it do +* To update namespace to qgds-bs5 +* Use package.json version as manifest version + + +### Manifest spec + +You can find the manifest spec in the [./spec](./spec) folder. + +Please be aware one major restriction is that manifest version; +* It can't be longer than 14 characters. +* It can't have a number starting with 0, regex pattern is as follows: + + Regex: ``^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$`` + + i.e. 1.0.0 is allowed, but 1.01.1 is not, 1.1.1 is valid but 1.2.120240921418 is too long -At the time of writing (2024 Sept ) -Version: -should have a maximum length of `14`. Must match regex: ^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$ -i.e. 1.0.0 is illegal, 1.1.1 is valid but 1.2.120240921418 is too long \ No newline at end of file diff --git a/esbuild.js b/esbuild.js index 080a485..931c663 100644 --- a/esbuild.js +++ b/esbuild.js @@ -3,10 +3,13 @@ const esbuild = require('esbuild'); const fs = require('fs'); const path = require('path'); +const chokidar = require('chokidar'); // Added chokidar for file watching // Get command-line arguments const args = process.argv.slice(2); +const isLocalBuild = args.includes('--local'); const isDevBuild = args.includes('--dev'); +const isWatchBuild = args.includes('--watch'); // Directory paths const srcDir = path.join(__dirname, 'src'); @@ -19,10 +22,12 @@ const packageVersion = packageJson.version; function getTimestamp() { const now = new Date(); + const month = String(now.getMonth()); const day = String(now.getDate()); const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); - return `${day}${hours}`; + return `${month}${day}${hours}${minutes}`; } // Add a timestamp only if it's a dev build @@ -62,15 +67,18 @@ function updateManifestVersion(manifestPath) { const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8')); const oldVersion = manifest.version; const version = isDevBuild ? `${packageVersion}${getTimestamp()}` : `${packageVersion}`; + const namespace = isDevBuild ? `qgds-bs5-dev` : `qgds-bs5`; + + if (!isLocalBuild) { manifest.version = version; - fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8'); - console.log(`Updated version in ${manifestPath} to ${version}`); + manifest.namespace = namespace; + } + fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8'); + console.log(`Updated version in ${manifestPath} to ${version} with namespace ${namespace}`); } -// Get all main.cjs files -const files = findFiles(srcDir); -files.forEach((file) => { +function processFile(file) { const relativePath = path.relative(srcDir, file); const outFile = path.join(distDir, relativePath); @@ -98,7 +106,7 @@ files.forEach((file) => { entryPoints: [file], outfile: outFile, minify: !isDevBuild, - sourcemap: isDevBuild, + sourcemap: isDevBuild }); console.log(`Processed CSS ${file} to ${outFile}`); } else if (file.endsWith('.scss')) { @@ -116,4 +124,26 @@ files.forEach((file) => { // Copy non-CJS, non-CSS files copyFile(file, outFile); } -}); \ No newline at end of file +} + +console.log("clean dist") +if (fs.existsSync("./dist")) { + fs.rmSync("./dist", { recursive: true }); +} + + +const files = findFiles(srcDir); +files.forEach((file) => { + processFile(file); +}); + +if (isWatchBuild) { + chokidar.watch(srcDir, { ignoreInitial: true }).on('all', (event, filePath) => { + if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) { + console.log(`File ${event}: ${filePath}`); + processFile(filePath); + } + }); + + console.log('Watching for changes...'); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d98d9dc..a6e2a67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,23 @@ { "name": "@qld-gov-au/qgds-bootstrap5-dxp", - "version": "0.0.1", + "version": "2024.9.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@qld-gov-au/qgds-bootstrap5-dxp", - "version": "0.0.1", + "version": "2024.9.13", "license": "ISC", "dependencies": { "@qld-gov-au/qgds-bootstrap5": "^1.1.9" }, "devDependencies": { "@squiz/dxp-cli-next": "^5.19.1", + "chokidar": "^3.6.0", "esbuild": "0.23.1", "esbuild-plugin-copy": "2.1.1", - "esbuild-sass-plugin": "3.3.1" + "esbuild-sass-plugin": "3.3.1", + "npm-run-all2": "^6.2.2" } }, "node_modules/@apidevtools/json-schema-ref-parser": { @@ -8837,6 +8839,20 @@ "node": ">= 10" } }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -10932,6 +10948,12 @@ "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "dev": true }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -10985,6 +11007,15 @@ "integrity": "sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==", "dev": true }, + "node_modules/json-parse-even-better-errors": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-3.0.2.tgz", + "integrity": "sha512-fi0NG4bPjCHunUJffmLd0gxssIgkNmArMvis4iNah6Owg1MCJjWhEcDLmsK6iGkJq3tHwbDkTlce70/tmXN4cQ==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -11255,6 +11286,15 @@ "node": ">=0.12" } }, + "node_modules/memorystream": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", + "integrity": "sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==", + "dev": true, + "engines": { + "node": ">= 0.10.0" + } + }, "node_modules/merge": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/merge/-/merge-2.1.1.tgz", @@ -11430,6 +11470,76 @@ "node": ">=8" } }, + "node_modules/npm-normalize-package-bin": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-3.0.1.tgz", + "integrity": "sha512-dMxCf+zZ+3zeQZXKxmyuCKlIDPGuv8EF940xbkC4kQVDTtqoh6rJFO+JTKSA6/Rwi0getWmtuy4Itup0AMcaDQ==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/npm-run-all2": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/npm-run-all2/-/npm-run-all2-6.2.2.tgz", + "integrity": "sha512-Q+alQAGIW7ZhKcxLt8GcSi3h3ryheD6xnmXahkMRVM5LYmajcUrSITm8h+OPC9RYWMV2GR0Q1ntTUCfxaNoOJw==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.2.1", + "cross-spawn": "^7.0.3", + "memorystream": "^0.3.1", + "minimatch": "^9.0.0", + "pidtree": "^0.6.0", + "read-package-json-fast": "^3.0.2", + "shell-quote": "^1.7.3" + }, + "bin": { + "npm-run-all": "bin/npm-run-all/index.js", + "npm-run-all2": "bin/npm-run-all/index.js", + "run-p": "bin/run-p/index.js", + "run-s": "bin/run-s/index.js" + }, + "engines": { + "node": "^14.18.0 || ^16.13.0 || >=18.0.0", + "npm": ">= 8" + } + }, + "node_modules/npm-run-all2/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/npm-run-all2/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/npm-run-all2/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -11660,6 +11770,15 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -11774,6 +11893,18 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pidtree": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.6.0.tgz", + "integrity": "sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==", + "dev": true, + "bin": { + "pidtree": "bin/pidtree.js" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", @@ -12112,6 +12243,19 @@ "node": ">=0.8" } }, + "node_modules/read-package-json-fast": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-3.0.2.tgz", + "integrity": "sha512-0J+Msgym3vrLOUB3hzQCuZHII0xkNGCtz/HJH9xZshwv9DbDwkw1KaE3gx/e2J5rpEY5rtOy6cyhKOPrkP7FZw==", + "dev": true, + "dependencies": { + "json-parse-even-better-errors": "^3.0.0", + "npm-normalize-package-bin": "^3.0.0" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -12974,6 +13118,36 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "dev": true }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/shell-quote": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", + "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/side-channel": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", @@ -13823,6 +13997,21 @@ "defaults": "^1.0.3" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/which-boxed-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", diff --git a/package.json b/package.json index 6644368..324e010 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qld-gov-au/qgds-bootstrap5-dxp", - "version": "2024.19.1", + "version": "1.0.2", "description": "SQUIZ DXP Component System components for Squiz CMS to generate html for qgds-bootstrap5 library", "repository": { "type": "git", @@ -12,9 +12,13 @@ "login": "dxp-next auth login", "lint": "echo 'fix lint me'", "build": "node esbuild.js --dev", + "build:local": "node esbuild.js --local", + "watch": "node esbuild.js --dev --watch", "release": "node esbuild.js", "test": "echo 'no unit tests built yet'", - "serve": "npm run build && node ./node_modules/@squiz/dxp-cli-next/bin/dxp.js cmp dev-ui ./dist" + "serve:squiz-dev-ui": "node ./node_modules/@squiz/dxp-cli-next/bin/dxp.js cmp dev-ui ./dist", + "serve": "npm run build:local && npm run serve:squiz-dev-ui", + "serve:watch": "npm-run-all --parallel --race watch serve:squiz-dev-ui" }, "keywords": [], "author": "", @@ -26,7 +30,9 @@ "devDependencies": { "@squiz/dxp-cli-next": "^5.19.1", "esbuild": "0.23.1", + "chokidar": "^3.6.0", "esbuild-plugin-copy": "2.1.1", - "esbuild-sass-plugin": "3.3.1" + "esbuild-sass-plugin": "3.3.1", + "npm-run-all2": "6.2.2" } } diff --git a/src/accordion/manifest.json b/src/accordion/manifest.json index 13fe1d1..e12acdd 100644 --- a/src/accordion/manifest.json +++ b/src/accordion/manifest.json @@ -8,10 +8,10 @@ "id": "queue", "color": { "type": "hex", - "value": "#ae81ff" + "value": "#ae71ff" } }, - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "mainFunction": "main", "functions": [ { diff --git a/src/blockquote/manifest.json b/src/blockquote/manifest.json index 041809b..72ec495 100644 --- a/src/blockquote/manifest.json +++ b/src/blockquote/manifest.json @@ -4,7 +4,7 @@ "name": "blockquote", "displayName": "Blockquote Component", "description": "QGDS Bootstrap 5 - Blockquote Component", - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "mainFunction": "main", "functions": [ { diff --git a/src/callout/manifest.json b/src/callout/manifest.json index f539333..e8b61d1 100644 --- a/src/callout/manifest.json +++ b/src/callout/manifest.json @@ -4,7 +4,7 @@ "name": "callout", "displayName": "Callout Component", "description": "QGDS Bootstrap 5 - Callout Component", - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "mainFunction": "main", "functions": [ { diff --git a/src/inpageAlert/manifest.json b/src/inpageAlert/manifest.json index e5d192e..085fac4 100644 --- a/src/inpageAlert/manifest.json +++ b/src/inpageAlert/manifest.json @@ -1,7 +1,7 @@ { "$schema": "http://localhost:3000/schemas/v1.json", "name": "inpagealert", - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "displayName": "Inpage Alert Component", "description": "QGDS Bootstrap 5 - Inpage alert Component", "version": "1.0.0", diff --git a/src/table/manifest.json b/src/table/manifest.json index 527bb9a..e922f8b 100644 --- a/src/table/manifest.json +++ b/src/table/manifest.json @@ -4,7 +4,7 @@ "name": "table", "displayName": "Table Component", "description": "QGDS Bootstrap 5 - Table Component", - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "mainFunction": "main", "functions": [ { diff --git a/src/video/manifest.json b/src/video/manifest.json index 3e5537f..c7afaf8 100644 --- a/src/video/manifest.json +++ b/src/video/manifest.json @@ -4,7 +4,7 @@ "name": "video", "displayName": "Video Component", "description": "QGDS Bootstrap 5 - Video Component", - "namespace": "qgds-bs5-dev", + "namespace": "qgds-bs5-local", "mainFunction": "main", "functions": [ {