From b703d2f105c56099c07abfb5b117d602317aae0c Mon Sep 17 00:00:00 2001 From: Ryan Koch Date: Wed, 3 Jan 2024 13:07:51 -0600 Subject: [PATCH] Adds SSG as CLI option and adjusts code to check for string rather than boolean. --- package.json | 8 ++++---- packages/env-loader/src/cli-options.ts | 13 ++++++++++++- scripts/yarn/build.js | 2 +- scripts/yarn/build:preview.js | 3 --- scripts/yarn/dev.js | 2 +- scripts/yarn/export.js | 2 +- src/lib/drupal/drupalClient.ts | 7 ++++--- 7 files changed, 23 insertions(+), 14 deletions(-) delete mode 100644 scripts/yarn/build:preview.js diff --git a/package.json b/package.json index b818e2ebf..ee4e8c526 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ ], "scripts": { "setup": "node scripts/yarn/setup.js", - "dev": "yarn build:env-loader && node ./scripts/yarn/dev.js", - "build": "yarn build:env-loader && node ./scripts/yarn/build.js", + "dev": "yarn build:env-loader && node ./scripts/yarn/dev.js --SSG=false", + "build": "yarn build:env-loader && node ./scripts/yarn/build.js --USE_REDIS=true", "build:env-loader": "tsc -b ./packages/env-loader/tsconfig.json", - "build:preview": "yarn build:env-loader && node ./scripts/yarn/build:preview.js", + "build:preview": "yarn build:env-loader && node ./scripts/yarn/build.js --SSG=false", "build:sitemap": "yarn build:env-loader & node ./scripts/yarn/build:sitemap.js", "start": "yarn build:env-loader && node ./scripts/yarn/start.js", - "export": "yarn build:env-loader && node ./scripts/yarn/export.js --USE_REDIS", + "export": "yarn build:env-loader && node ./scripts/yarn/export.js --USE_REDIS=true", "export:serve": "http-server out -p 8001", "redis": "docker run --name next-redis -p 6379:6379 -d redis", "redis:cli": "docker exec -it next-redis redis-cli", diff --git a/packages/env-loader/src/cli-options.ts b/packages/env-loader/src/cli-options.ts index 02ac5d9e3..c7ec11be4 100644 --- a/packages/env-loader/src/cli-options.ts +++ b/packages/env-loader/src/cli-options.ts @@ -80,9 +80,20 @@ export const getCliOptions = (scriptName: string): EnvVars => { .option('--DRUPAL_CLIENT_SECRET ', 'Drupal client secret') .option('--DRUPAL_PREVIEW_SECRET ', 'Drupal preview secret') .option('--DRUPAL_SITE_ID ', 'Drupal site ID') - .option('--USE_REDIS', 'Enable redis') + .addOption( + new Option('--USE_REDIS ', 'Enable redis').choices([ + 'true', + 'false', + ]) + ) .option('--REDIS_URL ', 'Redis URL') .option('--SITE_URL ', 'Origin used for generated absolute paths') + .addOption( + new Option( + '--SSG ', + 'Run logic in getStaticPaths to generate all page URLs' + ).choices(['true', 'false']) + ) configureAdditionalHelpText(program, scriptName) diff --git a/scripts/yarn/build.js b/scripts/yarn/build.js index da1e3f09c..079f58cf4 100644 --- a/scripts/yarn/build.js +++ b/scripts/yarn/build.js @@ -1,3 +1,3 @@ const { processEnv } = require('env-loader') -processEnv('SSG=true next build') +processEnv('next build') diff --git a/scripts/yarn/build:preview.js b/scripts/yarn/build:preview.js deleted file mode 100644 index 797b66992..000000000 --- a/scripts/yarn/build:preview.js +++ /dev/null @@ -1,3 +0,0 @@ -const { processEnv } = require('env-loader') - -processEnv('SSG=false next build') diff --git a/scripts/yarn/dev.js b/scripts/yarn/dev.js index 5645d144c..09e4997ac 100644 --- a/scripts/yarn/dev.js +++ b/scripts/yarn/dev.js @@ -1,3 +1,3 @@ const { processEnv } = require('env-loader') -processEnv('yarn setup && SSG=false next dev') +processEnv('yarn setup && next dev') diff --git a/scripts/yarn/export.js b/scripts/yarn/export.js index 205f6868a..79c5df3f5 100644 --- a/scripts/yarn/export.js +++ b/scripts/yarn/export.js @@ -1,3 +1,3 @@ const { processEnv } = require('env-loader') -processEnv('SSG=true next build && next export') +processEnv('next build && next export') diff --git a/src/lib/drupal/drupalClient.ts b/src/lib/drupal/drupalClient.ts index d23e88f4f..d38a5ee6d 100644 --- a/src/lib/drupal/drupalClient.ts +++ b/src/lib/drupal/drupalClient.ts @@ -14,8 +14,9 @@ export const drupalClient = new DrupalClient(baseUrl, { clientSecret: process.env.DRUPAL_CLIENT_SECRET, }, // Generally use cache for `yarn export` as it generates all pages - cache: process.env.USE_REDIS - ? redisCache(createRedisClient(process.env.REDIS_URL)) - : null, + cache: + process.env.USE_REDIS === 'true' + ? redisCache(createRedisClient(process.env.REDIS_URL)) + : null, previewSecret: process.env.DRUPAL_PREVIEW_SECRET, })