Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/environment setup automation #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { exec } = require('child_process');

if( !process.env.SENDGRID_API_KEY ) {
console.log('Adding API...')
const execCallback = (err, stdout, stderr) => {
if(err) {
console.error(`ERROR: ${err}`);
}
if(stderr) {
console.error(`STDERR: ${stderr}`);
}
console.log('Done. If on Windows, please restart console. Otherwise, run command again.');
process.exit(1);
}

let thisPlatform = process.platform;
if( thisPlatform === 'win32' ) {
exec('sendgrid.bat', execCallback);
} else if( thisPlatform === 'darwin' || thisPlatform === 'linux') {
exec('bash sendgrid.env', execCallback);
} else {
console.warn('WARNING: OS is not Windows/MacOS/Linux. Please set your environment variables manually.');
process.exit(1);
}
} else if( !( typeof process.env.SENDGRID_API_KEY === 'string' && process.env.SENDGRID_API_KEY.startsWith('SG.') ) ) {
console.warn('WARNING: Invalid API Key. Verify that the API key is correct in the env/bat file.');
process.exit(1);
} else {
console.log('Environment variables detected, proceeding...');
return;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "node env.js && next dev",
"build": "next build",
"start": "next start",
"test": "jest"
Expand Down