Files

2.8 KiB

@zos-apps/config

Shared configuration, types, and hooks for zOS applications. Eliminates duplicate code across 70+ apps.

Installation

npm install @zos-apps/config

Features

  • Build Configuration: Shared tsconfig, tsup, and ESLint configs
  • TypeScript Types: Common types for app props, game state, coordinates
  • React Hooks: Reusable hooks for keyboard, game loops, storage, timers

Usage

Types

import type { AppProps, GameState, Point, Direction, KeyMap } from '@zos-apps/config';

const MyApp: React.FC<AppProps> = ({ onClose }) => {
  return <div>...</div>;
};

Hooks

import { 
  useKeyboard,
  useGameLoop,
  useHighScore,
  useGameState,
  useTimer,
  useLocalStorage,
  useAnimationFrame,
  useGrid,
} from '@zos-apps/config';

useKeyboard

useKeyboard({
  ArrowUp: 'up', ArrowDown: 'down',
  ' ': 'pause',
}, (action) => {
  if (action === 'pause') togglePause();
  else move(action);
}, { enabled: !gameOver });

useGameLoop

useGameLoop(() => {
  updateGame();
}, 100, isPlaying);

useHighScore

const { highScore, updateHighScore } = useHighScore('my-game');
if (score > highScore) updateHighScore(score);

useGameState

const { 
  score, isPaused, isGameOver,
  start, pause, togglePause, gameOver, reset, addScore 
} = useGameState();

useTimer

const { elapsed, isRunning, start, stop, reset } = useTimer();

useLocalStorage

const [settings, setSettings] = useLocalStorage('settings', defaultSettings);

useGrid

const { grid, setCell, getCell, fill, clear } = useGrid(10, 20, null);

Build Configuration

tsconfig.json:

{
  "extends": "@zos-apps/config/tsconfig"
}

tsup.config.ts:

import { createConfig } from '@zos-apps/config/tsup';
export default createConfig();

// With customization:
export default createConfig({
  minify: false,
  entry: ['src/index.tsx', 'src/worker.ts'],
});

eslint.config.js:

import config from '@zos-apps/config/eslint';
export default config;

Available Types

Type Description
AppProps Standard props for all zOS apps
AppComponent Type for app components
GameState Common game state interface
Direction 4-way direction type
Direction8 8-way direction type
Point 2D coordinate { x, y }
Size Dimensions { width, height }
Rect Bounding rectangle
KeyMap<T> Keyboard mapping type
Grid<T> 2D array type
HighScoreEntry High score with metadata
OverlayState Pause/game over overlay state
TimerState Timer state
DifficultyLevel Difficulty preset

License

MIT