-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from conveyal/simplify-deploy
Simplify deploy
- Loading branch information
Showing
11 changed files
with
160 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
/* global describe, it */ | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const BUILD_DIR = path.join(process.cwd(), '__tests__/test-utils/tmp') | ||
const MOCK_DIR = path.join(process.cwd(), '__tests__/test-utils/mocks') | ||
const files = [ | ||
[`${MOCK_DIR}/index.js`, `${BUILD_DIR}/index.js`], | ||
[`${MOCK_DIR}/index.css`, `${BUILD_DIR}/index.css`] | ||
] | ||
|
||
describe('lib > push to s3', () => { | ||
const configPush = require('../../lib/push-to-s3') | ||
const build = require('../../lib/build') | ||
const createPushToS3 = require('../../lib/push-to-s3') | ||
const loadConfig = require('../../lib/load-config') | ||
const createLogger = require('../../lib/logger') | ||
|
||
it('should compile JavaScript and CSS and send to s3 via aws-sdk', () => { | ||
const config = loadConfig(process.cwd(), 'configurations/default', 'development') | ||
const push = configPush({ | ||
const push = createPushToS3({ | ||
env: 'development', | ||
config, | ||
log: createLogger(), | ||
minify: false, | ||
s3bucket: 'test-bucket' | ||
}) | ||
return Promise.all([ | ||
push([`${MOCK_DIR}/index.js`, `${BUILD_DIR}/index.js`]), | ||
push([`${MOCK_DIR}/index.css`, `${BUILD_DIR}/index.css`]) | ||
]) | ||
return build({ | ||
config, | ||
env: 'development', | ||
files | ||
}).then(() => | ||
Promise.all(files.map((f) => | ||
push({body: fs.readFileSync(f[0]), outfile: f[0]})))) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
const fetch = require('isomorphic-fetch') | ||
const nodeEmoji = require('node-emoji') | ||
const slack = require('./notify-slack') | ||
|
||
module.exports = function ({channel, webhook} = {}) { | ||
if (webhook) { | ||
return function (text) { | ||
emojifyLog(text) | ||
return slack({channel, text, webhook}) | ||
} | ||
const logToConsole = (text) => | ||
Promise.resolve(console.log(emojify(text))) | ||
const logToErrorConsole = (text) => | ||
Promise.resolve(console.error(emojify(text))) | ||
|
||
module.exports.log = logToConsole | ||
module.exports.error = logToErrorConsole | ||
|
||
module.exports.logToSlack = ({channel, webhook}) => { | ||
module.exports.log = (text) => { | ||
logToConsole(text) | ||
return notifySlack({channel, text, webhook}) | ||
} | ||
return function (text) { | ||
return Promise.resolve(emojifyLog(text)) | ||
|
||
module.exports.error = (text) => { | ||
logToErrorConsole(text) | ||
return notifySlack({channel, text, webhook}) | ||
} | ||
} | ||
|
||
function emojifyLog (text) { | ||
function emojify (text) { | ||
const strippedLinks = text.replace(/<[^|>]+\|([^>]+)>/g, '$1') | ||
console.log(nodeEmoji.emojify(strippedLinks)) | ||
return nodeEmoji.emojify(strippedLinks) | ||
} | ||
|
||
function notifySlack ({ | ||
channel, | ||
text, | ||
webhook | ||
}) { | ||
return fetch(webhook, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
channel, | ||
text | ||
}) | ||
}) | ||
.then((response) => response.text()) | ||
.catch((err) => { | ||
logToErrorConsole('Error posting to Slack webhook') | ||
logToErrorConsole(err) | ||
return err | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.