Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows non-existent platforms #7

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/checks/core_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,45 @@ export const countCoresInZip: CheckFn = async (zip, reporter) => {
}
}

export const checkAllSpecifiedPlatformsExist: CheckFn = async (
zip,
reporter
) => {
export const checkSpecifiedPlatformsExist: CheckFn = async (zip, reporter) => {
const coreFiles = await coresList(zip)

for (const coreFile of coreFiles) {
const json = await getJSONFromZip<CoreJSON>(zip, coreFile)
if (!json) continue

const { success } = await coreJsonSchema.safeParseAsync(json)
if (!success) continue

const platformIds = json.core.metadata.platform_ids
const atLeastOnePlatformExists = (
await Promise.all(
platformIds.map(
async (p) => await fileExistsInZip(zip, `Platforms/${p}.json`)
)
)
).some((e) => e)

if (!atLeastOnePlatformExists) {
reporter.error(
`Core ${coreFile} should specify at least 1 platform with a matching platform.json file`,
"\n https://www.analogue.co/developer/docs/platform-metadata#platform.json:~:text=All%20cores%20that%20specify%20a%20platform%20but%20no%20matching%20file%20is%20found%20for%20that%20platform%20will%20not%20display%20any%20additional%20information%20about%20the%20platform%20nor%20be%20able%20to%20access%20future%20features%20in%20Analogue%20OS."
)
}

for (const platformId of platformIds) {
const platformPath = `Platforms/${platformId}.json`
const platformExists = await fileExistsInZip(zip, platformPath)

if (!platformExists) {
reporter.error(
if (!platformExists && !atLeastOnePlatformExists) {
reporter.recommend(
`Specified platform ${platformId} is missing, ${platformPath} should exist`,
"\n https://www.analogue.co/developer/docs/platform-metadata#platform.json"
)
}

if (!platformExists) continue

const platformImagePath = `Platforms/_images/${platformId}.bin`
const platformImageExists = await fileExistsInZip(zip, platformImagePath)

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { checkForRootFiles } from "./checks/folders"
import { Reporter } from "./report"
import {
checkAllMentionedFilesExist,
checkAllSpecifiedPlatformsExist,
checkSpecifiedPlatformsExist,
checkCoreFolderName,
checkForSemver,
checkCoreJSONSchema,
Expand Down Expand Up @@ -62,7 +62,7 @@ export const processZip = async (
await checkCoreJSONSchema(zip, reporter)
await countCoresInZip(zip, reporter)
await checkForSemver(zip, reporter)
await checkAllSpecifiedPlatformsExist(zip, reporter)
await checkSpecifiedPlatformsExist(zip, reporter)

// input

Expand Down
2 changes: 1 addition & 1 deletion src/schemas/instance_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const instanceJsonSchema = z.strictObject({
.optional(),
data_slots: z
.array(
z.strictObject({
z.object({
id: intOrHexSchema({ bits: 16, signed: false }),
filename: z.string().max(255),
})
Expand Down
Loading