vue-jscodeshift-adapter
Advanced tools
Comparing version 1.1.1 to 1.2.0
# Change Log | ||
## [1.2.0] - 2018-03-18 | ||
### Added | ||
- Ability to run on directory containing js and vue files. | ||
## [1.1.1] - 2018-03-13 | ||
@@ -4,0 +9,0 @@ ### Fixed |
@@ -12,2 +12,6 @@ const compiler = require('vue-template-compiler'); | ||
return function newTransform(fileInfo, api, options) { | ||
if (!fileInfo.path.endsWith('.vue')) { | ||
return transform(fileInfo, api, options); | ||
} | ||
const sfcDescriptor = compiler.parseComponent(fileInfo.source); | ||
@@ -14,0 +18,0 @@ const $ = cheerio.load(fileInfo.source); |
{ | ||
"name": "vue-jscodeshift-adapter", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Run jscodeshift on Vue single file components", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# vue-jscodeshift-adapter | ||
[![Build Status](https://travis-ci.org/psalaets/vue-jscodeshift-adapter.svg?branch=master)](https://travis-ci.org/psalaets/vue-jscodeshift-adapter) | ||
Run [jscodeshift](https://github.com/facebook/jscodeshift) on Vue single file components | ||
@@ -15,13 +17,18 @@ | ||
### 1. Create a wrapped transform function | ||
The two main use cases for `vue-jscodeshift-adapter` are: | ||
This module wraps the `transform()` function, enabling it to run on Vue single file components (sfc). | ||
1. Run a codemod on some `.js` and/or `.vue` files | ||
2. Modify one or more parts of some `.vue` files | ||
The two main use cases are: | ||
### Use case 1: Run a codemod on some `.js` and/or `.vue` files | ||
- a. Modify one or more parts of an sfc | ||
- b. Run a codemod on just the `<script>` part of an sfc | ||
|When transforming|`fileInfo.source` will be| | ||
|-----------------|-------------------------| | ||
|`.js` file | the contents of the file| | ||
|`.vue` file | the contents of `<script>`| | ||
#### a. Modify a sfc's script, template or style | ||
The source file will be updated appropriately based on the return value of your `transform()`. | ||
#### 1a. Create wrapped transform function | ||
`my-transform.js`: | ||
@@ -31,3 +38,26 @@ | ||
const adapt = require('vue-jscodeshift-adapter'); | ||
const someCodemod = require('some-codemod'); | ||
module.exports = adapt(someCodemod); | ||
``` | ||
#### 1b. Run jscodeshift | ||
``` | ||
$ jscodeshift <path> -t my-transform.js --extensions vue,js | ||
``` | ||
See [jscodeshift readme](https://github.com/facebook/jscodeshift#usage-cli) for more info. | ||
### Use case 2: Modify one or more parts of some `.vue` files | ||
Modify a sfc's script, template or style. | ||
#### 2a. Create wrapped transform function | ||
`my-transform.js`: | ||
```js | ||
const adapt = require('vue-jscodeshift-adapter'); | ||
function myTransform(fileInfo, api, options) { | ||
@@ -48,21 +78,5 @@ const script = fileInfo.script.content; | ||
#### b. Run an existing codemod on sfc | ||
#### 2b. Run jscodeshift | ||
After wrapping, you can run [jscodeshift-compatible codemods](https://www.npmjs.com/search?q=codemod%20jscodeshift&page=1&ranking=optimal) on your sfc because | ||
1. `fileInfo.source` will be the content of the sfc's `<script>` | ||
2. If `transform()` returns a string, that string becomes the content of `<script>` | ||
`my-transform.js`: | ||
```js | ||
const adapt = require('vue-jscodeshift-adapter'); | ||
const someCodemod = require('some-codemod'); | ||
module.exports = adapt(someCodemod); | ||
``` | ||
### 2. Run jscodeshift | ||
``` | ||
$ jscodeshift <path> -t my-transform.js --extensions vue | ||
@@ -69,0 +83,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19957
635
86
23
1