stream.onError(error => { exitCode = 1 log.warn('\x07error: pipeline %s', pipelineName) log.warn(error) if (error.stack) log.warn(error.stack) })
events.forEach((event, idx) => { if (event.createTime > maxCreateTime) { if (event.createTime < createTime || createTime === null) createTime = event.createTime if (event.createTime > nextMaxCreateTime) nextMaxCreateTime = event.createTime } let offset = event.lineCount - 1 data += event.data if (data[data.length - 1] !== '\n') { data += '\n' ++offset } let sourceMap try { sourceMap = event.sourceMap } catch (e) { log.warn('\x07could not construct identity source map for %s', event.projectPath) if (e.message) log.warn(e.message) } if (sourceMap) { sourceMaps.push(sourceMap) } if (idx < events.length - 1) offsets.push(cumOffset += offset) })
export function writeEvent(basePath, event) { var { fileType } = event var projectFile = path.basename(event.path) var { projectPath } = event // the projectPath remains the same but the basePath is changed to point to // the output directory event.basePath = basePath var outputPath = event.path if (event.type === 'remove') { return unlink(outputPath).then(() => { return event.supportsSourceMap ? unlink(outputPath + '.map').then(() => event) : event }) } var { data } = event var outputDir = path.dirname(outputPath) var promise = ensureDir(path.dirname(outputPath)).then(() => { return writeFile(outputPath, data) }) if (event.supportsSourceMap) { var sourceMap try { sourceMap = event.sourceMap } catch (e) { log.warn('\x07could not construct identity source map for %s', projectPath) if (e.message) log.warn(e.message) } if (sourceMap) { var mapPath = projectFile + '.map' var suffix if (fileType === 'js') suffix = '//# sourceMappingURL=' + mapPath else if (fileType === 'css') suffix = '/*# sourceMappingURL=' + mapPath + ' */' if (suffix) data += '\n' + suffix promise = promise.then(() => { sourceMap.sources = sourceMap.sources.map(source => path.relative(outputDir, source)) return writeFile(path.join(outputDir, mapPath), JSON.stringify(sourceMap)) }) } } return promise.then(() => event) }
export function invoke(opts = {}) { try { var exitCode = 0 var streams var compiler = new PipelineCompiler(opts) var startTime = Date.now() var relTime = (time = startTime) => ((Date.now() - time) / 1000).toFixed(3) return compileSighfile(compiler, opts) .then(_streams => { streams = _streams if (opts.verbose) log('waiting for subprocesses to start') return compiler.procPool.ready() }) .then(() => { if (opts.verbose) log('subprocesses started in %s seconds', relTime()) var pipeStartTime = Date.now() _.forEach(streams, (stream, pipelineName) => { stream.onValue(events => { var now = new Date var createTime = _.min(events, 'createTime').createTime var timeDuration = relTime(createTime ? createTime.getTime() : pipeStartTime) if (opts.verbose > 1) { log( 'pipeline %s complete: %s seconds %j', pipelineName, timeDuration, _.map(events, event => _.pick(event, 'type', 'path')) ) } else { log('pipeline %s complete: %s seconds', pipelineName, timeDuration) } }) stream.onError(error => { exitCode = 1 log.warn('\x07error: pipeline %s', pipelineName) log.warn(error) }) }) Bacon.mergeAll(_.values(streams)).onEnd(() => { if (opts.verbose) log('pipeline(s) complete: %s seconds', relTime()) compiler.destroy() process.exit(exitCode) }) }) } catch (e) { if (typeof e === 'function' && e instanceof Error) { log.warn(e.message) process.exit(1) } else { throw e } } }
events.forEach(event => { const { path, projectPath } = event const suffix = path !== projectPath ? ` [${event.projectPath}]` : '' log.nested(`${event.type} ${event.path}${suffix}`) })
export function invoke(opts = {}) { try { let exitCode = 0 let streams const compiler = new PipelineCompiler(opts) const startTime = Date.now() const relTime = (time = startTime) => ((Date.now() - time) / 1000).toFixed(3) return compileSighfile(compiler, opts) .then(_streams => { streams = _streams if (opts.verbose) log('waiting for subprocesses to start') return compiler.procPool.ready() }) .then(() => { if (opts.verbose) log('subprocesses started in %s seconds', relTime()) const pipeStartTime = Date.now() _.forEach(streams, (stream, pipelineName) => { stream.onValue(events => { const now = new Date const createTime = _.min(events, 'createTime').createTime const timeDuration = relTime(createTime ? createTime.getTime() : pipeStartTime) log('pipeline %s complete: %s seconds', pipelineName, timeDuration) if (opts.verbose > 1) { events.forEach(event => { const { path, projectPath } = event const suffix = path !== projectPath ? ` [${event.projectPath}]` : '' log.nested(`${event.type} ${event.path}${suffix}`) }) } }) stream.onError(error => { exitCode = 1 log.warn('\x07error: pipeline %s', pipelineName) log.warn(error) if (error.stack) log.warn(error.stack) }) }) Bacon.mergeAll(_.values(streams)).onEnd(() => { if (opts.verbose) log('pipeline(s) complete: %s seconds', relTime()) compiler.destroy() process.exit(exitCode) }) }) } catch (e) { if (typeof e === 'function' && e instanceof Error) { log.warn(e) if (e.stack) log.warn(e.stack) process.exit(1) } else { throw e } } }