mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
new selfhosted version
This commit is contained in:
@@ -4,7 +4,8 @@ import path from 'path';
|
||||
import child from 'child_process';
|
||||
import { createZip } from '../helpers/zip-helper';
|
||||
import { DeployHelper } from '../helpers/deploy-helper';
|
||||
import { DATABASE_CONNECTION_STRING_PRODUCTION, DATABASE_CONNECTION_STRING_TESTMODE, REMOTE_HOST_TESTMODE } from '../.config';
|
||||
import { CONSUMER, getEcosystemContent } from '../.config';
|
||||
import prettier from 'prettier';
|
||||
|
||||
const TMP_PATH = path.join(__dirname, '../../tmp');
|
||||
const LOCAL_PATH = path.join(__dirname, '../../consumer');
|
||||
@@ -26,25 +27,27 @@ async function main() {
|
||||
|
||||
if (!SKIP_BUILD) {
|
||||
console.log('Building');
|
||||
child.execSync(`cd ${LOCAL_PATH} && pnpm run build`);
|
||||
try {
|
||||
child.execSync(`cd ${LOCAL_PATH} && pnpm run build`);
|
||||
} catch (ex) {
|
||||
console.error(ex.stdout.toString());
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log('Creting zip file');
|
||||
console.log('Creating zip file');
|
||||
const archive = createZip(TMP_PATH + '/' + ZIP_NAME);
|
||||
archive.directory(LOCAL_PATH + '/dist', '/dist');
|
||||
|
||||
if (MODE === 'testmode') {
|
||||
const ecosystemContent = fs.readFileSync(LOCAL_PATH + '/ecosystem.config.js', 'utf8');
|
||||
const REDIS_URL = ecosystemContent.match(/REDIS_URL: ["'](.*?)["']/)[1];
|
||||
const devContent = ecosystemContent
|
||||
.replace(REDIS_URL, `redis://${REMOTE_HOST_TESTMODE}`)
|
||||
.replace(DATABASE_CONNECTION_STRING_PRODUCTION, `redis://${DATABASE_CONNECTION_STRING_TESTMODE}`);
|
||||
archive.append(Buffer.from(devContent), { name: '/ecosystem.config.js' });
|
||||
} else {
|
||||
archive.file(LOCAL_PATH + '/ecosystem.config.js', { name: '/ecosystem.config.js' })
|
||||
}
|
||||
const envObject =
|
||||
MODE === 'testmode' ? CONSUMER.getEnv_TESTMODE() :
|
||||
MODE === 'testlive' ? CONSUMER.getEnv_TESTLIVE() :
|
||||
CONSUMER.getEnv_PRODUCTION();
|
||||
|
||||
const ecosystemContentRaw = getEcosystemContent('consumer', 3031, 'cluster', 2, './dist/consumer/src/index.js', envObject);
|
||||
const ecosystemContent = await prettier.format(ecosystemContentRaw, { parser: 'babel' });
|
||||
archive.append(Buffer.from(ecosystemContent), { name: '/ecosystem.config.js' });
|
||||
|
||||
archive.file(LOCAL_PATH + '/package.json', { name: '/package.json' });
|
||||
archive.file(LOCAL_PATH + '/pnpm-lock.yaml', { name: '/pnpm-lock.yaml' });
|
||||
|
||||
30
scripts/consumer/run_local.ts
Normal file
30
scripts/consumer/run_local.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import child from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { CONSUMER } from '../.config';
|
||||
|
||||
export function main() {
|
||||
|
||||
const mode = process.argv[2];
|
||||
|
||||
const consumerFolder = path.join(__dirname, '../../consumer');
|
||||
|
||||
const getEnv = {
|
||||
'--production': CONSUMER.getEnv_PRODUCTION(),
|
||||
'--testmode': CONSUMER.getEnv_TESTMODE()
|
||||
}
|
||||
|
||||
const env = getEnv[mode];
|
||||
|
||||
if (!env) {
|
||||
console.error('use --production or --testmode')
|
||||
return;
|
||||
}
|
||||
|
||||
const p = child.exec(`ts-node ${consumerFolder}/src/index.ts`, { env });
|
||||
|
||||
p.stdout.on('data', (e) => { console.log(e.toString()); });
|
||||
p.stderr.on('data', (e) => { console.log(e.toString()); })
|
||||
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -12,17 +12,17 @@ helper.copy('utils/requireEnv.ts');
|
||||
helper.create('services');
|
||||
helper.copy('services/RedisStreamService.ts');
|
||||
helper.copy('services/DatabaseService.ts');
|
||||
helper.copy('services/EmailService.ts');
|
||||
|
||||
helper.create('schema');
|
||||
helper.copy('schema/UserSchema.ts');
|
||||
helper.copy('schema/UserLimitSchema.ts');
|
||||
helper.copy('schema/PremiumSchema.ts');
|
||||
|
||||
helper.create('schema/broker');
|
||||
helper.copy('schema/broker/LimitNotifySchema.ts');
|
||||
|
||||
helper.create('schema/project');
|
||||
helper.copy('schema/project/ProjectSchema.ts');
|
||||
helper.copy('schema/project/ProjectsLimits.ts');
|
||||
helper.copy('schema/project/ProjectsCounts.ts');
|
||||
|
||||
helper.create('schema/metrics');
|
||||
|
||||
Reference in New Issue
Block a user