取消默认自动打开浏览器,oak-cli添加--open参数,在服务启动后自动打开

This commit is contained in:
pqcqaq 2024-12-08 00:08:59 +08:00
parent d58dadbdd1
commit 9ea3535b12
6 changed files with 11 additions and 5 deletions

View File

@ -76,6 +76,7 @@ async function build(cmd) {
`SUB_DIR_NAME=${subdir}`,
`COMPILE_ANALYZE=${!!cmd.analyze}`,
`GENERATE_SOURCEMAP=${!!cmd.sourcemap}`,
!!cmd.open && `OPEN_IN_BROWSER=true`,
`PORT=${port || 3000}`,
!!cmd.memoryLimit && `MEMORY_LIMIT=${cmd.memoryLimit}`,
`node`,

View File

@ -63,6 +63,7 @@ commander_1.default
.option('--analyze', 'analyze')
.option('--memoryLimit <memoryLimit>', 'memoryLimit of node')
.option('--stackSize <number>', 'stackSize of node')
.option('--open', 'open in browser')
.option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')

View File

@ -60,7 +60,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
oakDevDependencyStr = `"${cliName}": "~${getPackageLatestVersion(cliName)}",`;
}
const serverInitScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/initServer.js" : "cross-env OAK_PLATFORM=server node scripts/initServer.js";
const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/startServer.js" : "cross-env OAK_PLATFORM=server node scripts/startServer.js";
// const serverStartScript = isDev ? "cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node scripts/startServer.js" : "cross-env OAK_PLATFORM=server node scripts/startServer.js";
const serverStartWatchScript = isDev ? "cross-env ENABLE_TRACE=true cross-env NODE_ENV=development cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/watchServer.js" : "cross-env OAK_PLATFORM=server node --stack-size=65500 scripts/watchServer.js";
return `{
"name": "${name}",
@ -97,8 +97,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i
"run:ios": "oak-cli run -p ios",
"run:android": "oak-cli run -p android",
"server:init": "${serverInitScript}",
"server:start": "${serverStartScript}",
"server:start:watch": "${serverStartWatchScript}",
"server:start": "${serverStartWatchScript}",
"postinstall": "npm run make:dep"
},
"keywords": [],

View File

@ -38,6 +38,8 @@ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
const useYarn = fs.existsSync(paths.yarnLockFile);
const isInteractive = process.stdout.isTTY;
const open = !!process.env.OPEN_IN_BROWSER;
// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1);
@ -128,8 +130,8 @@ checkBrowsers(paths.appPath, isInteractive)
);
}
console.log(chalk.cyan('Starting the development server...\n'));
openBrowser(urls.localUrlForBrowser);
// console.log(chalk.cyan('Starting the development server...\n'));
open && openBrowser(urls.localUrlForBrowser);
});
['SIGINT', 'SIGTERM'].forEach(function (sig) {

View File

@ -22,6 +22,7 @@ export default async function build(cmd: any) {
const mode = (cmd.mode || 'development') as Mode;
const target = cmd.target as Target;
const devMode = (cmd.devMode || 'server') as DevMode;
if (!cmd.target) {
Error(
`${error(
@ -101,6 +102,7 @@ export default async function build(cmd: any) {
`SUB_DIR_NAME=${subdir}`,
`COMPILE_ANALYZE=${!!cmd.analyze}`,
`GENERATE_SOURCEMAP=${!!cmd.sourcemap}`,
!!cmd.open && `OPEN_IN_BROWSER=true`,
`PORT=${port || 3000}`,
!!cmd.memoryLimit && `MEMORY_LIMIT=${cmd.memoryLimit}`,
`node`,

View File

@ -72,6 +72,7 @@ program
.option('--analyze', 'analyze')
.option('--memoryLimit <memoryLimit>', 'memoryLimit of node')
.option('--stackSize <number>', 'stackSize of node')
.option('--open' , 'open in browser')
.option('-t, --target <target>', 'target')
.option('-m, --mode <mode>', 'mode')
.option('-d, --subDir <subDirName>', 'subDirName')