Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target single file instead of dir #137

Open
TomDeSmet opened this issue Jan 30, 2024 · 2 comments
Open

Target single file instead of dir #137

TomDeSmet opened this issue Jan 30, 2024 · 2 comments

Comments

@TomDeSmet
Copy link

It would come in handy to be able to select a single file instead of a whole directory.

@jumika
Copy link

jumika commented Feb 20, 2024

We need this very much. Too many files and i get "Maximum call stack size exceeded" error. So i have to move some files at a time to a separate directory to work :(

@Triazic
Copy link

Triazic commented Dec 16, 2024

Here is a hacky bash script to achieve this.

Save it a file like vueclassmigrate.sh and add that to your path.

Usage: navigate to the folder containing the file you wish to migrate. In that directory, call eg.
vueclassmigrate.sh MyComponent.vue

# get the value of the first arg passed in
# if no arg is passed, coerce it into "."
if [ -z "$1" ]; then
  ARG="."
else
  ARG="$1"
fi

# if ARG is ".", then run npx vue-class-migrator migrate -d .
if [ "$ARG" = "." ]; then
  npx vue-class-migrator migrate -d .
else

  # get the current pwd
  ORIGINALPWD=$(pwd)
  
  # if ARG is not ".", then we have been asked to convert a specific file. 
  # first, we copy this file to a temporary directory
  TMPDIR=$(mktemp -d)
  cp "$ARG" "$TMPDIR"

  # then we cd to the temporary directory
  cd "$TMPDIR"

  # then we run npx vue-class-migrator migrate -d .
  npx vue-class-migrator migrate -d .

  # then we print ('cat') the migrated file
  # cat "$ARG"

  # then we pipe the contents of the migrated file to the original file
  cat "$ARG" > "$ORIGINALPWD/$ARG"

  # then we delete the temporary directory
  rm -rf "$TMPDIR"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants