mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: implemented dist package.json
This commit is contained in:
1 parent
e34a6c6e4b
commit
4c2b0253de
7 files changed
+46
-29
No files matched your search
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"main": "server.js",
|
"main": "server.cjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --enable-source-maps server.cjs"
|
"start": "node --enable-source-maps --trace-warnings server.cjs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+25
-18
@@ -1,5 +1,5 @@
|
|||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
import { mkdirSync, rmSync, writeFileSync } from 'fs';
|
import { copyFile, mkdir, rm, writeFile } from 'fs/promises';
|
||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
|
|
||||||
const isProd = !argv.includes('--dev');
|
const isProd = !argv.includes('--dev');
|
||||||
@@ -9,21 +9,21 @@ const buildServer = argv.includes('--build=server') | buildAll;
|
|||||||
|
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
// only remove in production to ensure no time is wasted in dev
|
// only remove in production to ensure no time is wasted in dev
|
||||||
console.log('Removing dist...');
|
console.log('🟡 Removing dist...');
|
||||||
rmSync('dist', { recursive: true, force: true });
|
await rm('dist', { recursive: true, force: true });
|
||||||
|
console.log('✅ Dist removed');
|
||||||
|
|
||||||
console.log('Creating dist...');
|
console.log('🟡 Creating dist...');
|
||||||
mkdirSync('dist');
|
await mkdir('dist');
|
||||||
|
console.log('✅ Dist created');
|
||||||
|
|
||||||
console.log('Caching tankopedia...');
|
console.log('🟡 Caching tankopedia...');
|
||||||
fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
fetch('https://www.blitzstars.com/bs-tankopedia.json')
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((tankopedia) => {
|
.then((tankopedia) => writeFile('./dist/tankopedia.json', tankopedia))
|
||||||
writeFileSync('./dist/tankopedia.json', tankopedia);
|
.then(() => console.log('✅ Tankopedia cached'));
|
||||||
console.log('Tankopedia cached');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Caching tank averages...');
|
console.log('🟡 Caching tank averages...');
|
||||||
fetch('https://www.blitzstars.com/api/tankaverages.json')
|
fetch('https://www.blitzstars.com/api/tankaverages.json')
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((individualTankAverages) => {
|
.then((individualTankAverages) => {
|
||||||
@@ -33,10 +33,17 @@ if (isProd) {
|
|||||||
tankAverages[individualTankAverage.tank_id] = individualTankAverage;
|
tankAverages[individualTankAverage.tank_id] = individualTankAverage;
|
||||||
});
|
});
|
||||||
|
|
||||||
writeFileSync('./dist/tankaverages.json', JSON.stringify(tankAverages));
|
return writeFile(
|
||||||
|
'./dist/tankaverages.json',
|
||||||
|
JSON.stringify(tankAverages),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then(() => console.log('✅ Tank averages cached'));
|
||||||
|
|
||||||
console.log('Tank averages cached');
|
console.log('🟡 Copying package.json...');
|
||||||
});
|
copyFile('package.dist.json', 'dist/package.json').then(() =>
|
||||||
|
console.log('✅ package.json copied'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commonOptions = {
|
const commonOptions = {
|
||||||
@@ -56,25 +63,25 @@ const commonOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (buildBot) {
|
if (buildBot) {
|
||||||
console.log('Building bot...');
|
console.log('🟡 Building bot...');
|
||||||
build({
|
build({
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
|
|
||||||
entryPoints: ['src/bot.ts'],
|
entryPoints: ['src/bot.ts'],
|
||||||
outfile: 'dist/bot.cjs',
|
outfile: 'dist/bot.cjs',
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('Bot built');
|
console.log('✅ Bot built');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildServer) {
|
if (buildServer) {
|
||||||
console.log('Building server...');
|
console.log('🟡 Building server...');
|
||||||
build({
|
build({
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
|
|
||||||
entryPoints: ['src/server.ts'],
|
entryPoints: ['src/server.ts'],
|
||||||
outfile: 'dist/server.cjs',
|
outfile: 'dist/server.cjs',
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('Server built');
|
console.log('✅ Server built');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ import { AccountInfo } from '../types/accountInfo.js';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: addStatTypeSubCommandGroups(
|
command: addStatTypeSubCommandGroups(
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
import { theme } from '../../../stitches.config.js';
|
import { theme } from '../../../stitches.config.js';
|
||||||
import { MarginProps as RootMarginProps } from './Root.js';
|
import { MarginInputProps } from './Root.js';
|
||||||
|
|
||||||
export enum MarginOrientation {
|
export enum MarginOrientation {
|
||||||
Vertical,
|
Vertical,
|
||||||
Horizontal,
|
Horizontal,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MarginProps extends RootMarginProps {
|
export interface MarginProps extends MarginInputProps {
|
||||||
verticalSeparations: number;
|
verticalSeparations: number;
|
||||||
orientation?: MarginOrientation;
|
orientation?: MarginOrientation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Margin, MarginOrientation } from './Margin.js';
|
|||||||
export const GRAPH_WIDTH = 544;
|
export const GRAPH_WIDTH = 544;
|
||||||
export const GRAPH_HEIGHT = 320;
|
export const GRAPH_HEIGHT = 320;
|
||||||
|
|
||||||
export interface MarginProps {
|
export interface MarginInputProps {
|
||||||
min: number;
|
min: number;
|
||||||
max: number;
|
max: number;
|
||||||
suffix?: string;
|
suffix?: string;
|
||||||
@@ -15,8 +15,8 @@ export interface MarginProps {
|
|||||||
|
|
||||||
export interface RootProps {
|
export interface RootProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
verticalMargin?: MarginProps;
|
verticalMargin?: MarginInputProps;
|
||||||
horizontalMargin?: MarginProps;
|
horizontalMargin?: MarginInputProps;
|
||||||
separations?: number;
|
separations?: number;
|
||||||
xMinLabel: string;
|
xMinLabel: string;
|
||||||
xMaxLabel: string;
|
xMaxLabel: string;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export default function throwError(message: string, cause: string) {
|
export default function throwError(message: string, cause?: string) {
|
||||||
return new Error(message, { cause });
|
return new Error(message, { cause });
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,31 @@
|
|||||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||||
import { CYCLIC_API } from '../../../constants/cyclic.js';
|
import { CYCLIC_API } from '../../../constants/cyclic.js';
|
||||||
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
|
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
|
||||||
|
import throwError from '../../../core/node/throwError.js';
|
||||||
import { commands } from '../index.js';
|
import { commands } from '../index.js';
|
||||||
|
|
||||||
export default async function handleButton(
|
export default async function handleButton(
|
||||||
interaction: ButtonInteraction<CacheType>,
|
interaction: ButtonInteraction<CacheType>,
|
||||||
) {
|
) {
|
||||||
|
await interaction.deferUpdate();
|
||||||
|
|
||||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
||||||
const commandName = url.pathname.split('/')[1];
|
const commandName = url.pathname.split('/')[1];
|
||||||
const button = commands[commandName]?.button;
|
const button = commands[commandName]?.button;
|
||||||
|
|
||||||
if (!button) {
|
if (!button) {
|
||||||
console.error(`Button handler not found for "${commandName}"`);
|
throwError(`Button handler not found for "${commandName}"`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.message.interaction?.user.id !== interaction.user.id) {
|
||||||
|
interaction.followUp({
|
||||||
|
ephemeral: true,
|
||||||
|
content: 'You are not the author of this command.',
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.deferUpdate();
|
|
||||||
await interaction.message.edit(
|
await interaction.message.edit(
|
||||||
await normalizeInteractionReturnable(button(interaction)),
|
await normalizeInteractionReturnable(button(interaction)),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user