plugins: platform-dependent distributions

Massimo Melina committed May 25, 2023 at 00:43 UTC d1c4b9211402abc094a0fa285ef86e8e857eef2f
2 files changed +19 -4
dev-plugins.md
+8
@@ -249,6 +249,13 @@ Be sure to also fill the "description" field, especially with words that people
249 The files intended to be installed must go in a folder named `dist`.
250 You can keep other files outside.
251
252 +If you have platform-dependent files, you can put those files in `dist-PLATFORM` or `dist-PLATFORM-ARCHITECTURE`.
253 +For example, if you want some files to be installed only on Windows with Intel CPUs, put them in `dist-win32-x64`.
254 +
255 +Possible values for platform are `aix`, `darwin`, `freebsd`, `linux`, `openbsd`, `sunos`, `win32`.
256 +
257 +Possible values for CPUs are `arm`, `arm64`, `ia32`, `mips`, `mipsel`, `ppc`, `ppc64`, `s390`, `s390x`, `x64`.
258 +
259 You can refer to these published plugins for reference, like
260 - https://github.com/rejetto/simple-player/
261 - https://github.com/rejetto/theme-example/
@@ -263,6 +270,7 @@ HFS will scan through them in inverted alphabetical order searching for a compat
270
271 - 8.2 (v0.46.0)
272 - entry.getNext, getPrevious, getNextFiltered, getPreviousFiltered, getDefaultIcon
273 + - platform-dependent distribution
274 - 8.1 (v0.45.0) should have been 0.44.0 but forgot to update number
275 - full URL support for frontend_js and frontend_css
276 - custom.html
src/github.ts
+11 -4
@@ -9,7 +9,7 @@ import { ApiError } from './apiMiddleware'
9 import _ from 'lodash'
10 import { DAY, HFS_REPO, HTTP_BAD_REQUEST, HTTP_CONFLICT } from './const'
11
12 -const DIST_ROOT = 'dist/'
12 +const DIST_ROOT = 'dist'
13
14 type DownloadStatus = true | undefined
15 const downloading: Record<string, DownloadStatus> = {}
@@ -39,9 +39,16 @@ export async function downloadPlugin(repo: string, branch='', overwrite?: boolea
39 const installPath = PLUGINS_PATH + '/' + folder
40 const GITHUB_ZIP_ROOT = short + '-' + branch // GitHub puts everything within this folder
41 const rootWithinZip = GITHUB_ZIP_ROOT + '/' + DIST_ROOT
42 + const foldersToCopy = [ // from longer to shorter, so we first test the longer
43 + rootWithinZip + '-' + process.platform + '-' + process.arch,
44 + rootWithinZip + '-' + process.platform,
45 + rootWithinZip,
46 + ].map(x => x + '/')
47 const stream = await httpsStream(`https://github.com/${repo}/archive/refs/heads/${branch}.zip`)
43 - await unzip(stream, path =>
44 - path.startsWith(rootWithinZip) && installPath + '/' + path.slice(rootWithinZip.length) )
48 + await unzip(stream, path => {
49 + const folder = foldersToCopy.find(x => path.startsWith(x))
50 + return folder ? installPath + '/' + path.slice(folder.length) : false
51 + })
52 downloadProgress(repo, undefined)
53 await rescan() // workaround: for some reason, operations are not triggering the rescan of the watched folder. Let's invoke it.
54 return folder
@@ -57,7 +64,7 @@ export function readGithubFile(uri: string) {
64 }
65
66 export async function readOnlinePlugin(repoInfo: { full_name: string, default_branch: string }, branch='') {
60 - const res = await readGithubFile(`${repoInfo.full_name}/${branch || repoInfo.default_branch}/${DIST_ROOT}plugin.js`)
67 + const res = await readGithubFile(`${repoInfo.full_name}/${branch || repoInfo.default_branch}/${DIST_ROOT}/plugin.js`)
68 const pl = parsePluginSource(repoInfo.full_name, res) // use 'repo' as 'id' client-side
69 pl.branch = branch || undefined
70 return pl