Skip to content

Commit

Permalink
Deprecate package.json in favor of ccmod.json
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Feb 15, 2024
1 parent 811facb commit f795e0c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
4 changes: 2 additions & 2 deletions build/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function writeMods(db: PackageDB): Promise<void> {
'A mod. (Description not available; contact mod author and have them add a description to their package.json file)'
),
license: ccmod?.license || meta!.license,
page: getHomepage(ccmod?.homepage || meta!.homepage),
page: getRepositoryEntry(ccmod?.repository || ccmod?.homepage || meta!.homepage), /* old field, should be unused, kept for compatibility */
archive_link: install.url,
hash: install.hash,
version: ccmod?.version || meta!.version,
Expand All @@ -84,7 +84,7 @@ export async function writeMods(db: PackageDB): Promise<void> {
})
}

export function getHomepage(url?: string): Page[] {
export function getRepositoryEntry(url?: string): Page[] {
if (!url) {
return []
}
Expand Down
4 changes: 2 additions & 2 deletions build/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import stream from 'stream'
import yauzl from 'yauzl'
import { download, streamToBuffer } from './download'
import fs from 'fs'
import { getHomepage } from './db'
import { getRepositoryEntry } from './db'
import * as github from '@octokit/openapi-types'

export type ModMetadatas = {
Expand Down Expand Up @@ -171,7 +171,7 @@ async function getStarsAndTimestamp(
ccmod: PkgCCMod | undefined,
fetchTimestamp: boolean
): Promise<{ stars: number; timestamp?: number } | undefined> {
const homepageArr = getHomepage(ccmod?.homepage || meta!.homepage)
const homepageArr = getRepositoryEntry(ccmod?.repository || meta!.homepage)
if (homepageArr.length == 0) return
if (homepageArr.length > 1) throw new Error('Multi page star counting not supported')
const { name, url } = homepageArr[0]
Expand Down
4 changes: 2 additions & 2 deletions build/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ declare type PkgCCMod = {
description?: LocalizedString
license?: string
homepage?: string
keywords?: string[]
repository?: string
tags?: string[]
authors?: Person[]
icons?: Record<string, FilePath>
type?: 'mod' | 'library'

dependencies?: Record<string, SemverConstraint>

Expand Down
71 changes: 40 additions & 31 deletions build/tests/npDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ function testPackage(jsonData, mod, name) {

expect(typeof mod.metadata === 'object',
'metadata (type: object) required').to.be.true;
expect(Array.isArray(mod.metadata),
'metadata (type: object) required').to.be.false;
expect(mod.metadata !== null,
'metadata (type: object) required').to.be.true;
// expect(Array.isArray(mod.metadata),
// 'metadata (type: object) required').to.be.false;
// expect(mod.metadata !== null,
// 'metadata (type: object) required').to.be.true;

expect(mod.metadataCCMod !== undefined, 'metadataCCMod (type: object) required').to.be.true


expect(typeof mod.installation === 'object',
'installation (type: array) required').to.be.true;
Expand All @@ -50,16 +53,19 @@ function testPackage(jsonData, mod, name) {
'installation (type: array) required').to.be.true;
});

if (mod && mod.metadata) {
testMetadata(jsonData, mod.metadata);
}
if (mod && mod.metadataCCMod) {
testMetadataCCMod(jsonData, mod.metadataCCMod);
}

if (mod && mod.installation) {
testInstallation(mod);
}
if (mod) {
if (mod.metadata) {
testMetadata(jsonData, mod.metadata);
}

if (mod.metadataCCMod) {
testMetadataCCMod(jsonData, mod.metadataCCMod);
}

if (mod.installation) {
testInstallation(mod);
}
}
});
}

Expand Down Expand Up @@ -140,29 +146,32 @@ function testMetadataCCMod(jsonData, ccmod) {
expect(typeof ccmod.id === 'string',
'ccmod.id (type: string) required').to.be.true;

expect([undefined, 'mod', 'library'].includes(ccmod.type),
'ccmod.type (type: string) must have one of: '
+ '[undefined, "mod", "library"]').to.be.true;

expect(ccmod.version === undefined
|| semver.valid(ccmod.version) !== null,
'ccmod.version (type: string) must be undefined or valid semver')
expect(typeof ccmod.version === 'string'
&& semver.valid(ccmod.version) !== null,
'ccmod.version (type: string) is missing or isnt valid semver')
.to.be.true;

expect(ccmod.title === undefined
|| typeof ccmod.title === 'string'
expect(typeof ccmod.title === 'string'
|| typeof ccmod.title === 'object',
'ccmod.title (type: string) has wrong type').to.be.true;
expect(ccmod.description === undefined
|| typeof ccmod.description === 'string'
|| typeof ccmod.description === 'object',
'ccmod.description (type: string) has wrong type').to.be.true;
expect(ccmod.license === undefined
|| typeof ccmod.license === 'string',
'ccmod.license (type: string) has wrong type').to.be.true;
'ccmod.title (type: string) is missing or has wrong type').to.be.true;
expect(ccmod.description !== undefined && (
typeof ccmod.description === 'string'
|| typeof ccmod.description === 'object'),
'ccmod.description (type: string) is missing or has wrong type').to.be.true;
expect(ccmod.homepage === undefined
|| typeof ccmod.homepage === 'string',
'ccmod.homepage (type: string) has wrong type').to.be.true;

expect(typeof ccmod.repository === 'string',
'ccmod.repository (type: string) is missing or has wrong type').to.be.true;

expect(ccmod.tags !== undefined
&& Array.isArray(ccmod.tags),
'ccmod.tags (type: array) is missing or has wrong type').to.be.true;

expect(ccmod.authors !== undefined
&& Array.isArray(ccmod.tags),
'ccmod.tags (type: array) is missing or has wrong type').to.be.true;
});

if (ccmod.dependencies) {
Expand Down

0 comments on commit f795e0c

Please sign in to comment.