-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add suggestions for incorrect ids
Aligns the id validation of the UUID and Actions[0].UUID within the manifest to match the directory name (minus the .sdPlugin suffix)
- Loading branch information
Showing
7 changed files
with
83 additions
and
40 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
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
import { colorize } from "../../../common/stdout"; | ||
import { rule } from "../../rule"; | ||
import { type PluginContext } from "../plugin"; | ||
|
||
/** | ||
* Validates the unique identifiers within the manifest, ensuring the `UUID` matches the parent directory, and the actions' `UUID` are unique and are prefixed with the plugin's `UUID`. | ||
*/ | ||
export const manifestUuids = rule<PluginContext>(async function (plugin: PluginContext) { | ||
const { value: manifest } = plugin.manifest; | ||
|
||
// When the directory name is a valid identifier, check it matches the identifier in the manifest. | ||
if (plugin.hasValidId && manifest.UUID?.value !== undefined && plugin.id !== manifest.UUID.value) { | ||
this.addError(plugin.manifest.path, "must match parent directory name", { | ||
location: manifest.UUID.location, | ||
suggestion: `Expected: ${plugin.id}` | ||
}); | ||
} | ||
|
||
// Check all of the action identifiers. | ||
const uuids = new Set<string>(); | ||
manifest.Actions?.forEach(({ UUID: uuid }) => { | ||
if (uuid?.value === undefined) { | ||
return; | ||
} | ||
|
||
// Validate the action identifier is unique. | ||
if (uuids.has(uuid.value)) { | ||
this.addError(plugin.manifest.path, "must be unique", uuid); | ||
} else { | ||
uuids.add(uuid.value); | ||
} | ||
|
||
// Check if the action identifier is prefixed with the plugin identifier. | ||
if (plugin.hasValidId && !uuid.value.startsWith(plugin.id)) { | ||
this.addWarning(plugin.manifest.path, `should be prefixed with ${colorize(plugin.id)}`, uuid); | ||
} | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
import { existsSync, lstatSync } from "node:fs"; | ||
import { basename } from "node:path"; | ||
import { colorize } from "../../../common/stdout"; | ||
import { isValidPluginId } from "../../../stream-deck"; | ||
import { rule } from "../../rule"; | ||
import { directorySuffix, type PluginContext } from "../plugin"; | ||
|
||
export const pathIsDirectoryAndUuid = rule<PluginContext>(function (plugin: PluginContext) { | ||
const name = basename(this.path); | ||
|
||
// Path exists. | ||
if (!existsSync(this.path)) { | ||
this.addError(this.path, "Path does not exist"); | ||
} else if (!lstatSync(this.path).isDirectory()) { | ||
this.addError(this.path, "Directory not found"); | ||
return; | ||
} | ||
|
||
// Path is a directory. | ||
if (!lstatSync(this.path).isDirectory()) { | ||
this.addError(this.path, "Path must be a directory"); | ||
return; | ||
} | ||
|
||
// Directory name suffix. | ||
if (!name.endsWith(directorySuffix)) { | ||
this.addError(this.path, "Name must be suffixed with '.sdPlugin'"); | ||
this.addError(this.path, `Name must be suffixed with ${colorize(".sdPlugin")}`); | ||
} | ||
|
||
if (!isValidPluginId(plugin.uuid)) { | ||
// Directory name is a valid identifier. | ||
if (!isValidPluginId(plugin.id)) { | ||
this.addError(this.path, "Name must be in reverse DNS format, and must only contain lowercase alphanumeric characters (a-z, 0-9), hyphens (-), and periods (.)", { | ||
suggestion: "Example: 'com.elgato.wave-link'" | ||
suggestion: "Example: com.elgato.wave-link" | ||
}); | ||
} | ||
}); |