@@ -4,8 +4,9 @@ import FormData from 'form-data'
4
4
import { createReadStream , existsSync , readdirSync , readFileSync } from 'fs'
5
5
import { basename , extname , join } from 'path'
6
6
import yaml from 'yaml'
7
- import { ReleaseOptions } from './cli/options.js'
7
+ import { CliOptions , ReleaseOptions } from './cli/options.js'
8
8
import { IMod } from './models/index.js'
9
+ import { parsePack } from './pack.js'
9
10
import type { PackData , Release , WebData } from './types.js'
10
11
11
12
export interface WebOptions {
@@ -17,12 +18,18 @@ export interface WebOptions {
17
18
export const defaultWebDir = 'web'
18
19
export const defaultApiUrl = 'https://packs.macarena.ceo/api'
19
20
21
+ function validateRelease < T > ( options : T & Partial < ReleaseOptions > ) : asserts options is T & ReleaseOptions {
22
+ if ( ! options . version ) throw new Error ( 'Version missing' )
23
+ if ( ! options . changelog ) throw new Error ( 'Changelog missing' )
24
+ if ( ! options . releaseType ) throw new Error ( 'Release-Type missing' )
25
+ }
26
+
20
27
export default class WebService {
21
28
private readonly api : AxiosInstance
22
29
private readonly dir : string
23
30
private readonly baseUrl : string
24
31
25
- constructor ( options : Readonly < WebOptions > ) {
32
+ constructor ( private readonly options : Readonly < CliOptions & WebOptions > ) {
26
33
if ( ! options . webToken ) throw new Error ( 'Web Token missing' )
27
34
28
35
this . dir = options . webDir ?? defaultWebDir
@@ -116,6 +123,16 @@ export default class WebService {
116
123
} )
117
124
}
118
125
126
+ async parseAndCreateRelease ( ) {
127
+ const options = { ...this . options }
128
+ const { mods, version } = await parsePack ( options )
129
+
130
+ if ( ! options . version ) options . version = version
131
+ validateRelease ( options )
132
+
133
+ await this . createRelease ( mods , options )
134
+ }
135
+
119
136
async createRelease ( mods : IMod [ ] , release : ReleaseOptions ) {
120
137
const releaseData : Release = {
121
138
date : new Date ( ) . toISOString ( ) ,
@@ -139,14 +156,3 @@ export function readPackData(dir: string): Partial<PackData> | null {
139
156
if ( ! existsSync ( file ) ) return null
140
157
return yaml . parse ( readFileSync ( file ) . toString ( ) )
141
158
}
142
-
143
- export async function getPackName ( options : Partial < WebOptions > ) {
144
- if ( options . webToken ) {
145
- const service = new WebService ( options as WebOptions )
146
- const data = await service . getWebData ( )
147
- return data . name
148
- } else {
149
- const packData = readPackData ( options . webDir ?? 'web' )
150
- return packData ?. name
151
- }
152
- }
0 commit comments