UNPKG

fusox

Version:

Command line wrapper for fuse-box

101 lines (85 loc) 3.09 kB
const {parseBoolean, findExistingFile, printHeader} = require('../helpers') const path = require('path') const util = require('util') const {existsSync} = require('fs') const fsb = require('fuse-box') const {YAMLPlugin} = require('fuse-box-yaml') module.exports = {parseBuildServerFlags, buildServerCommand} function parseBuildServerFlags (args, flags) { let customMainFile = args.main let assetsMainPath = 'dist' let runDevServer = flags.runApplication let watchForChanges = args.watch === undefined ? runDevServer : parseBoolean(args.watch) // let treeshakeCode = args.treeshake === undefined ? flags.mode === 'production' : parseBoolean(args.treeshake) let customMainFilePath = customMainFile && flags.resolveSourcePath(customMainFile) let defaultMainFilePath = flags.resolveSourcePath('index.ts') let mainFilePath = findExistingFile(customMainFilePath, defaultMainFilePath) if (!mainFilePath || !existsSync(mainFilePath)) { throw new Error(util.format( 'Could not find main file at "%s" or "%s", see "--main" option', flags.resolveSourcePathRelative(customMainFilePath), flags.resolveSourcePathRelative(defaultMainFilePath) )) } let mainFile = mainFilePath && path.basename(mainFilePath) let mainFilePathRelative = mainFilePath.replace(flags.sourcePath + '/', '') let appName = mainFile.replace(path.extname(mainFile), '') return { ...flags, appName, mainFile, mainFilePath, mainFilePathRelative, assetsMainPath, runDevServer, watchForChanges, // treeshakeCode } } function buildServerCommand (flags) { let fuse = fsb.FuseBox.init({ target: 'server', homeDir: flags.sourcePath, modulesFolder: flags.nodeModulesPath, output: util.format('%s/$name.js', flags.destinationPath), tsConfig: flags.tsconfigPath, sourceMaps: flags.generateSourceMaps, hash: false, cache: flags.useCache, log: true, ensureTsConfig: false, plugins: [ YAMLPlugin(), // fsb.EnvPlugin(flags.envConfig), fsb.JSONPlugin(), fsb.CopyPlugin({ useDefault: false, files: flags.assetFilesExtensions, dest: '.', resolve: flags.assetsMainPath }), fsb.ReplacePlugin(flags.processEnvConfig), flags.mode === 'production' && flags.uglifyCode && fsb.UglifyESPlugin(), // flags.mode === 'production' && fsb.QuantumPlugin({ // target: 'server', // treeshake: flags.treeshakeCode, // uglify: flags.uglifyCode, // containedAPI: flags.isolateBundleApi, // bakeApiIntoBundle: flags.appName, // }), ] }) let mainBundle = fuse.bundle(flags.appName) .instructions(util.format('> %s %s', flags.mainFilePathRelative, flags.dynamicFilesInstructions)) if (flags.runApplication) { mainBundle.completed((proc) => { printHeader('Running application') proc.start() }) } if (flags.watchForChanges && flags.mode === 'development') { mainBundle.watch() } printHeader('Launching fuse-box for "server"') return fuse.run() }