From 9c40a7f5ff24ed49e982033eac548e458162d892 Mon Sep 17 00:00:00 2001 From: Dominik Kundel Date: Thu, 15 Apr 2021 18:11:14 -0700 Subject: [PATCH] feat(templating): add support for .env.example files (#235) --- packages/twilio-run/__tests__/templating/filesystem.test.ts | 6 +++--- packages/twilio-run/src/templating/data.ts | 1 + packages/twilio-run/src/templating/filesystem.ts | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/twilio-run/__tests__/templating/filesystem.test.ts b/packages/twilio-run/__tests__/templating/filesystem.test.ts index d5ad89a8..bc8e34bc 100644 --- a/packages/twilio-run/__tests__/templating/filesystem.test.ts +++ b/packages/twilio-run/__tests__/templating/filesystem.test.ts @@ -415,9 +415,9 @@ test('installation with an existing dot-env file', async () => { expect(writeFile).toHaveBeenCalledWith( join('testing', '.env'), '# Comment\n' + - 'FOO=BAR\n' + - '\n\n' + - '# Variables for function ".env"\n' + // This seems to be a bug but is the output. + 'FOO=BAR\n' + + '\n\n' + + '# Variables for function "example"\n' + '# ---\n' + 'HELLO=WORLD\n', 'utf8' diff --git a/packages/twilio-run/src/templating/data.ts b/packages/twilio-run/src/templating/data.ts index c4235e0f..f5a900a6 100644 --- a/packages/twilio-run/src/templating/data.ts +++ b/packages/twilio-run/src/templating/data.ts @@ -149,6 +149,7 @@ export async function getTemplateFiles( return ( file.name === 'package.json' || file.name === '.env' || + file.name === '.env.example' || file.name === 'README.md' ); }) diff --git a/packages/twilio-run/src/templating/filesystem.ts b/packages/twilio-run/src/templating/filesystem.ts index 6fd3f15a..8ecf298d 100644 --- a/packages/twilio-run/src/templating/filesystem.ts +++ b/packages/twilio-run/src/templating/filesystem.ts @@ -8,9 +8,9 @@ import { install, InstallResult } from 'pkg-install'; import { downloadFile, fileExists, + mkdir, readFile, writeFile, - mkdir, } from '../utils/fs'; import { logger } from '../utils/logger'; import { TemplateFileInfo } from './data'; @@ -154,14 +154,14 @@ export async function writeFiles( path.join(assetsTargetDir, file.directory, file.name) ), }; - } else if (file.type === '.env') { + } else if (file.type === '.env' || file.type === '.env.example') { return { title: 'Configuring Environment Variables in .env', task: async (ctx: any) => { const output = await writeEnvFile( file.content, targetDir, - file.name + namespace ); ctx.env = output; },