-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from nextcloud-libraries/backport/207/stable1
[stable1] Allow to specify an output prefix and load app id from appinfo
- Loading branch information
Showing
2 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { lstatSync } from 'node:fs' | ||
import { join, resolve, sep } from 'node:path' | ||
|
||
/** | ||
* Check if a given path exists and is a directory | ||
* | ||
* @param {string} filePath The path | ||
* @return {boolean} | ||
*/ | ||
function isDirectory(filePath: string): boolean { | ||
const stats = lstatSync(filePath, { throwIfNoEntry: false }) | ||
return stats !== undefined && stats.isDirectory() | ||
} | ||
|
||
/** | ||
* Check if a given path exists and is a directory | ||
* | ||
* @param {string} filePath The path | ||
* @return {boolean} | ||
*/ | ||
function isFile(filePath: string): boolean { | ||
const stats = lstatSync(filePath, { throwIfNoEntry: false }) | ||
return stats !== undefined && stats.isFile() | ||
} | ||
|
||
/** | ||
* Find the path of nearest `appinfo/info.xml` relative to given path | ||
* | ||
* @param {string} currentPath The path to check for appinfo | ||
* @return {string|undefined} Either the full path including the `info.xml` part or `undefined` if no found | ||
*/ | ||
export function findAppinfo(currentPath: string): string | null { | ||
while (currentPath && currentPath !== sep) { | ||
const appinfoPath = join(currentPath, 'appinfo') | ||
if (isDirectory(appinfoPath) && isFile(join(appinfoPath, 'info.xml'))) { | ||
return join(appinfoPath, 'info.xml') | ||
} | ||
currentPath = resolve(currentPath, '..') | ||
} | ||
return undefined | ||
} |