diff --git a/.github/workflows/update_plugins_host.yml b/.github/workflows/host_plugins.yml similarity index 89% rename from .github/workflows/update_plugins_host.yml rename to .github/workflows/host_plugins.yml index ab3dc52..7a85fe8 100644 --- a/.github/workflows/update_plugins_host.yml +++ b/.github/workflows/host_plugins.yml @@ -1,4 +1,4 @@ -name: Update Plugins +name: Host Plugins on: push: @@ -6,7 +6,7 @@ on: - master jobs: - updatehost: + host: if: github.repository == 'LNReader/lnreader-sources' runs-on: ubuntu-latest steps: @@ -19,7 +19,7 @@ jobs: - name: Install dependencies run: npm install - - name: Update plugins host + - name: Host plugins run: | git config user.name "github-actions[bot]" git config user.email 41898282+github-actions[bot]@users.noreply.github.com diff --git a/host.ps1 b/host.ps1 index 98c81b7..93b8e31 100644 --- a/host.ps1 +++ b/host.ps1 @@ -2,16 +2,12 @@ $current=$(git rev-parse --abbrev-ref HEAD) $dist='dist' $exists=$(git show-ref refs/heads/$dist) -echo $current -echo $exists - if ($exists){ - git checkout $dist -}else{ - ## Make a new one - git checkout -b $dist + git branch -D $dist } +git checkout --orphan $dist + if(-Not $?){ # If checkout failed echo "==========" @@ -19,14 +15,14 @@ if(-Not $?){ exit 1 } -git merge $current --strategy-option theirs - +git reset +rm -r -fo .js +npm run clearMultisrc npm run generate npm run json -git add . -git add -f .dist .js/plugins -git commit -m "Update plugins host" +git add -f icons .dist .js/plugins +git commit -m "Host plugins" git push -f origin $dist -git checkout $current +git checkout -f $current diff --git a/host.sh b/host.sh index 060f816..67c85cc 100755 --- a/host.sh +++ b/host.sh @@ -3,11 +3,11 @@ dist=dist exists=`git show-ref refs/heads/$dist` if [ -n "$exists" ]; then - git checkout $dist -else - git checkout -b $dist + git branch -D $dist fi +git checkout --orphan $dist + if [ $? -eq 1 ]; then # If checkout failed echo "==========" @@ -15,15 +15,14 @@ if [ $? -eq 1 ]; then exit 1 fi -git merge $current --strategy-option theirs - -npm run clearMulti +git reset +rm -rf .js +npm run clearMultisrc npm run generate npm run json -git add . -git add -f .dist .js/plugins -git commit -m "Update plugins host" +git add -f icons .dist .js/plugins +git commit -m "Host plugins" git push -f origin $dist -git checkout $current +git checkout -f $current diff --git a/index.ts b/index.ts index 89f47b6..a5c37f0 100644 --- a/index.ts +++ b/index.ts @@ -71,8 +71,8 @@ app.post("/popularNovels/", async (req, res) => { filters, }); res.json(novels); - } catch (err) { - res.json({ error: err }); + } catch (err: unknown) { + res.json({ error: String(err) }); } }); app.post("/searchNovels/", async (req, res) => { @@ -84,8 +84,8 @@ app.post("/searchNovels/", async (req, res) => { req.body["searchTerm"] ); res.json(novels); - } catch (err) { - res.json({ error: err }); + } catch (err: unknown) { + res.json({ error: String(err) }); } }); app.post("/parseNovelAndChapters/", async (req, res) => { @@ -95,8 +95,8 @@ app.post("/parseNovelAndChapters/", async (req, res) => { req.body["novelUrl"] ); res.json(sourceNovel); - } catch (err) { - res.json({ error: err }); + } catch (err: unknown) { + res.json({ error: String(err) }); } }); app.post("/parseChapter/", async (req, res) => { @@ -106,8 +106,8 @@ app.post("/parseChapter/", async (req, res) => { req.body["chapterUrl"] ); res.send(chapterText); - } catch (err) { - res.json({ error: err }); + } catch (err: unknown) { + res.json({ error: String(err) }); } }); app.post("/fetchImage/", async (req, res) => { @@ -117,8 +117,8 @@ app.post("/fetchImage/", async (req, res) => { req.body["url"] ); res.send(base64); - } catch (err) { - res.json({ error: err }); + } catch (err: unknown) { + res.json({ error: String(err) }); } }); diff --git a/package.json b/package.json index 11c79c3..4cd4a60 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "exit 0", "json": "tsc && node ./.js/scripts/json_plugins.js", "generate": "ts-node ./scripts/multisrc/generate.ts", - "clearMulti": "ts-node ./scripts/clearMultisrc.ts", + "clearMultisrc": "find . -type f -wholename \"*plugins*\\[*\\]*.[t,j]s\" -delete", "less": "npx less ./test_web/static/css/index.less ./test_web/static/css/index.css", "host-linux": "chmod +x ./host.sh && ./host.sh", "host-windows": "powershell ./host.ps1" diff --git a/scripts/clearMultisrc.ts b/scripts/clearMultisrc.ts deleted file mode 100644 index fbe91f5..0000000 --- a/scripts/clearMultisrc.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as path from 'path' -import * as fs from 'fs' - -for (let pluginDir of ['plugins', path.join('.js', 'plugins')]){ - if(fs.existsSync(pluginDir)){ - fs.readdirSync(pluginDir).forEach(lang => { - const langDir = path.join(pluginDir, lang); - fs.readdirSync(langDir).forEach(plugin => { - if(plugin.includes("[") && plugin.includes("]")){ - fs.unlinkSync(path.join(langDir, plugin)); - } - }) - }) - } -} diff --git a/scripts/json_plugins.ts b/scripts/json_plugins.ts index 4e6ea30..77f902a 100644 --- a/scripts/json_plugins.ts +++ b/scripts/json_plugins.ts @@ -11,13 +11,18 @@ const { execSync } = require("child_process"); const REMOTE = execSync("git remote get-url origin") .toString() .replace(/[\s\n]/g, ""); -const CURRENT_BRANCH = execSync("git rev-parse --abbrev-ref HEAD") - .toString() - .replace(/[\s\n]/g, ""); -const USERNAME = REMOTE.split("/")[3].trim(); -const REPO = REMOTE.split("/")[4] - .trim() - .replace(/\.git$/, ""); +let CURRENT_BRANCH = 'dist'; +try { + CURRENT_BRANCH = execSync("git rev-parse --abbrev-ref HEAD") + .toString() + .replace(/[\s\n]/g, ""); +}catch { + // +} +const matched = REMOTE.match(/github\.com[:/](.+?)\/(.+?)\.git/); +if(!matched) throw Error("Cant parse git url"); +const USERNAME = matched[1]; +const REPO = matched[2]; const USER_CONTENT_LINK = `https://raw.githubusercontent.com/${USERNAME}/${REPO}/${CURRENT_BRANCH}`; const ICON_LINK = `${USER_CONTENT_LINK}/icons`;