Skip to content

Commit

Permalink
[chore] Fix javascript not being rebuilt after first change
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Jun 27, 2019
1 parent adba541 commit d42f36e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gulpfile.js
Expand Up @@ -75,8 +75,8 @@ if (path.win32 === path) {
libFragment = '$1/lib/'
}

const logCompile = (file, enc, cb) => {
gutil.log('Compiling', `'${chalk.cyan(file._path || file.path)}'...`)
const logCompile = from => (file, enc, cb) => {
gutil.log(`[${from}] Compiling`, `'${chalk.cyan(file._path || file.path)}'...`)
cb(null, file)
}

Expand All @@ -91,6 +91,9 @@ const pkgPath = (cwd, sourcePath) => path.relative(path.join(cwd, 'packages'), s
const getLogErrorHandler = () => plumber({errorHandler: err => gutil.log(err.stack)})
const getNoopErrorHandler = () => through.obj((chunk, enc, cb) => cb(null, chunk))
const buildTypeScript = getTypeScriptBuilder(getNoopErrorHandler)
const watchJavaScript = series(buildJavaScript, function watchJavascriptRebuild() {
watch(scripts, watchJavaScriptRebuild)
})
const watchTypeScript = series(
getTypeScriptBuilder(getLogErrorHandler),
function watchTypescriptRebuild() {
Expand All @@ -115,7 +118,7 @@ function buildJavaScript() {
hasChanged: compareModified
})
)
.pipe(through.obj(logCompile))
.pipe(through.obj(logCompile('JS')))
.pipe(babel())
.pipe(assetFilter.restore)
.pipe(
Expand All @@ -128,7 +131,7 @@ function buildJavaScript() {
.pipe(dest(packagesPath))
}

function watchJavaScript() {
function watchJavaScriptRebuild() {
return src(scripts, srcOpts)
.pipe(plumber({errorHandler: err => gutil.log(err.stack)}))
.pipe(
Expand All @@ -139,7 +142,7 @@ function watchJavaScript() {
})
)
.pipe(newer(packagesPath))
.pipe(through.obj(logCompile))
.pipe(through.obj(logCompile('JS')))
.pipe(babel())
.pipe(dest(packagesPath))
}
Expand Down Expand Up @@ -174,7 +177,7 @@ function getTypeScriptBuilder(getErrorHandler) {
})
)
.pipe(getErrorHandler())
.pipe(through.obj(logCompile))
.pipe(through.obj(logCompile('TS')))
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: './'}))
.pipe(dest(project.options.outDir))
)
Expand Down

0 comments on commit d42f36e

Please sign in to comment.