Untitled
import { sleep } from '../utils'; const skipAutoRun = process.env.__SKIP_AUTO_RUN__; process.env.__SKIP_AUTO_RUN__ = 'true'; import * as fs from 'fs'; import mongoose from 'mongoose'; import path from 'path'; import * as AdminApi from '../../apps/admin-api/src'; import ensureCampaign from './ensureCampaign'; delete process.env._CLEAN_UP; export type Config = { CAMPAIGN_ID: string; GAME_ID: string; GAME_INSTANCE_ID: string; TICKET_TYPE: string; CAMPAIGN_NAME: string; }; const main = async () => { let config: Config = {} as Config; const configPath = path.join(__dirname, 'config.json'); if (!fs.existsSync(configPath)) { config.CAMPAIGN_ID = new mongoose.Types.ObjectId().toString(); config.GAME_INSTANCE_ID = new mongoose.Types.ObjectId().toString(); config.GAME_ID = new mongoose.Types.ObjectId().toString(); config.CAMPAIGN_NAME = 'PVCB-Demo-Campaign'; fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); } else { config = JSON.parse(fs.readFileSync(configPath).toString()); } if (process.argv[2] === 'true') { process.env._CLEAN_UP = 'true'; } // const MONGO_URL = process.argv[3] ? process.argv[3] : 'mongodb://mongo:27017/gf-platform'; const MONGO_URL = process.argv[3] ? process.argv[3] : 'mongodb://localhost:27017/gf-platform'; const PORT = process.argv[4] ? parseInt(process.argv[4]) : 8000; console.log( 'MONGO_URL', MONGO_URL, 'PORT', PORT, 'CLEAN_UP', process.env._CLEAN_UP ); process.env.DISABLE_PLUGIN = 'true'; const adminApi = await AdminApi.main({ MONGO_URL, PORT }); const context = adminApi.getContext(); await ensureCampaign(context, config); await sleep(2000); await context.close(); process.env.__SKIP_AUTO_RUN__ = skipAutoRun; console.log('DONE'); }; main();
Leave a Comment