33// WARNING: any imported files need to be added to files in package.json
44
55import asar from "@electron/asar" ;
6+ import chalk from "chalk" ;
7+ import esbuild from "esbuild" ;
8+ import { sassPlugin } from "esbuild-sass-plugin" ;
69import {
710 copyFileSync ,
811 cpSync ,
@@ -12,18 +15,16 @@ import {
1215 rmSync ,
1316 writeFileSync ,
1417} from "fs" ;
15- import esbuild from "esbuild" ;
1618import path from "path" ;
19+ import type { PluginManifest , ThemeManifest } from "src/types" ;
1720import updateNotifier from "update-notifier" ;
18- import yargs , { ArgumentsCamelCase } from "yargs" ;
19- import { hideBin } from "yargs/helpers" ;
20- import chalk from "chalk" ;
21+ import { fileURLToPath , pathToFileURL } from "url" ;
2122import WebSocket from "ws" ;
22- import { release } from "./release.mjs" ;
23+ import yargs , { type ArgumentsCamelCase } from "yargs" ;
24+ import { hideBin } from "yargs/helpers" ;
2325import { logBuildPlugin } from "../src/util.mjs" ;
24- import { sassPlugin } from "esbuild-sass-plugin" ;
25- import { fileURLToPath , pathToFileURL } from "url" ;
26- import { AddonType , getAddonFolder , isMonoRepo , selectAddon } from "./mono.mjs" ;
26+ import { type AddonType , getAddonFolder , isMonoRepo , selectAddon } from "./mono.mjs" ;
27+ import { release } from "./release.mjs" ;
2728
2829interface BaseArgs {
2930 watch ? : boolean ;
@@ -92,6 +93,7 @@ function tryPort(port: number): Promise<WebSocket | undefined> {
9293 return ;
9394 }
9495
96+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
9597 const message = JSON . parse ( data . toString ( ) ) ;
9698 if ( message . evt !== "READY" ) {
9799 return ;
@@ -185,7 +187,7 @@ async function reload(id: string): Promise<void> {
185187
186188 reloading = true ;
187189
188- await new Promise ( ( resolve ) => {
190+ await new Promise < void > ( ( resolve ) => {
189191 /**
190192 *
191193 * @param {import('ws').RawData } data
@@ -201,7 +203,8 @@ async function reload(id: string): Promise<void> {
201203 reloading = false ;
202204 if ( reloadAgain ) {
203205 reloadAgain = false ;
204- resolve ( await reload ( id ) ) ;
206+ await reload ( id ) ;
207+ resolve ( ) ;
205208 return ;
206209 }
207210
@@ -257,7 +260,7 @@ async function bundleAddon(
257260 if ( ! existsSync ( "bundle" ) ) {
258261 mkdirSync ( "bundle" ) ;
259262 }
260- asar . createPackage ( distPath , `${ outputName } .asar` ) ;
263+ await asar . createPackage ( distPath , `${ outputName } .asar` ) ;
261264 copyFileSync ( `${ distPath } /manifest.json` , `${ outputName } .json` ) ;
262265
263266 console . log ( `Bundled ${ manifest . name } ` ) ;
@@ -273,7 +276,7 @@ async function handleContexts(
273276 await context . watch ( ) ;
274277 } else {
275278 await context . rebuild ( ) . catch ( ( ) => process . exit ( 1 ) ) ;
276- context . dispose ( ) ;
279+ await context . dispose ( ) ;
277280 }
278281 } ) ,
279282 ) ;
@@ -304,15 +307,15 @@ function buildAddons(buildFn: (args: Args) => Promise<void>, args: Args, type: A
304307 const addons = getAddonFolder ( type ) ;
305308
306309 addons . forEach ( ( addon ) => {
307- buildFn ( { ...args , addon } ) ;
310+ void buildFn ( { ...args , addon } ) ;
308311 } ) ;
309312}
310313
311314async function buildPlugin ( { watch, noInstall, production, noReload, addon } : Args ) : Promise < void > {
312315 const manifestPath = addon
313316 ? path . join ( directory , "plugins" , addon , "manifest.json" )
314317 : path . join ( directory , "manifest.json" ) ;
315- const manifest = JSON . parse ( readFileSync ( manifestPath . toString ( ) , "utf-8" ) ) ;
318+ const manifest : PluginManifest = JSON . parse ( readFileSync ( manifestPath . toString ( ) , "utf-8" ) ) ;
316319 const distPath = addon ? `dist/${ manifest . id } ` : "dist" ;
317320 const folderPath = addon ? path . join ( directory , "plugins" , addon ) : directory ;
318321
@@ -405,7 +408,7 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar
405408 esbuild . context (
406409 overwrites ( {
407410 ...common ,
408- entryPoints : [ path . join ( folderPath , manifest . renderer ) ] ,
411+ entryPoints : [ path . join ( folderPath , manifest . renderer ! ) ] ,
409412 outfile : `${ distPath } /renderer.js` ,
410413 } ) ,
411414 ) ,
@@ -419,7 +422,7 @@ async function buildPlugin({ watch, noInstall, production, noReload, addon }: Ar
419422 esbuild . context (
420423 overwrites ( {
421424 ...common ,
422- entryPoints : [ path . join ( folderPath , manifest . plaintextPatches ) ] ,
425+ entryPoints : [ path . join ( folderPath , manifest . plaintextPatches ! ) ] ,
423426 outfile : `${distPath } / plaintextPatches . js `,
424427 } ) ,
425428 ) ,
@@ -442,7 +445,7 @@ async function buildTheme({ watch, noInstall, production, noReload, addon }: Arg
442445 const manifestPath = addon
443446 ? path . join ( directory , "themes" , addon , "manifest.json" )
444447 : "manifest.json" ;
445- const manifest = JSON . parse ( readFileSync ( manifestPath . toString ( ) , "utf-8" ) ) ;
448+ const manifest : ThemeManifest = JSON . parse ( readFileSync ( manifestPath . toString ( ) , "utf-8" ) ) ;
446449 const distPath = addon ? `dist/${ manifest . id } ` : "dist" ;
447450 const folderPath = addon ? path . join ( directory , "themes" , addon ) : directory ;
448451
@@ -568,16 +571,20 @@ const { argv } = yargs(hideBin(process.argv))
568571 } ,
569572 async ( argv ) => {
570573 if ( argv . addon === "plugin" ) {
571- if ( argv . all && isMonoRepo ) return buildAddons ( buildPlugin , argv , "plugins" ) ;
572- else {
574+ if ( argv . all && isMonoRepo ) {
575+ buildAddons ( buildPlugin , argv , "plugins" ) ;
576+ return ;
577+ } else {
573578 const plugin = isMonoRepo ? await selectAddon ( "plugins" ) : undefined ;
574- buildPlugin ( { ...argv , addon : plugin ?. name } ) ;
579+ await buildPlugin ( { ...argv , addon : plugin ?. name } ) ;
575580 }
576581 } else if ( argv . addon === "theme" ) {
577- if ( argv . all && isMonoRepo ) return buildAddons ( buildTheme , argv , "themes" ) ;
578- else {
582+ if ( argv . all && isMonoRepo ) {
583+ buildAddons ( buildTheme , argv , "themes" ) ;
584+ return ;
585+ } else {
579586 const theme = isMonoRepo ? await selectAddon ( "themes" ) : undefined ;
580- buildTheme ( { ...argv , addon : theme ?. name } ) ;
587+ await buildTheme ( { ...argv , addon : theme ?. name } ) ;
581588 }
582589 } else {
583590 console . log ( "Invalid addon type." ) ;
@@ -596,23 +603,28 @@ const { argv } = yargs(hideBin(process.argv))
596603 } ,
597604 async ( argv ) => {
598605 if ( argv . addon === "plugin" ) {
599- if ( argv . all && isMonoRepo ) return bundleAddons ( buildPlugin , "plugins" ) ;
600- else {
606+ if ( argv . all && isMonoRepo ) {
607+ bundleAddons ( buildPlugin , "plugins" ) ;
608+ return ;
609+ } else {
601610 const addon = isMonoRepo ? await selectAddon ( "plugins" ) : undefined ;
602- bundleAddon ( buildPlugin , addon ?. name , "plugins" ) ;
611+ await bundleAddon ( buildPlugin , addon ?. name , "plugins" ) ;
603612 }
604613 } else if ( argv . addon === "theme" ) {
605- if ( argv . all && isMonoRepo ) return bundleAddons ( buildTheme , "themes" ) ;
606- else {
614+ if ( argv . all && isMonoRepo ) {
615+ bundleAddons ( buildTheme , "themes" ) ;
616+ return ;
617+ } else {
607618 const addon = isMonoRepo ? await selectAddon ( "themes" ) : undefined ;
608- bundleAddon ( buildTheme , addon ?. name , "themes" ) ;
619+ await bundleAddon ( buildTheme , addon ?. name , "themes" ) ;
609620 }
610621 } else {
611622 console . log ( "Invalid addon type." ) ;
612623 }
613624 sendUpdateNotification ( ) ;
614625 } ,
615626 )
627+ // eslint-disable-next-line @typescript-eslint/no-empty-function
616628 . command ( "release" , "Interactively release a new version of an addon" , ( ) => { } , release )
617629 . parserConfiguration ( {
618630 "boolean-negation" : false ,
0 commit comments