-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove experimental warning prevention - Split all commands into separate files
- Loading branch information
Showing
7 changed files
with
295 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { defineCommand } from 'citty'; | ||
import { getOptionFromBuildOption } from '../config.js'; | ||
import { | ||
FarmCLIBuildOptions, | ||
FarmCLICommonOptions, | ||
NormalizedFarmCLIBuildOptions | ||
} from '../types.js'; | ||
import { | ||
handleAsyncOperationErrors, | ||
resolveCliConfig, | ||
resolveCore | ||
} from '../utils.js'; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: 'build', | ||
description: 'compile the project in production mode' | ||
}, | ||
args: { | ||
root: { | ||
type: 'positional', | ||
description: 'root path', | ||
required: false, | ||
valueHint: 'path' | ||
}, | ||
outDir: { | ||
type: 'string', | ||
alias: 'o', | ||
description: 'output directory' | ||
}, | ||
input: { | ||
type: 'string', | ||
alias: 'i', | ||
description: 'input file path' | ||
}, | ||
watch: { type: 'boolean', alias: 'w', description: 'watch file change' }, | ||
target: { | ||
type: 'string', | ||
description: 'transpile targetEnv node, browser' | ||
}, | ||
format: { | ||
type: 'string', | ||
description: 'transpile format esm, commonjs' | ||
}, | ||
sourcemap: { | ||
type: 'boolean', | ||
description: 'output source maps for build' | ||
}, | ||
treeShaking: { | ||
type: 'boolean', | ||
description: 'Eliminate useless code without side effects' | ||
}, | ||
minify: { | ||
type: 'boolean', | ||
description: 'code compression at build time' | ||
} | ||
}, | ||
async run({ args }: { args: FarmCLICommonOptions & FarmCLIBuildOptions }) { | ||
const { root, configPath } = resolveCliConfig( | ||
args.root, | ||
args.config ?? args.c | ||
); | ||
|
||
const defaultOptions = { | ||
root, | ||
configPath, | ||
...getOptionFromBuildOption(args as NormalizedFarmCLIBuildOptions) | ||
}; | ||
|
||
const { build } = await resolveCore(); | ||
handleAsyncOperationErrors(build(defaultOptions), 'error during build'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { defineCommand } from 'citty'; | ||
import { FarmCLICommonOptions, ICleanOptions } from '../types.js'; | ||
import { resolveCliConfig, resolveCore } from '../utils.js'; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: 'clean', | ||
description: 'Clean up the cache built incrementally' | ||
}, | ||
args: { | ||
root: { | ||
type: 'positional', | ||
description: 'root path', | ||
required: false, | ||
valueHint: 'path' | ||
}, | ||
recursive: { | ||
type: 'boolean', | ||
alias: 'r', | ||
description: | ||
'Recursively search for node_modules directories and clean them' | ||
} | ||
}, | ||
async run({ args }: { args: FarmCLICommonOptions & ICleanOptions }) { | ||
const { root } = resolveCliConfig(args.root, args.config); | ||
|
||
const { clean } = await resolveCore(); | ||
try { | ||
await clean(root, args.recursive); | ||
} catch (e) { | ||
const { Logger } = await import('@farmfe/core'); | ||
const logger = new Logger(); | ||
logger.error(`Failed to clean cache: \n ${e.stack}`); | ||
process.exit(1); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { defineCommand } from 'citty'; | ||
import { | ||
FarmCLICommonOptions, | ||
FarmCLIServerOptions, | ||
GlobalFarmCLIOptions | ||
} from '../types.js'; | ||
import { | ||
handleAsyncOperationErrors, | ||
resolveCliConfig, | ||
resolveCommandOptions, | ||
resolveCore | ||
} from '../utils.js'; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: 'dev', | ||
description: | ||
'Compile the project in dev mode and serve it with farm dev server' | ||
}, | ||
args: { | ||
root: { | ||
type: 'positional', | ||
description: 'root path', | ||
required: false, | ||
valueHint: 'path' | ||
}, | ||
lazy: { type: 'boolean', alias: 'l', description: 'lazyCompilation' }, | ||
host: { type: 'string', description: 'specify host' }, | ||
port: { type: 'string', description: 'specify port' }, | ||
open: { type: 'boolean', description: 'open browser on server start' }, | ||
hmr: { type: 'boolean', description: 'enable hot module replacement' }, | ||
cors: { type: 'boolean', description: 'enable cors' }, | ||
strictPort: { | ||
type: 'boolean', | ||
description: 'specified port is already in use, exit with error' | ||
} | ||
}, | ||
async run({ args }: { args: FarmCLICommonOptions & FarmCLIServerOptions }) { | ||
const { root, configPath } = resolveCliConfig(args.root, args.config); | ||
|
||
const resolvedOptions = resolveCommandOptions(args as GlobalFarmCLIOptions); | ||
const defaultOptions = { | ||
root, | ||
compilation: { | ||
lazyCompilation: args.lazy | ||
}, | ||
server: resolvedOptions, | ||
clearScreen: args.clearScreen, | ||
configPath, | ||
mode: args.mode | ||
}; | ||
const { start } = await resolveCore(); | ||
handleAsyncOperationErrors(start(defaultOptions), 'Failed to start server'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { defineCommand } from 'citty'; | ||
import { | ||
FarmCLICommonOptions, | ||
FarmCLIPreviewOptions, | ||
GlobalFarmCLIOptions | ||
} from '../types.js'; | ||
import { | ||
handleAsyncOperationErrors, | ||
resolveCliConfig, | ||
resolveCommandOptions, | ||
resolveCore | ||
} from '../utils.js'; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: 'preview', | ||
description: 'compile the project in watch mode' | ||
}, | ||
args: { | ||
root: { | ||
type: 'positional', | ||
description: 'root path', | ||
required: false, | ||
valueHint: 'path' | ||
}, | ||
port: { type: 'string', description: 'specify port' }, | ||
open: { | ||
type: 'boolean', | ||
description: 'open browser on server preview start' | ||
} | ||
}, | ||
async run({ args }: { args: FarmCLICommonOptions & FarmCLIPreviewOptions }) { | ||
const { root, configPath } = resolveCliConfig(args.root, args.config); | ||
|
||
const resolvedOptions = resolveCommandOptions(args as GlobalFarmCLIOptions); | ||
const defaultOptions = { | ||
root, | ||
mode: args.mode, | ||
server: resolvedOptions, | ||
configPath, | ||
port: resolvedOptions.port | ||
}; | ||
|
||
const { preview } = await resolveCore(); | ||
handleAsyncOperationErrors( | ||
preview(defaultOptions), | ||
'Failed to start preview server' | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { defineCommand } from 'citty'; | ||
import { getOptionFromBuildOption } from '../config.js'; | ||
import { | ||
FarmCLIBuildOptions, | ||
GlobalFarmCLIOptions, | ||
NormalizedFarmCLIBuildOptions | ||
} from '../types.js'; | ||
import { | ||
handleAsyncOperationErrors, | ||
resolveCliConfig, | ||
resolveCore | ||
} from '../utils.js'; | ||
|
||
export default defineCommand({ | ||
meta: { | ||
name: 'watch', | ||
description: 'watch file change' | ||
}, | ||
args: { | ||
root: { | ||
type: 'positional', | ||
description: 'root path', | ||
required: false, | ||
valueHint: 'path' | ||
}, | ||
outDir: { | ||
type: 'string', | ||
alias: 'o', | ||
description: 'output directory' | ||
}, | ||
input: { | ||
type: 'string', | ||
alias: 'i', | ||
description: 'input file path' | ||
}, | ||
target: { | ||
type: 'string', | ||
description: 'transpile targetEnv node, browser' | ||
}, | ||
format: { | ||
type: 'string', | ||
description: 'transpile format esm, commonjs' | ||
}, | ||
sourcemap: { | ||
type: 'boolean', | ||
description: 'output source maps for build' | ||
}, | ||
treeShaking: { | ||
type: 'boolean', | ||
description: 'Eliminate useless code without side effects' | ||
}, | ||
minify: { | ||
type: 'boolean', | ||
description: 'code compression at build time' | ||
} | ||
}, | ||
async run({ args }: { args: FarmCLIBuildOptions & GlobalFarmCLIOptions }) { | ||
const { root, configPath } = resolveCliConfig( | ||
args.root, | ||
args.config ?? args.c | ||
); | ||
|
||
const defaultOptions = { | ||
root, | ||
configPath, | ||
...getOptionFromBuildOption(args as NormalizedFarmCLIBuildOptions) | ||
}; | ||
|
||
const { watch } = await resolveCore(); | ||
handleAsyncOperationErrors( | ||
watch(defaultOptions), | ||
'error during watch project' | ||
); | ||
} | ||
}); |
Oops, something went wrong.