Skip to content

Commit

Permalink
Merge pull request #11 from CloudCannon/feat/new-eleventy-config-files
Browse files Browse the repository at this point in the history
Support new eleventy config files
  • Loading branch information
rphillips-cc authored Oct 11, 2023
2 parents 4009ee6 + 146e9b4 commit 41a1ef1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 19 additions & 5 deletions src/lib/eleventy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { join, dirname } = require('path');
const Compiler = require('./compiler');
const { parseOptions } = require('../helpers/parser');
const { addEchoCommand } = require('../helpers/commands');
Expand All @@ -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
Expand All @@ -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 || ''}"`] : [])
Expand Down
42 changes: 32 additions & 10 deletions tests/eleventy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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"',
Expand Down

0 comments on commit 41a1ef1

Please sign in to comment.