diff --git a/.gitignore b/.gitignore index 134998a6..2c8adbc7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,9 @@ dist/ # user specific cache/ local/ +# debian build specific +deb-struct/usr # deply build binaries deploy/linux/build deploy/win32/build -deploy/darwin/build \ No newline at end of file +deploy/darwin/build diff --git a/control b/control new file mode 100644 index 00000000..eb83fe7a --- /dev/null +++ b/control @@ -0,0 +1,10 @@ +Package: Spotube +Version: 0.0.1 +Section: sound +Priority: optional +Architecture: all +Essential: no +Installed-Size: 44000 +Maintainer: KR Tirtho +Description: A music streaming app combining the power of Spotify & Youtube +Homepage: https://github.com/KRTirtho/spotube diff --git a/deb-config.json b/deb-config.json new file mode 100644 index 00000000..350df166 --- /dev/null +++ b/deb-config.json @@ -0,0 +1,4 @@ +{ + "appName": "name", + "version": "0.1" +} \ No newline at end of file diff --git a/deb-struct/DEBIAN/control b/deb-struct/DEBIAN/control new file mode 100644 index 00000000..eb83fe7a --- /dev/null +++ b/deb-struct/DEBIAN/control @@ -0,0 +1,10 @@ +Package: Spotube +Version: 0.0.1 +Section: sound +Priority: optional +Architecture: all +Essential: no +Installed-Size: 44000 +Maintainer: KR Tirtho +Description: A music streaming app combining the power of Spotify & Youtube +Homepage: https://github.com/KRTirtho/spotube diff --git a/deploy/linux/spotube/Spotube Icon.svg b/deploy/linux/spotube/Spotube Icon.svg new file mode 100644 index 00000000..954565fc --- /dev/null +++ b/deploy/linux/spotube/Spotube Icon.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/deploy/linux/spotube/spotube.desktop b/deploy/linux/spotube/spotube.desktop index a5c80915..7440c1ca 100644 --- a/deploy/linux/spotube/spotube.desktop +++ b/deploy/linux/spotube/spotube.desktop @@ -2,7 +2,7 @@ Type=Application Name=Spotube Exec=AppRun -Icon=default +Icon=spotube Comment=A music streaming app combining the power of Spotify & Youtube -Terminal=true +Terminal=false Categories=Music; diff --git a/deploy/linux/spotube/spotube.jpg b/deploy/linux/spotube/spotube.jpg deleted file mode 100644 index 4b544b71..00000000 Binary files a/deploy/linux/spotube/spotube.jpg and /dev/null differ diff --git a/deploy/linux/spotube/spotube.png b/deploy/linux/spotube/spotube.png new file mode 100644 index 00000000..93d05c6c Binary files /dev/null and b/deploy/linux/spotube/spotube.png differ diff --git a/package.json b/package.json index 04c47e3a..93ec81b8 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "start": "qode ./dist/index.js", "start:trace": "qode ./dist/index.js --trace", "debug": "qode --inspect ./dist/index.js", - "pack": "nodegui-packer -p ./dist" + "pack": "nodegui-packer -p ./dist", + "pack-deb": "node scripts/build-deb.js" }, "dependencies": { "@nodegui/nodegui": "^0.27.0", diff --git a/scripts/build-deb.js b/scripts/build-deb.js new file mode 100644 index 00000000..0ff4b7e1 --- /dev/null +++ b/scripts/build-deb.js @@ -0,0 +1,86 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const path = require("path"); +const fs = require("fs"); +const process = require("child_process"); +// Get the foldername +const deployDir = path.join("deploy"); // ./deploy relative to where command is executed +const debStructDir = path.join(__dirname, "..", "deb-struct"); // ./deb-struct relative to where command is executed +const configFile = path.join(deployDir, "config.json"); +const appName = JSON.parse(fs.readFileSync(configFile, { encoding: 'utf8' })).appName; +const appNameSanitized = appName.replace(' ', '').toLowerCase(); +const buildFolder = path.join(deployDir, "linux", "build", appName); +function cleanDirectories() { + console.log("Cleaning DEBIAN:"); + console.log(process.execSync('rm -rf ' + debStructDir + '/DEBIAN/*')); + console.log("Cleaning bin:"); + console.log(process.execSync('rm -rf ' + debStructDir + '/usr/bin/*')); + console.log("Cleaning lib:"); + console.log(process.execSync('rm -rf ' + debStructDir + '/usr/lib/*')); + console.log("Cleaning applications:"); + console.log(process.execSync('rm -rf ' + debStructDir + '/usr/share/applications/*')); +} +function copyControlFile() { + console.log("Copying control:"); + console.log(process.execSync('cp ./control ' + debStructDir + '/DEBIAN/control')); +} +function copyBuildFolderToLib() { + const folderPath = path.join(debStructDir, "usr", "lib"); + console.log("Copying Build Folder:"); + console.log(process.execSync('cp -R "' + buildFolder + '" "' + folderPath + '"')); + console.log(process.execSync('cp -R ./assets "' + path.join(folderPath, appName) + '"')); + if (appName !== appNameSanitized) { + console.log(process.execSync('mv "' + path.join(folderPath, appName) + '" "' + path.join(folderPath, appNameSanitized) + '"')); + } +} +function createSymlinkToBin() { + const folderPath = '"' + path.join(debStructDir, "usr", "bin", appName) + '"'; + console.log("Generating Symlink:"); + console.log(process.execSync('ln -s /usr/lib/' + appNameSanitized + '/qode ' + folderPath)); +} +function copyDesktopFileToApplications() { + console.log("Copying Desktop File:"); + const desktopSrc = path.join(buildFolder, getFilesFromPath(buildFolder, '.desktop')[0]); + const desktopDest = path.join(debStructDir, 'usr', 'share', 'applications', appName.replace(' ', '').toLowerCase() + '.desktop'); + console.log(process.execSync('cp "' + desktopSrc + '" "' + desktopDest + '"')); + // Copy icon and change relative Icon path to absolute path + const desktopContents = fs.readFileSync(desktopDest).toString(); + let m; + const regex = /^Icon=(.*)$/m; + const matches = regex.exec(desktopContents); + if (matches && matches.length > 1) { + const iconFileName = matches[1]; + if (!path.isAbsolute(iconFileName)) { + // check if file exists, look for extensions {.png,.svg,.svgz,.xpm} as @nodegui/packer does + let iconFileExt = ''; + for (const fileExt of ['png', 'svg', 'svgz', 'xpm']) { + if (fs.existsSync(path.join(path.dirname(desktopSrc), iconFileName + '.' + fileExt))) { + iconFileExt = fileExt; + break; + } + } + if (!iconFileExt) { + throw new Error(iconFileName + '{.png,.svg,.svgz,.xpm} defined in desktop file but not found in ' + path.dirname(desktopSrc)); + } + const absIconPath = '/' + path.join('usr', 'lib', appNameSanitized, iconFileName + '.' + iconFileExt); + fs.writeFileSync(desktopDest, desktopContents.replace(regex, 'Icon=' + absIconPath)); + console.log('Adjusted relative icon path: ' + iconFileName + ' => ' + absIconPath); + } + } +} +function createDeb() { + // Create DEBIAN File + console.log("Generating Debian:"); + console.log(process.execSync('dpkg-deb --build "' + debStructDir + '" "' + appNameSanitized + '.deb"')); +} +function getFilesFromPath(path, extension) { + let files = fs.readdirSync(path); + return files.filter(file => file.match(new RegExp(`.*\.(${extension})`, 'ig'))); +} +cleanDirectories(); +copyControlFile(); +copyBuildFolderToLib(); +createSymlinkToBin(); +copyDesktopFileToApplications(); +createDeb(); +//# sourceMappingURL=build-deb.js.map