From 536de2a3199b1befed54b6fe520a2e3fcefe0d90 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 26 Jan 2021 17:54:25 +0100 Subject: [PATCH] Implemented automatic ci env generation ref #118 --- package.json | 6 ++++-- scripts/create_testenv.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 scripts/create_testenv.ts diff --git a/package.json b/package.json index bb5f2a0..2653861 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,9 @@ "docs": "typedoc --out docs src", "test": "jest", "test:watch": "jest --watchAll", - "test:ci": "start-server-and-test dev http://localhost:4010/api/docs/openapi.json test", + "test:ci:generate_env": "ts-node scripts/create_testenv.ts", + "test:ci:run": "start-server-and-test dev http://localhost:4010/api/docs/openapi.json test", + "test:ci": "npm run test:ci:generate_env && npm run test:ci:run", "seed": "ts-node ./node_modules/typeorm/cli.js schema:sync && ts-node ./node_modules/typeorm-seeding/dist/cli.js seed", "openapi:export": "ts-node scripts/openapi_export.ts", "licenses:export": "license-exporter --md", @@ -102,4 +104,4 @@ "docs/*" ] } -} +} \ No newline at end of file diff --git a/scripts/create_testenv.ts b/scripts/create_testenv.ts new file mode 100644 index 0000000..1fa6c8c --- /dev/null +++ b/scripts/create_testenv.ts @@ -0,0 +1,37 @@ +import consola from "consola"; +import fs from "fs"; +import nodemailer from "nodemailer"; + + +nodemailer.createTestAccount((err, account) => { + if (err) { + console.error('Failed to create a testing account. ' + err.message); + return process.exit(1); + } + + const env = ` +APP_PORT=4010 +DB_TYPE=sqlite +DB_HOST=bla +DB_PORT=bla +DB_USER=bla +DB_PASSWORD=bla +DB_NAME=./test.sqlite +NODE_ENV=dev +POSTALCODE_COUNTRYCODE=DE +SEED_TEST_DATA=true +MAIL_SERVER=${account.smtp.host} +MAIL_PORT=${account.smtp.port} +MAIL_USER=${account.user} +MAIL_PASSWORD=${account.pass} +MAIL_FROM=${account.user}` + + try { + fs.writeFileSync("./.env", env, { encoding: "utf-8" }); + consola.success("Exported ci env to .env"); + } catch (error) { + consola.error("Couldn't export the ci env"); + } + +}); +