Skip to content

Commit

Permalink
Merge pull request #8 from haochang/set-env-vars
Browse files Browse the repository at this point in the history
Set the environment variables from the severless template before generating the client
  • Loading branch information
andrewphahn authored Jul 7, 2019
2 parents 0c968db + c1cc964 commit 82193d8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,20 @@ class ServerlessFullstackPlugin {
});
}

generateClient() {
setClientEnv() {
this.serverless.cli.log(`Setting the environment variables...`);
const serverlessEnv = this.serverless.service.provider.environment;

if (!serverlessEnv) {
return this.serverless.cli.log(
`No environment variables detected. Skipping step...`
);
}

return Object.assign({}, process.env, serverlessEnv);
}

generateClient() {
const clientCommand = this.options.clientCommand;
const clientSrcPath = this.options.clientSrcPath || '.';
if (clientCommand && this.cliOptions['generate-client'] !== false) {
Expand All @@ -112,7 +124,8 @@ class ServerlessFullstackPlugin {

performClientGeneration(command, args, clientSrcPath, resolve, reject) {
this.serverless.cli.log(`Generating client...`);
const proc = spawn(command, args, {cwd: clientSrcPath, env: process.env, shell: true});
const clientEnv = this.setClientEnv();
const proc = spawn(command, args, {cwd: clientSrcPath, env: clientEnv, shell: true});

proc.stdout.on('data', (data) => {
const printableData = data ? `${data}`.trim() : '';
Expand Down

0 comments on commit 82193d8

Please sign in to comment.