diff --git a/src/nginxconfig/generators/index.js b/src/nginxconfig/generators/index.js index 654b6ec..89f9706 100644 --- a/src/nginxconfig/generators/index.js +++ b/src/nginxconfig/generators/index.js @@ -38,59 +38,56 @@ import drupalConf from './conf/drupal.conf'; import magentoConf from './conf/magento.conf'; export default (domains, global) => { - const files = []; + const files = {}; // Base nginx config - files.push(['nginx.conf', toConf(nginxConf(domains, global))]); + files['nginx.conf'] = toConf(nginxConf(domains, global)); // Modularised configs if (global.tools.modularizedStructure.computed) { // Domain config for (const domain of domains) { - files.push([ - `sites-${global.tools.symlinkVhost.computed ? 'available' : 'enabled'}/${domain.server.domain.computed}.conf`, - toConf(websiteConf(domain, domains, global)), - ]); + files[`sites-${global.tools.symlinkVhost.computed ? 'available' : 'enabled'}/${domain.server.domain.computed}.conf`] = toConf(websiteConf(domain, domains, global)); } // Let's encrypt if (domains.some(d => d.https.certType.computed === 'letsEncrypt')) - files.push(['nginxconfig.io/letsencrypt.conf', toConf(letsEncryptConf(global))]); + files['nginxconfig.io/letsencrypt.conf'] = toConf(letsEncryptConf(global)); // Security - files.push(['nginxconfig.io/security.conf', toConf(securityConf(domains, global))]); + files['nginxconfig.io/security.conf'] = toConf(securityConf(domains, global)); // General - files.push(['nginxconfig.io/general.conf', toConf(generalConf(domains, global))]); + files['nginxconfig.io/general.conf'] = toConf(generalConf(domains, global)); // PHP if (domains.some(d => d.php.php.computed)) - files.push(['nginxconfig.io/php_fastcgi.conf', toConf(phpConf(domains, global))]); + files['nginxconfig.io/php_fastcgi.conf'] = toConf(phpConf(domains, global)); // Python if (domains.some(d => d.python.python.computed)) - files.push(['nginxconfig.io/python_uwsgi.conf', toConf(pythonConf(global))]); + files['nginxconfig.io/python_uwsgi.conf'] = toConf(pythonConf(global)); // Reverse proxy if (domains.some(d => d.reverseProxy.reverseProxy.computed)) - files.push(['nginxconfig.io/proxy.conf', toConf(proxyConf())]); + files['nginxconfig.io/proxy.conf'] = toConf(proxyConf()); // WordPress if (domains.some(d => d.php.wordPressRules.computed)) - files.push(['nginxconfig.io/wordpress.conf', toConf(wordPressConf(global))]); + files['nginxconfig.io/wordpress.conf'] = toConf(wordPressConf(global)); // Drupal if (domains.some(d => d.php.drupalRules.computed)) - files.push(['nginxconfig.io/drupal.conf', toConf(drupalConf(global))]); + files['nginxconfig.io/drupal.conf'] = toConf(drupalConf(global)); // Drupal if (domains.some(d => d.php.magentoRules.computed)) - files.push(['nginxconfig.io/magento.conf', toConf(magentoConf())]); + files['nginxconfig.io/magento.conf'] = toConf(magentoConf()); } else { // PHP if (domains.some(d => d.php.wordPressRules.computed)) - files.push(['nginxconfig.io/php_fastcgi.conf', toConf(phpConf(domains, global))]); + files['nginxconfig.io/php_fastcgi.conf'] = toConf(phpConf(domains, global)); } return files; diff --git a/src/nginxconfig/templates/app.vue b/src/nginxconfig/templates/app.vue index 38fb1c9..fe198f2 100644 --- a/src/nginxconfig/templates/app.vue +++ b/src/nginxconfig/templates/app.vue @@ -80,11 +80,11 @@ THE SOFTWARE.

{{ i18n.templates.app.configFiles }}

-
@@ -132,8 +132,8 @@ THE SOFTWARE. ready: false, splitColumn: false, confWatcherWaiting: false, - confFilesPrevious: [], - confFilesOutput: [], + confFilesPrevious: {}, + confFilesOutput: {}, }; }, computed: { @@ -222,17 +222,21 @@ THE SOFTWARE. this.$nextTick(() => this.checkChange(this.confFiles)); }, updateDiff(newConf, oldConf) { + const newFiles = {}; + // Work through each file in the new config - const newFiles = []; - for (const [newFileName, newFileConf] of newConf) { + for (const newFileName in newConf) { + if (!Object.prototype.hasOwnProperty.call(newConf, newFileName)) continue; + const newFileConf = newConf[newFileName]; + // If a file with the same name existed before, diff! // TODO: Handle diffing across file renames (eg. when a user changes a domain name) - const old = oldConf && oldConf.find(c => c[0] === newFileName); - if (old && this.hash(old[1]) !== this.hash(newFileConf)) { + const old = oldConf && oldConf[newFileName]; + if (old && this.hash(old) !== this.hash(newFileConf)) { console.info(`Diffing ${newFileName}...`); // Get the diff - const diff = diffLines(old[1], newFileConf); + const diff = diffLines(old, newFileConf); // Wrap additions in , drop removals const output = diff.map((change, index, array) => { @@ -263,13 +267,15 @@ THE SOFTWARE. }).join(''); // Store - newFiles.push([newFileName, output]); + newFiles[newFileName] = output; continue; } // No diffing, just store the new file - newFiles.push([newFileName, newFileConf]); + newFiles[newFileName] = newFileConf; } + + // Store this.$data.confFilesOutput = newFiles; this.$nextTick(() => this.$data.confWatcherWaiting = false); }, diff --git a/src/nginxconfig/templates/setup.vue b/src/nginxconfig/templates/setup.vue index 5bb7d18..d2ba4ae 100644 --- a/src/nginxconfig/templates/setup.vue +++ b/src/nginxconfig/templates/setup.vue @@ -114,15 +114,16 @@ THE SOFTWARE. const tar = pack(); // Add all our config files to the tar - for (const conf of this.$props.data.confFiles) { - tar.entry({ name: conf[0] }, conf[1]); + for (const fileName in this.$props.data.confFiles) { + if (!Object.prototype.hasOwnProperty.call(this.$props.data.confFiles, fileName)) continue; + tar.entry({ name: fileName }, this.$props.data.confFiles[fileName]); // If symlinks are enabled and this is in sites-available, symlink to sites-enabled - if (this.$props.data.global.tools.symlinkVhost.computed && conf[0].startsWith('sites-available')) + if (this.$props.data.global.tools.symlinkVhost.computed && fileName.startsWith('sites-available')) tar.entry({ - name: conf[0].replace(/^sites-available/, 'sites-enabled'), + name: fileName.replace(/^sites-available/, 'sites-enabled'), type: 'symlink', - linkname: `../${conf[0]}`, + linkname: `../${fileName}`, }); }