Skip to content

Commit

Permalink
chore: show version and commit in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
gera2ld committed Mar 9, 2024
1 parent 6bc5980 commit 7e10a12
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 8 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"build:js": "NODE_ENV=production rollup -c",
"build:types": "tsc -p tsconfig.prod.json",
"build": "run-s ci clean build:*",
"demo:cp": "cp src/demo/* dist",
"demo": "run-s build:js demo:cp"
"demo:dev": "DEMO=1 run-s demo:cp dev",
"demo:build": "DEMO=1 run-s build",
"demo:cp": "cp src/demo/index.html dist",
"demo": "run-s demo:build demo:cp"
},
"unpkg": "dist/index.js",
"jsdelivr": "dist/index.js",
Expand Down Expand Up @@ -47,7 +49,8 @@
"@gera2ld/plaid-test": "~2.6.0",
"del-cli": "^5.1.0",
"husky": "^9.0.11",
"jest-environment-jsdom": "^29.7.0"
"jest-environment-jsdom": "^29.7.0",
"vue": "^3.4.21"
},
"jest": {
"testEnvironment": "jsdom"
Expand Down
96 changes: 96 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 35 additions & 3 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { defineExternal, definePlugins } from '@gera2ld/plaid-rollup';
import { execSync } from 'node:child_process';
import { defineConfig } from 'rollup';
import pkg from './package.json' assert { type: 'json' };

const banner = `/*! ${pkg.name} v${pkg.version} | ${pkg.license} License */`;
const commit = execSync('git rev-parse --short HEAD').toString().trim();

const bundleOptions = {
extend: true,
esModule: false,
};
const values = {
'process.env.VERSION': JSON.stringify(pkg.version),
'process.env.COMMIT': JSON.stringify(commit),
};
const external = defineExternal(
Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }),
);

export default defineConfig([
{
Expand All @@ -17,10 +26,10 @@ export default defineConfig([
minimize: false,
replaceValues: {
'process.env.VM': false,
'process.env.VERSION': JSON.stringify(pkg.version),
...values,
},
}),
external: defineExternal(Object.keys(pkg.dependencies)),
external,
output: {
format: 'esm',
file: `dist/index.mjs`,
Expand All @@ -34,7 +43,7 @@ export default defineConfig([
minimize: false,
replaceValues: {
'process.env.VM': true,
'process.env.VERSION': JSON.stringify(pkg.version),
...values,
},
}),
output: {
Expand All @@ -45,4 +54,27 @@ export default defineConfig([
...bundleOptions,
},
},
...(process.env.DEMO
? [
{
input: 'src/demo/app.js',
plugins: definePlugins({
esm: true,
minimize: false,
replaceValues: {
'process.env.VM': true,
...values,
},
}),
external,
output: {
format: 'iife',
file: 'dist/app.js',
globals: {
vue: 'Vue',
},
},
},
]
: []),
]);
4 changes: 3 additions & 1 deletion src/demo/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { createApp, nextTick, ref, watch, onMounted } = Vue;
import { createApp, nextTick, ref, watch, onMounted } from 'vue';

createApp({
setup() {
const shortcuts = ref(`\
Expand Down Expand Up @@ -97,6 +98,7 @@ ArrowUp ArrowUp ArrowDown ArrowDown ArrowLeft ArrowRight ArrowLeft ArrowRight B

return {
version: VM.shortcut.version,
commit: process.env.COMMIT,
shortcuts,
sequence,
keyTriggered,
Expand Down
9 changes: 8 additions & 1 deletion src/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
<body>
<div id="app" class="max-w-screen-lg mx-auto px-2" un-cloak>
<h1 class="text-center"><em>@violentmonkey/shortcut</em> Playground</h1>
<p class="text-right text-gray-400 text-sm">Version: {{version}}</p>
<p class="text-right text-gray-400 text-sm">
Version: {{version}}
<a
class="text-blue-400"
:href="`https://github.com/violentmonkey/vm-shortcut/commit/${commit}`"
v-text="commit"
></a>
</p>
<h2>Triggering a Shortcut</h2>
<div class="flex mb-2">
<div class="flex-1">
Expand Down

0 comments on commit 7e10a12

Please sign in to comment.