-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move pack detection to seperate exported function
- Loading branch information
1 parent
7e9593e
commit b8891d3
Showing
4 changed files
with
56 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { ReleaseOptions } from './cli/options.js' | ||
export { CurseforgeOptions, default as CurseforgeService } from './curseforge.js' | ||
export { parsePack } from './pack.js' | ||
export { WebOptions, default as WebService } from './web.js' |
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,34 @@ | ||
import { existsSync, readFileSync } from 'fs' | ||
import { CliOptions } from './cli/options.js' | ||
import CurseforgeService, { CurseforgeOptions, validateCurseforgeOptions } from './curseforge.js' | ||
import PackwizService, { PackwizOptions, validatePackwizOptions } from './packwiz.js' | ||
|
||
function fromMinecraftInstance(options: CurseforgeOptions) { | ||
const file = options.curseforgePackFile ?? 'minecraftinstance.json' | ||
if (!existsSync(file)) throw new Error(`curseforge manifest file '${file}' does not exist`) | ||
|
||
const curseforge = new CurseforgeService(options) | ||
|
||
const parsed = JSON.parse(readFileSync(file).toString()) | ||
|
||
return curseforge.importCurseforgePack(parsed) | ||
} | ||
|
||
function fromPackwiz(options: CliOptions & PackwizOptions) { | ||
const service = new PackwizService(options) | ||
return service.importPackwizPack() | ||
} | ||
|
||
export async function parsePack(options: CliOptions) { | ||
if (options.curseforgePackFile || existsSync('minecraftinstance.json')) { | ||
validateCurseforgeOptions(options) | ||
return fromMinecraftInstance(options) | ||
} | ||
|
||
if (options.packwizFile || existsSync('pack.toml')) { | ||
validatePackwizOptions(options) | ||
return fromPackwiz(options) | ||
} | ||
|
||
throw new Error('No pack metadata file auto-detected') | ||
} |
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