UNPKG

cloudscript-server

Version:

A local environment for cloudscript development

56 lines (52 loc) 2.15 kB
require('colors'); const argv = require('minimist')(process.argv.slice(2)); const playfab = require('playfab-sdk'); const releaseCompiler = require('./src/compilers/releaseCompiler.js'); const fs = require('fs'); const path = require('path'); function UpdateCloudscript(args) { return new Promise((resolve, reject) => { playfab.PlayFabAdmin.UpdateCloudScript(args, (err, res) => { if (err) return reject(err); resolve(res.data); }); }) } module.exports = async (directory) => { require('dotenv').config({ path: require('path').join(directory, './.env') }); if (!argv.local) { playfab.settings.titleId = process.env['TITLE_ID']; playfab.settings.developerSecretKey = process.env['TITLE_SECRET']; } console.log("⚙️ Compiling...".blue); const startTime = Date.now(); let minified = releaseCompiler.compile(directory); console.log(`✔️ Compiled in ${Date.now() - startTime}ms`.blue); try { let commitComment = ``; if (process.env['GIT_COMMIT_HASH'] != null) commitComment = `Commit hash: ${process.env['GIT_COMMIT_HASH']}`; if (process.env['GIT_BRANCH'] != null) commitComment += `\nBranch: ${process.env['GIT_BRANCH']}`; if (commitComment.length != 0) commitComment = `\n${commitComment}\n` let startComment = `/*${commitComment.length > 0 ? "\n" : ""}This file was generated by the publisher.js script.${commitComment}*/\n` minified = startComment + minified; } catch (e) { console.error(e); } if (argv.local) { fs.writeFileSync(path.join(__dirname, 'cloudscript.min.js'), minified); console.log(`✅ Created minified file, run with --minified to use it`.green); return; } console.log("📤 Publishing...".blue); let response = await UpdateCloudscript({ Files: [{ FileContents: minified, FileName: 'cloudscript.min.js' }] }); console.log(`✅ Published revision: ${response.Revision}`.green); }