Skip to content

Commit 8676a39

Browse files
committed
Convert to modules
1 parent 9dcd4d2 commit 8676a39

7 files changed

Lines changed: 74 additions & 72 deletions

File tree

.eslintrc.cjs renamed to .eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
root: true,
33
extends: ['eslint:recommended', 'prettier'],
44
plugins: ['svelte'],
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// This file is partially copied from: https://github.com/LuanRT/BgUtils/blob/main/examples/node/index.ts
22

3-
const { Innertube, UniversalCache, Log } = require('youtubei.js')
4-
const { BG } = require('bgutils-js')
5-
const { JSDOM } = require('jsdom')
6-
const fetch = require('electron-fetch').default
3+
import { Innertube, UniversalCache, Log } from 'youtubei.js'
4+
import { BG } from 'bgutils-js'
5+
import { JSDOM } from 'jsdom'
6+
import electronFetch from 'electron-fetch'
7+
const fetch = electronFetch.default
78

89
const REQUEST_KEY = 'O43z0dpjhgX20SCx4KAo'
910

@@ -76,7 +77,7 @@ const setupDownloadInnertube = async () => {
7677
})
7778
}
7879

79-
module.exports.fetchYtStream = async (videoId) => {
80+
export const fetchYtStream = async (videoId) => {
8081
await setupDownloadInnertube()
8182

8283
const ytStream = await downloadInnertube.download(videoId, {
@@ -87,7 +88,7 @@ module.exports.fetchYtStream = async (videoId) => {
8788
return ytStream
8889
}
8990

90-
module.exports.searchYt = async (query) => {
91+
export const searchYt = async (query) => {
9192
await setupSearchInnertube()
9293

9394
const innertubeResults = await searchInnertube.search(query, {
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const { app, ipcMain, dialog, shell, Menu, BrowserWindow } = require('electron')
2-
const fs = require('fs')
3-
const fsPromises = require('fs/promises')
4-
const { execSync } = require('child_process')
5-
const path = require('path')
6-
const { compareVersions } = require('compare-versions')
7-
const fetch = require('electron-fetch').default
8-
const xxhash = require('xxhash-wasm')
9-
const serve = require('electron-serve').default
10-
const Store = require('electron-store').default
11-
const processQueue = require('./processQueue.cjs')
12-
const { searchYt } = require('./fetchYtStream.cjs')
1+
import { app, ipcMain, dialog, shell, Menu, BrowserWindow } from 'electron'
2+
import fs from 'fs'
3+
import fsPromises from 'fs/promises'
4+
import { execSync } from 'child_process'
5+
import path from 'path'
6+
import { compareVersions } from 'compare-versions'
7+
import electronFetch from 'electron-fetch'
8+
const fetch = electronFetch.default
9+
import xxhash from 'xxhash-wasm'
10+
import serve from 'electron-serve'
11+
import Store from 'electron-store'
12+
import * as processQueue from './processQueue.js'
13+
import { searchYt } from './fetchYtStream.js'
1314

1415
let electronStore = null
1516

@@ -202,7 +203,7 @@ function createWindow() {
202203
webPreferences: {
203204
sandbox: true,
204205
devTools: process.env.NODE_ENV === 'dev',
205-
preload: path.resolve(path.join(__dirname, 'preload.cjs')),
206+
preload: path.resolve(path.join(import.meta.dirname, 'preload.cjs')),
206207
},
207208
})
208209

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const os = require('os')
2-
const fs = require('fs/promises')
3-
const { createWriteStream } = require('fs')
4-
const { pipeline } = require('stream/promises')
5-
const path = require('path')
6-
const childProcess = require('child_process')
7-
const treeKill = require('tree-kill')
8-
const sanitizeFilename = require('sanitize-filename')
9-
const { app, BrowserWindow, powerSaveBlocker } = require('electron')
10-
const { fetchYtStream } = require('./fetchYtStream.cjs')
1+
import os from 'os'
2+
import fs from 'fs/promises'
3+
import { createWriteStream } from 'fs'
4+
import { pipeline } from 'stream/promises'
5+
import path from 'path'
6+
import childProcess from 'child_process'
7+
import treeKill from 'tree-kill'
8+
import sanitizeFilename from 'sanitize-filename'
9+
import { app, BrowserWindow, powerSaveBlocker } from 'electron'
10+
import { fetchYtStream } from './fetchYtStream.js'
1111

1212
let statusUpdateCallback = null,
1313
donateUpdateCallback = null
@@ -19,9 +19,9 @@ let curProgressFtStemIdx = null
1919
function getPathToThirdPartyApps() {
2020
if (process.env.NODE_ENV === 'dev') {
2121
if (process.platform === 'win32') {
22-
return path.resolve(path.join(__dirname, '..', 'win-extra-files', 'ThirdPartyApps'))
22+
return path.resolve(path.join(import.meta.dirname, '..', 'win-extra-files', 'ThirdPartyApps'))
2323
} else if (process.platform === 'darwin') {
24-
return path.resolve(path.join(__dirname, '..', 'mac-extra-files', 'ThirdPartyApps'))
24+
return path.resolve(path.join(import.meta.dirname, '..', 'mac-extra-files', 'ThirdPartyApps'))
2525
} else {
2626
return null
2727
}
@@ -37,7 +37,7 @@ function getPathToThirdPartyApps() {
3737
function getPathToModels() {
3838
if (process.env.NODE_ENV === 'dev') {
3939
if (process.platform === 'win32' || process.platform === 'darwin') {
40-
return path.resolve(path.join(__dirname, '..', 'anyos-extra-files', 'Models'))
40+
return path.resolve(path.join(import.meta.dirname, '..', 'anyos-extra-files', 'Models'))
4141
} else {
4242
return null
4343
}
@@ -252,11 +252,11 @@ function getFfmpegCompressionArguments(filetype) {
252252
}
253253

254254
async function _processVideo(video, tmpDir) {
255-
const demucsModelName = module.exports.getModelName()
256-
const demucsStemsFiletype = module.exports.getOutputFormat()
255+
const demucsModelName = getModelName()
256+
const demucsStemsFiletype = getOutputFormat()
257257
const compressionArgs = getFfmpegCompressionArguments(demucsStemsFiletype)
258-
const needsPrefix = module.exports.getPrefixStemFilenameWithSongName()
259-
const needsOriginal = module.exports.getPreserveOriginalAudio()
258+
const needsPrefix = getPrefixStemFilenameWithSongName()
259+
const needsOriginal = getPreserveOriginalAudio()
260260

261261
const beginTime = Date.now()
262262
console.log(`BEGIN downloading/processing video "${video.videoId}" - "${video.title}"`)
@@ -295,7 +295,7 @@ async function _processVideo(video, tmpDir) {
295295
`Splitting video "${video.videoId}"; ${jobCount} jobs using model "${demucsModelName}"...`
296296
)
297297
const demucsExeArgs = [mediaPath, '-n', demucsModelName, '-j', jobCount]
298-
if (module.exports.getPyTorchBackend() === 'cpu') {
298+
if (getPyTorchBackend() === 'cpu') {
299299
console.log('Running with "-d cpu" to force CPU instead of CUDA')
300300
demucsExeArgs.push('-d', 'cpu')
301301
} else if (process.platform === 'darwin') {
@@ -385,9 +385,9 @@ async function _processVideo(video, tmpDir) {
385385
updateProgressRaw(video.videoId, 0.99)
386386

387387
const outputBasePathContainingFolder =
388-
video.mediaSource === 'local' && module.exports.getLocalFileOutputToContainingDir()
388+
video.mediaSource === 'local' && getLocalFileOutputToContainingDir()
389389
? path.dirname(mediaPath)
390-
: module.exports.getOutputPath()
390+
: getOutputPath()
391391
const outputBasePath = path.join(outputBasePathContainingFolder, outputFolderName)
392392
await fs.mkdir(outputBasePath, { recursive: true })
393393
console.log(`Copying all stems to "${outputBasePath}"`)
@@ -436,7 +436,7 @@ async function processVideo(video) {
436436
} catch (err) {
437437
console.trace(err)
438438

439-
const status = module.exports.getVideoStatus(video.videoId)
439+
const status = getVideoStatus(video.videoId)
440440
if (status === null) {
441441
console.log('Task was canceled by user.')
442442
} else {
@@ -456,7 +456,7 @@ async function processVideo(video) {
456456
}
457457

458458
// Will filter out the current (completed) video
459-
module.exports.setItems(curItems)
459+
setItems(curItems)
460460

461461
if (powerSaveBlockId !== null) {
462462
try {
@@ -471,9 +471,9 @@ async function processVideo(video) {
471471
}
472472
}
473473

474-
module.exports.setItems = async (items) => {
474+
export const setItems = async (items) => {
475475
items = items.filter((video) => {
476-
let status = module.exports.getVideoStatus(video.videoId)
476+
let status = getVideoStatus(video.videoId)
477477
if (status === null) {
478478
status = { step: 'queued' }
479479
setVideoStatusAndPath(video.videoId, status, null)
@@ -552,12 +552,12 @@ function setVideoStatusAndPath(videoId, status, path) {
552552
})
553553
}
554554

555-
module.exports.setElectronStore = (store) => {
555+
export const setElectronStore = (store) => {
556556
electronStore = store
557557
loadVideosDb()
558558
}
559559

560-
module.exports.getOutputPath = () => {
560+
export const getOutputPath = () => {
561561
if (electronStore) {
562562
const outputPath = electronStore.get('outputPath')
563563
if (outputPath) {
@@ -567,7 +567,7 @@ module.exports.getOutputPath = () => {
567567
return path.join(os.homedir(), 'Music', 'StemRoller')
568568
}
569569

570-
module.exports.getModelName = () => {
570+
export const getModelName = () => {
571571
if (electronStore) {
572572
const modelName = electronStore.get('modelName')
573573
if (modelName) {
@@ -577,39 +577,39 @@ module.exports.getModelName = () => {
577577
return 'htdemucs'
578578
}
579579

580-
module.exports.getLocalFileOutputToContainingDir = () => {
580+
export const getLocalFileOutputToContainingDir = () => {
581581
return electronStore.get('localFileOutputToContainingDir') || false
582582
}
583583

584-
module.exports.getPrefixStemFilenameWithSongName = () => {
584+
export const getPrefixStemFilenameWithSongName = () => {
585585
return electronStore.get('prefixStemFilenameWithSongName') || false
586586
}
587587

588-
module.exports.getPreserveOriginalAudio = () => {
588+
export const getPreserveOriginalAudio = () => {
589589
return electronStore.get('preserveOriginalAudio') || false
590590
}
591591

592-
module.exports.setOutputPath = (outputPath) => {
592+
export const setOutputPath = (outputPath) => {
593593
electronStore.set('outputPath', outputPath)
594594
}
595595

596-
module.exports.setModelName = (name) => {
596+
export const setModelName = (name) => {
597597
electronStore.set('modelName', name)
598598
}
599599

600-
module.exports.setLocalFileOutputToContainingDir = (value) => {
600+
export const setLocalFileOutputToContainingDir = (value) => {
601601
electronStore.set('localFileOutputToContainingDir', value)
602602
}
603603

604-
module.exports.setPrefixStemFilenameWithSongName = (value) => {
604+
export const setPrefixStemFilenameWithSongName = (value) => {
605605
electronStore.set('prefixStemFilenameWithSongName', value)
606606
}
607607

608-
module.exports.setPreserveOriginalAudio = (value) => {
608+
export const setPreserveOriginalAudio = (value) => {
609609
electronStore.set('preserveOriginalAudio', value)
610610
}
611611

612-
module.exports.getOutputFormat = () => {
612+
export const getOutputFormat = () => {
613613
if (electronStore) {
614614
const outputFormat = electronStore.get('outputFormat')
615615
if (outputFormat) {
@@ -619,11 +619,11 @@ module.exports.getOutputFormat = () => {
619619
return 'wav'
620620
}
621621

622-
module.exports.setOutputFormat = (outputFormat) => {
622+
export const setOutputFormat = (outputFormat) => {
623623
electronStore.set('outputFormat', outputFormat)
624624
}
625625

626-
module.exports.getPyTorchBackend = () => {
626+
export const getPyTorchBackend = () => {
627627
if (electronStore) {
628628
const backend = electronStore.get('pyTorchBackend')
629629
if (backend) {
@@ -633,27 +633,27 @@ module.exports.getPyTorchBackend = () => {
633633
return 'auto'
634634
}
635635

636-
module.exports.setPyTorchBackend = (backend) => {
636+
export const setPyTorchBackend = (backend) => {
637637
electronStore.set('pyTorchBackend', backend)
638638
}
639639

640-
module.exports.getVideoStatus = (videoId) => {
640+
export const getVideoStatus = (videoId) => {
641641
if (videoId in videosDb) {
642642
return videosDb[videoId].status
643643
} else {
644644
return null
645645
}
646646
}
647647

648-
module.exports.getVideoPath = (videoId) => {
648+
export const getVideoPath = (videoId) => {
649649
if (videoId in videosDb) {
650650
return videosDb[videoId].path
651651
} else {
652652
return null
653653
}
654654
}
655655

656-
module.exports.deleteVideoStatusAndPath = (videoId) => {
656+
export const deleteVideoStatusAndPath = (videoId) => {
657657
if (videoId in videosDb) {
658658
const nulledEntry = videosDb[videoId]
659659
for (const i in nulledEntry) {
@@ -670,24 +670,24 @@ module.exports.deleteVideoStatusAndPath = (videoId) => {
670670
}
671671
}
672672

673-
module.exports.isBusy = () => {
673+
export const isBusy = () => {
674674
return (
675675
curItems.filter((video) => {
676-
const status = module.exports.getVideoStatus(video.videoId)
676+
const status = getVideoStatus(video.videoId)
677677
return status.step === 'processing' || status.step === 'downloading'
678678
}).length > 0
679679
)
680680
}
681681

682-
module.exports.registerStatusUpdateCallback = (callback) => {
682+
export const registerStatusUpdateCallback = (callback) => {
683683
statusUpdateCallback = callback
684684
}
685685

686-
module.exports.registerDonateUpdateCallback = (callback) => {
686+
export const registerDonateUpdateCallback = (callback) => {
687687
donateUpdateCallback = callback
688688
}
689689

690-
module.exports.deleteTmpFolders = async () => {
690+
export const deleteTmpFolders = async () => {
691691
const tmpBasePath = os.tmpdir()
692692
const items = await fs.readdir(tmpBasePath)
693693
for (const itemName of items) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "Unlicense",
99
"author": "StemRoller Developers",
1010
"repository": "https://github.com/stemrollerapp/stemroller.git",
11-
"main": "main-src/main.cjs",
11+
"main": "main-src/main.js",
1212
"scripts": {
1313
"download-third-party-apps": "node download-third-party-apps.js",
1414
"dev": "cross-env NODE_ENV=dev STEMROLLER_RUN_FROM_SOURCE=true npm run dev:all",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
plugins: {
33
'@tailwindcss/postcss': {},
44
autoprefixer: {},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const defaultTheme = require('tailwindcss/defaultTheme')
1+
import defaultTheme from 'tailwindcss/defaultTheme'
22

3-
module.exports = {
3+
export default {
44
content: ['./renderer-src/**/*.{html,js,svelte,ts}'],
55
theme: {
66
extend: {
77
fontFamily: {
8-
'sans': ['Mukta', ...defaultTheme.fontFamily.sans],
8+
sans: ['Mukta', ...defaultTheme.fontFamily.sans],
99
},
1010
},
1111
},

0 commit comments

Comments
 (0)