import { createServer, logger, Command, ModeOptions, LogLevelOptions, UserStore, is_node_version } from '..' import { app_base, app_system, app_marked } from "./apps"; import path from "node:path"; const isNode14_ = is_node_version('<=', '14.0.0') const command = new Command('f2e-server3') .option('-m, --mode ', 'server mode: dev, build or prod', 'dev', ModeOptions) .option('-g, --gzip ', 'enable gzip', true) .option('-r, --root ', 'root', process.cwd()) .option('-l, --level ', 'log level: DEBUG, INFO, LOG, WARN, ERROR', 'DEBUG', LogLevelOptions) .action(async (options) => { const { mode, gzip, level, root } = options logger.setLevel(level) createServer({ root, mode, gzip, ssl: { passphrase: 'x509', key_file_name: path.join(root, './test/ssl/private.pem'), cert_file_name: path.join(root, './test/ssl/csr.crt'), }, mimeTypes: { 'ts': 'text/plain', 'hbs': 'text/plain', }, buildFilter: (pathname) => { return /^(src|templates|test($|\/index1?\.html|\/start)|README|package|$)/.test(pathname) }, outputFilter: (pathname) => { return /^(static|test($|\/index1?\.html|\/start)|README|package|$)/.test(pathname) }, watchFilter: (pathname) => { return /^(test|README|package|$)/.test(pathname) }, esbuild: { with_bundle_analyze: true, reg_inject: /\.html$/, }, less: { entryPoints: [{ in: 'test/app/app.less', out: 'static/app.css', }], }, postcss: { // 仅支持单个 entryPoints: { in: './test/main.css', out: 'static/main.css', }, plugins: [ require('tailwindcss')({ optimize: mode === 'build', config: './tailwind.config.js', }), ], }, alias: { 'static/monokai-sublime.css': 'node_modules/highlight.js/styles/monokai-sublime.css', }, include: { entryPoints: ['test/app/pages/include.html'], recursive: true, }, try_files: 'test/index.html', auth: isNode14_ ? false : { redirect: true, store: new UserStore('.f2e_cache/auth.db'), }, middlewares: [ app_base, app_system, app_marked, ], livereload: { reg_inject: /\.(html|md)$/, }, }) }) command.parse(process.argv)