@@ -11,33 +11,39 @@ import {
1111 statSync ,
1212} from "fs" ;
1313import { join } from "path" ;
14- import fgrpkg from "@terascope/fetch-github-release" ;
15- const downloadRelease = fgrpkg ;
16- import json2toml from "json2toml" ;
1714import child_process from "child_process" ;
1815import { zip } from "zip-a-folder" ;
19- import fsepkg from "fs-extra" ;
20- const move = fsepkg . move ;
16+ import fsepkg , { copy } from "fs-extra" ;
2117const remove = fsepkg . remove ;
2218import * as core from "@actions/core" ;
2319
2420// Setting it so that it's consistent with installs from thunderstore
2521const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod" ;
22+ const NEBULA_API_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerModApi" ;
2623const DIST_FOLDER = "dist" ;
2724const DIST_RELEASE_FOLDER = join ( DIST_FOLDER , "release" ) ;
28- const DIST_NEBULA_FOLDER = join ( DIST_RELEASE_FOLDER , "nebula" ) ;
29- const DIST_TSTORE_CLI_FOLDER = join ( DIST_RELEASE_FOLDER , "tstore-cli" ) ;
30- const DIST_TSTORE_CLI_EXE_PATH = join ( DIST_TSTORE_CLI_FOLDER , "tstore-cli.exe" ) ;
31- const DIST_TSTORE_CLI_CONFIG_PATH = join (
32- DIST_TSTORE_CLI_FOLDER ,
33- "publish.toml"
25+ const DIST_NEBULA_FOLDER = join (
26+ DIST_RELEASE_FOLDER ,
27+ NEBULA_RELEASE_FOLDER_NAME
28+ ) ;
29+ const DIST_NEBULA_API_FOLDER = join (
30+ DIST_RELEASE_FOLDER ,
31+ NEBULA_API_RELEASE_FOLDER_NAME
3432) ;
33+ const DIST_TSTORE_CLI_FOLDER = join ( "Libs" , "tcli" ) ;
34+ const DIST_TSTORE_CLI_EXE_PATH = join ( DIST_TSTORE_CLI_FOLDER , "tcli.exe" ) ;
3535const PLUGIN_INFO_PATH = "NebulaPatcher\\PluginInfo.cs" ;
36+ const API_PLUGIN_INFO_PATH = "NebulaAPI\\NebulaModAPI.cs" ;
3637const pluginInfo = getPluginInfo ( ) ;
38+ const apiPluginInfo = getApiPluginInfo ( ) ;
3739const TSTORE_ARCHIVE_PATH = join (
3840 DIST_RELEASE_FOLDER ,
3941 "nebula-thunderstore.zip"
4042) ;
43+ const TSTORE_API_ARCHIVE_PATH = join (
44+ DIST_RELEASE_FOLDER ,
45+ "nebula-api-thunderstore.zip"
46+ ) ;
4147const GH_ARCHIVE_PATH = join (
4248 DIST_RELEASE_FOLDER ,
4349 "Nebula_" + pluginInfo . version + ".zip"
@@ -48,29 +54,40 @@ const CHANGELOG_PATH = "CHANGELOG.md";
4854
4955async function main ( ) {
5056 if ( ! existsSync ( DIST_NEBULA_FOLDER ) ) {
51- throw DIST_NEBULA_FOLDER + " does not exist" ;
57+ let err = DIST_NEBULA_FOLDER + " does not exist" ;
58+ core . setFailed ( err ) ;
59+ throw err ;
5260 }
5361
54- if ( ! existsSync ( DIST_TSTORE_CLI_FOLDER ) ) {
55- mkdirSync ( DIST_TSTORE_CLI_FOLDER , { recursive : true } ) ;
62+ if ( ! existsSync ( DIST_NEBULA_API_FOLDER ) ) {
63+ let err = DIST_NEBUDIST_NEBULA_API_FOLDERLA_FOLDER + " does not exist" ;
64+ core . setFailed ( err ) ;
65+ throw err ;
5666 }
5767
5868 try {
5969 generateReleaseBody ( ) ;
6070 } catch ( err ) {
6171 core . setFailed ( err ) ;
72+ throw err ;
6273 }
6374
6475 generateManifest ( ) ;
76+ generateApiManifest ( ) ;
6577 copyIcon ( ) ;
78+ copyApiIcon ( ) ;
6679 copyReadme ( ) ;
80+ copyApiReadme ( ) ;
6781 appendChangelog ( ) ;
82+ appendApiChangelog ( ) ;
6883 copyLicenses ( ) ;
84+ copyApiLicense ( ) ;
6985
7086 await createTStoreArchive ( ) ;
87+ await createTStoreApiArchive ( ) ;
7188 await createGHArchive ( ) ;
7289
73- await doTStoreRelease ( ) ;
90+ uploadToTStore ( ) ;
7491}
7592
7693function getPluginInfo ( ) {
@@ -83,13 +100,29 @@ function getPluginInfo() {
83100 } ;
84101}
85102
103+ function getApiPluginInfo ( ) {
104+ const pluginInfoRaw = readFileSync ( API_PLUGIN_INFO_PATH ) . toString ( "utf-8" ) ;
105+ const versionInfoRaw = readFileSync (
106+ join ( "NebulaAPI" , "version.json" )
107+ ) . toString ( "utf-8" ) ;
108+ return {
109+ name : pluginInfoRaw . match ( / A P I _ N A M E = " ( .* ) " ; / ) [ 1 ] ,
110+ id : pluginInfoRaw . match ( / A P I _ G U I D = " ( .* ) " ; / ) [ 1 ] ,
111+ version : JSON . parse ( versionInfoRaw ) . version ,
112+ } ;
113+ }
114+
86115function generateManifest ( ) {
87116 const manifest = {
88117 name : pluginInfo . name ,
89118 description :
90119 "With this mod you will be able to play with your friends in the same game!" ,
91120 version_number : pluginInfo . version ,
92- dependencies : [ "xiaoye97-BepInEx-5.4.11" , "PhantomGamers-IlLine-1.0.0" ] ,
121+ dependencies : [
122+ "xiaoye97-BepInEx-5.4.11" ,
123+ `nebula-${ apiPluginInfo . name } -${ apiPluginInfo . version } ` ,
124+ "PhantomGamers-IlLine-1.0.0" ,
125+ ] ,
93126 website_url : "https://github.com/hubastard/nebula" ,
94127 } ;
95128 writeFileSync (
@@ -98,26 +131,64 @@ function generateManifest() {
98131 ) ;
99132}
100133
134+ function generateApiManifest ( ) {
135+ const manifest = {
136+ name : apiPluginInfo . name ,
137+ description : "API for other mods to work with the Nebula Multiplayer Mod" ,
138+ version_number : apiPluginInfo . version ,
139+ website_url : "https://github.com/hubastard/nebula" ,
140+ } ;
141+ writeFileSync (
142+ join ( DIST_NEBULA_API_FOLDER , "manifest.json" ) ,
143+ JSON . stringify ( manifest , null , 2 )
144+ ) ;
145+ }
146+
101147function copyIcon ( ) {
102148 copyFileSync ( MOD_ICON_PATH , join ( DIST_NEBULA_FOLDER , "icon.png" ) ) ;
103149}
104150
151+ function copyApiIcon ( ) {
152+ copyFileSync (
153+ join ( "NebulaAPI" , "icon.png" ) ,
154+ join ( DIST_NEBULA_API_FOLDER , "icon.png" )
155+ ) ;
156+ }
157+
105158function copyReadme ( ) {
106159 copyFileSync ( README_PATH , join ( DIST_NEBULA_FOLDER , README_PATH ) ) ;
107160}
108161
162+ function copyApiReadme ( ) {
163+ copyFileSync (
164+ join ( "NebulaAPI" , README_PATH ) ,
165+ join ( DIST_NEBULA_API_FOLDER , README_PATH )
166+ ) ;
167+ }
168+
109169function appendChangelog ( ) {
110170 appendFileSync (
111171 join ( DIST_NEBULA_FOLDER , README_PATH ) ,
112172 "\n" + readFileSync ( CHANGELOG_PATH )
113173 ) ;
114174}
115175
176+ function appendApiChangelog ( ) {
177+ appendFileSync (
178+ join ( DIST_NEBULA_API_FOLDER , README_PATH ) ,
179+ "\n" + readFileSync ( join ( "NebulaAPI" , CHANGELOG_PATH ) )
180+ ) ;
181+ }
182+
116183function copyLicenses ( ) {
117184 copyFileSync ( "LICENSE" , join ( DIST_NEBULA_FOLDER , "nebula.LICENSE" ) ) ;
118185 copyFolderContent ( "Licenses" , DIST_NEBULA_FOLDER ) ;
119186}
120187
188+ function copyApiLicense ( ) {
189+ copyFileSync ( "LICENSE" , join ( DIST_NEBULA_API_FOLDER , "nebula.LICENSE" ) ) ;
190+ }
191+
121192function copyFolderContent ( src , dst , excludedExts ) {
122193 readdirSync ( src ) . forEach ( ( file ) => {
123194 const srcPath = join ( src , file ) ;
@@ -138,54 +209,6 @@ function copyFolderContent(src, dst, excludedExts) {
138209 } ) ;
139210}
140211
141- async function doTStoreRelease ( ) {
142- const user = "Windows10CE" ;
143- const repo = "tstore-cli" ;
144- const outputdir = DIST_TSTORE_CLI_FOLDER ;
145- const leaveZipped = false ;
146- const disableLogging = false ;
147-
148- // Define a function to filter releases.
149- function filterRelease ( release ) {
150- // Filter out prereleases.
151- return release . prerelease === false ;
152- }
153-
154- // Define a function to filter assets.
155- function filterAsset ( asset ) {
156- // Select assets that contain the string 'windows'.
157- return asset . name . includes ( "tstore-cli.exe" ) ;
158- }
159-
160- try {
161- await downloadRelease (
162- user ,
163- repo ,
164- outputdir ,
165- filterRelease ,
166- filterAsset ,
167- leaveZipped ,
168- disableLogging
169- ) ;
170- console . log ( "Successfully downloaded tstore-cli.exe" ) ;
171- await new Promise ( ( r ) => setTimeout ( r , 2000 ) ) ;
172- generateTStoreConfig ( ) ;
173- uploadToTStore ( ) ;
174- } catch ( err ) {
175- console . error ( err . message ) ;
176- }
177- }
178-
179- function generateTStoreConfig ( ) {
180- const config = {
181- author : "nebula" ,
182- communities : [ "dyson-sphere-program" ] ,
183- nsfw : false ,
184- zip : TSTORE_ARCHIVE_PATH ,
185- } ;
186- writeFileSync ( DIST_TSTORE_CLI_CONFIG_PATH , json2toml ( config ) ) ;
187- }
188-
189212function generateReleaseBody ( ) {
190213 const changelog = readFileSync ( CHANGELOG_PATH , "utf-8" ) ;
191214 const versionRegExp = new RegExp (
@@ -215,37 +238,46 @@ function generateReleaseBody() {
215238 join ( DIST_RELEASE_FOLDER , "BODY.md" ) ,
216239 "# Alpha Version " + currentVersion + "\n\n### Changes\n" + body
217240 ) ;
218-
219- console . log ( body ) ;
220241}
221242
222243async function createTStoreArchive ( ) {
223244 await zip ( DIST_NEBULA_FOLDER , TSTORE_ARCHIVE_PATH ) ;
224245}
225246
247+ async function createTStoreApiArchive ( ) {
248+ await zip ( DIST_NEBULA_API_FOLDER , TSTORE_API_ARCHIVE_PATH ) ;
249+ }
250+
226251async function createGHArchive ( ) {
227252 // Ensure contents are within subfolder in zip
228- await move (
253+ await copy (
229254 DIST_NEBULA_FOLDER ,
230255 join ( DIST_FOLDER , "tmp" , NEBULA_RELEASE_FOLDER_NAME )
231256 ) ;
232- await zip ( join ( DIST_FOLDER , "tmp" ) , GH_ARCHIVE_PATH ) ;
233- await move (
234- join ( DIST_FOLDER , "tmp" , NEBULA_RELEASE_FOLDER_NAME ) ,
235- DIST_NEBULA_FOLDER
257+ await copy (
258+ DIST_NEBULA_API_FOLDER ,
259+ join ( DIST_FOLDER , "tmp" , NEBULA_API_RELEASE_FOLDER_NAME )
236260 ) ;
261+ await zip ( join ( DIST_FOLDER , "tmp" ) , GH_ARCHIVE_PATH ) ;
237262 await remove ( join ( DIST_FOLDER , "tmp" ) ) ;
238263}
239264
240265function uploadToTStore ( ) {
241- child_process . execSync (
242- DIST_TSTORE_CLI_EXE_PATH +
243- " publish --config " +
244- DIST_TSTORE_CLI_CONFIG_PATH ,
245- function ( err ) {
246- console . error ( err ) ;
247- }
248- ) ;
266+ try {
267+ child_process . execSync (
268+ `"${ DIST_TSTORE_CLI_EXE_PATH } " publish --file "${ TSTORE_ARCHIVE_PATH } " --token "${ process . env . TSTORE_TOKEN } " --use-session-auth`
269+ ) ;
270+ } catch ( error ) {
271+ console . error ( `Thunderstore upload failed for ${ TSTORE_ARCHIVE_PATH } ` ) ;
272+ }
273+
274+ try {
275+ child_process . execSync (
276+ `"${ DIST_TSTORE_CLI_EXE_PATH } " publish --file "${ TSTORE_API_ARCHIVE_PATH } " --token "${ process . env . TSTORE_TOKEN } " --use-session-auth`
277+ ) ;
278+ } catch ( error ) {
279+ console . error ( `Thunderstore upload failed for ${ TSTORE_API_ARCHIVE_PATH } ` ) ;
280+ }
249281}
250282
251283main ( ) ;
0 commit comments