Skip to content

Commit aed04e0

Browse files
committed
Instead of detetecting changed input-location.json entries just pass in changed mod ids as program argument
1 parent b02173d commit aed04e0

6 files changed

Lines changed: 29 additions & 32 deletions

File tree

‎build/src/fs-util.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DatabaseInfo, InputLocation, InputLocations, PackageDB } from './types'
1+
import type { DatabaseInfo, InputLocations, PackageDB } from './types'
22

33
export type ReadFunc = (path: string) => Promise<string | undefined>
44
export type WriteFunc = (path: string, data: Buffer | string) => Promise<void>
@@ -22,18 +22,3 @@ export async function readDbInfo(read: ReadFunc): Promise<DatabaseInfo> {
2222
const dbInfo: DatabaseInfo = JSON.parse(data)
2323
return dbInfo
2424
}
25-
26-
function stringifyLocation(loc: InputLocation) {
27-
const body = Object.entries(loc)
28-
.map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`)
29-
.join(', ')
30-
return '{ ' + body + ' }'
31-
}
32-
33-
export function stringifyInputLocations(locations: InputLocations) {
34-
const pad = ' '.repeat(4)
35-
const body = Object.entries(locations)
36-
.map(([k, v]) => `${pad}${JSON.stringify(k)}: ${stringifyLocation(v)}`)
37-
.join(',\n')
38-
return `{\n${body}\n}`
39-
}

‎build/src/main.ts‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ async function main() {
1818

1919
const branch: string = process.argv[2]
2020

21-
let type: 'scratch' | undefined = process.argv[3] as any
22-
if (type != 'scratch' && type !== undefined) {
23-
throw new Error(`Invalid second arguemnt: "${type}"\n`)
24-
}
21+
const isFromScratch = process.argv[3] == 'scratch'
22+
const changedModIds = process.argv[3]?.split(',') ?? []
2523

2624
const repoBranches = await getRepoBranches()
2725
if (!repoBranches.includes(branch)) {
@@ -35,7 +33,8 @@ async function main() {
3533
}
3634

3735
await createNpDatabase(
38-
type == 'scratch',
36+
isFromScratch,
37+
changedModIds,
3938
(path: string) => gitReadFunc(branch, path),
4039
gitWriteFunc
4140
)
@@ -51,7 +50,12 @@ async function main() {
5150
)
5251
}
5352

54-
async function createNpDatabase(fromScratch: boolean, read: ReadFunc, write: WriteFunc) {
53+
async function createNpDatabase(
54+
fromScratch: boolean,
55+
changedModIds: string[],
56+
read: ReadFunc,
57+
write: WriteFunc
58+
) {
5559
const locations = await readInputLocations(read)
5660

5761
let dbToMerge: PackageDB = {}
@@ -67,16 +71,19 @@ async function createNpDatabase(fromScratch: boolean, read: ReadFunc, write: Wri
6771
if (fromScratch) {
6872
inputLocationsToFetch = Object.values(locations)
6973
} else {
70-
for (const modId in locations) {
74+
for (const modId of changedModIds) {
7175
const loc = locations[modId]
72-
if (loc.type === undefined || loc.type == 'zip') {
73-
if (loc.changed) inputLocationsToFetch.push(loc)
74-
}
76+
if (!loc) throw new Error(`mod: "${modId}" not found in input-locations.json`)
77+
inputLocationsToFetch.push(loc)
7578
}
7679
for (const modId in oldDb) {
7780
if (!locations[modId]) delete oldDb[modId]
7881
}
7982
}
83+
if (inputLocationsToFetch.length == 0) {
84+
console.log('no input locations specified')
85+
process.exit(1)
86+
}
8087

8188
const packages = await Promise.all(inputLocationsToFetch.map(loc => source.get(loc, write)))
8289

‎build/src/types.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export type ZipInputLocation = {
1111
/** If provided, then the ccmod.json file is at this location in the archive, regardless of 'source'.
1212
This must pretty much only be used for base packages. */
1313
ccmodPath?: string
14-
//* should the entry be updated on database update */
15-
changed?: boolean
1614
}
1715

1816
export type ExternalToolInputLocation = {

‎docs/DATABASE.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ Modifying the database manually is sometimes required, for example when removing
4343
- In the case of `stable`, run `export BRANCH=stable`
4444
3. Switch to the branch you choose with.
4545
To do that, run `git checkout $BRANCH`
46-
4. Add your mod to the `input-locations.json` file. For specific details, see [DATABASE.md](/docs/DATABASE.md)
46+
4. Add your mod to the `input-locations.json` file.
4747
5. Commit the changes
4848
6. Switch back to the `master` branch.
4949
To do that, run `git checkout master`
5050
7. Now to update the `npDatabase.json` file, run:
5151
- Run `bun ci`
5252
- Now you have two choices:
5353
- If you just want to have the entry you just changed updated, run:
54-
`bun run start`
54+
`bun run start 'my-mod-id'`
55+
Replace `my-mod-id` with your mod id (it is a comma seperated list)
5556
- If you want to re-generate the entire database from scratch, run:
56-
`bun run startScratch`
57+
`bun run start scratch`
5758
8. If successful, you should be checked-out on the selected branch
5859
10. Amend the last commit to also include the current changes
5960
11. Switch back to the `master` branch

‎input-locations.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cc-multibakery": { "url": "https://github.com/krypciak/cc-multibakery/releases/download/v0.8.10/cc-multibakery-0.8.10.ccmod" },
3+
"cc-instanceinator": { "url": "https://github.com/krypciak/cc-instanceinator/releases/download/v1.1.7/cc-instanceinator-1.1.7.ccmod" },
4+
"cc-variable-charge-time": { "url": "https://github.com/krypciak/cc-variable-charge-time/releases/download/v1.0.0/cc-variable-charge-time-1.0.0.ccmod" },
5+
"cc-krypek-lib": { "url": "https://github.com/krypciak/cc-krypek-lib/releases/download/v1.4.0/cc-krypek-lib-1.4.0.ccmod" },
6+
"cc-multibakery-additions": { "url": "https://github.com/XenonA7/cc-multibakery-additions/archive/refs/tags/0.8.0.zip" }
7+
}

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "A build script for ccmoddb",
55
"scripts": {
66
"start": "bun build/src/main.ts $BRANCH",
7-
"startScratch": "bun build/src/main.ts $BRANCH scratch",
87
"test": "bun test",
98
"format": "prettier ./build/src -w"
109
},

0 commit comments

Comments
 (0)