create-pika-minigame 2.6.2 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pika-minigame",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "CLI to scaffold Pika mini-game projects (bare React Native 0.77)",
5
5
  "author": "Pika Team",
6
6
  "license": "MIT",
@@ -13,6 +13,10 @@ let recordingStartTime = 0;
13
13
 
14
14
  // Configure mock behavior (edit these for testing)
15
15
  const MOCK_CONFIG = {
16
+ // Mock access token for API calls (replace with real token for testing)
17
+ accessToken: '__DEV_TOKEN__',
18
+ // Mock user ID
19
+ userId: 'dev-user-123',
16
20
  // Set to a number (0-100) to always return this score, or null for random
17
21
  fixedScore: null as number | null,
18
22
  // Minimum recording time in ms (like real API)
@@ -48,6 +52,16 @@ const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
48
52
  * Edit these to test different scenarios.
49
53
  */
50
54
  export const mockHost: HostBridge = {
55
+ auth: {
56
+ getAccessToken: () => {
57
+ console.log('[MockHost] getAccessToken called');
58
+ return MOCK_CONFIG.accessToken;
59
+ },
60
+ getUserId: () => {
61
+ console.log('[MockHost] getUserId called');
62
+ return MOCK_CONFIG.userId;
63
+ },
64
+ },
51
65
  pronunciation: {
52
66
  startRecording: async () => {
53
67
  if (isRecording) {
@@ -128,6 +142,7 @@ export const mockHost: HostBridge = {
128
142
  * Mock host that always fails - useful for testing error states.
129
143
  */
130
144
  export const mockHostWithErrors: HostBridge = {
145
+ auth: mockHost.auth,
131
146
  pronunciation: {
132
147
  startRecording: async () => {
133
148
  throw new Error('Microphone permission denied');
@@ -143,6 +158,7 @@ export const mockHostWithErrors: HostBridge = {
143
158
  * Mock host with slow responses - useful for testing loading states.
144
159
  */
145
160
  export const mockHostSlow: HostBridge = {
161
+ auth: mockHost.auth,
146
162
  pronunciation: {
147
163
  startRecording: async () => {
148
164
  await delay(2000);
@@ -135,9 +135,11 @@ cat > "$BUILD_DIR/index.html" << EOF
135
135
  </html>
136
136
  EOF
137
137
 
138
- # Create vercel.json for proper routing
138
+ # Create vercel.json with project name for proper routing
139
+ # Using project name ensures each game gets its own Vercel project
139
140
  cat > "$BUILD_DIR/vercel.json" << EOF
140
141
  {
142
+ "name": "${PROJECT_NAME}",
141
143
  "headers": [
142
144
  {
143
145
  "source": "/(.*)",
@@ -1,8 +1,9 @@
1
- import React, { useState, useCallback } from 'react';
1
+ import React, { useState, useCallback, useEffect } from 'react';
2
2
  import { View, Text, StyleSheet } from 'react-native';
3
3
  import { TopBar, Button, Card } from './components';
4
4
  import { semantic, space, typography, color, radius } from './tokens';
5
5
  import { GameProps, Screen } from './types';
6
+ import { getAccessToken, getUserId } from './hooks/useHostBridge';
6
7
 
7
8
  /**
8
9
  * {{PROJECT_NAME_PASCAL}} - Main App Component
@@ -16,6 +17,18 @@ const App: React.FC<GameProps> = ({ onExit, onGameOver, host }) => {
16
17
  const [screen, setScreen] = useState<Screen>('home');
17
18
  const [score, setScore] = useState(0);
18
19
 
20
+ // Example: Get access token from host (falls back to mock in dev mode)
21
+ const accessToken = getAccessToken(host);
22
+ const userId = getUserId(host);
23
+
24
+ // Example: Use token for API calls
25
+ useEffect(() => {
26
+ if (__DEV__) {
27
+ console.log('[Game] Access Token:', accessToken ? `${accessToken.substring(0, 20)}...` : 'none');
28
+ console.log('[Game] User ID:', userId);
29
+ }
30
+ }, [accessToken, userId]);
31
+
19
32
  const handleStartGame = useCallback(() => {
20
33
  setScreen('game');
21
34
  setScore(0);
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Hook to access host bridge (auth, pronunciation, etc.)
3
+ * Falls back to mock values when running standalone (not in host app)
4
+ */
5
+
6
+ export interface HostAuth {
7
+ getAccessToken: () => string;
8
+ getUserId: () => string | null;
9
+ }
10
+
11
+ export interface HostBridge {
12
+ auth: HostAuth;
13
+ pronunciation?: {
14
+ startRecording: () => Promise<void>;
15
+ stopAndCheck: (target: string) => Promise<any>;
16
+ cancel: () => Promise<void>;
17
+ };
18
+ }
19
+
20
+ export interface GameBridgeProps {
21
+ onExit: () => void;
22
+ onGameOver?: (result: { score: number }) => void;
23
+ host: HostBridge;
24
+ }
25
+
26
+ // Mock token for standalone development - replace with your test token
27
+ const MOCK_ACCESS_TOKEN = '__DEV_TOKEN__';
28
+ const MOCK_USER_ID = 'dev-user-123';
29
+
30
+ /**
31
+ * Create a mock host bridge for standalone development
32
+ */
33
+ export function createMockHostBridge(): HostBridge {
34
+ return {
35
+ auth: {
36
+ getAccessToken: () => MOCK_ACCESS_TOKEN,
37
+ getUserId: () => MOCK_USER_ID,
38
+ },
39
+ pronunciation: {
40
+ startRecording: async () => {
41
+ console.log('[MockHost] startRecording');
42
+ },
43
+ stopAndCheck: async (target: string) => {
44
+ console.log('[MockHost] stopAndCheck:', target);
45
+ return { totalScore: 85, words: [] };
46
+ },
47
+ cancel: async () => {
48
+ console.log('[MockHost] cancel');
49
+ },
50
+ },
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Get access token from host bridge
56
+ * @param host - Host bridge from props (undefined when running standalone)
57
+ * @returns Access token string
58
+ */
59
+ export function getAccessToken(host?: HostBridge): string {
60
+ if (host?.auth?.getAccessToken) {
61
+ return host.auth.getAccessToken();
62
+ }
63
+ // Fallback for standalone development
64
+ console.warn('[useHostBridge] No host bridge, using mock token');
65
+ return MOCK_ACCESS_TOKEN;
66
+ }
67
+
68
+ /**
69
+ * Get user ID from host bridge
70
+ * @param host - Host bridge from props (undefined when running standalone)
71
+ * @returns User ID or null
72
+ */
73
+ export function getUserId(host?: HostBridge): string | null {
74
+ if (host?.auth?.getUserId) {
75
+ return host.auth.getUserId();
76
+ }
77
+ return MOCK_USER_ID;
78
+ }
@@ -18,6 +18,13 @@ export interface PronunciationResult {
18
18
  * In dev mode, this is mocked by MockHost.
19
19
  */
20
20
  export interface HostBridge {
21
+ /** Auth info from host app */
22
+ auth: {
23
+ /** Get current access token (empty if not logged in) */
24
+ getAccessToken: () => string;
25
+ /** Get current user ID (null if not logged in) */
26
+ getUserId: () => string | null;
27
+ };
21
28
  pronunciation: {
22
29
  startRecording: () => Promise<void>;
23
30
  stopAndCheck: (target: string) => Promise<PronunciationResult>;