This file contains hidden or 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
    
  
  
    
  | const assert = require('assert'); | |
| const _ = require('lodash'); | |
| function throwsAsync(block, expectedError, message) { | |
| return block() | |
| .then(res => { | |
| assert.fail(res, expectedError, message, 'is'); | |
| }, err => { | |
| if (_.isFunction(expectedError)) { | |
| // note that assert.throws doesn't work with custom Error constructors | 
  
    
      This file contains hidden or 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
    
  
  
    
  | const fs = require('fs'); | |
| const assert = require('assert'); | |
| const _ = require('lodash'); | |
| function fileExists(filePath, msg) { | |
| try { | |
| fs.statSync(filePath); | |
| } | |
| catch (err) { | |
| if (_.includes(['ENOENT', 'ENOTDIR'], err.code)) { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | function intent({DOM}) { | |
| return { | |
| addTodo: DOM.get('input', 'change'). | |
| map(evt => evt.target.value). | |
| filter(val => val.trim().length), | |
| removeTodo: DOM.get('button', 'click'). | |
| // Map the remove button click to the item text | |
| map(evt => evt.target.previousElementSibling.innerText.trim()) | |
| }; | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | function Deferred() { | |
| var deferred = { | |
| resolve: null, | |
| reject: null | |
| }; | |
| deferred.promise = new Promise((resolve, reject) => { | |
| // Save resolve/reject to deferred, for later usage. | |
| deferred.resolve = resolve; | |
| deferred.reject = reject; | |
| }); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /** | |
| * eg. | |
| * | |
| * poll( | |
| * () => Promise.resolve(Math.random()), | |
| * val => val > 0.5 | |
| * ) | |
| * .then(val => console.log(`You won, with ${val}!`)); | |
| * | |
| * @param {():Promise<T>} run | 
  
    
      This file contains hidden or 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
    
  
  
    
  | function mockReadFile(mockPath, content) { | |
| // see https://gist.github.com/eschwartz/955a3f8925e24270550cb635dd49c12b | |
| const deferred = Deferred(); | |
| sinon.stub(fs, 'readFile', _.wrap(fs.readFile, (origFn, path, encoding, cb) => { | |
| if (path !== mockPath) { | |
| return origFn.readFile(path, encoding, cb); | |
| } | |
| // Only resolve `fs.readFile` when deferred is resolved | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import * as fs from 'fs'; | |
| import * as assert from 'assert'; | |
| import * as _ from 'lodash'; | |
| function assertFileExists(filePath:string, msg?:string) { | |
| try { | |
| fs.statSync(filePath); | |
| } | |
| catch (err) { | |
| if (_.includes(['ENOENT', 'ENOTDIR'], err.code)) { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | # Add these lines to your dockerfile, before `npm install` | |
| # Copy the bitbucket private key to your docker image | |
| COPY ./bitbucket_ssh_key /opt/my-app | |
| # Copy the ssh script to your docker image | |
| COPY ./ssh-bitbucket.sh /opt/my-app | |
| # Tell git to use your `ssh-bitbucket.sh` script | |
| ENV GIT_SSH="/opt/map-project-tile-server/ssh-bitbucket.sh" | 
  
    
      This file contains hidden or 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
    
  
  
    
  | const childProcess = require('child_process'); | |
| // otherwise we get a stupid warning. | |
| process.stdout.setMaxListeners(100); | |
| process.stderr.setMaxListeners(100); | |
| /** | |
| * Promisified child_process.exec | |
| * | |
| * @param cmd | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /** | |
| * Run a series of async functions in sequence, | |
| * so that each fn waits to run until the last one has completed. | |
| * | |
| * @param {function():Promise<T>} fns | |
| * @returns {Promise<T[]> | |
| */ | |
| function sequence(fns) { | |
| return fns | |
| .reduce((_prevResults, fn) => ( |