@farmfe/cli
Advanced tools
Comparing version 0.6.0 to 0.6.1
import { readFileSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
import { cac } from 'cac'; | ||
import { DefaultLogger } from '@farmfe/core'; | ||
import { resolveCore, getConfigPath, resolveCommandOptions } from './utils.js'; | ||
import { DefaultLogger, preventExperimentalWarning } from '@farmfe/core'; | ||
import { resolveCore, getConfigPath, resolveCommandOptions, handleAsyncOperationErrors } from './utils.js'; | ||
import { COMMANDS } from './plugin/index.js'; | ||
import path from 'node:path'; | ||
const logger = new DefaultLogger(); | ||
@@ -15,3 +15,5 @@ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)).toString()); | ||
.option('--base <path>', 'public base path') | ||
.option('--clearScreen', 'allow/disable clear screen when logging'); | ||
.option('--clearScreen', 'allow/disable clear screen when logging', { | ||
default: true | ||
}); | ||
// dev command | ||
@@ -40,3 +42,3 @@ cli | ||
server: resolveOptions, | ||
clearScreen: options.clearScreen ?? true, | ||
clearScreen: options.clearScreen, | ||
configPath, | ||
@@ -46,9 +48,3 @@ mode: options.mode | ||
const { start } = await resolveCore(); | ||
try { | ||
await start(defaultOptions); | ||
} | ||
catch (e) { | ||
logger.error(`Failed to start server:\n ${e.stack}`); | ||
process.exit(1); | ||
} | ||
handleAsyncOperationErrors(start(defaultOptions), 'Failed to start server'); | ||
}); | ||
@@ -86,9 +82,3 @@ // build command | ||
const { build } = await resolveCore(); | ||
try { | ||
build(defaultOptions); | ||
} | ||
catch (e) { | ||
logger.error(`error during build:\n${e.stack}`); | ||
process.exit(1); | ||
} | ||
handleAsyncOperationErrors(build(defaultOptions), 'error during build'); | ||
}); | ||
@@ -115,9 +105,3 @@ cli | ||
const { watch } = await resolveCore(); | ||
try { | ||
watch(defaultOptions); | ||
} | ||
catch (e) { | ||
logger.error(`error during watch project:\n${e.stack}`); | ||
process.exit(1); | ||
} | ||
handleAsyncOperationErrors(watch(defaultOptions), 'error during watch project'); | ||
}); | ||
@@ -137,9 +121,3 @@ cli | ||
const { preview } = await resolveCore(); | ||
try { | ||
preview(defaultOptions); | ||
} | ||
catch (e) { | ||
logger.error(`Failed to start preview server:\n${e.stack}`); | ||
process.exit(1); | ||
} | ||
handleAsyncOperationErrors(preview(defaultOptions), 'Failed to start preview server'); | ||
}); | ||
@@ -181,2 +159,4 @@ cli | ||
}); | ||
// use mdn browser compatibility data with experimental warning in terminal so prevent experimental warning | ||
preventExperimentalWarning(); | ||
cli.help(); | ||
@@ -183,0 +163,0 @@ cli.version(version); |
@@ -65,3 +65,3 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; | ||
export function formatTargetDir(targetDir) { | ||
return targetDir?.trim().replace(/\/+$/g, ''); | ||
return targetDir?.trim()?.replace(/\/+$/g, ''); | ||
} | ||
@@ -110,2 +110,11 @@ /** | ||
} | ||
export async function handleAsyncOperationErrors(asyncOperation, errorMessage) { | ||
try { | ||
await asyncOperation; | ||
} | ||
catch (error) { | ||
logger.error(`${errorMessage}:\n${error.stack}`); | ||
process.exit(1); | ||
} | ||
} | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@farmfe/cli", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "CLI of Farm", | ||
@@ -47,4 +47,4 @@ "type": "module", | ||
"@types/inquirer": "^9.0.3", | ||
"@farmfe/cli": "0.6.0", | ||
"@farmfe/core": "0.15.0" | ||
"@farmfe/cli": "0.6.1", | ||
"@farmfe/core": "0.16.2" | ||
}, | ||
@@ -51,0 +51,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64171
670