Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues with package paths in macos #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions routes/routes-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ router.post('/readExcelData', async (req, res) => {
// this just dumps data out as-is.

// var excelFile = path.join(__dirname, '..', 'ASSETS', req.body.filename); // fails when packaged
var excelFile = path.join(process.cwd(), 'ASSETS', req.body.filename);
var excelFile = path.join(config.startUpPath, 'ASSETS', req.body.filename);
var workSheetsData;
try {

Expand Down Expand Up @@ -216,7 +216,8 @@ router.post('/exportCSVfile', async (req, res) => {
try {
let timestamp = spx.prettifyDate(new Date(), 'YYYY-MM-DD-HHMMSS');
let filenameref = item_relpath.split('.')[0].replace('\\', '/').split('/').slice(-1)[0];
let CSVfileRef = path.join(process.cwd(), 'ASSETS', 'csv', filenameref + '_' + timestamp + '.csv');
// let CSVfileRef = path.join(process.cwd(), 'ASSETS', 'csv', filenameref + '_' + timestamp + '.csv'); // failed in (at least, macos) PKG version
let CSVfileRef = path.join(config.startUpPath, 'ASSETS', 'csv', filenameref + '_' + timestamp + '.csv');
console.log('Writing file ' + CSVfileRef);
await spx.writeTextFile(CSVfileRef,CSVdata);
res.status(200).send('Yea man');
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ app.engine('handlebars', exphbs({
DropdownOptionsLANG() {
let html = '';
let sel = '';
let fileListData = spx.getJSONFileList('./locales/');
// let fileListData = spx.getJSONFileList('./locales/'); // failed in (at least, macos) PKG version
let fileListData = spx.getJSONFileList(path.resolve(spx.getStartUpFolder(), './locales/'));
fileListData.files.forEach((element,i) => {
sel = '';
if (element.name == config.general.langfile)
Expand Down
3 changes: 2 additions & 1 deletion utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const myFormat = printf(({ level, message, label, timestamp }) => {

let LOGLEVEL = config.general.loglevel || 'debug';
let LOGFOLDER = config.general.logfolder || 'LOG';
var logFile = path.resolve(process.cwd(),LOGFOLDER, 'access.log');
// var logFile = path.resolve(process.cwd(),LOGFOLDER, 'access.log'); // failed in (at least, macos) PKG version
var logFile = path.resolve(config.startUpPath, LOGFOLDER, 'access.log');

const logger = createLogger({
format: combine(
Expand Down
7 changes: 5 additions & 2 deletions utils/spx_getconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
}
},


readConfig: function () {
// read config.json. Usage: "cfg.readConfig()"
return new Promise(resolve => {
Expand All @@ -36,7 +36,7 @@ module.exports = {
// var startUpPath = path.resolve(process.execPath + '/..'); // This works while in pkg, but not in Node, so here we go:

let startUpPath, runtime
if ( process.pkg ) {
if ( typeof process.pkg !== 'undefined' && process.pkg ) {
runtime = 'pkg'
startUpPath = path.resolve(process.execPath + '/..');
} else {
Expand Down Expand Up @@ -141,6 +141,9 @@ module.exports = {
global.config = JSON.parse(configFileStr);
}

// added to avoid circular dependency in spx_server_functions when used spx.startUpPath()
global.config.startUpPath = startUpPath;

// folderchecks
this.makeFolderIfNotExist(global.config.general.logfolder);
this.makeFolderIfNotExist(global.config.general.dataroot);
Expand Down
6 changes: 1 addition & 5 deletions utils/spx_server_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ module.exports = {
getStartUpFolder: function () {
// a workaround to resolve the path to the current startup folder
// on this runtime session (node vs binary pkg)
if ( process.pkg ) {
return path.resolve(process.execPath + '/..');
} else {
return process.cwd();
}
return config.startUpPath;
},


Expand Down