Automatically create .env file on first run.
This commit is contained in:
parent
2db3ca7dc3
commit
313ba9dedf
2 changed files with 24 additions and 3 deletions
|
@ -1,3 +1,3 @@
|
|||
module.exports = {
|
||||
files: JSON.parse(process.env.AUDIO_FILES_ARRAY),
|
||||
files: JSON.parse(process.env.AUDIO_FILES_ARRAY || "[]"),
|
||||
};
|
||||
|
|
25
index.js
25
index.js
|
@ -4,10 +4,14 @@ require('dotenv').config();
|
|||
const express = require('express');
|
||||
const q = require('q');
|
||||
const fs = require('fs');
|
||||
const stat = q.denodeify(fs.stat);
|
||||
const writeFile = q.denodeify(fs.writeFile);
|
||||
const readdir = q.denodeify(fs.readdir);
|
||||
const cors = require('cors');
|
||||
const execFile = q.denodeify(require('child_process').execFile);
|
||||
const musicMetadata = require('music-metadata');
|
||||
const path = require('path');
|
||||
|
||||
const ws = require('./ws');
|
||||
const config = require('./config.js');
|
||||
|
||||
|
@ -47,8 +51,26 @@ const getDuration = (filename) => {
|
|||
});
|
||||
};
|
||||
|
||||
const audioDir = path.join(__dirname, 'frontend/public/audio');
|
||||
|
||||
q.resolve()
|
||||
.then(() => getDuration(path.join(__dirname + '/frontend/public/audio', files[0])))
|
||||
.then(() => {
|
||||
const envPath = path.join(__dirname, '.env');
|
||||
return stat(envPath)
|
||||
.catch(() => {
|
||||
return readdir(audioDir)
|
||||
.then(files => {
|
||||
if(files.length) {
|
||||
const contents = `
|
||||
AUDIO_FILES_ARRAY=${JSON.stringify(files)}
|
||||
`;
|
||||
|
||||
return writeFile(envPath, contents, 'utf8');
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
.then(() => getDuration(path.join(audioDir, files[0])))
|
||||
.then(audioLength => {
|
||||
let startTime = Date.now();
|
||||
|
||||
|
@ -56,6 +78,5 @@ q.resolve()
|
|||
})
|
||||
.catch(e => {
|
||||
console.error(e);
|
||||
metaFile.close();
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue