-
-
Save JaminFarr/18f498fff09b6612757f9dc4b6169347 to your computer and use it in GitHub Desktop.
Convert Gulp 3 to Gulp 4 with a codemod
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
// Use https://astexplorer.net/ | |
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
const root = j(file.source); | |
const gulpTaskCalls = root.find(j.CallExpression, { | |
callee: { | |
object: { | |
name: 'gulp' | |
}, | |
property: { | |
name: 'task' | |
} | |
} | |
}); | |
gulpTaskCalls.forEach(p => { | |
if(p.node.arguments[1].type === 'ArrayExpression') { | |
const dependentTasks = p.node.arguments[1].elements; | |
const isThirdArgFunction = p.node.arguments[2].type === "FunctionExpression" || p.node.arguments[2].type === "ArrowFunctionExpression" | |
if (isThirdArgFunction) { | |
dependentTasks.push(p.node.arguments[2]) | |
delete p.node.arguments[2]; | |
} | |
p.node.arguments[1] = j.callExpression( | |
j.identifier('gulp.series'), | |
dependentTasks | |
); | |
} | |
}); | |
return root.toSource({quote: 'single'}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment