Skip to content

Commit

Permalink
Update cache action usage to v1 in GitHub workflows (#28)
Browse files Browse the repository at this point in the history
* chore: Update cache action usage to v1 in GitHub workflows

* chore: reorganize scripts in package.json

* chore: Update package.json version to 2.0.0

* chore: Update next.config.mjs to include output option for exporting

* chore: Update audio file paths to use relative URLs

* chore: fixed favicon

* chore: Remove deprecated version field and update package.json version to 2.0.0
  • Loading branch information
codemile authored Jun 1, 2024
1 parent a2082b7 commit abf6f35
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 74 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
NEXT_PUBLIC_BRAND_NAME=Tetromino
NEXT_PUBLIC_GITHUB=https://github.com/reactgular/tetromino
NEXT_PUBLIC_STORAGE_KEY=tetromino
NEXT_PUBLIC_VERSION=2.0.0
# Base path for loading audio files
NEXT_PUBLIC_BASE=/tetromino
NEXT_PUBLIC_ANALYTICS=
3 changes: 1 addition & 2 deletions .env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NEXT_PUBLIC_BASE=http://localhost:3000/
NEXT_PUBLIC_BASE=/
NEXT_PUBLIC_ANALYTICS=

8 changes: 4 additions & 4 deletions .github/workflows/deploy-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v4

- name: "📦 Install dependencies"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "install"

Expand All @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand All @@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v4

- name: "📦 Install dependencies"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "install"

Expand All @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand All @@ -44,7 +44,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand All @@ -60,7 +60,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand All @@ -75,7 +75,7 @@ jobs:
uses: actions/checkout@v4

- name: "💽 Restore node_modules cache"
uses: reactgular/cache@main
uses: reactgular/cache@v1
with:
mode: "restore"

Expand Down
4 changes: 3 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
output: "export"
};

export default nextConfig;
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "tetromino",
"version": "0.1.0",
"version": "2.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"dev": "next dev",
"lint": "next lint",
"sort": "npx --yes sort-package-json",
"start": "next start"
},
"dependencies": {
"@material-ui/core": "^4.12.4",
Expand Down
Binary file removed src/app/favicon.ico
Binary file not shown.
15 changes: 14 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import {App} from '../components/templates/App';
import {Providers} from '../components/templates/Providers';

/**
* Read the package.json within a server component, so we don't
* expose the entire package.json to the client.
*/
const getPackageJsonVersion = () => {
try {
return require('../../package.json').version;
} catch (err) {
console.error('Could not find package.json. Please make sure the file exists and is valid JSON.', err);
return '0.0.0';
}
};

export default function Home() {
return (
<Providers>
<App />
<App version={getPackageJsonVersion()} />
</Providers>
);
}
8 changes: 6 additions & 2 deletions src/components/atoms/app/AppCopyright.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import {FaGithub} from 'react-icons/fa';
import {environment} from '../../../environment/environment';
import {ClassNameProps} from '../../particles/particles.types';

export const AppCopyright: FC<ClassNameProps> = ({className}) => {
export interface AppCopyrightProps {
version: string;
}

export const AppCopyright: FC<AppCopyrightProps & ClassNameProps> = ({version, className}) => {
return (
<div className={classNames(className, 'flex text-xs space-x-2')}>
<div>Version {environment.version}</div>
<div>Version {version}</div>
<a
href={environment.github}
className="flex text-primary hover:underline items-center space-x-1"
Expand Down
7 changes: 5 additions & 2 deletions src/components/organisms/dialogs/OptionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import {GameOptions} from '../game/GameOptions';

export interface OptionsDialogProps {
selectWelcoming?: () => boolean;

version: string;
}

export const OptionsDialog: FC<OptionsDialogProps & Partial<AppDialogControl>> =
({
selectWelcoming = GameSelectors.welcoming,
selectOpen = AppSelectors.isOpen(AppDialogType.OPTIONS)
selectOpen = AppSelectors.isOpen(AppDialogType.OPTIONS),
version
}) => {
const welcoming = useSelector(selectWelcoming);
return (
Expand All @@ -25,7 +28,7 @@ export const OptionsDialog: FC<OptionsDialogProps & Partial<AppDialogControl>> =
selectOpen={selectOpen}
>
<GameOptions darkMode={!welcoming} />
<AppCopyright className="mt-auto mx-auto mt-5" />
<AppCopyright version={version} className="mx-auto mt-5" />
</AppDialog>
);
};
20 changes: 10 additions & 10 deletions src/components/particles/audio.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import {environment} from '../../environment/environment';
import {UiOption} from './ui/UiSelect';

export const AUDIO_FILES = [
`${environment.base}/audio/music/bonkers-for-arcades.mp3`,
`${environment.base}/audio/music/the-ice-cream-man.mp3`,
`${environment.base}/audio/music/8-bit-perplexion.mp3`,
`${environment.base}/audio/music/its-raining-pixels.mp3`,
`${environment.base}/audio/music/arcade-puzzler.mp3`
`${environment.base}audio/music/bonkers-for-arcades.mp3`,
`${environment.base}audio/music/the-ice-cream-man.mp3`,
`${environment.base}audio/music/8-bit-perplexion.mp3`,
`${environment.base}audio/music/its-raining-pixels.mp3`,
`${environment.base}audio/music/arcade-puzzler.mp3`
];

export const SOUND_FINISHED = `${environment.base}/audio/sounds/power-down-13.mp3`;
export const SOUND_LEVEL = `${environment.base}/audio/sounds/retro-chip-power.mp3`;
export const SOUND_SCORE = `${environment.base}/audio/sounds/ui-quirky-19.mp3`;
export const SOUND_DROP = `${environment.base}/audio/sounds/zapsplat_bambo_swoosh.mp3`;
export const SOUND_LEVEL_10 = `${environment.base}/audio/sounds/zapsplat_level_up.mp3`;
export const SOUND_FINISHED = `${environment.base}audio/sounds/power-down-13.mp3`;
export const SOUND_LEVEL = `${environment.base}audio/sounds/retro-chip-power.mp3`;
export const SOUND_SCORE = `${environment.base}audio/sounds/ui-quirky-19.mp3`;
export const SOUND_DROP = `${environment.base}audio/sounds/zapsplat_bambo_swoosh.mp3`;
export const SOUND_LEVEL_10 = `${environment.base}audio/sounds/zapsplat_level_up.mp3`;

export const PRELOAD_AUDIO = [
SOUND_FINISHED,
Expand Down
17 changes: 9 additions & 8 deletions src/components/particles/hooks/usePersist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import {useEffect} from 'react';
import {useSelector} from 'react-redux';
import {useAppDispatch} from '../../../store/app-store';
import {AppActions} from '../../../store/app/app-actions';
import {APP_PERSIST_DEFAULT, AppPersist} from '../../../store/app/app-model';
import {AppPersist} from '../../../store/app/app-model';
import {AppSelectors} from '../../../store/app/app-selectors';

export const usePersist = (storageKey: string) => {
export const usePersist = (version: string, storageKey: string) => {
const persist = useSelector(AppSelectors.persist);
const dispatch = useAppDispatch();

useEffect(() => {
const json = localStorage.getItem(storageKey);
if (json) {
try {
const data: AppPersist = JSON.parse(json);
if (data?.version === APP_PERSIST_DEFAULT.version) {
dispatch(AppActions.persist(data));
const data: AppPersist & {version: string} = JSON.parse(json);
if (data?.version === version) {
const {version, ...state} = data;
dispatch(AppActions.persist(state));
}
} catch (err) {
console.error('Could not read persist data.', err);
}
}
}, [storageKey, dispatch]);
}, [version, storageKey, dispatch]);

useEffect(() => {
localStorage.setItem(storageKey, JSON.stringify(persist));
}, [storageKey, persist]);
localStorage.setItem(storageKey, JSON.stringify({...persist, version}));
}, [version, storageKey, persist]);
};
10 changes: 7 additions & 3 deletions src/components/templates/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import {GameDesktop} from './GameDesktop';
import {GameMobile} from './GameMobile';
import {Welcome} from './Welcome';

export const App: FC = () => {
export interface AppProps {
version: string;
}

export const App: FC<AppProps> = ({version}) => {
const welcoming = useSelector(GameSelectors.welcoming);
const isWideScreen = useMediaQuery('(min-width:600px)');
const isShortScreen = useMediaQuery('(max-height:850px)');
const isNarrowScreen = useMediaQuery('(max-width:380px)');

usePageView('/');
usePersist(environment.storageKey);
usePersist(version, environment.storageKey);
useTitle();

const game = useMemo(() => {
Expand All @@ -49,7 +53,7 @@ export const App: FC = () => {
<PauseDialog />
<FinishDialog />
<HighScoresDialog />
<OptionsDialog />
<OptionsDialog version={version} />
<CreditsDialog />
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion src/environment/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const endsInSlash = (str: string): string => str.endsWith('/') ? str : `${str}/`;

export interface Environment {
analytics: string;

Expand All @@ -9,6 +11,9 @@ export interface Environment {

storageKey: string;

/**
* @deprecated
*/
version: string;
}

Expand All @@ -18,5 +23,5 @@ export const environment: Environment = {
github: process.env.NEXT_PUBLIC_GITHUB as string,
storageKey: process.env.NEXT_PUBLIC_STORAGE_KEY as string,
version: process.env.NEXT_PUBLIC_VERSION as string,
base: process.env.NEXT_PUBLIC_BASE as string
base: endsInSlash(process.env.NEXT_PUBLIC_BASE as string ?? '/')
};
19 changes: 1 addition & 18 deletions src/store/app/app-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,6 @@ export type AppPersist = Pick<
| 'music_type'
| 'high_scores'
| 'keys'
> & {version: string};

/**
* Defaults persist values.
*/
export const APP_PERSIST_DEFAULT: AppPersist = {
dark: APP_INITIAL_STATE.dark,
ghost_piece: APP_INITIAL_STATE.ghost_piece,
start_level: APP_INITIAL_STATE.start_level,
sound: APP_INITIAL_STATE.sound,
sound_volume: APP_INITIAL_STATE.sound_volume,
music: APP_INITIAL_STATE.music,
music_volume: APP_INITIAL_STATE.music_volume,
music_type: APP_INITIAL_STATE.music_type,
high_scores: APP_INITIAL_STATE.high_scores,
keys: APP_INITIAL_STATE.keys,
version: environment.version
};
>;

export const APP_NAME = 'app';
4 changes: 1 addition & 3 deletions src/store/app/app-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {createSelector} from '@reduxjs/toolkit';
import {environment} from '../../environment/environment';
import {selectRoot} from '../select-root';
import {AppDialogType, AppPersist} from './app-model';
import {AppDialogType, AppModel, AppPersist} from './app-model';

export namespace AppSelectors {
/**
Expand Down Expand Up @@ -97,7 +96,6 @@ export namespace AppSelectors {
keys
): AppPersist => {
return {
version: environment.version,
dark,
ghost_piece,
start_level,
Expand Down
11 changes: 2 additions & 9 deletions src/store/app/app-state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {createSlice} from '@reduxjs/toolkit';
import ReactGA from 'react-ga';
import {KEY_BINDINGS} from '../../components/particles/key_bindings.types';
import {environment} from '../../environment/environment';
import {AppActions} from './app-actions';
import {APP_INITIAL_STATE, APP_NAME} from './app-model';
import {APP_INITIAL_STATE, APP_NAME, AppModel} from './app-model';

export namespace AppState {
const track = (action: string, value?: number) => {
Expand Down Expand Up @@ -104,13 +103,7 @@ export namespace AppState {
};
})
.addCase(AppActions.persist, (state, {payload}) => {
const {version, ...restore} = payload;
if (version === environment.version) {
return {
...state,
...restore
};
}
return {...payload} satisfies AppModel;
});
}
});
Expand Down

0 comments on commit abf6f35

Please sign in to comment.