Skip to content

Commit a72884f

Browse files
committed
make command output prettier :)
1 parent 843af80 commit a72884f

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed
Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from "chalk";
12
import { dedent } from "ts-dedent";
23
import { configFileName } from "../../config";
34
import { logger } from "../../logger";
@@ -17,44 +18,48 @@ export function logRuntimeTypesMessage(
1718
const isNodeTypesInstalled = tsconfigTypes.find((type) => type === "node");
1819
const updatedTypesString = buildUpdatedTypesString(tsconfigTypes, outFile);
1920

20-
logger.info(`✨ Runtime types written to ${outFile}`);
21-
21+
if (isWorkersTypesInstalled) {
22+
logAction(
23+
"Migrate from @cloudflare/workers-types to generated runtime types"
24+
);
25+
logger.log(
26+
chalk.dim(
27+
"`wrangler types` now generates runtime types and supersedes @cloudflare/workers-types."
28+
)
29+
);
30+
logger.log(
31+
chalk.dim(
32+
"You should now uninstall @cloudflare/workers-types and remove it from your tsconfig.json."
33+
)
34+
);
35+
logger.log("");
36+
}
2237
if (updatedTypesString) {
23-
logger.info(dedent`
24-
📣 Add the generated types to the types array in your tsconfig.json:
25-
26-
{
27-
"compilerOptions": {
28-
...
29-
"types": ${updatedTypesString}
30-
...
31-
}
32-
}
33-
34-
`);
35-
} else if (isWorkersTypesInstalled) {
36-
logger.info(dedent`
37-
📣 Replace the existing "@cloudflare/workers-types" entry with the generated types path:
38+
logAction(`Update your tsconfig.json to include the generated types`);
39+
logger.log(
40+
chalk.dim(dedent`
3841
{
3942
"compilerOptions": {
40-
...
4143
"types": ${updatedTypesString}
42-
...
4344
}
4445
}
45-
46-
`);
47-
}
48-
if (isWorkersTypesInstalled) {
49-
logger.info('📣 You can now uninstall "@cloudflare/workers-types".');
46+
`)
47+
);
48+
logger.log("");
5049
}
5150
if (isNodeCompat && !isNodeTypesInstalled) {
52-
logger.info(
53-
'📣 Since you have Node.js compatibility mode enabled, you should consider adding Node.js for TypeScript by running "npm i --save-dev @types/[email protected]". Please see the docs for more details: https://developers.cloudflare.com/workers/languages/typescript/#transitive-loading-of-typesnode-overrides-cloudflareworkers-types'
51+
logAction("Install types@node");
52+
logger.log(
53+
chalk.dim(
54+
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev @types/node${isWorkersTypesInstalled ? '@20.8.3". For more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '".'}`
55+
)
5456
);
57+
logger.log("");
5558
}
56-
logger.info(
57-
`📣 Remember to run 'wrangler types --x-include-runtime' again if you change 'compatibility_date' or 'compatibility_flags' in your ${configFileName(configPath)} file.\n`
59+
logger.log(
60+
`📖 Read about runtime types\n` +
61+
`${chalk.dim("https://developers.cloudflare.com/workers/languages/typescript/#generate-runtime-types")}\n\n` +
62+
`📣 Remember to rerun 'wrangler types' after you change your ${configFileName(configPath)} file.\n`
5863
);
5964
}
6065

@@ -76,3 +81,7 @@ function buildUpdatedTypesString(
7681

7782
return JSON.stringify(updatedTypesArray);
7883
}
84+
85+
const logAction = (msg: string) => {
86+
logger.log(chalk.hex("#BD5B08").bold("Action required"), msg);
87+
};

0 commit comments

Comments
 (0)