Skip to content

Commit eca4d16

Browse files
ygj6PeterAlfredLee
authored andcommitted
add a question, remind user to back up files
1 parent 6b21ce7 commit eca4d16

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

bin/vue-codemod.ts

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as yargs from 'yargs'
88
import * as globby from 'globby'
99

1010
import createDebug from 'debug'
11+
import { question } from 'readline-sync'
1112

1213
import builtInTransformations from '../transformations'
1314
import { excludedTransformations } from '../transformations'
@@ -59,6 +60,15 @@ const {
5960

6061
// TODO: port the `Runner` interface of jscodeshift
6162
async function main() {
63+
// Remind user to back up files
64+
const answer = question('Warning!!\n ' +
65+
'This tool may overwrite files.\n' +
66+
'Enter yes to continue:'
67+
)
68+
if (answer.trim() !== 'yes') {
69+
return
70+
}
71+
6272
const resolvedPaths = globby.sync(files as string[])
6373
if (transformationName != undefined) {
6474
const transformationModule = loadTransformationModule(transformationName)

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"globby": "^11.0.2",
3737
"jscodeshift": "^0.11.0",
3838
"lru-cache": "^6.0.0",
39+
"readline-sync": "^1.4.10",
3940
"source-map": "^0.6.1",
4041
"vue-eslint-parser": "^7.6.0",
4142
"yargs": "^16.2.0"
@@ -47,6 +48,7 @@
4748
"@types/jest": "^26.0.3",
4849
"@types/lodash": "^4.14.170",
4950
"@types/node": "^12.12.47",
51+
"@types/readline-sync": "^1.4.3",
5052
"@types/yargs": "^15.0.4",
5153
"@typescript-eslint/parser": "^4.27.0",
5254
"eslint": "^7.29.0",

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,11 @@
12731273
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.1.6.tgz#f4b1efa784e8db479cdb8b14403e2144b1e9ff03"
12741274
integrity sha512-6gOkRe7OIioWAXfnO/2lFiv+SJichKVSys1mSsgyrYHSEjk8Ctv4tSR/Odvnu+HWlH2C8j53dahU03XmQdd5fA==
12751275

1276+
"@types/readline-sync@^1.4.3":
1277+
version "1.4.3"
1278+
resolved "https://registry.yarnpkg.com/@types/readline-sync/-/readline-sync-1.4.3.tgz#eac55a39d5a349912062c9e5216cd550c07fd9c8"
1279+
integrity sha512-YP9NVli96E+qQLAF2db+VjnAUEeZcFVg4YnMgr8kpDUFwQBnj31rPLOVHmazbKQhaIkJ9cMHsZhpKdzUeL0KTg==
1280+
12761281
"@types/stack-utils@^2.0.0":
12771282
version "2.0.0"
12781283
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
@@ -4383,6 +4388,11 @@ read-pkg@^5.2.0:
43834388
parse-json "^5.0.0"
43844389
type-fest "^0.6.0"
43854390

4391+
readline-sync@^1.4.10:
4392+
version "1.4.10"
4393+
resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.10.tgz#41df7fbb4b6312d673011594145705bf56d8873b"
4394+
integrity sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==
4395+
43864396
43874397
version "0.17.2"
43884398
resolved "https://registry.yarnpkg.com/recast/-/recast-0.17.2.tgz#f18f18cf20bf3fad4522621a7f9c2ada37276814"

0 commit comments

Comments
 (0)