aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-09 22:16:29 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-09 22:17:26 +0100
commitfb7118ff1c8f0dcd61f15e51b193512283d83fa1 (patch)
tree721cee6a64b44a56b7f05f39750a65cda5fb4ef6 /scripts
parentbuild: Add eslint-plugin-jest (diff)
downloadsophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.tar.gz
sophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.tar.zst
sophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.zip
build: Add eslint-plugin-unicorn
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/build.js12
-rw-r--r--scripts/updateElectronVendors.js (renamed from scripts/update-electron-vendors.js)20
-rw-r--r--scripts/watch.js52
3 files changed, 42 insertions, 42 deletions
diff --git a/scripts/build.js b/scripts/build.js
index 88267e5..66a1506 100644
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -1,11 +1,11 @@
1import { join } from 'path'; 1import path from 'node:path';
2 2
3import { build as esbuildBuild } from 'esbuild'; 3import { build as esbuildBuild } from 'esbuild';
4import { build as viteBuild } from 'vite'; 4import { build as viteBuild } from 'vite';
5 5
6import fileURLToDirname from '../config/fileURLToDirname.js'; 6import fileUrlToDirname from '../config/fileUrlToDirname.js';
7 7
8const thisDir = fileURLToDirname(import.meta.url); 8const thisDir = fileUrlToDirname(import.meta.url);
9 9
10/** 10/**
11 * @param {string} packageName 11 * @param {string} packageName
@@ -26,7 +26,7 @@ async function buildPackageEsbuild(packageName) {
26 */ 26 */
27function buildPackageVite(packageName) { 27function buildPackageVite(packageName) {
28 return viteBuild({ 28 return viteBuild({
29 configFile: join(thisDir, `../packages/${packageName}/vite.config.js`), 29 configFile: path.join(thisDir, `../packages/${packageName}/vite.config.js`),
30 }); 30 });
31} 31}
32 32
@@ -52,7 +52,7 @@ function buildAll() {
52 ]); 52 ]);
53} 53}
54 54
55buildAll().catch((err) => { 55buildAll().catch((error) => {
56 console.error(err); 56 console.error(error);
57 process.exit(1); 57 process.exit(1);
58}); 58});
diff --git a/scripts/update-electron-vendors.js b/scripts/updateElectronVendors.js
index 6ff5c06..5e8ab36 100644
--- a/scripts/update-electron-vendors.js
+++ b/scripts/updateElectronVendors.js
@@ -1,12 +1,12 @@
1import { execSync } from 'child_process'; 1import { execSync } from 'node:child_process';
2import { writeFile } from 'fs/promises'; 2import { writeFile } from 'node:fs/promises';
3import { join } from 'path'; 3import path from 'node:path';
4 4
5import electronPath from 'electron'; 5import electronPath from 'electron';
6 6
7import fileURLToDirname from '../config/fileURLToDirname.js'; 7import fileUrlToDirname from '../config/fileUrlToDirname.js';
8 8
9const thisDir = fileURLToDirname(import.meta.url); 9const thisDir = fileUrlToDirname(import.meta.url);
10 10
11/** 11/**
12 * Returns versions of electron vendors 12 * Returns versions of electron vendors
@@ -40,17 +40,17 @@ function updateVendors() {
40 const chromeMajorVersion = 40 const chromeMajorVersion =
41 electronRelease.v8.split('.')[0] + electronRelease.v8.split('.')[1]; 41 electronRelease.v8.split('.')[0] + electronRelease.v8.split('.')[1];
42 42
43 const browserslistrcPath = join(thisDir, '../.browserslistrc'); 43 const browserslistrcPath = path.join(thisDir, '../.browserslistrc');
44 44
45 return Promise.all([ 45 return Promise.all([
46 writeFile( 46 writeFile(
47 join(thisDir, '../.electron-vendors.cache.json'), 47 path.join(thisDir, '../.electron-vendors.cache.json'),
48 `${JSON.stringify( 48 `${JSON.stringify(
49 { 49 {
50 chrome: chromeMajorVersion, 50 chrome: chromeMajorVersion,
51 node: nodeMajorVersion, 51 node: nodeMajorVersion,
52 }, 52 },
53 null, 53 undefined,
54 2, 54 2,
55 )}\n`, 55 )}\n`,
56 ), 56 ),
@@ -59,7 +59,7 @@ function updateVendors() {
59 ]); 59 ]);
60} 60}
61 61
62updateVendors().catch((err) => { 62updateVendors().catch((error) => {
63 console.error(err); 63 console.error(error);
64 process.exit(1); 64 process.exit(1);
65}); 65});
diff --git a/scripts/watch.js b/scripts/watch.js
index cf5dbfd..455cfd9 100644
--- a/scripts/watch.js
+++ b/scripts/watch.js
@@ -1,21 +1,21 @@
1import { spawn } from 'child_process'; 1import { spawn } from 'node:child_process';
2import { join } from 'path'; 2import path from 'node:path';
3 3
4import { watch } from 'chokidar'; 4import { watch } from 'chokidar';
5import electronPath from 'electron'; 5import electronPath from 'electron';
6import { build as esbuildBuild } from 'esbuild'; 6import { build as esbuildBuild } from 'esbuild';
7import { createServer } from 'vite'; 7import { createServer } from 'vite';
8 8
9import fileURLToDirname from '../config/fileURLToDirname.js'; 9import fileUrlToDirname from '../config/fileUrlToDirname.js';
10 10
11/** @type {string} */ 11/** @type {string} */
12const thisDir = fileURLToDirname(import.meta.url); 12const thisDir = fileUrlToDirname(import.meta.url);
13 13
14/** @type {string} */ 14/** @type {string} */
15const sharedModule = join(thisDir, '../packages/shared/dist/index.mjs'); 15const sharedModule = path.join(thisDir, '../packages/shared/dist/index.mjs');
16 16
17/** @type {string} */ 17/** @type {string} */
18const serviceSharedModule = join( 18const serviceSharedModule = path.join(
19 thisDir, 19 thisDir,
20 '../packages/service-shared/dist/index.mjs', 20 '../packages/service-shared/dist/index.mjs',
21); 21);
@@ -48,7 +48,7 @@ async function setupEsbuildWatcher(packageName, extraPaths, callback) {
48 48
49 const incrementalBuild = await esbuildBuild(config); 49 const incrementalBuild = await esbuildBuild(config);
50 const paths = [ 50 const paths = [
51 join(thisDir, `../packages/${packageName}/src`), 51 path.join(thisDir, `../packages/${packageName}/src`),
52 ...(extraPaths || []), 52 ...(extraPaths || []),
53 ]; 53 ];
54 const watcher = watch(paths, { 54 const watcher = watch(paths, {
@@ -64,18 +64,18 @@ async function setupEsbuildWatcher(packageName, extraPaths, callback) {
64 .rebuild?.() 64 .rebuild?.()
65 .then(() => { 65 .then(() => {
66 if (callback) { 66 if (callback) {
67 console.log(`\u26a1 Reloading package ${packageName}`); 67 console.log(`\u26A1 Reloading package ${packageName}`);
68 callback(); 68 callback();
69 } 69 }
70 }) 70 })
71 .catch((err) => { 71 .catch((error) => {
72 if (typeof err === 'object' && 'errors' in err) { 72 if (typeof error === 'object' && 'errors' in error) {
73 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- We just checked. 73 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- We just checked.
74 const { errors } = err; 74 const { errors } = error;
75 if (Array.isArray(errors)) { 75 if (Array.isArray(errors)) {
76 const errCount = errors.length; 76 const errCount = errors.length;
77 console.error( 77 console.error(
78 '\ud83d\udd25', 78 '\uD83D\uDD25',
79 errCount, 79 errCount,
80 errCount > 1 ? 'errors' : 'error', 80 errCount > 1 ? 'errors' : 'error',
81 'while rebuilding package', 81 'while rebuilding package',
@@ -85,10 +85,10 @@ async function setupEsbuildWatcher(packageName, extraPaths, callback) {
85 } 85 }
86 } 86 }
87 console.error( 87 console.error(
88 '\ud83d\udd25', 88 '\uD83D\uDD25',
89 'error while rebuilding package', 89 'error while rebuilding package',
90 packageName, 90 packageName,
91 err, 91 error,
92 ); 92 );
93 }); 93 });
94 }); 94 });
@@ -106,7 +106,7 @@ async function setupDevServer(packageName) {
106 clearScreen: false, 106 clearScreen: false,
107 }, 107 },
108 }, 108 },
109 configFile: join(thisDir, `../packages/${packageName}/vite.config.js`), 109 configFile: path.join(thisDir, `../packages/${packageName}/vite.config.js`),
110 }); 110 });
111 await viteDevServer.listen(); 111 await viteDevServer.listen();
112 return viteDevServer; 112 return viteDevServer;
@@ -155,16 +155,16 @@ function setupMainPackageWatcher(viteDevServer) {
155 process.env.VITE_DEV_SERVER_URL = `${protocol}//${hostOrDefault}:${portOrDefault}/`; 155 process.env.VITE_DEV_SERVER_URL = `${protocol}//${hostOrDefault}:${portOrDefault}/`;
156 156
157 /** @type {import('child_process').ChildProcessByStdio<null, null, import('stream').Readable> 157 /** @type {import('child_process').ChildProcessByStdio<null, null, import('stream').Readable>
158 | null} */ 158 | undefined} */
159 let spawnProcess = null; 159 let spawnProcess;
160 160
161 return setupEsbuildWatcher( 161 return setupEsbuildWatcher(
162 'main', 162 'main',
163 [serviceSharedModule, sharedModule], 163 [serviceSharedModule, sharedModule],
164 () => { 164 () => {
165 if (spawnProcess !== null) { 165 if (spawnProcess !== undefined) {
166 spawnProcess.kill('SIGINT'); 166 spawnProcess.kill('SIGINT');
167 spawnProcess = null; 167 spawnProcess = undefined;
168 } 168 }
169 169
170 spawnProcess = spawn(String(electronPath), ['.'], { 170 spawnProcess = spawn(String(electronPath), ['.'], {
@@ -188,11 +188,11 @@ async function setupDevEnvironment() {
188 process.env.MODE = 'development'; 188 process.env.MODE = 'development';
189 process.env.NODE_ENV = 'development'; 189 process.env.NODE_ENV = 'development';
190 190
191 /** @type {import('vite').ViteDevServer | null} */ 191 /** @type {import('vite').ViteDevServer | undefined} */
192 let viteDevServer = null; 192 let viteDevServer;
193 /** @type {(event: import('vite').HMRPayload) => void} */ 193 /** @type {(event: import('vite').HMRPayload) => void} */
194 const sendEvent = (event) => { 194 const sendEvent = (event) => {
195 if (viteDevServer !== null) { 195 if (viteDevServer !== undefined) {
196 viteDevServer.ws.send(event); 196 viteDevServer.ws.send(event);
197 } 197 }
198 }; 198 };
@@ -216,16 +216,16 @@ async function setupDevEnvironment() {
216 ), 216 ),
217 ]); 217 ]);
218 218
219 if (viteDevServer === null) { 219 if (viteDevServer === undefined) {
220 console.error('Failed to create vite dev server'); 220 console.error('Failed to create vite dev server');
221 return; 221 return;
222 } 222 }
223 223
224 console.log('\ud83c\udf80 Sophie is starting up'); 224 console.log('\uD83C\uDF80 Sophie is starting up');
225 await setupMainPackageWatcher(viteDevServer); 225 await setupMainPackageWatcher(viteDevServer);
226} 226}
227 227
228setupDevEnvironment().catch((err) => { 228setupDevEnvironment().catch((error) => {
229 console.error(err); 229 console.error(error);
230 process.exit(1); 230 process.exit(1);
231}); 231});