Skip to content

Commit 68117e6

Browse files
committed
chore: Add prettier, mirroring the stackable-apps configuration
Scoped away from the inherited upstream src/ files until the planned upstream re-sync, so the diff against antora-ui-default stays readable. prettier --check runs as part of npm run lint (and therefore in CI). knip is deliberately not added: handlebars templates and classic browser scripts have no import graph, and most dependencies are referenced from playbook YAML or css, so it would need to ignore nearly everything to stay quiet.
1 parent a67c1e6 commit 68117e6

8 files changed

Lines changed: 110 additions & 78 deletions

File tree

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
node_modules/
3+
# inherited upstream files stay untouched until the upstream re-sync,
4+
# so the diff against antora-ui-default remains readable
5+
src/

ui/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": false,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100
6+
}

ui/build.mjs

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
// The scripts are consumed as classic <script src> tags, so every js entry is
66
// built as a self-contained IIFE in its own vite pass (rollup cannot code-split
77
// iife output, which is exactly what we want here).
8-
import { build } from 'vite'
9-
import { copyFileSync, cpSync, createWriteStream, mkdirSync, readdirSync, rmSync } from 'node:fs'
10-
import { resolve, basename } from 'node:path'
11-
import { ZipArchive } from 'archiver'
8+
import { build } from 'vite';
9+
import { copyFileSync, cpSync, createWriteStream, mkdirSync, readdirSync, rmSync } from 'node:fs';
10+
import { resolve, basename } from 'node:path';
11+
import { ZipArchive } from 'archiver';
1212

13-
const root = import.meta.dirname
14-
const src = resolve(root, 'src')
15-
const staged = resolve(root, 'build/ui')
13+
const root = import.meta.dirname;
14+
const src = resolve(root, 'src');
15+
const staged = resolve(root, 'build/ui');
1616

1717
// js/site.js is the concatenation of the numbered scripts, in order. They are
1818
// self-contained IIFEs, so a virtual entry with side-effect imports preserves
1919
// the behaviour.
2020
const siteScripts = readdirSync(resolve(src, 'js'))
2121
.filter((name) => /^\d+-.+\.js$/.test(name))
22-
.sort()
23-
const virtualSiteId = 'virtual:site.js'
22+
.sort();
23+
const virtualSiteId = 'virtual:site.js';
2424

2525
// Every js/vendor/*.bundle.js becomes js/vendor/<name>.js with its CommonJS
2626
// requires bundled in (this replaces browserify).
@@ -30,11 +30,11 @@ const jsEntries = [
3030
.filter((name) => name.endsWith('.bundle.js'))
3131
.map((name) => ({
3232
name: `vendor/${basename(name, '.bundle.js')}`,
33-
input: resolve(src, 'js', 'vendor', name),
34-
})),
35-
]
33+
input: resolve(src, 'js', 'vendor', name)
34+
}))
35+
];
3636

37-
function config (overrides) {
37+
function config(overrides) {
3838
return {
3939
configFile: false,
4040
root,
@@ -49,71 +49,75 @@ function config (overrides) {
4949
load: (id) =>
5050
id === virtualSiteId
5151
? siteScripts.map((name) => `import '${resolve(src, 'js', name)}'`).join('\n')
52-
: undefined,
53-
},
52+
: undefined
53+
}
5454
],
55-
...overrides,
56-
}
55+
...overrides
56+
};
5757
}
5858

59-
rmSync(resolve(root, 'build'), { recursive: true, force: true })
59+
rmSync(resolve(root, 'build'), { recursive: true, force: true });
6060

6161
for (const entry of jsEntries) {
62-
await build(config({
62+
await build(
63+
config({
64+
build: {
65+
outDir: staged,
66+
emptyOutDir: false,
67+
rollupOptions: {
68+
input: entry.input,
69+
output: {
70+
format: 'iife',
71+
entryFileNames: `js/${entry.name}.js`,
72+
inlineDynamicImports: true
73+
}
74+
}
75+
}
76+
})
77+
);
78+
}
79+
80+
await build(
81+
config({
6382
build: {
6483
outDir: staged,
6584
emptyOutDir: false,
85+
assetsInlineLimit: 0,
6686
rollupOptions: {
67-
input: entry.input,
87+
input: resolve(src, 'css', 'site.css'),
6888
output: {
69-
format: 'iife',
70-
entryFileNames: `js/${entry.name}.js`,
71-
inlineDynamicImports: true,
72-
},
73-
},
74-
},
75-
}))
76-
}
77-
78-
await build(config({
79-
build: {
80-
outDir: staged,
81-
emptyOutDir: false,
82-
assetsInlineLimit: 0,
83-
rollupOptions: {
84-
input: resolve(src, 'css', 'site.css'),
85-
output: {
86-
assetFileNames: (asset) => {
87-
const name = asset.names[0] ?? ''
88-
if (name === 'site.css') return 'css/site.css'
89-
if (/^fa-.+\.(woff2?|ttf)$/.test(name)) return 'webfonts/[name][extname]'
90-
if (/\.(woff2?|ttf)$/.test(name)) return 'font/[name][extname]'
91-
if (/\.(svg|png|gif|ico|jpg)$/.test(name)) return 'img/[name][extname]'
92-
return 'css/[name][extname]'
93-
},
94-
},
95-
},
96-
},
97-
}))
89+
assetFileNames: (asset) => {
90+
const name = asset.names[0] ?? '';
91+
if (name === 'site.css') return 'css/site.css';
92+
if (/^fa-.+\.(woff2?|ttf)$/.test(name)) return 'webfonts/[name][extname]';
93+
if (/\.(woff2?|ttf)$/.test(name)) return 'font/[name][extname]';
94+
if (/\.(svg|png|gif|ico|jpg)$/.test(name)) return 'img/[name][extname]';
95+
return 'css/[name][extname]';
96+
}
97+
}
98+
}
99+
}
100+
})
101+
);
98102

99103
// webfonts/ ships as-is: the Font Awesome css references it with
100104
// runtime-relative urls that vite cannot (and must not) rewrite
101105
for (const dir of ['helpers', 'layouts', 'partials', 'img', 'webfonts']) {
102-
cpSync(resolve(src, dir), resolve(staged, dir), { recursive: true })
106+
cpSync(resolve(src, dir), resolve(staged, dir), { recursive: true });
103107
}
104108
for (const file of ['NOTICE', 'LICENSE']) {
105-
copyFileSync(resolve(root, file), resolve(staged, file))
109+
copyFileSync(resolve(root, file), resolve(staged, file));
106110
}
107111

108-
const zipPath = resolve(root, 'build/ui-bundle.zip')
109-
mkdirSync(resolve(root, 'build'), { recursive: true })
112+
const zipPath = resolve(root, 'build/ui-bundle.zip');
113+
mkdirSync(resolve(root, 'build'), { recursive: true });
110114
await new Promise((resolvePromise, reject) => {
111-
const output = createWriteStream(zipPath)
112-
const archive = new ZipArchive()
113-
output.on('close', resolvePromise)
114-
archive.on('error', reject)
115-
archive.pipe(output)
116-
archive.directory(staged, false)
117-
archive.finalize()
118-
})
119-
console.log(`bundled ${zipPath}`)
115+
const output = createWriteStream(zipPath);
116+
const archive = new ZipArchive();
117+
output.on('close', resolvePromise);
118+
archive.on('error', reject);
119+
archive.pipe(output);
120+
archive.directory(staged, false);
121+
archive.finalize();
122+
});
123+
console.log(`bundled ${zipPath}`);

ui/eslint.config.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
1+
import js from '@eslint/js';
2+
import globals from 'globals';
33

44
export default [
55
js.configs.recommended,
66
{
7-
ignores: ['build/**', 'node_modules/**'],
7+
ignores: ['build/**', 'node_modules/**']
88
},
99
{
1010
files: ['src/js/**/*.js', 'src/helpers/*.js'],
1111
ignores: ['src/js/vendor/*.bundle.js'],
1212
languageOptions: {
1313
sourceType: 'commonjs',
14-
globals: { ...globals.browser, ...globals.commonjs },
15-
},
14+
globals: { ...globals.browser, ...globals.commonjs }
15+
}
1616
},
1717
{
1818
files: ['src/js/vendor/*.bundle.js'],
1919
languageOptions: {
2020
sourceType: 'module',
21-
globals: globals.browser,
22-
},
21+
globals: globals.browser
22+
}
2323
},
2424
{
2525
files: ['build.mjs', 'vite.config.js'],
2626
languageOptions: {
27-
globals: globals.node,
28-
},
29-
},
30-
]
27+
globals: globals.node
28+
}
29+
}
30+
];

ui/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict'
1+
'use strict';
22

33
// This placeholder script allows this package to be discovered using require.resolve.
44
// It may be used in the future to export information about the files in this UI.

ui/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"type": "module",
77
"scripts": {
88
"bundle": "node build.mjs",
9-
"lint": "eslint . && stylelint 'src/css/*.css'"
9+
"lint": "eslint . && stylelint 'src/css/*.css' && prettier --check .",
10+
"format": "prettier --write ."
1011
},
1112
"engines": {
1213
"node": ">= 24.0.0"
@@ -24,6 +25,7 @@
2425
"eslint": "^10.7.0",
2526
"globals": "^17.7.0",
2627
"highlight.js": "^10.7",
28+
"prettier": "^3.9.5",
2729
"stylelint": "^17.14.0",
2830
"stylelint-config-standard": "^40.0.0",
2931
"vite": "^8.1.4"

ui/renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"local>stackabletech/.github:renovate-config"
5-
]
3+
"extends": ["local>stackabletech/.github:renovate-config"]
64
}

0 commit comments

Comments
 (0)