Skip to content

Commit

Permalink
fix(prepublish): Less magic when parsing entries
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Nov 8, 2016
1 parent b9c94e6 commit 71eb6e8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/bin/mastarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('mastarm cli', () => {
})
})

describe.skip('prepublish', function () {
describe('prepublish', function () {
const buildDir = util.buildDir
const mockDir = util.mockDir

Expand Down
5 changes: 3 additions & 2 deletions __tests__/lib/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ describe('prepublish', () => {

it('should transpile entries to a specific outdir', () => {
const results = prepublish({
entries: util.parseEntries([`${mockDir}/index.js`], buildDir),
env: 'development'
entries: util.parseEntries([`${mockDir}/index.js`]),
env: 'development',
outdir: buildDir
})

expect(results.length === 1).toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion bin/mastarm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ commander
const pushToS3 = require('../lib/push-to-s3')
const config = loadConfig(process.cwd(), commander.config, commander.env)
const get = util.makeGetFn([options, commander, config.settings])
const files = util.parseEntries([...entries, ...(get('entries') || [])], get('outdir'))
const files = util.parseEntries([...entries, ...(get('entries') || [])])
util.assertEntriesExist(files)
Promise.all(files.map(pushToS3({
cloudfront: get('cloudfront'),
Expand Down
8 changes: 5 additions & 3 deletions lib/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function ({
return entries.reduce((results, entry) =>
fs.statSync(entry[0]).isDirectory()
? [...results, ...transformDir({config: babelConfig(env), entry, outdir})]
: [...results, transformFile({config: babelConfig(env), entry})], [])
: [...results, transformFile({config: babelConfig(env), entry, outdir})], [])
}

function transformDir ({
Expand All @@ -33,9 +33,11 @@ function transformDir ({

function transformFile ({
config,
entry
entry,
outdir
}) {
const [filename, filepath] = entry
const filename = entry[0]
const filepath = entry[1] || `${outdir}/${filename}`
const results = babel.transform(fs.readFileSync(filename, 'utf8'), Object.assign({}, config, {filename, sourceMaps: true}))
mkdirp.sync(path.dirname(filepath))
fs.writeFileSync(filepath, results.code + '\n\n//# sourceMappingURL=' + path.basename(filepath))
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.makeGetFn = (targets) => {
*
* @return {Array[String, String]} entries
*/
exports.parseEntries = function (entries) {
exports.parseEntries = function (entries, outdir) {
return unique(entries)
.map((entry) => entry.split(':'))
}
Expand Down

0 comments on commit 71eb6e8

Please sign in to comment.