mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-07 20:39:14 -05:00
feat: add transformScript to GeneratorAPI (#4188)
(cherry picked from commit 5460ca498f)
This commit is contained in:
@@ -6,6 +6,7 @@ const resolve = require('resolve')
|
||||
const { isBinaryFileSync } = require('isbinaryfile')
|
||||
const semver = require('semver')
|
||||
const mergeDeps = require('./util/mergeDeps')
|
||||
const runCodemod = require('./util/runCodemod')
|
||||
const stringifyJS = require('./util/stringifyJS')
|
||||
const ConfigTransform = require('./ConfigTransform')
|
||||
const { getPluginLink, toShortPluginId, loadModule } = require('@vue/cli-shared-utils')
|
||||
@@ -300,6 +301,22 @@ class GeneratorAPI {
|
||||
return fn
|
||||
}
|
||||
|
||||
/**
|
||||
* Run codemod on a script file or the script part of a .vue file
|
||||
* @param {string} file the path to the file to transform
|
||||
* @param {Codemod} codemod the codemod module to run
|
||||
* @param {object} options additional options for the codemod
|
||||
*/
|
||||
transformScript (file, codemod, options) {
|
||||
this._injectFileMiddleware(files => {
|
||||
files[file] = runCodemod(
|
||||
codemod,
|
||||
{ path: this.resolve(file), source: files[file] },
|
||||
options
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Add import statements to a file.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user