create-pika-minigame 2.6.2 → 2.6.4

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/bin/cli.js CHANGED
@@ -274,6 +274,7 @@ ${colors.reset}
274
274
  'typescript': '~5.3.0',
275
275
  'serve': '^14.2.0',
276
276
  'eslint': '^8.0.0',
277
+ 'pika-minigame-sdk': '^1.0.0',
277
278
  };
278
279
 
279
280
  // Add build and deploy scripts (use pika-build.sh for MF compatibility)
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.4",
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": "/(.*)",
@@ -2,8 +2,8 @@
2
2
  #
3
3
  # Pika Mini-Game Build Script
4
4
  #
5
- # Builds the mini-game using the Pika host's build environment to ensure
6
- # Module Federation compatibility.
5
+ # Builds the mini-game for Module Federation compatibility.
6
+ # Uses pika-minigame-sdk if installed, otherwise falls back to host repo.
7
7
  #
8
8
  # Usage:
9
9
  # ./scripts/pika-build.sh ios
@@ -16,28 +16,44 @@ PLATFORM=${1:-ios}
16
16
 
17
17
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
18
18
  PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
19
- PROJECT_NAME=$(node -e "console.log(require('./app.json').name)" 2>/dev/null || basename "$PROJECT_DIR" | sed 's/-/_/g')
20
-
21
- # Pika host repo - contains the correct node_modules
22
- # Change this to your robotapp location or set PIKA_HOST_DIR env var
23
- PIKA_HOST_DIR="${PIKA_HOST_DIR:-$HOME/robotapp}"
19
+ PROJECT_NAME=$(node -e "console.log(require('./package.json').name || require('./app.json').name)" 2>/dev/null || basename "$PROJECT_DIR" | sed 's/-/_/g')
20
+ SCOPE=$(echo "$PROJECT_NAME" | sed 's/-/_/g' | tr '[:upper:]' '[:lower:]')
24
21
 
25
22
  echo "🎮 Pika Mini-Game Builder"
26
23
  echo "========================="
27
- echo "Project: ${PROJECT_NAME}"
24
+ echo "Project: ${PROJECT_NAME} (scope: ${SCOPE})"
28
25
  echo "Platform: ${PLATFORM}"
29
- echo "Host dir: ${PIKA_HOST_DIR}"
30
26
  echo ""
31
27
 
28
+ # Method 1: Check for pika-minigame-sdk (preferred)
29
+ SDK_PATH="${PROJECT_DIR}/node_modules/pika-minigame-sdk"
30
+ if [ -d "$SDK_PATH" ]; then
31
+ echo "📦 Using pika-minigame-sdk"
32
+
33
+ # Set public path if MF_PUBLIC_PATH is set
34
+ PUBLIC_PATH_ARG=""
35
+ if [ -n "$MF_PUBLIC_PATH" ]; then
36
+ PUBLIC_PATH_ARG="--public-path $MF_PUBLIC_PATH"
37
+ fi
38
+
39
+ npx pika-build ${PLATFORM} ${PUBLIC_PATH_ARG}
40
+ exit 0
41
+ fi
42
+
43
+ # Method 2: Fall back to Pika host repo
44
+ PIKA_HOST_DIR="${PIKA_HOST_DIR:-$HOME/robotapp}"
45
+
46
+ echo "📁 Using host repo: ${PIKA_HOST_DIR}"
47
+
32
48
  # Verify host directory exists
33
49
  if [ ! -d "${PIKA_HOST_DIR}/node_modules/@callstack/repack" ]; then
34
- echo "❌ Error: Pika host not found at ${PIKA_HOST_DIR}"
35
50
  echo ""
36
- echo "Please either:"
37
- echo " 1. Set PIKA_HOST_DIR environment variable to your robotapp location"
38
- echo " 2. Or clone robotapp to ~/robotapp and run 'npm install'"
51
+ echo " Error: Build environment not found"
52
+ echo ""
53
+ echo "Please install pika-minigame-sdk:"
54
+ echo " npm install pika-minigame-sdk --save-dev"
39
55
  echo ""
40
- echo "Example:"
56
+ echo "Or set PIKA_HOST_DIR to your robotapp location:"
41
57
  echo " export PIKA_HOST_DIR=/path/to/robotapp"
42
58
  echo " ./scripts/pika-build.sh ios"
43
59
  exit 1
@@ -72,8 +88,8 @@ cat > "${WORKSPACE_DIR}/package.json" << EOF
72
88
  "version": "1.0.0",
73
89
  "private": true,
74
90
  "scripts": {
75
- "build:ios": "npx react-native webpack-bundle --platform ios --entry-file index.js --dev false --bundle-output build/outputs/ios/local/index.ios.bundle --assets-dest build/outputs/ios/local",
76
- "build:android": "npx react-native webpack-bundle --platform android --entry-file index.js --dev false --bundle-output build/outputs/android/local/index.android.bundle --assets-dest build/outputs/android/local"
91
+ "build:ios": "npx react-native webpack-bundle --platform ios --entry-file index.js --dev false",
92
+ "build:android": "npx react-native webpack-bundle --platform android --entry-file index.js --dev false"
77
93
  },
78
94
  "peerDependencies": {
79
95
  "react": "18.3.1",
@@ -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>;