From bcc7871d873e902281db96843e59b0cd469e08d8 Mon Sep 17 00:00:00 2001 From: Ross Phillips <12723297+rphillips-cc@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:30:21 +1300 Subject: [PATCH 1/2] Support new eleventy default config files --- src/lib/eleventy.js | 24 +++++++++++++++++++----- tests/eleventy.test.js | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/lib/eleventy.js b/src/lib/eleventy.js index ff45cde..2014117 100644 --- a/src/lib/eleventy.js +++ b/src/lib/eleventy.js @@ -1,4 +1,3 @@ -const { join, dirname } = require('path'); const Compiler = require('./compiler'); const { parseOptions } = require('../helpers/parser'); const { addEchoCommand } = require('../helpers/commands'); @@ -22,8 +21,6 @@ function getInstallCommands(buildConfig) { ]; } - const configPath = buildConfig.config || '.eleventy.js'; - const configMovedPath = join(dirname(configPath), 'default-eleventy.config.js'); const pluginTag = buildConfig.use_beta_plugin ? 'next' : 'latest'; // npm pkg set requires npm version >= 7 @@ -37,11 +34,28 @@ function getInstallCommands(buildConfig) { // Install dependencies 'npm install', + ...( + buildConfig.config + ? [ + `if [ -f "${buildConfig.config}" ]; then export ELEVENTY_CONFIG="${buildConfig.config}"; fi` + ] + : [ + // Find default config path (in reverse order to match priority) + 'if [ -f eleventy.config.cjs ]; then export ELEVENTY_CONFIG=eleventy.config.cjs; fi', + 'if [ -f eleventy.config.js ]; then export ELEVENTY_CONFIG=eleventy.config.js; fi', + 'if [ -f .eleventy.js ]; then export ELEVENTY_CONFIG=.eleventy.js; fi' + ] + ), + + 'export ELEVENTY_CONFIG_DIR=`dirname $ELEVENTY_CONFIG`', + 'echo $ELEVENTY_CONFIG', + 'echo $ELEVENTY_CONFIG_DIR', + // Move the site config file to injected config require location - `if [ -f ${configPath} ]; then mv ${configPath} ${configMovedPath}; fi`, + 'if [ -f $ELEVENTY_CONFIG ]; then mv $ELEVENTY_CONFIG "$ELEVENTY_CONFIG_DIR/default-eleventy.config.js"; fi', // Move injected config to the original site config location - `cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js ${configPath}`, + 'cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js $ELEVENTY_CONFIG', // Set environment variable for plugin to read ...(buildConfig.input ? [`export CC_ELEVENTY_INPUT="${buildConfig.input || ''}"`] : []) diff --git a/tests/eleventy.test.js b/tests/eleventy.test.js index 999ff99..ad6904c 100644 --- a/tests/eleventy.test.js +++ b/tests/eleventy.test.js @@ -13,11 +13,22 @@ test('outputs with empty config', () => { 'echo \'$ npm install\'', 'npm install', - 'echo \'$ if [ -f .eleventy.js ]; then mv .eleventy.js default-eleventy.config.js; fi\'', - 'if [ -f .eleventy.js ]; then mv .eleventy.js default-eleventy.config.js; fi', - - 'echo \'$ cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js .eleventy.js\'', - 'cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js .eleventy.js', + "echo '$ if [ -f eleventy.config.cjs ]; then export ELEVENTY_CONFIG=eleventy.config.cjs; fi'", + 'if [ -f eleventy.config.cjs ]; then export ELEVENTY_CONFIG=eleventy.config.cjs; fi', + "echo '$ if [ -f eleventy.config.js ]; then export ELEVENTY_CONFIG=eleventy.config.js; fi'", + 'if [ -f eleventy.config.js ]; then export ELEVENTY_CONFIG=eleventy.config.js; fi', + "echo '$ if [ -f .eleventy.js ]; then export ELEVENTY_CONFIG=.eleventy.js; fi'", + 'if [ -f .eleventy.js ]; then export ELEVENTY_CONFIG=.eleventy.js; fi', + "echo '$ export ELEVENTY_CONFIG_DIR=`dirname $ELEVENTY_CONFIG`'", + 'export ELEVENTY_CONFIG_DIR=`dirname $ELEVENTY_CONFIG`', + "echo '$ echo $ELEVENTY_CONFIG'", + 'echo $ELEVENTY_CONFIG', + "echo '$ echo $ELEVENTY_CONFIG_DIR'", + 'echo $ELEVENTY_CONFIG_DIR', + "echo '$ if [ -f $ELEVENTY_CONFIG ]; then mv $ELEVENTY_CONFIG \"$ELEVENTY_CONFIG_DIR/default-eleventy.config.js\"; fi'", + 'if [ -f $ELEVENTY_CONFIG ]; then mv $ELEVENTY_CONFIG "$ELEVENTY_CONFIG_DIR/default-eleventy.config.js"; fi', + "echo '$ cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js $ELEVENTY_CONFIG'", + 'cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js $ELEVENTY_CONFIG', 'echo "$ source .cloudcannon/prebuild"', 'if [ -f ".cloudcannon/prebuild" ]; then source .cloudcannon/prebuild; else echo "Not found."; fi', @@ -67,11 +78,22 @@ test('outputs with @next config', () => { 'echo \'$ npm install\'', 'npm install', - 'echo \'$ if [ -f .eleventy.js ]; then mv .eleventy.js default-eleventy.config.js; fi\'', - 'if [ -f .eleventy.js ]; then mv .eleventy.js default-eleventy.config.js; fi', - - 'echo \'$ cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js .eleventy.js\'', - 'cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js .eleventy.js', + "echo '$ if [ -f eleventy.config.cjs ]; then export ELEVENTY_CONFIG=eleventy.config.cjs; fi'", + 'if [ -f eleventy.config.cjs ]; then export ELEVENTY_CONFIG=eleventy.config.cjs; fi', + "echo '$ if [ -f eleventy.config.js ]; then export ELEVENTY_CONFIG=eleventy.config.js; fi'", + 'if [ -f eleventy.config.js ]; then export ELEVENTY_CONFIG=eleventy.config.js; fi', + "echo '$ if [ -f .eleventy.js ]; then export ELEVENTY_CONFIG=.eleventy.js; fi'", + 'if [ -f .eleventy.js ]; then export ELEVENTY_CONFIG=.eleventy.js; fi', + "echo '$ export ELEVENTY_CONFIG_DIR=`dirname $ELEVENTY_CONFIG`'", + 'export ELEVENTY_CONFIG_DIR=`dirname $ELEVENTY_CONFIG`', + "echo '$ echo $ELEVENTY_CONFIG'", + 'echo $ELEVENTY_CONFIG', + "echo '$ echo $ELEVENTY_CONFIG_DIR'", + 'echo $ELEVENTY_CONFIG_DIR', + "echo '$ if [ -f $ELEVENTY_CONFIG ]; then mv $ELEVENTY_CONFIG \"$ELEVENTY_CONFIG_DIR/default-eleventy.config.js\"; fi'", + 'if [ -f $ELEVENTY_CONFIG ]; then mv $ELEVENTY_CONFIG "$ELEVENTY_CONFIG_DIR/default-eleventy.config.js"; fi', + "echo '$ cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js $ELEVENTY_CONFIG'", + 'cp node_modules/eleventy-plugin-cloudcannon/src/inject-cloudcannon.config.js $ELEVENTY_CONFIG', 'echo \'$ export CC_ELEVENTY_INPUT="src"\'', 'export CC_ELEVENTY_INPUT="src"', From 146e9b4197adc807ddd9b5a2265c9f64dfd797a7 Mon Sep 17 00:00:00 2001 From: Ross Phillips <12723297+rphillips-cc@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:31:03 +1300 Subject: [PATCH 2/2] Increase version to 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c7f6a4..b314430 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cloudcannon/command-builder", - "version": "1.0.50", + "version": "1.1.0", "description": "A script that builds the script that builds your site", "main": "src/index.js", "scripts": {