-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathrollup.config.helper.mjs
More file actions
97 lines (85 loc) · 2.83 KB
/
rollup.config.helper.mjs
File metadata and controls
97 lines (85 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import image from '@rollup/plugin-image';
import postcss from 'rollup-plugin-postcss';
import postcssPresetEnv from 'postcss-preset-env';
import postcssLit from 'rollup-plugin-postcss-lit';
import { description, repository } from './package.json';
// pad string to target width with spaces to center it
function pad(str, targetWidth) {
let width = str.length;
let totalPadding = Math.round(targetWidth - width);
if (totalPadding < 0) totalPadding = 0;
let leftPadding = Math.floor(totalPadding / 2);
let rightPadding = Math.ceil(totalPadding / 2);
let result = ' '.repeat(leftPadding) + str + ' '.repeat(rightPadding);
// Final safety net — ensure not under target
while (result.length < targetWidth) {
result = ' ' + result + ' ';
}
// Avoid overshooting (rare edge case)
while (result.length > targetWidth) {
result = result.slice(1, -1);
}
return result;
}
function padByWidth(str) {
const strWidth = str.length;
// add 3 spaces to each side
const targetWidth = strWidth + 8;
return pad(str, targetWidth);
}
const styles = {
gradient: '#4b6cb7, #182848',
border: '#4b6cb7',
};
export function logCardInfo(version) {
const part1 = '🌒 LUNAR-PHASE-CARD 🌃';
const part2 = `· ${version} ·`;
const { gradient, border } = styles;
const part1Gradient = `background: linear-gradient(90deg, ${gradient});color: #ffffff;`;
const part2Gradient = `background: linear-gradient(-90deg, ${gradient});color: #FFFFFF90;`;
const sharedStyle = `padding: 2px 0px; border: 0.5px solid; text-shadow: 0 2px 2px rgba(1, 1, 1, 0.2); font-family: Roboto,Verdana,Geneva,sans-serif; border-color: ${border};`;
const part1Style = `${part1Gradient}${sharedStyle}border-right: none; border-radius: 6px 0 0 6px;`;
const part2Style = `${part2Gradient}${sharedStyle};border-left: none; border-radius: 0 6px 6px 0;`;
const repo = `Github: ${repository.url}`;
const sponsor = 'If you like the card, consider supporting the developer: https://github.com/sponsors/ngocjohn';
return `
console.groupCollapsed(
"%c${padByWidth(part1)}%c${padByWidth(part2)}",
'${part1Style}',
'${part2Style}',
);
console.info('${description}');
console.info('${repo}');
console.info('${sponsor}');
console.groupEnd();
`;
}
export const defaultPlugins = [
nodeResolve({
preferBuiltins: false,
}),
json(),
commonjs(),
image(),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
}),
postcss({
plugins: [
postcssPresetEnv({
stage: 1,
features: {
'nesting-rules': true,
},
}),
],
extract: false,
inject: false,
}),
postcssLit(),
];