Skip to content

Commit 2782704

Browse files
[autofix.ci] apply automated fixes
1 parent 59dd481 commit 2782704

File tree

1 file changed

+77
-76
lines changed

1 file changed

+77
-76
lines changed
Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { existsSync, promises as fsp } from "node:fs";
2-
import { dirname } from "node:path";
3-
import process from "node:process";
4-
5-
import { box, outro } from "@clack/prompts";
6-
import { setupDotenv } from "c12";
7-
import { defineCommand } from "citty";
8-
import { colors } from "consola/utils";
9-
import { join, resolve } from "pathe";
10-
import { x } from "tinyexec";
11-
12-
import { loadKit } from "../utils/kit";
13-
import { logger } from "../utils/logger";
14-
import { relativeToProcess } from "../utils/paths";
1+
import { existsSync, promises as fsp } from 'node:fs'
2+
import { dirname } from 'node:path'
3+
import process from 'node:process'
4+
5+
import { box, outro } from '@clack/prompts'
6+
import { setupDotenv } from 'c12'
7+
import { defineCommand } from 'citty'
8+
import { colors } from 'consola/utils'
9+
import { join, resolve } from 'pathe'
10+
import { x } from 'tinyexec'
11+
12+
import { loadKit } from '../utils/kit'
13+
import { logger } from '../utils/logger'
14+
import { relativeToProcess } from '../utils/paths'
1515
import {
1616
cwdArgs,
1717
dotEnvArgs,
1818
envNameArgs,
1919
extendsArgs,
2020
legacyRootDirArgs,
2121
logLevelArgs,
22-
} from "./_shared";
22+
} from './_shared'
2323

2424
const command = defineCommand({
2525
meta: {
26-
name: "preview",
27-
description: "Launches Nitro server for local testing after `nuxi build`.",
26+
name: 'preview',
27+
description: 'Launches Nitro server for local testing after `nuxi build`.',
2828
},
2929
args: {
3030
...cwdArgs,
@@ -33,18 +33,18 @@ const command = defineCommand({
3333
...extendsArgs,
3434
...legacyRootDirArgs,
3535
port: {
36-
type: "string",
37-
description: "Port to listen on",
38-
alias: ["p"],
36+
type: 'string',
37+
description: 'Port to listen on',
38+
alias: ['p'],
3939
},
4040
...dotEnvArgs,
4141
},
4242
async run(ctx) {
43-
process.env.NODE_ENV = process.env.NODE_ENV || "production";
43+
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
4444

45-
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
45+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir)
4646

47-
const { loadNuxt } = await loadKit(cwd);
47+
const { loadNuxt } = await loadKit(cwd)
4848

4949
const resolvedOutputDir = await new Promise<string>((res) => {
5050
loadNuxt({
@@ -59,114 +59,115 @@ const command = defineCommand({
5959
...(ctx.args.extends && { extends: ctx.args.extends }),
6060
modules: [
6161
function (_, nuxt) {
62-
nuxt.hook("nitro:init", (nitro) => {
62+
nuxt.hook('nitro:init', (nitro) => {
6363
res(
6464
resolve(
6565
nuxt.options.srcDir || cwd,
66-
nitro.options.output.dir || ".output",
67-
"nitro.json",
66+
nitro.options.output.dir || '.output',
67+
'nitro.json',
6868
),
69-
);
70-
});
69+
)
70+
})
7171
},
7272
],
7373
},
7474
})
75-
.then((nuxt) => nuxt.close())
76-
.catch(() => "");
77-
});
75+
.then(nuxt => nuxt.close())
76+
.catch(() => '')
77+
})
7878

79-
const defaultOutput = resolve(cwd, ".output", "nitro.json"); // for backwards compatibility
79+
const defaultOutput = resolve(cwd, '.output', 'nitro.json') // for backwards compatibility
8080

81-
const nitroJSONPaths = [resolvedOutputDir, defaultOutput].filter(Boolean);
82-
const nitroJSONPath = nitroJSONPaths.find((p) => existsSync(p));
81+
const nitroJSONPaths = [resolvedOutputDir, defaultOutput].filter(Boolean)
82+
const nitroJSONPath = nitroJSONPaths.find(p => existsSync(p))
8383
if (!nitroJSONPath) {
8484
logger.error(
85-
`Cannot find ${colors.cyan("nitro.json")}. Did you run ${colors.cyan("nuxi build")} first? Search path:\n${nitroJSONPaths.join("\n")}`,
86-
);
87-
process.exit(1);
85+
`Cannot find ${colors.cyan('nitro.json')}. Did you run ${colors.cyan('nuxi build')} first? Search path:\n${nitroJSONPaths.join('\n')}`,
86+
)
87+
process.exit(1)
8888
}
89-
const outputPath = dirname(nitroJSONPath);
90-
const nitroJSON = JSON.parse(await fsp.readFile(nitroJSONPath, "utf-8"));
89+
const outputPath = dirname(nitroJSONPath)
90+
const nitroJSON = JSON.parse(await fsp.readFile(nitroJSONPath, 'utf-8'))
9191

9292
if (!nitroJSON.commands.preview) {
93-
logger.error("Preview is not supported for this build.");
94-
process.exit(1);
93+
logger.error('Preview is not supported for this build.')
94+
process.exit(1)
9595
}
9696

9797
const info = [
98-
["Node.js:", `v${process.versions.node}`],
99-
["Nitro preset:", nitroJSON.preset],
100-
["Working directory:", relativeToProcess(cwd)],
101-
] as const;
102-
const _infoKeyLen = Math.max(...info.map(([label]) => label.length));
98+
['Node.js:', `v${process.versions.node}`],
99+
['Nitro preset:', nitroJSON.preset],
100+
['Working directory:', relativeToProcess(cwd)],
101+
] as const
102+
const _infoKeyLen = Math.max(...info.map(([label]) => label.length))
103103

104-
logger.message("");
104+
logger.message('')
105105
box(
106106
[
107-
"",
108-
"You are previewing a Nuxt app. In production, do not use this CLI. ",
107+
'',
108+
'You are previewing a Nuxt app. In production, do not use this CLI. ',
109109
`Instead, run ${colors.cyan(nitroJSON.commands.preview)} directly.`,
110-
"",
110+
'',
111111
...info.map(
112112
([label, value]) =>
113-
`${label.padEnd(_infoKeyLen, " ")} ${colors.cyan(value)}`,
113+
`${label.padEnd(_infoKeyLen, ' ')} ${colors.cyan(value)}`,
114114
),
115-
"",
116-
].join("\n"),
117-
colors.yellow(" Previewing Nuxt app "),
115+
'',
116+
].join('\n'),
117+
colors.yellow(' Previewing Nuxt app '),
118118
{
119-
contentAlign: "left",
120-
titleAlign: "left",
121-
width: "auto",
119+
contentAlign: 'left',
120+
titleAlign: 'left',
121+
width: 'auto',
122122
titlePadding: 2,
123123
contentPadding: 2,
124124
rounded: true,
125125
withGuide: true,
126126
formatBorder: (text: string) => colors.yellow(text),
127127
},
128-
);
128+
)
129129

130-
const envFileName = ctx.args.dotenv || ".env";
130+
const envFileName = ctx.args.dotenv || '.env'
131131

132-
const envExists = existsSync(resolve(cwd, envFileName));
132+
const envExists = existsSync(resolve(cwd, envFileName))
133133

134134
if (envExists) {
135135
logger.info(
136136
`Loading ${colors.cyan(envFileName)}. This will not be loaded when running the server in production.`,
137-
);
138-
await setupDotenv({ cwd, fileName: envFileName });
139-
} else if (ctx.args.dotenv) {
140-
logger.error(`Cannot find ${colors.cyan(envFileName)}.`);
137+
)
138+
await setupDotenv({ cwd, fileName: envFileName })
139+
}
140+
else if (ctx.args.dotenv) {
141+
logger.error(`Cannot find ${colors.cyan(envFileName)}.`)
141142
}
142143

143-
const port =
144-
ctx.args.port ??
145-
process.env.NUXT_PORT ??
146-
process.env.NITRO_PORT ??
147-
process.env.PORT;
144+
const port
145+
= ctx.args.port
146+
?? process.env.NUXT_PORT
147+
?? process.env.NITRO_PORT
148+
?? process.env.PORT
148149

149150
outro(
150151
`Running ${colors.cyan(nitroJSON.commands.preview)} in ${colors.cyan(relativeToProcess(cwd))}`,
151-
);
152+
)
152153

153-
const [cmd, ...cmdArgs] = nitroJSON.commands.preview.split(" ");
154+
const [cmd, ...cmdArgs] = nitroJSON.commands.preview.split(' ')
154155
const resolvedCmdArgs = cmdArgs.map((arg: string) =>
155156
existsSync(join(outputPath, arg)) ? join(outputPath, arg) : arg,
156-
);
157+
)
157158
await x(cmd, resolvedCmdArgs, {
158159
throwOnError: true,
159160
nodeOptions: {
160-
stdio: "inherit",
161+
stdio: 'inherit',
161162
cwd,
162163
env: {
163164
...process.env,
164165
NUXT_PORT: port,
165166
NITRO_PORT: port,
166167
},
167168
},
168-
});
169+
})
169170
},
170-
});
171+
})
171172

172-
export default command;
173+
export default command

0 commit comments

Comments
 (0)