mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Webatrice: improve prebuild steps and add .env configs (#4564)
* create .env file for server configuration * render client version * automate env file * add prestart command * create server-props.json instead of using .env * automate master proto file Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
408a13c937
commit
88b861d632
15 changed files with 119 additions and 21175 deletions
58
webclient/prebuild.js
Normal file
58
webclient/prebuild.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
const fse = require('fs-extra');
|
||||
const util = require('util');
|
||||
const exec = util.promisify(require('child_process').exec);
|
||||
|
||||
const protoFilesDir = './public/pb';
|
||||
const serverPropsFile = './src/server-props.json';
|
||||
const masterProtoFile = './src/proto-files.json';
|
||||
|
||||
const sharedFiles = [
|
||||
['../common/pb', protoFilesDir],
|
||||
['../cockatrice/resources/countries', './src/images/countries'],
|
||||
];
|
||||
|
||||
|
||||
(async () => {
|
||||
// make sure these files finish copying before master file is created
|
||||
await copySharedFiles();
|
||||
|
||||
createMasterProtoFile();
|
||||
createServerProps();
|
||||
})();
|
||||
|
||||
async function copySharedFiles() {
|
||||
try {
|
||||
return await Promise.all(sharedFiles.map(([src, dest]) => fse.copy(src, dest, { overwrite: true })));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function createMasterProtoFile() {
|
||||
try {
|
||||
fse.readdir(protoFilesDir, (err, files) => {
|
||||
if (err) throw err;
|
||||
|
||||
fse.outputFile(masterProtoFile, JSON.stringify(files.filter(file => /\.proto$/.test(file))));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
async function createServerProps() {
|
||||
try {
|
||||
fse.outputFile(serverPropsFile, JSON.stringify({
|
||||
REACT_APP_VERSION: await getCommitHash(),
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
async function getCommitHash() {
|
||||
return (await exec('git rev-parse HEAD')).stdout.trim();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue