Skip to content

Commit

Permalink
get environment from bundle info
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibanPirate committed Apr 10, 2023
1 parent ef92a3e commit 9e83814
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.deploy.stg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: "Bundle info"
shell: bash
run: |
yarn generate:bundle-info ${{ github.ref_name }}
yarn generate:bundle-info ${{ github.ref_name }} stage
- name: "Build"
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: "Bundle info"
shell: bash
run: |
yarn generate:bundle-info ${{ github.ref_name }}
yarn generate:bundle-info ${{ github.ref_name }} production
- name: "Build"
shell: bash
Expand Down
6 changes: 1 addition & 5 deletions mobile/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ const { readFileSync } = require("fs");
const internalIp = require("internal-ip");
const localIP = internalIp.v4.sync();

let bundleInfo = { version: require("./package.json").version };
let bundleInfo = { version: require("./package.json").version, environment: "development" };
try {
bundleInfo = JSON.parse(readFileSync(".bundle-info.json").toString());
} catch (error) {
/**/
}

bundleInfo.channel = process.env.BUILD_CHANNEL;
if (bundleInfo.channel) throw new Error("BUILD_CHANNEL is not defined");

module.exports = function (api) {
api.cache(true);
return {
Expand Down
8 changes: 4 additions & 4 deletions mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"build:alone:watch": "tsc --watch --preserveWatchOutput",
"build:android": "eas build -p android --no-wait --non-interactive",
"build:ios": "eas build -p ios --no-wait --non-interactive",
"build:production": "cross-env BUILD_CHANNEL=production yarn build:ios --profile production && cross-env BUILD_CHANNEL=production yarn build:android --profile production",
"build:stage": "cross-env BUILD_CHANNEL=stage yarn build:ios --profile stage && cross-env BUILD_CHANNEL=stage yarn build:android --profile stage",
"build:watch": "cross-env BUILD_CHANNEL=development lerna run build:alone:watch [email protected]/mobile --include-dependencies --parallel",
"build:production": "yarn build:ios --profile production && yarn build:android --profile production",
"build:stage": "yarn build:ios --profile stage && yarn build:android --profile stage",
"build:watch": "lerna run build:alone:watch [email protected]/mobile --include-dependencies --parallel",
"clean": "lerna run clean:alone [email protected]/mobile --include-dependencies --stream",
"clean:alone": "rimraf .expo dist",
"combine:components": "rnhc combine -c",
Expand Down Expand Up @@ -93,7 +93,7 @@
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --loglevel warn",
"lint:tsc": "tsc --noEmit",
"start:dev": "echo \" \n\\033[0;32mPlease run in a separate terminal session the following command:\n \n\\033[0;32myarn --cwd=mobile start:expo\n \n \"",
"start:expo": "cross-env BUILD_CHANNEL=development expo start --port 1010",
"start:expo": "expo start --port 1010",
"test": "yarn build && yarn test:alone",
"test:alone": "jest --rootDir .",
"test:watch": "npm-run-all build --parallel build:watch \"test:alone --watch {@}\" --"
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/types/__global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare global {
interface Window {
bundleInfo: {
version: string;
channel: "production" | "stage" | "development";
environment: "production" | "stage" | "development";
};
}
}
2 changes: 1 addition & 1 deletion mobile/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const getEnv = () => {
switch (window.bundleInfo.channel) {
switch (window.bundleInfo.environment) {
case "production":
return "production";
case "stage":
Expand Down
5 changes: 5 additions & 0 deletions packages/tooling/bundle-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { writeFileSync } from "fs";
const version = process.argv[2];
if (!version) throw new Error("Please provide a version");

// Get the environment passed as argument
const environment = process.argv[3];
if (!environment) throw new Error("Please provide an environment");

console.log(`Creating .bundle-info.json ...`);

writeFileSync(
".bundle-info.json",
JSON.stringify(
{
version,
environment,
},
null,
2,
Expand Down

0 comments on commit 9e83814

Please sign in to comment.