Skip to content

Commit

Permalink
Merge pull request #38 from degica/dev
Browse files Browse the repository at this point in the history
Dark-mode with publish script
  • Loading branch information
chathurapathiranage authored Jul 22, 2024
2 parents d40710b + 5bfbba6 commit dee8f80
Show file tree
Hide file tree
Showing 36 changed files with 777 additions and 368 deletions.
3 changes: 2 additions & 1 deletion payment_sdk/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
"@assets": "./src/assets",
"@components": "./src/components",
"@util": "./src/util",
"@context": "./src/context"
"@context": "./src/context",
"@theme": "./src/theme",
}
}
]
Expand Down
5 changes: 5 additions & 0 deletions payment_sdk/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export default [
pattern: "@assets/**",
group: "internal",
position: "after"
},
{
pattern: "@theme/**",
group: "internal",
position: "after"
}
],
pathGroupsExcludedImportTypes: ["react", "react-native"],
Expand Down
4 changes: 4 additions & 0 deletions payment_sdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ module.exports = {
setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"],
transformIgnorePatterns: [],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/src/" }),
testPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/dist/"
]
};
1 change: 1 addition & 0 deletions payment_sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "npm run build:js && npm run build:types && npm pack",
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --copy-files",
"build:types": "tsc --emitDeclarationOnly && tsc-alias",
"release": "./scripts/publish.sh",
"test": "jest",
"lint": "eslint ."
},
Expand Down
114 changes: 114 additions & 0 deletions payment_sdk/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

RELEASE_TYPE=${1:-}

echo_help() {
cat << EOF
USAGE:
./scripts/publish <release_type>
ARGS:
<release_type>
A Semantic Versioning release type used to bump the version number. Either "patch", "minor", or "major".
EOF
}

create_github_release() {
local current_version=$(node -p "require('./package.json').version")
local release_notes="v$current_version
Please see the [CHANGELOG.md](https://github.com/degica/mobile-sdk_react-native/blob/master/CHANGELOG.md) for details on this release."

if which hub | grep -q "not found"; then
create_github_release_fallback "$release_notes"
else
echo "Creating GitHub release for tag: v$current_version"
echo ""
echo -n " "
hub release create -em "$release_notes" "v$current_version"
fi
}

create_github_release_fallback() {
local release_notes=$1
cat << EOF
Remember to create a release on GitHub at https://github.com/degica/mobile-sdk_react-native/releases/new with the following notes:
$release_notes
EOF
}

# Show help if no arguments passed
if [ $# -eq 0 ]; then
echo "Error! Missing release type argument"
echo ""
echo_help
exit 1
fi

# Show help message if -h, --help, or help passed
case $1 in
-h | --help | help)
echo_help
exit 0
;;
esac

# Validate passed release type
case $RELEASE_TYPE in
patch | minor | major)
;;
*)
echo "Error! Invalid release type supplied"
echo ""
echo_help
exit 1
;;
esac

# Make sure our working dir is the repo root directory
cd "$(git rev-parse --show-toplevel)"

echo "Fetching git remotes"
git fetch

GIT_STATUS=$(git status)
if ! grep -q 'On branch master' <<< "$GIT_STATUS"; then
echo "Error! Must be on master branch to publish"
exit 1
fi

if ! grep -q "Your branch is up to date with 'origin/master'." <<< "$GIT_STATUS"; then
echo "Error! Must be up to date with origin/master to publish"
exit 1
fi

if ! grep -q 'working tree clean' <<< "$GIT_STATUS"; then
echo "Error! Cannot publish with dirty working tree"
exit 1
fi

echo "Installing dependencies"
npm ci

echo "Running tests"
npm run test

echo "Building the project"
npm run build

echo "Bumping package.json $RELEASE_TYPE version and tagging commit"
npm version $RELEASE_TYPE

echo "Publishing release to npm"
npm publish --access=public

echo "Pushing git commit and tag"
git push --follow-tags

echo "Publish successful!"
echo ""

create_github_release

echo "Done!"
23 changes: 23 additions & 0 deletions payment_sdk/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ global.__DEV__ = process.env.NODE_ENV !== "production";
// jest.mock('react-native-worklets-core', () => ({
// Worklets: jest.fn(),
// }));

jest.mock('react-i18next', () => ({
useTranslation: () => {
return {
t: (str) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
};
},
initReactI18next: {
type: '3rdParty',
init: () => {},
},
}));

jest.mock('./src/context/ThemeContext', () => ({
ThemeProvider: ({ children }) => children,
useTheme: () => ({
mode: 'light',
toggleMode: jest.fn(),
}),
}));
24 changes: 14 additions & 10 deletions payment_sdk/src/__tests__/CardInputGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Actions, DispatchContext, StateContext } from "../context/state";
import CardInputGroup from "../components/CardInputGroup";
import { isCardNumberValid, validateCardExpiry } from "../util/validator";

import { ThemeProvider } from "../context/ThemeContext";

// Mock helper functions
jest.mock("../util/helpers", () => ({
formatCreditCardNumber: jest.fn(),
Expand Down Expand Up @@ -38,11 +40,13 @@ const mockDispatch = jest.fn();
describe("CardInputGroup Component", () => {
const renderWithContext = (component: ReactNode) => {
return render(
<StateContext.Provider value={mockState}>
<DispatchContext.Provider value={mockDispatch}>
{component}
</DispatchContext.Provider>
</StateContext.Provider>
<ThemeProvider>
<StateContext.Provider value={mockState}>
<DispatchContext.Provider value={mockDispatch}>
{component}
</DispatchContext.Provider>
</StateContext.Provider>
</ThemeProvider>
);
};

Expand All @@ -55,7 +59,7 @@ describe("CardInputGroup Component", () => {
const { getByTestId } = renderWithContext(
<CardInputGroup
inputErrors={inputGroupMockValues}
resetError={(data: string) => {}}
resetError={(data: string) => { }}
/>
);

Expand All @@ -77,7 +81,7 @@ describe("CardInputGroup Component", () => {
const { getByTestId } = renderWithContext(
<CardInputGroup
inputErrors={inputGroupMockValues}
resetError={(data: string) => {}}
resetError={(data: string) => { }}
/>
);

Expand All @@ -102,7 +106,7 @@ describe("CardInputGroup Component", () => {
const { getByTestId } = renderWithContext(
<CardInputGroup
inputErrors={inputGroupMockValues}
resetError={(data: string) => {}}
resetError={(data: string) => { }}
/>
);

Expand All @@ -125,7 +129,7 @@ describe("CardInputGroup Component", () => {
const { getByTestId } = renderWithContext(
<CardInputGroup
inputErrors={inputGroupMockValues}
resetError={(data: string) => {}}
resetError={(data: string) => { }}
/>
);

Expand All @@ -148,7 +152,7 @@ describe("CardInputGroup Component", () => {
const { getByTestId } = renderWithContext(
<CardInputGroup
inputErrors={inputGroupMockValues}
resetError={(data: string) => {}}
resetError={(data: string) => { }}
/>
);

Expand Down
Binary file added payment_sdk/src/assets/images/close_dm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dee8f80

Please sign in to comment.