Skip to content

Migra o bundler do projeto para utilizar o Vite #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
71f3118
chore: add vite
alvarogfn Nov 22, 2023
3a615ed
fix: change browser router to hash router
alvarogfn Nov 23, 2023
dd8c366
refactor: remove dist electron
alvarogfn Nov 23, 2023
454dc38
chore: update vite config
alvarogfn Nov 23, 2023
b3736d5
chore: update eslint config
alvarogfn Nov 23, 2023
70bccc6
chore: move electron config from package.json to electron builder json
alvarogfn Nov 23, 2023
ffe3485
chore: add electron base files
alvarogfn Nov 23, 2023
2d7e503
chore: update setupTests.js
alvarogfn Nov 23, 2023
20af7c1
style: eslint --fix
alvarogfn Nov 23, 2023
4a6b966
chore: update yarn lock
alvarogfn Nov 23, 2023
6ff076b
chore: uncomment husky files
alvarogfn Nov 23, 2023
2f70525
Merge branch 'master' of https://github.com/hatcoders/octopost into a…
alvarogfn Nov 23, 2023
705cc13
fix: add extension in home.module.scss
alvarogfn Nov 23, 2023
818231e
chore: update pipeline
alvarogfn Nov 27, 2023
34840cc
chore: update pipeline
alvarogfn Nov 27, 2023
24c05ab
chore: update css module vitest resolution
alvarogfn Nov 27, 2023
8323ece
test: update usePostsStore mock
alvarogfn Nov 27, 2023
61a4359
style: just space
alvarogfn Nov 29, 2023
68661b3
docs: update contributing docs
alvarogfn Nov 29, 2023
2343d73
Merge branch 'master' of https://github.com/alvarogfn/octopost into a…
alvarogfn Nov 29, 2023
2539644
Merge branch 'master' of https://github.com/Alecell/octopost into alv…
alvarogfn Nov 29, 2023
b15fd5b
Merge branch 'master' of https://github.com/Alecell/octopost into alv…
alvarogfn Nov 30, 2023
2bd2cdd
style: just prettier
alvarogfn Nov 30, 2023
a9f3d8f
revert: update electron configuration
alvarogfn Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

122 changes: 122 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
root: true,
env: { browser: true, es2020: true },
ignorePatterns: [
'dist',
'.eslintrc.cjs',
'.next',
'.vscode',
'node_modules',
'!*.scss',
],
extends: ['eslint:recommended'],
plugins: ['prettier', 'eslint-plugin-import-helpers'],
rules: {
'prettier/prettier': ['error', { endOfLine: 'auto' }],
'no-console': 'error',
'import-helpers/order-imports': [
'error',
{
newlinesBetween: 'always',
groups: [
'/^react.*/',
'/^next/',
'module',
[
'/^\\~interfaces/',
'/^\\~store/',
'/^\\~snippets/',
'/^\\~hooks/',
'/^\\~services/',
'/^\\~transformers/',
'/^\\~constants/',
'/^\\~utils/',
'/^\\~enums/',
'/^\\~types/',
'/^\\~config/',
],
'/^(\\.|\\.\\.)(\\/[a-z]{1}\\w+)*$/',
'/^\\~components/',
'/^(\\.|\\.\\.)(\\/[\\w]+)*((\\/[A-Z]{1}\\w+)){1}$/',
'/\\~styles/',
'/^(\\.|\\.\\.).*(\\.scss)$/',
'/^(\\.|\\.\\.).*(\\.(svg|png|jpg|jpeg))$/',
],
alphabetize: { order: 'asc', ignoreCase: true },
},
],
},
overrides: [
// test files with vitest
{
files: ['**/*.spec.*'],
extends: ['plugin:vitest/recommended'],
plugins: ['vitest'],
},
// react rules
{
files: ['src/**.(ts|tsx)'],
extends: ['plugin:react-hooks/recommended', 'plugin:react/recommended'],
plugins: ['react'],
},

// stories
{
files: ['**/*.stories.tsx'],
rules: {
'no-console': 'off',
},
},
// configuration files
{
files: '.eslintrc.js',
rules: {
'no-undef': 'off',
},
},
// validate typescript files
{
extends: ['plugin:@typescript-eslint/recommended'],
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
// TODO: Colocar regra de underscore em variaveis membro e regra de nomeclatura de classe abstrata
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'interface',
prefix: ['I'],
format: ['PascalCase'],
},
{
selector: 'enum',
prefix: ['E'],
format: ['PascalCase'],
},
{
selector: 'typeAlias',
prefix: ['T'],
format: ['PascalCase'],
},
],
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
files: ['./src/types/*.ts', '*.d.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['*.js'],
rules: {
'no-console': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
},
],
});
89 changes: 0 additions & 89 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
yarn install
yarn build

- name: Run Jest tests
run: yarn test --watchAll=false
- name: Run Vitest tests
run: yarn test --watch=false

- name: Lint tests
run: yarn lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typings/
# Nuxt.js build / generate output
.nuxt
dist
dist-electron

# Gatsby files
.cache/
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ Bem-vindo ao Octopost! Agradecemos pelo seu interesse em contribuir para este pr
4. **Revisão de Código:** A equipe de mantenedores do projeto irá revisar o seu PR. Esteja disposto a fazer ajustes se necessário.
5. **Merge e Fechamento:** Após a revisão bem-sucedida, suas alterações serão mescladas à branch principal. Seu PR será fechado.

## Gerando Builds do Electron para Windows do Linux

Se você por algum motivo precisa buildar a aplicação (gerar um .exe) a partir do linux, será necessário instalar as dependências necessárias:

```bash
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install wine32
```

## Diretrizes de Contribuição

- **Estilo de Código:** Siga as convenções de estilo de código existentes no projeto.[Style Guide](https://github.com/Alecell/octopost/blob/master/STYLEGUIDE.md)
Expand Down
11 changes: 0 additions & 11 deletions config-overrides.js

This file was deleted.

16 changes: 16 additions & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"productName": "octopost",
"mac": {
"target": {
"target": "default",
"arch": ["universal"]
},
"category": "public.app-category.productivity"
},
"extends": null,
"files": ["dist/**/*", "dist-electron", "package.json"],
"directories": {
"buildResources": "assets"
}
}
28 changes: 28 additions & 0 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable @typescript-eslint/naming-convention */
/// <reference types="vite-plugin-electron/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* ├─┬ dist
* │ ├─┬ electron
* │ │ ├── main.js
* │ │ └── preload.js
* │ ├── index.html
* │ ├── ...other-static-files-from-public
* │
* ```
*/
DIST: string;
/** /dist/ or /public/ */
VITE_PUBLIC: string;
}
}

// Used in Renderer process, expose in `preload.ts`
interface Window {
ipcRenderer: import('electron').IpcRenderer;
}
54 changes: 33 additions & 21 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
import { app, BrowserWindow } from 'electron';
import * as isDev from 'electron-is-dev';
import * as path from 'path';
import path from 'path';

process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';

process.env.DIST = path.join(__dirname, '../dist');
process.env.VITE_PUBLIC = app.isPackaged
? process.env.DIST
: path.join(process.env.DIST, '../public');

if (!app.requestSingleInstanceLock()) {
app.quit();
process.exit(0);
}

let win: BrowserWindow | null;

function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
win = new BrowserWindow({
icon: path.join(process.env.VITE_PUBLIC, 'logo.svg'),
webPreferences: {
preload: path.join(__dirname, './preload.js'),
nodeIntegration: true,
contextIsolation: false,
},
});

win.loadURL(
isDev
? 'http://localhost:3000'
: `file://${path.join(__dirname, '../build/index.html')}`
);
// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString());
});

win.webContents.openDevTools();
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
win.webContents.openDevTools();
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(process.env.DIST, 'index.html'));
}
}

app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
app.quit();
win = null;
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
app.whenReady().then(createWindow);
Loading