Skip to content

Commit 3c390c1

Browse files
committed
Improve loading experience + verbose flag
1 parent 0379577 commit 3c390c1

File tree

8 files changed

+156
-25
lines changed

8 files changed

+156
-25
lines changed

.changeset/mean-lizards-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/cli': minor
3+
---
4+
5+
Improves loading behaviour with spinners and status updates. Also exposes --verbose flag for more granular logging

packages/cli/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
"start:dev": "ts-node src/index.ts"
1616
},
1717
"dependencies": {
18-
"@codeshift/fetcher": "0.0.2",
19-
"@codeshift/initializer": "0.1.9",
18+
"@codeshift/fetcher": "^0.0.2",
19+
"@codeshift/initializer": "^0.1.9",
2020
"@codeshift/types": "*",
21-
"@codeshift/validator": "0.2.4",
21+
"@codeshift/validator": "^0.2.4",
2222
"chalk": "^4.1.0",
2323
"commander": "^8.2.0",
2424
"fs-extra": "^9.1.0",
2525
"jscodeshift": "^0.13.1",
2626
"live-plugin-manager": "^0.15.1",
2727
"lodash": "^4.17.21",
28+
"ora": "^5.4.1",
2829
"semver": "^7.3.5",
2930
"ts-node": "^9.1.1"
3031
}

packages/cli/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ program
4949
)
5050
.option(
5151
'-c, --cpus <value>',
52-
'start at most N child processes to process source files',
52+
'Start at most N child processes to process source files',
5353
)
5454
.option('-d, --dry', 'dry run (no changes are made to files)')
5555
.option('--run-in-band', 'run serially in the current process')
56+
.addOption(
57+
new Option(
58+
'--verbose <parser>',
59+
'Show more information about the transform process',
60+
)
61+
.choices(['0', '1', '2'])
62+
.default('0'),
63+
)
5664
.addHelpText(
5765
'after',
5866
`

packages/cli/src/main.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import semver from 'semver';
22
import chalk from 'chalk';
3-
// import path from 'path';
3+
import ora from 'ora';
44
import { PluginManager } from 'live-plugin-manager';
55
import merge from 'lodash/merge';
66
// @ts-ignore Run transform(s) on path https://github.com/facebook/jscodeshift/issues/398
@@ -49,21 +49,41 @@ export default async function main(paths: string[], flags: Flags) {
4949
const pkgName =
5050
shouldPrependAtSymbol + pkg.split(/[@#]/).filter(str => !!str)[0];
5151

52-
console.log(chalk.green('Attempting to download package:'), pkgName);
53-
5452
let codeshiftConfig: CodeshiftConfig | undefined;
5553
let remoteConfig: CodeshiftConfig | undefined;
5654

55+
const spinner = ora(
56+
`${chalk.green('Attempting to download package:')}, ${pkgName}`,
57+
).start();
58+
5759
try {
5860
codeshiftConfig = await fetchPackage(
5961
getCodeshiftPackageName(pkgName),
6062
packageManager,
6163
);
62-
} catch (error) {}
64+
spinner.succeed(
65+
`${chalk.green(
66+
`Found CodeshiftCommunity package: `,
67+
)} ${getCodeshiftPackageName(pkgName)}`,
68+
);
69+
} catch (error) {
70+
spinner.warn(
71+
`${chalk.yellow(
72+
`Unable to locate CodeshiftCommunity package: `,
73+
)} ${getCodeshiftPackageName(pkgName)}`,
74+
);
75+
}
6376

6477
try {
6578
remoteConfig = await fetchRemotePackage(pkgName, packageManager);
66-
} catch (error) {}
79+
spinner.succeed(
80+
`${chalk.green(`Found codeshift package: `)} ${pkgName}`,
81+
);
82+
} catch (error) {
83+
spinner.warn(
84+
`${chalk.yellow(`Unable to locate codeshift package: `)} ${pkgName}`,
85+
);
86+
}
6787

6888
if (!codeshiftConfig && !remoteConfig) {
6989
throw new Error(
@@ -72,17 +92,6 @@ Make sure the package name "${pkgName}" is correct and try again.`,
7292
);
7393
}
7494

75-
if (codeshiftConfig) {
76-
console.log(
77-
chalk.green(`Found codeshift package:`),
78-
getCodeshiftPackageName(pkgName),
79-
);
80-
}
81-
82-
if (remoteConfig) {
83-
console.log(chalk.green(`Found codeshift package:`), pkgName);
84-
}
85-
8695
const config: CodeshiftConfig = merge({}, remoteConfig, codeshiftConfig);
8796

8897
if (!isValidConfig(config)) {
@@ -175,7 +184,7 @@ Make sure the package name "${pkgName}" is correct and try again.`,
175184
console.log(chalk.green('Running transform:'), transform);
176185

177186
await jscodeshift.run(transform, paths, {
178-
verbose: 0,
187+
verbose: flags.verbose,
179188
dry: flags.dry,
180189
print: true,
181190
babel: true,

packages/cli/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ export interface Flags {
3636
cpus?: number;
3737
dry?: boolean;
3838
runInBand?: boolean;
39+
verbose?: '0' | '1' | '2';
3940
}

packages/cli/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"module": "commonjs",
65
"target": "es6",
76
"esModuleInterop": true,
87
"resolveJsonModule": true,

website/docs/api/codeshift-cli.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ Ignore files that match a provided glob expression
103103

104104
- `$ codeshift --ignore-pattern node_modules /project/src/file.js`
105105

106+
### --verbose
107+
108+
Show more information about the transform process
109+
110+
**default:**
111+
112+
- `0`
113+
114+
**example:**
115+
116+
- `$ codeshift --verbose 2 /project/src/file.js`
117+
106118
### --version, -v
107119

108120
Get current version number

yarn.lock

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ balanced-match@^1.0.0:
22462246
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
22472247
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
22482248

2249+
base64-js@^1.3.1:
2250+
version "1.5.1"
2251+
resolved "https://packages.atlassian.com/api/npm/npm-remote/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
2252+
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
2253+
22492254
base@^0.11.1:
22502255
version "0.11.2"
22512256
resolved "https://registry.npmjs.org/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
@@ -2278,6 +2283,15 @@ big.js@^5.2.2:
22782283
resolved "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
22792284
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
22802285

2286+
bl@^4.1.0:
2287+
version "4.1.0"
2288+
resolved "https://packages.atlassian.com/api/npm/npm-remote/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
2289+
integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==
2290+
dependencies:
2291+
buffer "^5.5.0"
2292+
inherits "^2.0.4"
2293+
readable-stream "^3.4.0"
2294+
22812295
boxen@^1.3.0:
22822296
version "1.3.0"
22832297
resolved "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b"
@@ -2364,6 +2378,14 @@ buffer-from@1.x, buffer-from@^1.0.0:
23642378
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
23652379
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
23662380

2381+
buffer@^5.5.0:
2382+
version "5.7.1"
2383+
resolved "https://packages.atlassian.com/api/npm/npm-remote/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
2384+
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
2385+
dependencies:
2386+
base64-js "^1.3.1"
2387+
ieee754 "^1.1.13"
2388+
23672389
builtin-modules@^3.1.0:
23682390
version "3.2.0"
23692391
resolved "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887"
@@ -2529,6 +2551,18 @@ cli-cursor@^2.1.0:
25292551
dependencies:
25302552
restore-cursor "^2.0.0"
25312553

2554+
cli-cursor@^3.1.0:
2555+
version "3.1.0"
2556+
resolved "https://packages.atlassian.com/api/npm/npm-remote/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307"
2557+
integrity sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==
2558+
dependencies:
2559+
restore-cursor "^3.1.0"
2560+
2561+
cli-spinners@^2.5.0:
2562+
version "2.6.1"
2563+
resolved "https://packages.atlassian.com/api/npm/npm-remote/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d"
2564+
integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==
2565+
25322566
cli-width@^2.0.0:
25332567
version "2.2.1"
25342568
resolved "https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48"
@@ -3907,6 +3941,11 @@ iconv-lite@0.4.24, iconv-lite@^0.4.24:
39073941
dependencies:
39083942
safer-buffer ">= 2.1.2 < 3"
39093943

3944+
ieee754@^1.1.13:
3945+
version "1.2.1"
3946+
resolved "https://packages.atlassian.com/api/npm/npm-remote/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
3947+
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
3948+
39103949
ignore-walk@^3.0.3:
39113950
version "3.0.4"
39123951
resolved "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.4.tgz#c9a09f69b7c7b479a5d74ac1a3c0d4236d2a6335"
@@ -3968,7 +4007,7 @@ inflight@^1.0.4:
39684007
once "^1.3.0"
39694008
wrappy "1"
39704009

3971-
inherits@2, inherits@^2.0.3, inherits@~2.0.3:
4010+
inherits@2, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
39724011
version "2.0.4"
39734012
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
39744013
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
@@ -4144,6 +4183,11 @@ is-html@^1.1.0:
41444183
dependencies:
41454184
html-tags "^1.0.0"
41464185

4186+
is-interactive@^1.0.0:
4187+
version "1.0.0"
4188+
resolved "https://packages.atlassian.com/api/npm/npm-remote/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e"
4189+
integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==
4190+
41474191
is-module@^1.0.0:
41484192
version "1.0.0"
41494193
resolved "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591"
@@ -4207,6 +4251,11 @@ is-typedarray@^1.0.0, is-typedarray@~1.0.0:
42074251
resolved "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
42084252
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=
42094253

4254+
is-unicode-supported@^0.1.0:
4255+
version "0.1.0"
4256+
resolved "https://packages.atlassian.com/api/npm/npm-remote/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
4257+
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==
4258+
42104259
is-windows@^1.0.0, is-windows@^1.0.2:
42114260
version "1.0.2"
42124261
resolved "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
@@ -5047,6 +5096,14 @@ lodash@4.x, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.21,
50475096
resolved "https://packages.atlassian.com/api/npm/npm-remote/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
50485097
integrity sha1-Z5WRxWTDv/quhFTPCz3zcMPWkRw=
50495098

5099+
log-symbols@^4.1.0:
5100+
version "4.1.0"
5101+
resolved "https://packages.atlassian.com/api/npm/npm-remote/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503"
5102+
integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==
5103+
dependencies:
5104+
chalk "^4.1.0"
5105+
is-unicode-supported "^0.1.0"
5106+
50505107
loud-rejection@^1.0.0:
50515108
version "1.6.0"
50525109
resolved "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
@@ -5600,6 +5657,21 @@ optionator@^0.8.1, optionator@^0.8.2:
56005657
type-check "~0.3.2"
56015658
word-wrap "~1.2.3"
56025659

5660+
ora@^5.4.1:
5661+
version "5.4.1"
5662+
resolved "https://packages.atlassian.com/api/npm/npm-remote/ora/-/ora-5.4.1.tgz#1b2678426af4ac4a509008e5e4ac9e9959db9e18"
5663+
integrity sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==
5664+
dependencies:
5665+
bl "^4.1.0"
5666+
chalk "^4.1.0"
5667+
cli-cursor "^3.1.0"
5668+
cli-spinners "^2.5.0"
5669+
is-interactive "^1.0.0"
5670+
is-unicode-supported "^0.1.0"
5671+
log-symbols "^4.1.0"
5672+
strip-ansi "^6.0.0"
5673+
wcwidth "^1.0.1"
5674+
56035675
os-homedir@^1.0.0:
56045676
version "1.0.2"
56055677
resolved "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
@@ -6024,6 +6096,15 @@ readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@^2.2.2:
60246096
string_decoder "~1.1.1"
60256097
util-deprecate "~1.0.1"
60266098

6099+
readable-stream@^3.4.0:
6100+
version "3.6.0"
6101+
resolved "https://packages.atlassian.com/api/npm/npm-remote/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
6102+
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
6103+
dependencies:
6104+
inherits "^2.0.3"
6105+
string_decoder "^1.1.1"
6106+
util-deprecate "^1.0.1"
6107+
60276108
recast@^0.20.3, recast@^0.20.4:
60286109
version "0.20.5"
60296110
resolved "https://registry.npmjs.org/recast/-/recast-0.20.5.tgz#8e2c6c96827a1b339c634dd232957d230553ceae"
@@ -6200,6 +6281,14 @@ restore-cursor@^2.0.0:
62006281
onetime "^2.0.0"
62016282
signal-exit "^3.0.2"
62026283

6284+
restore-cursor@^3.1.0:
6285+
version "3.1.0"
6286+
resolved "https://packages.atlassian.com/api/npm/npm-remote/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e"
6287+
integrity sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==
6288+
dependencies:
6289+
onetime "^5.1.0"
6290+
signal-exit "^3.0.2"
6291+
62036292
ret@~0.1.10:
62046293
version "0.1.15"
62056294
resolved "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
@@ -6267,7 +6356,7 @@ rxjs@^6.4.0:
62676356
dependencies:
62686357
tslib "^1.9.0"
62696358

6270-
safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2:
6359+
safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0:
62716360
version "5.2.1"
62726361
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
62736362
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
@@ -6690,6 +6779,13 @@ string-width@^4.1.0, string-width@^4.2.0:
66906779
is-fullwidth-code-point "^3.0.0"
66916780
strip-ansi "^6.0.0"
66926781

6782+
string_decoder@^1.1.1:
6783+
version "1.3.0"
6784+
resolved "https://packages.atlassian.com/api/npm/npm-remote/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
6785+
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
6786+
dependencies:
6787+
safe-buffer "~5.2.0"
6788+
66936789
string_decoder@~1.1.1:
66946790
version "1.1.1"
66956791
resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
@@ -7161,7 +7257,7 @@ use@^3.1.0:
71617257
resolved "https://registry.npmjs.org/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
71627258
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==
71637259

7164-
util-deprecate@~1.0.1:
7260+
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
71657261
version "1.0.2"
71667262
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
71677263
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

0 commit comments

Comments
 (0)