added packages into dockploy 5
This commit is contained in:
@@ -18,6 +18,12 @@ import * as bcrypt from 'bcryptjs';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const existingAdmins = await prisma.adminUser.count();
|
||||
if (existingAdmins > 0 && process.env.RUN_SEED !== 'force') {
|
||||
console.log('Seed skipped; admin users already exist');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Seeding fabric_trade database...');
|
||||
|
||||
await prisma.productFavorite.deleteMany();
|
||||
|
||||
+9519
File diff suppressed because one or more lines are too long
+39
-1
@@ -140188,6 +140188,42 @@ var require_apply_migrations = __commonJS({
|
||||
}
|
||||
});
|
||||
|
||||
// dist/run-seed.js
|
||||
var require_run_seed = __commonJS({
|
||||
"dist/run-seed.js"(exports2) {
|
||||
"use strict";
|
||||
var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
|
||||
return mod && mod.__esModule ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports2, "__esModule", { value: true });
|
||||
exports2.runBundledSeed = runBundledSeed;
|
||||
var node_fs_1 = require("node:fs");
|
||||
var node_child_process_1 = require("node:child_process");
|
||||
var node_path_1 = __importDefault2(require("node:path"));
|
||||
function runBundledSeed() {
|
||||
const seedFile = node_path_1.default.join(process.cwd(), "runtime", "seed.cjs");
|
||||
if (!(0, node_fs_1.existsSync)(seedFile)) {
|
||||
console.log("No runtime/seed.cjs; skipping seed");
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = (0, node_child_process_1.spawn)(process.execPath, [seedFile], {
|
||||
stdio: "inherit",
|
||||
env: process.env
|
||||
});
|
||||
child.on("exit", (code) => {
|
||||
if (code === 0)
|
||||
resolve();
|
||||
else
|
||||
reject(new Error(`seed exited ${code}`));
|
||||
});
|
||||
child.on("error", reject);
|
||||
});
|
||||
}
|
||||
__name(runBundledSeed, "runBundledSeed");
|
||||
}
|
||||
});
|
||||
|
||||
// dist/main.js
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var core_1 = require_core3();
|
||||
@@ -140196,9 +140232,11 @@ var swagger_1 = require_dist6();
|
||||
var express_1 = require_express2();
|
||||
var app_module_1 = require_app_module();
|
||||
var apply_migrations_1 = require_apply_migrations();
|
||||
var run_seed_1 = require_run_seed();
|
||||
async function bootstrap() {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
await (0, apply_migrations_1.applyPendingMigrations)();
|
||||
await (0, run_seed_1.runBundledSeed)();
|
||||
}
|
||||
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
||||
const bodyLimit = process.env.BODY_LIMIT || "25mb";
|
||||
@@ -140219,7 +140257,7 @@ async function bootstrap() {
|
||||
const swaggerConfig = new swagger_1.DocumentBuilder().setTitle("Fabric Trade API").setDescription("API \u0633\u0631\u0648\u0631 \u062A\u062C\u0627\u0631\u062A \u067E\u0627\u0631\u0686\u0647").setVersion("1.0").addBearerAuth().build();
|
||||
const document2 = swagger_1.SwaggerModule.createDocument(app, swaggerConfig);
|
||||
swagger_1.SwaggerModule.setup(`${globalPrefix}/docs`, app, document2);
|
||||
const port = process.env.PORT ?? 3e3;
|
||||
const port = Number(process.env.PORT) || 3e3;
|
||||
await app.listen(port);
|
||||
console.log(`Fabric Trade API listening on http://localhost:${port}/${globalPrefix}`);
|
||||
console.log(`Swagger docs at http://localhost:${port}/${globalPrefix}/docs`);
|
||||
|
||||
@@ -83,9 +83,27 @@ writeFileSync(
|
||||
`${JSON.stringify({ name: 'fabric-trade-runtime', private: true, type: 'commonjs' }, null, 2)}\n`,
|
||||
)
|
||||
|
||||
console.log('==> esbuild seed')
|
||||
execSync(
|
||||
[
|
||||
'npx --yes esbuild prisma/seed.ts',
|
||||
'--bundle',
|
||||
'--platform=node',
|
||||
'--target=node22',
|
||||
'--format=cjs',
|
||||
'--outfile=runtime/seed.cjs',
|
||||
'--keep-names',
|
||||
'--legal-comments=none',
|
||||
].join(' '),
|
||||
{ stdio: 'inherit' },
|
||||
)
|
||||
|
||||
if (!existsSync(path.join(runtimeDir, 'server.cjs'))) {
|
||||
throw new Error('runtime/server.cjs ساخته نشد')
|
||||
}
|
||||
if (!existsSync(path.join(runtimeDir, 'seed.cjs'))) {
|
||||
throw new Error('runtime/seed.cjs ساخته نشد')
|
||||
}
|
||||
|
||||
console.log(`runtime/server.cjs ${mb(path.join(runtimeDir, 'server.cjs'))}`)
|
||||
console.log(`runtime/${engineName} ${mb(path.join(runtimeDir, engineName))}`)
|
||||
|
||||
+3
-1
@@ -4,10 +4,12 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { json, urlencoded } from 'express';
|
||||
import { AppModule } from './app.module';
|
||||
import { applyPendingMigrations } from './apply-migrations';
|
||||
import { runBundledSeed } from './run-seed';
|
||||
|
||||
async function bootstrap() {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
await applyPendingMigrations();
|
||||
await runBundledSeed();
|
||||
}
|
||||
|
||||
const app = await NestFactory.create(AppModule);
|
||||
@@ -42,7 +44,7 @@ async function bootstrap() {
|
||||
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup(`${globalPrefix}/docs`, app, document);
|
||||
|
||||
const port = process.env.PORT ?? 3000;
|
||||
const port = Number(process.env.PORT) || 3000;
|
||||
await app.listen(port);
|
||||
console.log(
|
||||
`Fabric Trade API listening on http://localhost:${port}/${globalPrefix}`,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { spawn } from 'node:child_process'
|
||||
import path from 'node:path'
|
||||
|
||||
export function runBundledSeed(): Promise<void> {
|
||||
const seedFile = path.join(process.cwd(), 'runtime', 'seed.cjs')
|
||||
if (!existsSync(seedFile)) {
|
||||
console.log('No runtime/seed.cjs; skipping seed')
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, [seedFile], {
|
||||
stdio: 'inherit',
|
||||
env: process.env,
|
||||
})
|
||||
child.on('exit', (code) => {
|
||||
if (code === 0) resolve()
|
||||
else reject(new Error(`seed exited ${code}`))
|
||||
})
|
||||
child.on('error', reject)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user