mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Database build script.
This commit is contained in:
parent
b905824d50
commit
c3da37c0b0
5 changed files with 57 additions and 26 deletions
22
scripts/build-db-client.js
Normal file
22
scripts/build-db-client.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require('dotenv').config();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { getDatabase, getNpmCommand, runCommand } = require('./common');
|
||||
|
||||
(async () => {
|
||||
const db = getDatabase();
|
||||
|
||||
if (!db) {
|
||||
throw new Error('Database not specified');
|
||||
}
|
||||
|
||||
const src = path.resolve(__dirname, `../prisma/schema.${db}.prisma`);
|
||||
const dest = path.resolve(__dirname, '../prisma/schema.prisma');
|
||||
|
||||
fs.copyFileSync(src, dest);
|
||||
|
||||
await runCommand(getNpmCommand(), ['run', 'prisma-generate']).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
})();
|
||||
29
scripts/common.js
Normal file
29
scripts/common.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const { spawn } = require('child_process');
|
||||
|
||||
function getDatabase() {
|
||||
return process.env.DATABASE_URL.split(':')[0];
|
||||
}
|
||||
|
||||
function runCommand(cmd, args = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(cmd, args);
|
||||
|
||||
child.stdout.on('data', data => process.stdout.write(data));
|
||||
|
||||
child.stderr.on('data', data => process.stdout.write(data));
|
||||
|
||||
child.on('error', err => reject(err));
|
||||
|
||||
child.on('exit', (code, signal) => resolve({ code, signal }));
|
||||
});
|
||||
}
|
||||
|
||||
function getNpmCommand() {
|
||||
return /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDatabase,
|
||||
runCommand,
|
||||
getNpmCommand,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue