-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtypes.ts
More file actions
266 lines (236 loc) · 8.34 KB
/
types.ts
File metadata and controls
266 lines (236 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
export type InputLocation = ZipInputLocation | ExternalToolInputLocation
export type ZipInputLocation = {
type?: 'zip' | undefined
/** The URL of the ZIP file. */
url: string
/** The subdirectory in which the package.json file is kept.
Note that GitHub archives have an additional enclosing directory, so you will usually need to use this.
Only this subdirectory & subdirectories of it are extracted, and it is extracted at the target installation directory. */
source?: string
/** If provided, then the package.json file is at this location in the archive, regardless of 'source'.
This must pretty much only be used for base packages. */
packageJSONPath?: string
/** the same as packageJSONPath but for ccmod.json */
ccmodPath?: string
}
export type ExternalToolInputLocation = {
type: 'externaltool'
/** The URL of the ZIP file. */
url: string
}
/** The content of the input-locations.json file. */
export type InputLocations = InputLocation[]
/** An os.platform() value (see https://nodejs.org/api/os.html#os_os_platform ) */
export type NodeOSPlatform = NodeJS.Platform
/** Imported from https://github.com/CCDirectLink/CLS/blob/master/proposals/1/standardized-mod-format.md */
export type Semver = string
export type SemverConstraint = string
/**
* @deprecated
* Represents a kind of package.
* Please be aware that "base" is reserved for packages that absolutely require special-case local detection,
* and special-case UI to be user-friendly, such as CCLoader and NWJS upgrades.
* (In particular, CrossCode, CCLoader and NWJS upgrades require custom detection methods for their local copies.)
**/
export type PackageType = 'mod' | 'tool' | 'base'
/**
** A page relating to the mod.
**/
export type Page = {
/** The name of the page. For the canonical GitHub or GitLab page, this must be "GitHub" / "GitLab". */
name: string
url: string
}
/**
** @deprecated
** This is related to the supported package metadata for mods, on purpose.
** Note, however, that the 'dependencies' key is NOT supported.
** Also note the care to try not to reinvent NPM fields, but also to avoid them when inappropriate.
** Some mods will use NPM packages, have NPM build commands (See: TypeScript mods), etc.
** So it's very important to keep the package metadata format safe for NPM to read,
** and that means ensuring all package metadata is either avoided by NPM or understood by it.
**/
export type PkgMetadata = {
/** This is the unique ID for this package, used for dependency handling. Note that this DOES NOT have to avoid collision with the NPM registry. */
name: string
/** If not provided, defaults to "mod". */
ccmodType?: PackageType
/** This is the version of the package for dependency purposes. (see https://docs.npmjs.com/files/package.json ) */
version: Semver
/** This is the dependencies of the package, if any. If not present, `dependencies` is checked. */
/** If `dependencies` contains NPM packages, you must supply at least an empty object here to prevent issues. */
ccmodDependencies?: Record<string, SemverConstraint>
/** This is the dependencies of the package, if any. WARNING: THIS CONFLICTS WITH NPM. DO NOT USE. NEW MODS WITH THIS WILL NOT BE ACCEPTED. */
dependencies?: Record<string, SemverConstraint>
/** Below here is metadata that has no effect on function. */
/** This is the name the user is supposed to see. Really meant as a preservation mechanism for old mods.json naming information. Defaults to name. */
ccmodHumanName?: string
/** This is the description of the package. (see https://docs.npmjs.com/files/package.json ) */
description?: string
/** SPDX license identifier or human readable text (see https://docs.npmjs.com/files/package.json ) */
license?: string
/** Homepage URL (see https://docs.npmjs.com/files/package.json ) */
homepage?: string
/** NPM scripts */
scripts?: Record<string, string>
}
type FilePath = string
export type LocalizedString = Record<Locale, string> | string
type Locale = string
type Person = /* PersonDetails | */ string
/** interface PersonDetails { */
/** name: LocalizedString */
/** email?: LocalizedString */
/** url?: LocalizedString */
/** comment?: LocalizedString */
/** } */
/**
* Mod tags that are in the ccmod.json standard
**/
export const ValidTags = [
'QoL',
'player character',
'party member',
'combat arts',
'pvp duel',
'arena',
'dungeon',
'quests',
'maps',
'boss',
'puzzle',
'ng+',
'cosmetic',
'music',
'fun',
'cheats',
'speedrun',
'widget',
'language',
'accessibility',
'dev',
'library',
'base',
'externaltool'
] as const
/**
* Mod tags that are in the ccmod.json standard
**/
export type ValidTags = typeof ValidTags[number]
/**
* All mods in the database must have these fields
**/
export type ValidPkgCCMod = {
/** Mod unique identifier. Not shown to the user */
id: string
/** A proper semver */
version: Semver
/** Title shown to users */
title: LocalizedString
/** Description shown to users */
description: LocalizedString
/** License string, not validated */
license?: string
/** Mod homepage, a URL */
homepage?: string
/** Mod git repository, a URL */
repository: string
/** A list of mod tags */
tags?: ValidTags[]
/** A list of mod authors */
authors: Person[] | Person
/** Only the size 24 is supported */
icons?: Record<string, FilePath>
/** Require certain mods for the mod to function */
dependencies?: Record<string, SemverConstraint>
/** Browser specific. Tell the game what files to load */
assets?: FilePath[]
/** Browser specific */
assetsDir?: FilePath
modPrefix?: string
plugin?: FilePath
preload?: FilePath
postload?: FilePath
prestart?: FilePath
poststart?: FilePath
}
/**
* What ccloader requires for the mod to function
**/
export type PkgCCMod = Partial<ValidPkgCCMod> & {
id: string
}
/** Represents some set of hashes for something. */
export type PkgHash = {
/** Lowercase hexadecimal-encoded SHA-256 hash of the data. */
sha256: string
}
/**
* Represents a method of installing the package.
**/
export type InstallMethod = InstallMethodZip
export type InstallMethodBase = {
/** The URL of the file to download.
* (example: "https://github.com/CCDirectLink/CCLoader/archive/master.zip")
* (example: "https://github.com/CCDirectLink/CC-ChargedBalls/releases/download/1.0.0/ChargedBalls.ccmod")
**/
url: string
/** The hash of the file at url. */
hash: PkgHash
/** If present, constrains the platform this method may be used for. */
platform?: NodeOSPlatform
}
/**
* Includes .zip and .ccmod files
**/
export type InstallMethodZip = InstallMethodBase & {
type?: 'zip'
/** If provided, the subdirectory of the ZIP that is the root of the extraction (example: "CCLoader-master") */
source?: string
}
/**
* Includes .zip and .ccmod files
**/
export type InstallMethodExternalTool = InstallMethodBase & {
type: 'externaltool'
}
/**
* Represents the release page info fetched from the mods repository
**/
export interface ReleasePage {
/** Body of the release in Markdown */
body: string
/** The tag name. There is an attempt to convert it to a proper semver, but if it fails it
* is just the raw tag name */
version: string
/** UNIX timestamp of the release */
timestamp: number
/** Page url */
url: string
}
/**
* Represents a package in the database.
**/
export type Package = {
/** ccmod.json Metadata for the package. */
metadataCCMod?: ValidPkgCCMod
/** Installation methods (try in order) */
installation: InstallMethod[]
/** Number of GitHub stars the project has. */
stars?: number
/** UNIX timestamp of the project repository last push date. */
lastUpdateTimestamp?: number
/** All repository release page contents */
releasePages?: ReleasePage[]
}
/**
* Represents the database. Stored in npDatabase.json and npDatabase.min.json
**/
export type PackageDB = Record<string, Package>
/**
* Database information. Stored in db-info.json
**/
export interface DatabaseInfo {
/** Can be either a url to a npDatabase.min.json file or the name of a local repo branch */
parentBranches: string[]
}