From 7f528da6cb173c7337efe0b777466861b031a510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Cora=C3=A7=C3=A3o?= Date: Sat, 10 Feb 2024 21:31:59 +0000 Subject: [PATCH] fix #54 --- configs/configOptions.json | 4 +-- package.json | 2 +- src/flow.js | 57 +++++++++++++++++++++++--------------- src/utils.js | 1 + 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/configs/configOptions.json b/configs/configOptions.json index c1c18a7..7827753 100644 --- a/configs/configOptions.json +++ b/configs/configOptions.json @@ -9,7 +9,7 @@ }, { "text": "Site's logo", - "method": "configLoop", + "method": "configImage", "file": "./config/_default/languages.en.toml", "parent": "params", "key": "logo", @@ -17,7 +17,7 @@ }, { "text": "Site's secondary logo", - "method": "configLoop", + "method": "configImage", "file": "./config/_default/languages.en.toml", "parent": "params", "key": "secondaryLogo", diff --git a/package.json b/package.json index 6d40232..9affa92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blowfish-tools", - "version": "1.0.0", + "version": "1.1.0", "description": "CLI to initialize and configure a Blowfish project.", "main": "cli.js", "bin": { diff --git a/src/flow.js b/src/flow.js index 3493487..485122e 100644 --- a/src/flow.js +++ b/src/flow.js @@ -427,19 +427,32 @@ export default class flow { process.exit(0); } - utils.run('cp ' + newValue + ' ./assets/', false); - newValue = newValue.split('/').pop(); - if (!parent) { - data[variable] = newValue - } else if (data[parent]) { - data[parent][variable] = newValue + var processChanges = () => { + utils.run('cp ' + newValue + ' ./assets/', false); + newValue = newValue.split('/').pop(); + + if (!parent) { + data[variable] = newValue + } else if (data[parent]) { + data[parent][variable] = newValue + } else { + data[parent] = {} + data[parent][variable] = newValue + } + + utils.saveFileSync(file, toml.stringify(data)); + } + + if (!utils.directoryExists('./assets/')) { + utils.run('mkdir assets', false) + .then(() => { + processChanges() + }); } else { - data[parent] = {} - data[parent][variable] = newValue + processChanges() } - utils.saveFileSync(file, toml.stringify(data)); } static async configMenus(file) { @@ -845,7 +858,7 @@ var exitOption = { var configOptionsJSONList = utils.readAppJsonConfig('configOptions.json'); -function createAction (method, file, parent, key, description) { +function createAction(method, file, parent, key, description) { return async (list) => { await flow[method]( file, @@ -894,11 +907,11 @@ var options = [ var tempList = [] for (var i in configOptions) { - if (configOptions[i].parent === null || configOptions[i].method === 'exit'){ - + if (configOptions[i].parent === null || configOptions[i].method === 'exit') { + } - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -912,7 +925,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === 'author' || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -926,7 +939,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "homepage" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -940,7 +953,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "header" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -954,7 +967,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "footer" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -968,7 +981,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "article" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -982,7 +995,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "list" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -996,7 +1009,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "taxonomy" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -1010,7 +1023,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].parent === "term" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); @@ -1024,7 +1037,7 @@ var options = [ var tempList = [] for (var i in configOptions) { if (configOptions[i].method === "configImage" || configOptions[i].method === 'exit') - tempList.push(configOptions[i]) + tempList.push(configOptions[i]) } flow.enterConfigMode(tempList); diff --git a/src/utils.js b/src/utils.js index 87334fd..ad561dc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -69,6 +69,7 @@ export default class utils { try { return fs.existsSync(path); } catch (err) { + console.log(err) return false; } }