Skip to content

Commit

Permalink
fix: deployment to gh-pages, list of versions now published in versio…
Browse files Browse the repository at this point in the history
…ns.json
  • Loading branch information
divdavem committed Aug 30, 2023
1 parent 0754263 commit bac770c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ jobs:
working-directory: gh-pages
run: |
if [ -n "$VERSION" ]; then
export DOC_PATH="v$(node scripts/versionDocFolder.js "$VERSION")"
export DOC_PATH="v$(node ../scripts/versionDocFolder.js "$VERSION")"
else
export DOC_PATH="${{ inputs.docPath }}"
fi
rm -rf "$DOC_PATH"
cp -a ../demo/dist "$DOC_PATH"
rm -f latest && ln -s v$(npx semver v* | tail -1) latest
node ../scripts/updateVersionsList.js
git add .
git commit --allow-empty -a -m "$DOC_PATH from ${{ github.sha }}"
git push origin gh-pages
12 changes: 12 additions & 0 deletions demo/scripts/emitFile.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {Plugin} from 'vite';
import type {EmittedFile} from 'rollup';

export const emitFile = (emittedFile: EmittedFile): Plugin => {
return {
name: 'emit-file',
apply: 'build',
async buildStart(info) {
this.emitFile(emittedFile);
},
};
};
13 changes: 11 additions & 2 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import pkg from '../core/package.json';
import {copySamples} from './scripts/copySamples.plugin';
import {docExtractor} from './scripts/doc.plugin';
import {includeSamples} from './scripts/includeSamples.plugin';
import {emitFile} from './scripts/emitFile.plugin';

const proxy: Record<string, string | ProxyOptions> = {
'/angular/samples': {
Expand All @@ -22,6 +23,8 @@ const proxy: Record<string, string | ProxyOptions> = {
},
};

const version = JSON.stringify((pkg as any).version ?? '0.0.0');

// https://vitejs.dev/config/
export default defineConfig({
envDir: path.join(__dirname, 'env'),
Expand All @@ -36,8 +39,14 @@ export default defineConfig({
port: 4000,
proxy: {},
},
plugins: [copySamples(), includeSamples(), sveltekit(), docExtractor()],
plugins: [
copySamples(),
includeSamples(),
sveltekit(),
docExtractor(),
emitFile({type: 'asset', fileName: 'version.json', name: 'version.json', source: version}),
],
define: {
'import.meta.env.AGNOSUI_VERSION': JSON.stringify((pkg as any).version ?? '0.0.0'),
'import.meta.env.AGNOSUI_VERSION': version,
},
});
29 changes: 29 additions & 0 deletions scripts/updateVersionsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require('fs');
const path = require('path');
const semver = require('semver');

const ghPagesFolder = process.cwd();
const availableVersions = fs
.readdirSync(ghPagesFolder)
.filter((folder) => folder.startsWith('v') && fs.statSync(path.join(ghPagesFolder, folder)).isDirectory())
.map((folder) => {
const version = JSON.parse(fs.readFileSync(path.join(ghPagesFolder, folder, 'version.json'), 'utf8'));
return {
folder,
version,
};
});

availableVersions.sort((a, b) => -semver.compareBuild(a.version, b.version));
fs.writeFileSync('versions.json', JSON.stringify(availableVersions));
try {
fs.unlinkSync('latest');
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
}
fs.symlinkSync(availableVersions[0].folder, 'latest');

console.log('Ordered list of available versions:');
console.log(availableVersions);

0 comments on commit bac770c

Please sign in to comment.