// bundle-submit.js // Copyright (C) 2022 Rob Colbert @rob@nicecrew.digital // License: Apache-2.0 'use strict'; import 'dotenv/config'; import path, { dirname } from 'path'; import { fileURLToPath } from 'url'; const __dirname = dirname(fileURLToPath(import.meta.url)); // jshint ignore:line import { createRequire } from "module"; const require = createRequire(import.meta.url); // jshint ignore:line import fetch, { FormData, fileFrom } from 'node-fetch'; /* * This script loads the developer's credentials, verifies that a bundle exists, * and sends that bundle to the configured hosting environment. */ (async ( ) => { try { const pkg = require(path.join(__dirname, 'package.json')); const formData = new FormData(); formData.set('package', pkg); const bundleFileName = path.join(__dirname, 'bundle', process.argv[2]); const bundleFile = fileFrom(bundleFileName, 'application/gzip'); formData.set('bundle-file', bundleFile, 'nice-bundle.tar.gz'); const response = await fetch(`https://${process.env.ARCADE_HOST}/submissions`, { method: 'POST', headers: { 'X-Game-Id': process.env.ARCADE_GAME_ID, 'X-Developer-Id': process.env.ARCADE_DEVELOPER_ID, 'X-Developer-Key': process.env.ARCADE_DEVELOPER_KEY, }, body: formData, }); const message = await response.text(); console.log(message); } catch (error) { console.log('ERROR:', error.message, error); } finally { console.log('Nice Arcade bundle submission process complete.'); } })();