From d85f09cbed5f3d2501f791e689011ae127df1cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20Marussy?= Date: Sun, 9 Jan 2022 20:33:53 +0100 Subject: build: Add prettier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit eslint will also enforce prettier rules, so there is no need to call prettier separately in CI. Signed-off-by: Kristóf Marussy --- .electron-builder.config.cjs | 14 +-- .eslintignore | 3 - .eslintrc.cjs | 40 +++----- .prettierignore | 26 +++++ .yarnrc.yml | 10 +- CONTRIBUTING.md | 29 +++--- README.md | 16 +-- config/buildConstants.js | 8 +- config/getEsbuildConfig.js | 2 +- config/jest.config.base.js | 20 ++-- config/tsconfig.base.json | 4 +- docs/architecture.md | 14 +-- jest.config.js | 8 +- package.json | 4 + packages/main/esbuild.config.js | 33 ++++--- .../src/controllers/__tests__/initConfig.spec.ts | 20 +++- .../controllers/__tests__/initNativeTheme.spec.ts | 8 +- packages/main/src/controllers/initConfig.ts | 21 ++-- packages/main/src/devTools.ts | 16 +-- packages/main/src/index.ts | 108 ++++++++++++--------- packages/main/src/init.ts | 9 +- .../main/src/services/ConfigPersistenceService.ts | 4 +- .../services/impl/ConfigPersistenceServiceImpl.ts | 22 +++-- packages/main/src/stores/MainStore.ts | 46 +++++---- packages/main/src/stores/SharedStore.ts | 5 +- packages/main/src/utils/log.ts | 7 +- packages/main/tsconfig.json | 5 +- packages/main/types/importMeta.d.ts | 2 +- packages/preload/esbuild.config.js | 8 +- .../__tests__/createSophieRenderer.spec.ts | 56 +++++++---- .../src/contextBridge/createSophieRenderer.ts | 29 +++--- packages/preload/tsconfig.json | 10 +- packages/preload/types/importMeta.d.ts | 2 +- packages/renderer/.eslinrc.cjs | 5 +- packages/renderer/index.html | 9 +- .../src/components/BrowserViewPlaceholder.tsx | 55 +++++------ packages/renderer/src/components/StoreProvider.tsx | 13 +-- packages/renderer/src/components/ThemeProvider.tsx | 28 +++--- .../src/components/ToggleDarkModeButton.tsx | 4 +- packages/renderer/src/devTools.ts | 4 +- packages/renderer/src/stores/RendererStore.ts | 81 ++++++++-------- packages/renderer/tsconfig.json | 10 +- packages/renderer/vite.config.js | 10 +- packages/service-inject/.eslintrc.cjs | 5 +- packages/service-inject/esbuild.config.js | 4 +- packages/service-inject/tsconfig.json | 12 +-- packages/service-preload/esbuild.config.js | 8 +- packages/service-preload/tsconfig.json | 6 +- packages/service-preload/types/importMeta.d.ts | 2 +- packages/service-shared/.eslintrc.cjs | 5 +- packages/service-shared/esbuild.config.js | 8 +- packages/service-shared/src/index.ts | 10 +- packages/service-shared/src/ipc.ts | 3 +- packages/service-shared/tsconfig.build.json | 4 +- packages/service-shared/tsconfig.json | 6 +- packages/shared/.eslintrc.cjs | 5 +- packages/shared/esbuild.config.js | 10 +- packages/shared/src/index.ts | 18 ++-- packages/shared/src/stores/Config.ts | 7 +- packages/shared/src/stores/SharedStore.ts | 3 +- packages/shared/tsconfig.build.json | 4 +- packages/shared/tsconfig.json | 6 +- prettier.config.cjs | 4 + scripts/build.js | 31 +++--- scripts/update-electron-vendors.js | 26 +++-- scripts/watch.js | 101 ++++++++++--------- tsconfig.json | 3 +- yarn.lock | 57 ++++++++++- 68 files changed, 636 insertions(+), 540 deletions(-) create mode 100644 .prettierignore create mode 100644 prettier.config.cjs diff --git a/.electron-builder.config.cjs b/.electron-builder.config.cjs index 9e2d11f..f406cc8 100644 --- a/.electron-builder.config.cjs +++ b/.electron-builder.config.cjs @@ -43,18 +43,20 @@ const config = { */ async function burnFuses(context) { /** @type {string} */ - const ext = { - darwin: '.app', - win32: '.exe', - }[context.electronPlatformName] || ''; + const ext = + { + darwin: '.app', + win32: '.exe', + }[context.electronPlatformName] || ''; const electronBinaryPath = join( context.appOutDir, - `${context.packager.appInfo.productFilename}${ext}` + `${context.packager.appInfo.productFilename}${ext}`, ); /** @type {import('@electron/fuses').FuseConfig} */ const fuseConfig = { version: FuseVersion.V1, - resetAdHocDarwinSignature: context.electronPlatformName === 'darwin' && context.arch === Arch.arm64, + resetAdHocDarwinSignature: + context.electronPlatformName === 'darwin' && context.arch === Arch.arm64, [FuseV1Options.RunAsNode]: false, [FuseV1Options.EnableCookieEncryption]: true, [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false, diff --git a/.eslintignore b/.eslintignore index 01b8bcb..afc6ff1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -22,8 +22,5 @@ coverage .idea npm-debug.log.* .pnpm-debug.log* -*.css.d.ts -*.sass.d.ts -*.scss.d.ts dist/ diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7b05d5d..1301de4 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,19 +1,15 @@ -const project = [ - './tsconfig.json', - './packages/*/tsconfig.json', -]; +const project = ['./tsconfig.json', './packages/*/tsconfig.json']; module.exports = { root: true, - plugins: [ - '@typescript-eslint', - ], + plugins: ['@typescript-eslint'], extends: [ 'airbnb', 'airbnb-typescript', 'airbnb/hooks', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', + 'plugin:prettier/recommended', ], env: { es6: true, @@ -56,9 +52,7 @@ module.exports = { }, overrides: [ { - files: [ - '**/stores/**/*.ts', - ], + files: ['**/stores/**/*.ts'], rules: { // In a mobx-state-tree action, we assign to the properties of `self` to update the store. 'no-param-reassign': 'off', @@ -67,10 +61,7 @@ module.exports = { }, }, { - files: [ - '**/__tests__/*.{ts,tsx}', - '**/*.{spec,test}.{ts,tsx}', - ], + files: ['**/__tests__/*.{ts,tsx}', '**/*.{spec,test}.{ts,tsx}'], rules: { // If a non-null assertion fails in a test, the test will also fail anyways. '@typescript-eslint/no-non-null-assertion': 'off', @@ -79,21 +70,14 @@ module.exports = { }, }, { - files: [ - '**/*.js', - ], + files: ['**/*.js'], rules: { // ESM requires extensions for imports. - 'import/extensions': [ - 'error', - 'ignorePackages', - ], + 'import/extensions': ['error', 'ignorePackages'], }, }, { - files: [ - '**/*.cjs', - ], + files: ['**/*.cjs'], parserOptions: { sourceType: 'script', }, @@ -102,10 +86,10 @@ module.exports = { files: [ '.electron-builder.config.cjs', 'config/**/*.{cjs,js}', - 'jest.config.js', + '*.config.{cjs,js}', 'scripts/**/*.js', 'packages/*/.eslintrc.cjs', - 'packages/*/*.config.js', + 'packages/*/*.config.{cjs,js}', ], env: { // Config files are never run in a browser (even in frontend projects). @@ -126,9 +110,7 @@ module.exports = { }, }, { - files: [ - 'packages/*/*.config.js', - ], + files: ['packages/*/*.config.{cjs,js}'], rules: { // Allow relative imports of config files from the root package. 'import/no-relative-packages': 'off', diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..afc6ff1 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,26 @@ +# Logs +.log/ +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Coverage directory used by tools like istanbul +coverage +.eslintcache + +# Dependencies directories +.yarn +.vite + +# OSX +.DS_Store + +.idea +npm-debug.log.* +.pnpm-debug.log* + +dist/ diff --git a/.yarnrc.yml b/.yarnrc.yml index e8caff1..7ffac8d 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -11,15 +11,15 @@ nodeLinker: node-modules packageExtensions: eslint-config-airbnb-typescript@*: peerDependencies: - eslint: "*" - eslint-plugin-import: "*" + eslint: '*' + eslint-plugin-import: '*' plugins: - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs - spec: "@yarnpkg/plugin-interactive-tools" + spec: '@yarnpkg/plugin-interactive-tools' - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs - spec: "@yarnpkg/plugin-workspace-tools" + spec: '@yarnpkg/plugin-workspace-tools' - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs - spec: "@yarnpkg/plugin-typescript" + spec: '@yarnpkg/plugin-typescript' yarnPath: .yarn/releases/yarn-3.1.1.cjs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46ba3d6..e1d73d4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,29 +10,28 @@ Contributors are welcome to add their contact information to the license headers > Everyone is permitted to copy and distribute verbatim copies of this > license document, but changing it is not allowed. > -> > Developer's Certificate of Origin 1.1 > > By making a contribution to this project, I certify that: > > (a) The contribution was created in whole or in part by me and I -> have the right to submit it under the open source license -> indicated in the file; or +> have the right to submit it under the open source license +> indicated in the file; or > > (b) The contribution is based upon previous work that, to the best -> of my knowledge, is covered under an appropriate open source -> license and I have the right under that license to submit that -> work with modifications, whether created in whole or in part -> by me, under the same open source license (unless I am -> permitted to submit under a different license), as indicated -> in the file; or +> of my knowledge, is covered under an appropriate open source +> license and I have the right under that license to submit that +> work with modifications, whether created in whole or in part +> by me, under the same open source license (unless I am +> permitted to submit under a different license), as indicated +> in the file; or > > (c) The contribution was provided directly to me by some other -> person who certified (a), (b) or (c) and I have not modified -> it. +> person who certified (a), (b) or (c) and I have not modified +> it. > > (d) I understand and agree that this project and the contribution -> are public and that a record of the contribution (including all -> personal information I submit with it, including my sign-off) is -> maintained indefinitely and may be redistributed consistent with -> this project or the open source license(s) involved. +> are public and that a record of the contribution (including all +> personal information I submit with it, including my sign-off) is +> maintained indefinitely and may be redistributed consistent with +> this project or the open source license(s) involved. diff --git a/README.md b/README.md index b40bab3..6c8b45a 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ The project structure is based on [Vite Electron Builder Boilerplate](https://gi After installing `node`, you can install `yarn` with -``` sh +```sh npm i -g yarn ``` To start working, install all dependencies with -``` sh +```sh yarn install --immutable ``` @@ -33,7 +33,7 @@ yarn types To start a development instance of Sophie, which will reload on source changes, run -``` sh +```sh yarn watch ``` @@ -51,7 +51,7 @@ yarn watch:test To build the application in release mode, run -``` sh +```sh yarn compile ``` @@ -69,8 +69,8 @@ yarn run lint ## License -> Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com>
-> Copyright (C) 2022 Vijay A <vraravam@users.noreply.github.com> +> Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com>
+> Copyright (C) 2022 Vijay A <vraravam@users.noreply.github.com> > > This program is free software: you can redistribute it and/or modify > it under the terms of the GNU Affero General Public License as @@ -78,7 +78,7 @@ yarn run lint > > This program is distributed in the hope that it will be useful, > but WITHOUT ANY WARRANTY; without even the implied warranty of -> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > GNU Affero General Public License for more details. > You should have received a copy of the GNU Affero General Public License -> along with this program. If not, see <[https://www.gnu.org/licenses/](https://www.gnu.org/licenses/)>. +> along with this program. If not, see <[https://www.gnu.org/licenses/](https://www.gnu.org/licenses/)>. diff --git a/config/buildConstants.js b/config/buildConstants.js index 9083d78..3c55500 100644 --- a/config/buildConstants.js +++ b/config/buildConstants.js @@ -7,11 +7,15 @@ const thisDir = fileURLToDirname(import.meta.url); // We import this from a vite config, where top-level await is not available (es2021), // so we have to use the synchronous filesystem API. -const electronVendorsJson = readFileSync(join(thisDir, '../.electron-vendors.cache.json'), 'utf8'); +const electronVendorsJson = readFileSync( + join(thisDir, '../.electron-vendors.cache.json'), + 'utf8', +); /** @type {{ chrome: number; node: number; }} */ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -const { chrome: chromeVersion, node: nodeVersion } = JSON.parse(electronVendorsJson); +const { chrome: chromeVersion, node: nodeVersion } = + JSON.parse(electronVendorsJson); /** @type {string} */ export const banner = `/*! diff --git a/config/getEsbuildConfig.js b/config/getEsbuildConfig.js index b338d68..930f19f 100644 --- a/config/getEsbuildConfig.js +++ b/config/getEsbuildConfig.js @@ -25,7 +25,7 @@ export default function getEsbuildConfig(config, extraMetaEnvVars) { js: banner, }, ...config, - sourcemap: isDevelopment ? (config.sourcemap || true) : false, + sourcemap: isDevelopment ? config.sourcemap || true : false, define: { 'process.env.NODE_ENV': modeString, 'process.env.MODE': modeString, diff --git a/config/jest.config.base.js b/config/jest.config.base.js index 463e498..21f93be 100644 --- a/config/jest.config.base.js +++ b/config/jest.config.base.js @@ -9,22 +9,22 @@ export default { transform: { '\\.tsx?$': join(thisDir, 'jestEsbuildTransformer.js'), }, - extensionsToTreatAsEsm: [ - '.ts', - '.tsx', - ], + extensionsToTreatAsEsm: ['.ts', '.tsx'], moduleNameMapper: { '^@sophie/(.+)$': join(thisDir, '../packages/$1/src/index.ts'), '^(\\.{1,2}/.*)\\.jsx?$': '$1', // Workaround for jest to recognize the vendored dependencies of chalk. - '^#ansi-styles$': join(thisDir, '../node_modules/chalk/source/vendor/ansi-styles/index.js'), - '^#supports-color$': join(thisDir, '../node_modules/chalk/source/vendor/supports-color/index.js'), + '^#ansi-styles$': join( + thisDir, + '../node_modules/chalk/source/vendor/ansi-styles/index.js', + ), + '^#supports-color$': join( + thisDir, + '../node_modules/chalk/source/vendor/supports-color/index.js', + ), }, resetMocks: true, restoreMocks: true, testEnvironment: 'node', - testPathIgnorePatterns: [ - '/dist/', - '/node_modules/', - ], + testPathIgnorePatterns: ['/dist/', '/node_modules/'], }; diff --git a/config/tsconfig.base.json b/config/tsconfig.base.json index 255f334..ff7594e 100644 --- a/config/tsconfig.base.json +++ b/config/tsconfig.base.json @@ -12,8 +12,6 @@ "isolatedModules": true, "skipLibCheck": true, "checkJs": true, - "lib": [ - "esnext" - ] + "lib": ["esnext"] } } diff --git a/docs/architecture.md b/docs/architecture.md index 6467b6f..0122809 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6,9 +6,9 @@ title: Architecture Sophie is designed to -* display _services_, i.e., web pages, most of which are messaging web applications, -* allow the user to quickly switch between services and save resources by displaying multiple services in the same desktop applications, -* provide integrations for services, e.g., to manage unread message counts and notification in a single place. +- display _services_, i.e., web pages, most of which are messaging web applications, +- allow the user to quickly switch between services and save resources by displaying multiple services in the same desktop applications, +- provide integrations for services, e.g., to manage unread message counts and notification in a single place. Integrations for services are provided by pluggable _recipes_ to allow adding support for new services easily. A recipe may come directly from Sophie, a third party (under AGPLv3 licensing), or be created by the user themselves. @@ -21,9 +21,9 @@ Sophie is built on the [Electron](https://www.electronjs.org/) application frame Electron makes two facilities readily available to display foreign web pages: -* The easier solution that mimics the HTML `