write as cjs

This commit is contained in:
srgooglo 2022-10-04 15:04:31 +02:00
parent fcded2db92
commit 39a3355812
2 changed files with 17 additions and 10 deletions

View File

@ -2,11 +2,12 @@ require("dotenv").config()
const packagejson = require("../package.json") const packagejson = require("../package.json")
import fs from "fs" const fs = require("fs")
import path from "path" const path = require("path")
import express from "express" const express = require("express")
import cors from "cors" const cors = require("cors")
import setupLatestRelease from "./lib/setupDist"
const { setupLatestRelease } = require("./lib/setupDist")
global.remoteRepo = "ragestudio/comty" global.remoteRepo = "ragestudio/comty"
global.cachePath = path.join(process.cwd(), "cache") global.cachePath = path.join(process.cwd(), "cache")
@ -44,6 +45,7 @@ async function runServer() {
app.listen(portListen) app.listen(portListen)
console.log(`Running Wrapper v${packagejson.version}`)
console.log(`🌐 Listening app in port [${portListen}]`) console.log(`🌐 Listening app in port [${portListen}]`)
} }

View File

@ -8,7 +8,7 @@ const octokit = new Octokit({
// auth: process.env.GITHUB_TOKEN // auth: process.env.GITHUB_TOKEN
}) })
export async function getLatestReleaseBundleFromGithub() { async function getLatestReleaseBundleFromGithub() {
console.log("Getting latest release bundle from github...") console.log("Getting latest release bundle from github...")
const release = await octokit.repos.getLatestRelease({ const release = await octokit.repos.getLatestRelease({
@ -21,7 +21,7 @@ export async function getLatestReleaseBundleFromGithub() {
return bundle return bundle
} }
export async function downloadBundle(bundle) { async function downloadBundle(bundle) {
// check if bundle exists // check if bundle exists
if (fs.existsSync(path.join(global.cachePath, "app_dist.7z"))) { if (fs.existsSync(path.join(global.cachePath, "app_dist.7z"))) {
fs.unlinkSync(path.join(global.cachePath, "app_dist.7z")) fs.unlinkSync(path.join(global.cachePath, "app_dist.7z"))
@ -43,7 +43,7 @@ export async function downloadBundle(bundle) {
}) })
} }
export async function extractBundle() { async function extractBundle() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log("Extracting bundle...") console.log("Extracting bundle...")
@ -57,7 +57,7 @@ export async function extractBundle() {
}) })
} }
export async function setupLatestRelease() { async function setupLatestRelease() {
// create cache folder // create cache folder
if (!fs.existsSync(global.cachePath)) { if (!fs.existsSync(global.cachePath)) {
fs.mkdirSync(global.cachePath) fs.mkdirSync(global.cachePath)
@ -84,4 +84,9 @@ export async function setupLatestRelease() {
} }
} }
export default setupLatestRelease module.exports = {
getLatestReleaseBundleFromGithub,
downloadBundle,
extractBundle,
setupLatestRelease,
}