diff --git a/examples/refactor-react/package.json b/examples/refactor-react/package.json index 87544a4fa..0746d2105 100644 --- a/examples/refactor-react/package.json +++ b/examples/refactor-react/package.json @@ -2,7 +2,7 @@ "name": "react-template", "version": "1.0.0", "scripts": { - "dev": "farm start", + "dev": "farm", "start": "farm start", "build": "farm build", "preview": "farm preview", diff --git a/packages/cli/README.md b/packages/cli/README.md index 7c6c7bcb7..16546f99f 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -8,20 +8,26 @@ pnpm add @farmfe/cli -D ``` -start your farm project: +start your farm project in development mode: ```sh -farm start +farm dev ``` -build: +build your farm project in production mode: ```sh farm build ``` -preview: +preview your farm project in production mode: ```sh farm preview ``` + +clean your farm persistent cache: + +```sh +farm clean +``` diff --git a/packages/cli/package.json b/packages/cli/package.json index 645e414fa..4a4884d53 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,28 +28,20 @@ }, "files": [ "dist", - "bin", - "templates" + "bin" ], "scripts": { "start": "rimraf dist && tsc -b -w", "build": "tsc -b", - "type-check": "tsc --noEmit", "prepublishOnly": "npm run build" }, "engines": { "node": ">= 16" }, "dependencies": { - "cac": "^6.7.14", - "cross-spawn": "^7.0.3", - "inquirer": "9.2.12", - "walkdir": "^0.4.1" + "cac": "^6.7.14" }, - "devDependencies": { - "@farmfe/cli": "workspace:*", - "@farmfe/core": "workspace:*", - "@types/cross-spawn": "^6.0.2", - "@types/inquirer": "^9.0.3" + "peerDependencies": { + "@farmfe/core": "workspace:*" } } diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 3e3891ced..17881076f 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,11 +1,11 @@ +import { VERSION as CORE_VERSION } from '@farmfe/core'; import { cac } from 'cac'; - import { + VERSION, handleAsyncOperationErrors, resolveCliConfig, resolveCommandOptions, - resolveCore, - version + resolveCore } from './utils.js'; import type { UserConfig } from '@farmfe/core'; @@ -120,7 +120,7 @@ cli .action(async (root: string, options: CliBuildOptions & GlobalCliOptions) => { const defaultOptions = { root, - configFile: options.configFile, + configFile: options.config, mode: options.mode, watch: options.watch, compilation: { @@ -158,7 +158,7 @@ cli .action(async (root: string, options: CliBuildOptions & GlobalCliOptions) => { const defaultOptions = { root, - configFile: options.configFile, + configFile: options.config, mode: options.mode, compilation: { watch: options.watch, @@ -202,7 +202,7 @@ cli host: options.host, open: options.open }, - configPath: options.configPath, + configFile: options.config, port: options.port, compilation: { output: { @@ -236,17 +236,8 @@ cli ); }); -// Listening for unknown command -cli.on('command:*', async () => { - const { Logger } = await import('@farmfe/core'); - const logger = new Logger(); - logger.error( - `Unknown command place Run "farm --help" to see available commands` - ); -}); - cli.help(); -cli.version(version); +cli.version(`@farmfe/cli ${VERSION} @farmfe/core ${CORE_VERSION}`); cli.parse(); diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index dc3074b3b..c005567c9 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -2,13 +2,9 @@ export interface GlobalCliOptions { '--'?: string[]; c?: boolean | string; config?: string; - configPath?: string; base?: string; m?: string; mode?: 'development' | 'production' | string; - l?: boolean; - lazy?: boolean; - port?: number; clearScreen?: boolean; } @@ -19,7 +15,6 @@ export interface CleanOptions { export interface CliServerOptions { port?: number; open?: boolean; - https?: boolean; hmr?: boolean; cors?: boolean; strictPort?: boolean; @@ -32,11 +27,12 @@ export interface CliBuildOptions { input?: string; w?: boolean; watch?: boolean; + l?: boolean; + lazy?: boolean; sourcemap?: boolean; minify?: boolean; treeShaking?: boolean; format?: 'cjs' | 'esm'; - configFile?: string | undefined; target?: | 'browser' | 'node' @@ -46,7 +42,10 @@ export interface CliBuildOptions { | 'browser-legacy' | 'browser-es2015' | 'browser-es2017' - | 'browser-esnext'; + | 'browser-esnext' + | 'library' + | 'library-browser' + | 'library-node'; } export interface CliPreviewOptions { diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index ec9c7a0c9..eb91de764 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -78,8 +78,8 @@ export function cleanOptions( * @returns resolve command options */ export function resolveCommandOptions( - options: GlobalCliOptions -): GlobalCliOptions { + options: GlobalCliOptions & CliServerOptions +): GlobalCliOptions & CliServerOptions { const resolveOptions = { ...options }; filterDuplicateOptions(resolveOptions); return cleanOptions(resolveOptions); @@ -143,6 +143,8 @@ export function resolveCliConfig( }; } -export const { version } = JSON.parse( +const { version } = JSON.parse( readFileSync(new URL('../package.json', import.meta.url)).toString() ); + +export const VERSION = version; diff --git a/packages/core/src/config/constants.ts b/packages/core/src/config/constants.ts index af8f50e90..dbad9016e 100644 --- a/packages/core/src/config/constants.ts +++ b/packages/core/src/config/constants.ts @@ -1,3 +1,5 @@ +import { readFileSync } from 'node:fs'; + export const DEFAULT_CONFIG_NAMES = [ 'farm.config.ts', 'farm.config.js', @@ -15,3 +17,9 @@ export const CUSTOM_KEYS = { }; export const FARM_RUST_PLUGIN_FUNCTION_ENTRY = 'func.js'; + +const { version } = JSON.parse( + readFileSync(new URL('../../package.json', import.meta.url)).toString() +); + +export const VERSION = version; diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts index ce500cfce..49934d101 100644 --- a/packages/core/src/config/index.ts +++ b/packages/core/src/config/index.ts @@ -73,6 +73,7 @@ import type { } from './types.js'; export * from './types.js'; +export * from './constants.js'; export function defineFarmConfig(config: UserConfig): UserConfig; export function defineFarmConfig( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 20a0f0717..fefca51b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2276,28 +2276,6 @@ importers: cac: specifier: ^6.7.14 version: 6.7.14 - cross-spawn: - specifier: ^7.0.3 - version: 7.0.3 - inquirer: - specifier: 9.2.12 - version: 9.2.12 - walkdir: - specifier: ^0.4.1 - version: 0.4.1 - devDependencies: - '@farmfe/cli': - specifier: workspace:* - version: 'link:' - '@farmfe/core': - specifier: workspace:* - version: link:../core - '@types/cross-spawn': - specifier: ^6.0.2 - version: 6.0.4 - '@types/inquirer': - specifier: ^9.0.3 - version: 9.0.6 packages/core: dependencies: @@ -5003,9 +4981,6 @@ packages: '@types/cookies@0.7.9': resolution: {integrity: sha512-SrGYvhKohd/WSOII0WpflC73RgdJhQoqpwq9q+n/qugNGiDSGYXfHy3QvB4+X+J/gYe27j2fSRnK4B+1A3nvsw==} - '@types/cross-spawn@6.0.4': - resolution: {integrity: sha512-GGLpeThc2Bu8FBGmVn76ZU3lix17qZensEI4/MPty0aZpm2CHfgEMis31pf5X5EiudYKcPAsWciAsCALoPo5dw==} - '@types/d3-timer@2.0.2': resolution: {integrity: sha512-Dz39VLKZhWWeqSqbgYKF5BDJDUiPITo9M2cev/+HQBvXs+biES2d3LndnopuJ5YwaKK1h56CPWqDB+ghUXhm9A==} @@ -5066,9 +5041,6 @@ packages: '@types/http-proxy@1.17.14': resolution: {integrity: sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==} - '@types/inquirer@9.0.6': - resolution: {integrity: sha512-1Go1AAP/yOy3Pth5Xf1DC3nfZ03cJLCPx6E2YnSN/5I3w1jHBVH4170DkZ+JxfmA7c9kL9+bf9z3FRGa4kNAqg==} - '@types/is-ci@3.0.3': resolution: {integrity: sha512-FdHbjLiN2e8fk9QYQyVYZrK8svUDJpxSaSWLUga8EZS1RGAvvrqM9zbVARBtQuYPeLgnJxM2xloOswPwj1o2cQ==} @@ -5252,9 +5224,6 @@ packages: '@types/supertest@6.0.2': resolution: {integrity: sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg==} - '@types/through@0.0.32': - resolution: {integrity: sha512-7XsfXIsjdfJM2wFDRAtEWp3zb2aVPk5QeyZxGlVK57q4u26DczMHhJmlhr0Jqv0THwxam/L8REXkj8M2I/lcvw==} - '@types/tinycolor2@1.4.5': resolution: {integrity: sha512-uLJijDHN5E6j5n1qefF9oaeplgszXglWXWTviMoFr/YxgvbyrkFil20yDT7ljhCiTQ/BfCYtxfJS81LdTro5DQ==} @@ -8192,10 +8161,6 @@ packages: resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==} engines: {node: '>=8'} - figures@5.0.0: - resolution: {integrity: sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==} - engines: {node: '>=14'} - figures@6.1.0: resolution: {integrity: sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==} engines: {node: '>=18'} @@ -8853,10 +8818,6 @@ packages: resolution: {integrity: sha512-M1WuAmb7pn9zdFRtQYk26ZBoY043Sse0wVDdk4Bppr+JOXyQYybdtvK+l9wUibhtjdjvtoiNy8tk+EgsYIUqKg==} engines: {node: '>=12.0.0'} - inquirer@9.2.12: - resolution: {integrity: sha512-mg3Fh9g2zfuVWJn6lhST0O7x4n03k7G8Tx5nvikJkbq8/CK47WDVm+UznF0G6s5Zi0KcyUisr6DU8T67N5U+1Q==} - engines: {node: '>=14.18.0'} - inquirer@9.2.15: resolution: {integrity: sha512-vI2w4zl/mDluHt9YEQ/543VTCwPKWiHzKtm9dM2V0NdFcqEexDAjUHzO1oA60HRNaVifGXXM1tRRNluLVHa0Kg==} engines: {node: '>=18'} @@ -9109,10 +9070,6 @@ packages: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} - is-unicode-supported@1.3.0: - resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} - engines: {node: '>=12'} - is-unicode-supported@2.0.0: resolution: {integrity: sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==} engines: {node: '>=18'} @@ -13235,10 +13192,6 @@ packages: typescript: optional: true - walkdir@0.4.1: - resolution: {integrity: sha512-3eBwRyEln6E1MSzcxcVpQIhRG8Q1jLvEqRmCZqS3dsfXEDR/AhOF4d+jHg1qvDCpYaVRZjENPQyrVxAkQqxPgQ==} - engines: {node: '>=6.0.0'} - walker@1.0.8: resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==} @@ -17355,10 +17308,6 @@ snapshots: '@types/keygrip': 1.0.4 '@types/node': 18.18.8 - '@types/cross-spawn@6.0.4': - dependencies: - '@types/node': 18.18.8 - '@types/d3-timer@2.0.2': {} '@types/debug@4.1.12': @@ -17433,11 +17382,6 @@ snapshots: dependencies: '@types/node': 18.18.8 - '@types/inquirer@9.0.6': - dependencies: - '@types/through': 0.0.32 - rxjs: 7.8.1 - '@types/is-ci@3.0.3': dependencies: ci-info: 3.9.0 @@ -17650,10 +17594,6 @@ snapshots: '@types/methods': 1.1.4 '@types/superagent': 8.1.7 - '@types/through@0.0.32': - dependencies: - '@types/node': 18.18.8 - '@types/tinycolor2@1.4.5': {} '@types/ua-parser-js@0.7.39': {} @@ -21276,11 +21216,6 @@ snapshots: dependencies: escape-string-regexp: 1.0.5 - figures@5.0.0: - dependencies: - escape-string-regexp: 5.0.0 - is-unicode-supported: 1.3.0 - figures@6.1.0: dependencies: is-unicode-supported: 2.0.0 @@ -22040,24 +21975,6 @@ snapshots: through: 2.3.8 wrap-ansi: 6.2.0 - inquirer@9.2.12: - dependencies: - '@ljharb/through': 2.3.13 - ansi-escapes: 4.3.2 - chalk: 5.3.0 - cli-cursor: 3.1.0 - cli-width: 4.1.0 - external-editor: 3.1.0 - figures: 5.0.0 - lodash: 4.17.21 - mute-stream: 1.0.0 - ora: 5.4.1 - run-async: 3.0.0 - rxjs: 7.8.1 - string-width: 4.2.3 - strip-ansi: 6.0.1 - wrap-ansi: 6.2.0 - inquirer@9.2.15: dependencies: '@ljharb/through': 2.3.13 @@ -22272,8 +22189,6 @@ snapshots: is-unicode-supported@0.1.0: {} - is-unicode-supported@1.3.0: {} - is-unicode-supported@2.0.0: {} is-weakmap@2.0.2: {} @@ -27213,8 +27128,6 @@ snapshots: optionalDependencies: typescript: 5.4.5 - walkdir@0.4.1: {} - walker@1.0.8: dependencies: makeerror: 1.0.12