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

Add -s option to configure meteor settings #6

Open
wants to merge 1 commit into
base: master
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ This program is designed to be run inside of a MeteorJS project and will do the
-b DIR Overwrite BUILD_DIR
-e VAR=value Environment variables to set on the deployed heroku instance.
-E `FILE` Env file to be read for environment variables to be set.
-s `FILE` Meteor settings file to be set as METEOR_SETTINGS environment variable.

Commands:
[] By default deploys a MeteorJS application to heroku.
Expand All @@ -82,4 +83,8 @@ This program is designed to be run inside of a MeteorJS project and will do the
– Deploy using env file

$ meteor-hero -E prod.env

– Deploy with Meteor settings file

$ meteor-hero -s settings.json
```
6 changes: 6 additions & 0 deletions commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function help () {
-E ${bold.underline(
`FILE`
)} Env file to be read for environment variables to be set.
-s ${bold.underline(
`FILE`
)} Meteor settings file to be set as METEOR_SETTINGS environment variable

${grey(`Commands:`)}
[] By default deploys a MeteorJS application to heroku.
Expand All @@ -49,6 +52,9 @@ function help () {

${cyan(`$ meteor-hero -E prod.env`)}

${grey(`–`)} Deploy with Meteor settings file

${cyan(`$ meteor-hero -s settings.json`)}
`)
// .slice(1, -1)
}
Expand Down
10 changes: 8 additions & 2 deletions commands/newDeploy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const tar = require('tar')
const { execSync } = require('child_process')
const { explain, meteorBuildDir, logger, objToEnvStr, clearBuildFolder } = require('../helpers')
const { explain, meteorBuildDir, logger, objToEnvStr, clearBuildFolder, getMeteorSettingsAsString } = require('../helpers')
const { herokuCreate } = require('../commandHelpers')
const dockerFile = require('../dockerfile')
const dotenv = require('dotenv')
Expand Down Expand Up @@ -80,9 +80,15 @@ function getCustomEnv (args) {
)
: {}

// Meteor settings
const meteorSettings = args['s']
? { METEOR_SETTINGS: getMeteorSettingsAsString(args['s']) }
: {};

return {
...envFileEnv,
...envArgsEnv
...envArgsEnv,
...meteorSettings
}
}

Expand Down
9 changes: 9 additions & 0 deletions helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { execSync } = require('child_process')
const os = require('os')
const yargs = require('yargs')
const del = require('del')
Expand Down Expand Up @@ -43,10 +44,18 @@ function explain (explanation) {
process.exit(1)
}

function getMeteorSettingsAsString(fileName) {
// Remove all line breaks
const json = execSync(`cat ${fileName}`).toString().trim().replace(/\t|\r?\n|\r/g, "");
// Wrap in quotes so JSON string can work with heroku config:set
return `'${json}'`;
}

module.exports = {
args,
clearBuildFolder,
explain,
getMeteorSettingsAsString,
logger,
meteorBuildDir,
objToEnvStr
Expand Down
16 changes: 15 additions & 1 deletion helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
const delMock = jest.fn()
jest.doMock('del', () => delMock)
jest.doMock('os', () => ({ homedir: () => '$HOMEDIR' }))
jest.doMock('child_process', () => ({ execSync: (_) =>
`{
"a": {
"b": 1
}
}`
}));

process.argv = [ 'node', 'meteor-hero', '-e', 'something', '-e', 'anotherarg' ]

Expand All @@ -12,7 +19,8 @@ const {
logger,
objToEnvStr,
meteorBuildDir,
clearBuildFolder
clearBuildFolder,
getMeteorSettingsAsString,
} = require('./helpers')

it('args', () => {
Expand Down Expand Up @@ -63,3 +71,9 @@ describe('meteorBuildDir', () => {
})
})

describe('getMeteorSettingsAsString', () => {
it('trims line breaks and wraps in single quotes', () => {
console.log(getMeteorSettingsAsString());
expect(getMeteorSettingsAsString()).toBe(`'{ \"a\": { \"b\": 1 } }'`);
})
})