-
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 #164 from conveyal/dev
v3.7.2
- Loading branch information
Showing
13 changed files
with
213 additions
and
202 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,25 +1,34 @@ | ||
/* global describe, it */ | ||
|
||
const BUILD_DIR = '__tests__/test-utils/tmp' | ||
const MOCK_DIR = '__tests__/test-utils/mocks' | ||
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs') | ||
const exorcist = require('exorcist') | ||
const mkdirp = require('mkdirp') | ||
const path = require('path') | ||
|
||
const browserify = require('./browserify') | ||
const logger = require('./logger') | ||
|
||
/** | ||
* | ||
* @return Promise | ||
*/ | ||
|
||
module.exports = function buildJs ({config, entry, env, minify, outfile, watch}) { | ||
const pipeline = minify | ||
? browserify.minify({config, entry, env}) | ||
: browserify({config, entry, env}) | ||
const bundle = () => new Promise((resolve, reject) => { | ||
if (outfile) { | ||
mkdirp.sync(path.dirname(outfile)) | ||
pipeline.bundle() | ||
.pipe(exorcist(`${outfile}.map`)) | ||
.pipe(fs.createWriteStream(outfile)) | ||
.on('error', reject) | ||
.on('finish', resolve) | ||
} else { | ||
pipeline.bundle((err, buf) => { | ||
if (err) reject(err) | ||
else resolve(buf) | ||
}) | ||
} | ||
}) | ||
|
||
if (watch) { | ||
pipeline.plugin(require('watchify'), {poll: true}) | ||
pipeline.plugin(require('errorify')) | ||
pipeline.on('update', bundle) | ||
pipeline.on('log', logger.log) | ||
} | ||
|
||
return bundle() | ||
} |
Oops, something went wrong.