Skip to content

Commit

Permalink
fix: staging
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthecat committed Jan 8, 2025
1 parent c4855e7 commit 3f6fac9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASS }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
pnpm stage:sequence
pnpm staging:sequence
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -185,5 +185,5 @@ jobs:
- <b>Linux:</b> ${{ steps.interact_with_storage.outputs.linux_app }}
- <b>MacOS:</b> ${{ steps.interact_with_storage.outputs.macos_app }}
- <b>MacOS_arm:</b> ${{ steps.interact_with_storage.outputs.macos_64_app }}
<b>Stage web:</b> https://spektr-stg.novasama-tech.org/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pnpm install
```

```sh
# Start Electron and prebuild app in stage mode. You can also access app with browser.
# Start Electron and prebuild app in staging mode. You can also access app with browser.
pnpm preview
```

Expand Down Expand Up @@ -94,8 +94,8 @@ pnpm types
```

```sh
# Build app in stage mode.
pnpm stage:sequence
# Build app in staging mode.
pnpm staging:sequence
```

```sh
Expand Down
7 changes: 4 additions & 3 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const author = AUTHOR;
export const version = VERSION;
export const description = DESCRIPTION;
export const electronProtocol =
process.env.NODE_ENV === 'stage' ? `${NAME.replace('-', '')}-stage` : NAME.replace('-', '');
export const title = process.env.NODE_ENV === 'stage' ? 'Nova Spektr Stage' : 'Nova Spektr';
process.env.NODE_ENV === 'staging' ? `${NAME.replace('-', '')}-stage` : NAME.replace('-', '');
export const title = process.env.NODE_ENV === 'staging' ? 'Nova Spektr Stage' : 'Nova Spektr';
export const appId =
process.env.NODE_ENV === 'stage'
process.env.NODE_ENV === 'staging'
? `com.${AUTHOR_IN_KEBAB_CASE}.${NAME}.stage`.toLowerCase()
: `com.${AUTHOR_IN_KEBAB_CASE}.${NAME}`.toLowerCase();

Expand Down Expand Up @@ -59,4 +59,5 @@ export const folders = {
storybookBuild: resolve('release/storybook'),

coverage: resolve('./.coverage'),
cache: resolve('./node_modules/.cache'),
};
2 changes: 1 addition & 1 deletion docker/Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /project
RUN npm install -g pnpm
RUN pnpm install
RUN if [ "$BUILD_TYPE" = "development" ]; then \
pnpm build:stage && pnpm postbuild:stage; \
pnpm build:staging && pnpm postbuild:staging; \
else\
pnpm build && pnpm postbuild; \
fi
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@
"scripts": {
"config": "node config/bin.js",
"electron": "electron .",
"preview": "pnpm build:stage && concurrently \"pnpm renderer:preview\" \"pnpm electron\"",
"preview": "cross-env RENDERER_SOURCE=localhost pnpm build:staging && concurrently \"pnpm renderer:preview\" \"pnpm electron\"",
"start": "pnpm r clean:build main:dev preload:dev && concurrently \"pnpm main:dev:watch\" \"pnpm preload:dev:watch\" \"pnpm renderer:dev:watch\" \"pnpm electron\"",
"start:renderer": "pnpm renderer:dev:watch",
"renderer:dev": "cross-env CHAINS_FILE=chains-dev TOKENS_FILE=tokens-dev LOGGER=false vite build -c vite.config.renderer.ts",
"renderer:dev:watch": "cross-env CHAINS_FILE=chains-dev TOKENS_FILE=tokens-dev LOGGER=false vite -c vite.config.renderer.ts",
"renderer:stage": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens vite build --mode stage -c vite.config.renderer.ts",
"renderer:staging": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens vite build --mode staging -c vite.config.renderer.ts",
"renderer:prod": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens vite build --mode production -c vite.config.renderer.ts",
"renderer:preview": "vite preview --mode stage --port $(pnpm --silent run config renderer.server.port) -c vite.config.renderer.ts",
"renderer:preview": "vite preview --mode staging --port $(pnpm --silent run config renderer.server.port) -c vite.config.renderer.ts",
"preload:dev": "vite build --mode development -c vite.config.preload.ts",
"preload:dev:watch": "vite build --mode development -c vite.config.preload.ts --watch",
"preload:stage": "vite build --mode stage -c vite.config.preload.ts",
"preload:staging": "vite build --mode staging -c vite.config.preload.ts",
"preload:prod": "vite build --mode production -c vite.config.preload.ts",
"main:dev": "vite build --mode development -c vite.config.main.ts",
"main:dev:watch": "vite build --mode development -c vite.config.main.ts --watch",
"main:stage": "vite build --mode stage -c vite.config.main.ts",
"main:staging": "vite build --mode staging -c vite.config.main.ts",
"main:prod": "vite build -c vite.config.main.ts",
"build": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens pnpm r clean:prod main:prod preload:prod renderer:prod",
"build:dev": "cross-env CHAINS_FILE=chains-dev TOKENS_FILE=tokens-dev pnpm r clean:prod main:dev preload:dev renderer:dev",
"build:stage": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens pnpm r clean:prod renderer:stage preload:stage main:stage",
"build:staging": "cross-env CHAINS_FILE=chains TOKENS_FILE=tokens pnpm r clean:prod renderer:staging preload:staging main:staging",
"postbuild": "node scripts/postbuild.js",
"postbuild:stage": "node scripts/postbuild.js stage",
"postbuild:staging": "node scripts/postbuild.js staging",
"dist": "cross-env NODE_ENV=production electron-builder --config electron-builder.js -p never",
"dist:stage": "cross-env NODE_ENV=stage electron-builder --config electron-builder.js -p never",
"dist:staging": "cross-env NODE_ENV=staging electron-builder --config electron-builder.js -p never",
"clean:build": "rimraf $(pnpm --silent run config folders.devBuild)",
"clean:prod": "rimraf $(pnpm --silent run config folders.prodBuild)",
"stage:sequence": "pnpm r clean:build clean:prod build:stage postbuild:stage dist:stage",
"staging:sequence": "pnpm r clean:build clean:prod build:staging postbuild:staging dist:staging",
"prod:sequence": "pnpm r clean:build clean:prod build postbuild dist",
"test": "cross-env POLKADOTJS_DISABLE_ESM_CJS_WARNING=1 vitest run",
"test:ui": "cross-env POLKADOTJS_DISABLE_ESM_CJS_WARNING=1 vitest --ui",
Expand Down
4 changes: 2 additions & 2 deletions scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ async function createPackageJSONDistVersion() {
...restOfPackageJSON,
};

// Check if the script was run with the 'stage' argument
if (process.argv.includes('stage')) {
// Check if the script was run with the 'staging' argument
if (process.argv.includes('staging')) {
packageJSONDistVersion.name += '-stage';
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/factories/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ export function createWindow(): BrowserWindow {

webPreferences: {
nodeIntegration: false,
preload: join(__dirname, 'preload.js'),
preload: join(__dirname, 'preload.cjs'),
},
});

if (ENVIRONMENT.IS_DEV) {
if (ENVIRONMENT.RENDERER_SOURCE === 'localhost') {
window.loadURL(`${renderer.server.protocol}${renderer.server.host}:${renderer.server.port}`);

window.webContents.openDevTools({ mode: 'bottom' });
} else {
window.loadURL('file://' + __dirname + '/index.html');
}

if (ENVIRONMENT.IS_DEV) {
window.webContents.openDevTools({ mode: 'bottom' });
}

session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['User-Agent'] = 'Nova Spektr';
delete details.requestHeaders['Origin'];
Expand Down
3 changes: 2 additions & 1 deletion src/main/shared/constants/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const ENVIRONMENT = {
RENDERER_SOURCE: process.env.RENDERER_SOURCE,
IS_DEV: import.meta.env.MODE === 'development',
IS_STAGE: import.meta.env.MODE === 'stage',
IS_STAGE: import.meta.env.MODE === 'staging',
};
9 changes: 8 additions & 1 deletion vite.config.main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'path';

import { type UserConfigFn } from 'vite';

import { folders, title, version } from './config';
Expand All @@ -7,13 +9,18 @@ const config: UserConfigFn = async ({ mode }) => {
const { default: tsconfigPaths } = await import('vite-tsconfig-paths');
const { default: target } = await import('vite-plugin-target');

const isDev = mode === 'development';

const rendererSource = process.env.RENDERER_SOURCE || (isDev ? 'localhost' : 'filesystem');

return defineConfig({
mode,
// root: folders.mainRoot,
cacheDir: resolve(folders.cache, 'vite-main'),
define: {
'process.env.PRODUCT_NAME': JSON.stringify(title),
'process.env.VERSION': JSON.stringify(version),
'process.env.BUILD_SOURCE': JSON.stringify(process.env.BUILD_SOURCE),
'process.env.RENDERER_SOURCE': JSON.stringify(rendererSource),
'process.env.LOGGER': JSON.stringify(process.env.LOGGER),
},
build: {
Expand Down
3 changes: 3 additions & 0 deletions vite.config.preload.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'path';

import { type UserConfigFn } from 'vite';

import { folders, title, version } from './config';
Expand All @@ -9,6 +11,7 @@ const config: UserConfigFn = async ({ mode }) => {

return defineConfig({
mode,
cacheDir: resolve(folders.cache, 'vite-preload'),
define: {
'process.env.PRODUCT_NAME': JSON.stringify(title),
'process.env.VERSION': JSON.stringify(version),
Expand Down
7 changes: 3 additions & 4 deletions vite.config.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const config: UserConfigFn = async ({ mode }) => {
const { nodePolyfills } = await import('vite-plugin-node-polyfills');

const isDev = mode === 'development';
const isProd = mode === 'production';
const isStage = mode === 'stage';
const isStage = mode === 'staging';

const commonPlugins = [
tsconfigPaths(),
Expand All @@ -29,8 +28,8 @@ const config: UserConfigFn = async ({ mode }) => {

return defineConfig({
mode: isStage ? 'production' : mode,
cacheDir: resolve(folders.cache, 'vite-renderer'),
root: resolve(folders.rendererRoot, 'app'),
base: '/',
define: {
'process.env.PRODUCT_NAME': JSON.stringify(title),
'process.env.VERSION': JSON.stringify(version),
Expand All @@ -45,7 +44,7 @@ const config: UserConfigFn = async ({ mode }) => {
},
build: {
sourcemap: isStage || undefined,
minify: isProd,
minify: !isDev,
outDir: folders.devBuild,
emptyOutDir: false,
target: 'es2021',
Expand Down

0 comments on commit 3f6fac9

Please sign in to comment.