diff --git a/src/configs/babel/development/plugins.js b/src/configs/babel/development/plugins.js index 938287d..fc4e89a 100644 --- a/src/configs/babel/development/plugins.js +++ b/src/configs/babel/development/plugins.js @@ -1,4 +1 @@ -export default (defaults = []) => [ - ...defaults, - require.resolve('react-hot-loader/babel') -] +export default (defaults = []) => [...defaults, require.resolve('react-hot-loader/babel')] diff --git a/src/configs/babel/write.js b/src/configs/babel/write.js index 86033fa..b366615 100644 --- a/src/configs/babel/write.js +++ b/src/configs/babel/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import babelConfig from '@/configs/babel/index' -const writeConfig = ( - dir = __dirname, - format = FileTypes.JSON_NO_EXT, - overwrite -) => { +const writeConfig = (dir = __dirname, format = FileTypes.JSON_NO_EXT, overwrite) => { return writeFile(dir, '.babelrc', babelConfig, format, overwrite) } diff --git a/src/configs/eslint/index.js b/src/configs/eslint/index.js index 0d671fe..6b35f65 100644 --- a/src/configs/eslint/index.js +++ b/src/configs/eslint/index.js @@ -16,12 +16,7 @@ const eslintConfig = loadConfig('eslint', { }, parser: 'babel-eslint', plugins: ['react', 'jest'], - extends: [ - 'airbnb', - 'prettier', - 'prettier/react', - 'plugin:jest/recommended' - ], + extends: ['airbnb', 'prettier', 'prettier/react', 'plugin:jest/recommended'], rules: { 'jsx-a11y/media-has-caption': 0, 'jsx-a11y/click-events-have-key-events': 0, @@ -144,12 +139,7 @@ const eslintConfig = loadConfig('eslint', { 'no-path-concat': 1, 'no-process-exit': 1, 'no-restricted-modules': 1, - 'no-restricted-syntax': [ - 'error', - 'ForInStatement', - 'LabeledStatement', - 'WithStatement' - ], + 'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'], 'no-sync': 1, 'brace-style': [1, '1tbs', { allowSingleLine: true }], diff --git a/src/configs/eslint/write.js b/src/configs/eslint/write.js index dec5286..db787fa 100644 --- a/src/configs/eslint/write.js +++ b/src/configs/eslint/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import eslintConfig from '@/configs/eslint/index' -const writeConfig = ( - dir = process.cwd(), - format = FileTypes.JSON_NO_EXT, - overwrite -) => { +const writeConfig = (dir = process.cwd(), format = FileTypes.JSON_NO_EXT, overwrite) => { return writeFile(dir, '.eslintrc', eslintConfig, format, overwrite) } diff --git a/src/configs/gitignore/index.js b/src/configs/gitignore/index.js index 58009f8..816853c 100644 --- a/src/configs/gitignore/index.js +++ b/src/configs/gitignore/index.js @@ -1,10 +1,6 @@ import mhyConfig from '@/configs/mhy' import { loadConfig } from '@/utils' -const gitignore = loadConfig('gitignore', [ - '/dist', - '/build', - ...mhyConfig.defaultIgnoreList -]) +const gitignore = loadConfig('gitignore', ['/dist', '/build', ...mhyConfig.defaultIgnoreList]) export default gitignore diff --git a/src/configs/gitignore/write.js b/src/configs/gitignore/write.js index 9f0e4bd..6279aac 100644 --- a/src/configs/gitignore/write.js +++ b/src/configs/gitignore/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import gitignore from '@/configs/gitignore/index' -const writeConfig = ( - dir = process.cwd(), - format = FileTypes.RAW, - overwrite -) => { +const writeConfig = (dir = process.cwd(), format = FileTypes.RAW, overwrite) => { return writeFile(dir, '.gitignore', gitignore.join('\n'), format, overwrite) } diff --git a/src/configs/mhy/index.js b/src/configs/mhy/index.js index d13188e..9133ffe 100644 --- a/src/configs/mhy/index.js +++ b/src/configs/mhy/index.js @@ -4,21 +4,10 @@ import fs from 'fs' import { loadConfig } from '@/utils' const mhyConfig = loadConfig('mhy', { - defaultIndexHtml: path.resolve( - __dirname, - '../..', - 'resources', - 'index.html' - ), + defaultIndexHtml: path.resolve(__dirname, '../..', 'resources', 'index.html'), get indexHtml() { - const projectIndexHtml = path.resolve( - process.cwd(), - this.srcFolder, - 'index.html' - ) - return fs.existsSync(projectIndexHtml) - ? projectIndexHtml - : this.defaultIndexHtml + const projectIndexHtml = path.resolve(process.cwd(), this.srcFolder, 'index.html') + return fs.existsSync(projectIndexHtml) ? projectIndexHtml : this.defaultIndexHtml }, srcFolder: 'src', distFolder: 'dist', diff --git a/src/configs/npmignore/write.js b/src/configs/npmignore/write.js index fd3a283..73a29ce 100644 --- a/src/configs/npmignore/write.js +++ b/src/configs/npmignore/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import npmignore from '@/configs/npmignore' -const writeConfig = ( - dir = process.cwd(), - format = FileTypes.RAW, - overwrite -) => { +const writeConfig = (dir = process.cwd(), format = FileTypes.RAW, overwrite) => { return writeFile(dir, '.npmignore', npmignore.join('\n'), format, overwrite) } diff --git a/src/configs/prettier/write.js b/src/configs/prettier/write.js index d5330cc..a5857af 100644 --- a/src/configs/prettier/write.js +++ b/src/configs/prettier/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import prettierConfig from '@/configs/prettier/index' -const writeConfig = ( - dir = process.cwd(), - format = FileTypes.JSON_NO_EXT, - overwrite -) => { +const writeConfig = (dir = process.cwd(), format = FileTypes.JSON_NO_EXT, overwrite) => { let filename switch (format) { case FileTypes.JS: diff --git a/src/configs/tslint/index.js b/src/configs/tslint/index.js index 7440d3b..be0cd9b 100644 --- a/src/configs/tslint/index.js +++ b/src/configs/tslint/index.js @@ -1,22 +1,12 @@ import { loadConfig } from '@/utils' const tslintConfig = loadConfig('tslint', { - extends: [ - 'tslint:recommended', - 'tslint-config-airbnb', - 'tslint-react', - 'tslint-config-prettier' - ], + extends: ['tslint:recommended', 'tslint-config-airbnb', 'tslint-react', 'tslint-config-prettier'], rules: { 'max-line-length': { options: [120] }, - 'variable-name': [ - true, - 'ban-keywords', - 'check-format', - 'allow-pascal-case' - ], + 'variable-name': [true, 'ban-keywords', 'check-format', 'allow-pascal-case'], semicolon: [true, 'never'], 'no-arg': true, 'no-bitwise': true, diff --git a/src/configs/tslint/write.js b/src/configs/tslint/write.js index b44727c..fb0b3fc 100644 --- a/src/configs/tslint/write.js +++ b/src/configs/tslint/write.js @@ -2,11 +2,7 @@ import FileTypes from '@/utils/fileTypes' import { writeFile } from '@/utils' import tslintConfig from '@/configs/tslint' -const writeConfig = ( - dir = process.cwd(), - format = FileTypes.JSON, - overwrite -) => { +const writeConfig = (dir = process.cwd(), format = FileTypes.JSON, overwrite) => { return writeFile(dir, 'tslint', tslintConfig, format, overwrite) } diff --git a/src/configs/typescript/index.js b/src/configs/typescript/index.js index dab0971..f662b03 100644 --- a/src/configs/typescript/index.js +++ b/src/configs/typescript/index.js @@ -29,10 +29,7 @@ const tsconfig = loadConfig('typescript', { return acc }, { - '*': [ - path.resolve(process.cwd(), 'node_modules', '*'), - path.resolve(_globalTypes, '../', '*') - ] + '*': [path.resolve(process.cwd(), 'node_modules', '*'), path.resolve(_globalTypes, '../', '*')] } ) }, @@ -41,10 +38,8 @@ const tsconfig = loadConfig('typescript', { }) // Setup @types -const isDirectory = source => dir => - fs.lstatSync(path.join(source, dir)).isDirectory() -const getDirectories = source => - fs.readdirSync(source).filter(isDirectory(source)) +const isDirectory = source => dir => fs.lstatSync(path.join(source, dir)).isDirectory() +const getDirectories = source => fs.readdirSync(source).filter(isDirectory(source)) // Set fixed types from mhy getDirectories(_globalTypes).forEach(dir => { diff --git a/src/configs/webpack/index.js b/src/configs/webpack/index.js index ca4cf9b..4390d99 100644 --- a/src/configs/webpack/index.js +++ b/src/configs/webpack/index.js @@ -1,8 +1,6 @@ import { loadConfig } from '@/utils' -process.env.WEBPACK_DEV_SERVER = process.argv.find(v => - v.includes('webpack-dev-server') -) +process.env.WEBPACK_DEV_SERVER = process.argv.find(v => v.includes('webpack-dev-server')) const webpackConfig = loadConfig('webpack', {}) diff --git a/src/configs/webpack/production/module/rules/eslint.js b/src/configs/webpack/production/module/rules/eslint.js index 3a81a0f..54b8c53 100644 --- a/src/configs/webpack/production/module/rules/eslint.js +++ b/src/configs/webpack/production/module/rules/eslint.js @@ -1,7 +1,5 @@ export default rules => { - const rule = rules.find(({ loader = '' }) => - loader.includes('eslint-loader') - ) + const rule = rules.find(({ loader = '' }) => loader.includes('eslint-loader')) rule.options = { ...rule.options, failOnWarning: true, diff --git a/src/configs/webpack/root/resolve.js b/src/configs/webpack/root/resolve.js index b5ae32e..c682b9e 100644 --- a/src/configs/webpack/root/resolve.js +++ b/src/configs/webpack/root/resolve.js @@ -3,21 +3,9 @@ import path from 'path' import mhyConfig from '@/configs/mhy' export default () => ({ - extensions: [ - '.js', - '.mjs', - '.jsx', - '.css', - '.scss', - '.ts', - '.tsx', - '.json' - ], + extensions: ['.js', '.mjs', '.jsx', '.css', '.scss', '.ts', '.tsx', '.json'], modules: Array.from( - new Set([ - path.resolve(__dirname, '../../../../node_modules'), - path.resolve(process.cwd(), 'node_modules') - ]) + new Set([path.resolve(__dirname, '../../../../node_modules'), path.resolve(process.cwd(), 'node_modules')]) ), alias: mhyConfig.defaultAliases }) diff --git a/src/processes/command/babel.js b/src/processes/command/babel.js index b74bbc2..cf63ff6 100644 --- a/src/processes/command/babel.js +++ b/src/processes/command/babel.js @@ -8,10 +8,5 @@ const commandHandler = argv => { } export default () => { - yargs.command( - ['babel', 'bb'], - 'compile src using Babel', - () => {}, - commandHandler - ) + yargs.command(['babel', 'bb'], 'compile src using Babel', () => {}, commandHandler) } diff --git a/src/processes/command/boot.js b/src/processes/command/boot.js index 317d005..723aeff 100644 --- a/src/processes/command/boot.js +++ b/src/processes/command/boot.js @@ -4,19 +4,13 @@ import yargs from 'yargs' // mhy boot [technology:react|vue|...] [template:default|...] [-o,--output: output path] const commandHandler = ({ technology, template, output }) => { - const source = path.resolve( - __dirname, - '../../../', - `templates/${technology}/${template}` - ) + const source = path.resolve(__dirname, '../../../', `templates/${technology}/${template}`) const destination = path.resolve(process.cwd(), output) fse.copy(source, destination, function(err) { if (err) { console.error(`mhy:boot:${technology}:${template}`) - console.error( - `An error occurred while copying the source to the destination: ${destination}` - ) + console.error(`An error occurred while copying the source to the destination: ${destination}`) console.error(err) return } diff --git a/src/processes/command/config.js b/src/processes/command/config.js index 87b9da1..60fb7eb 100644 --- a/src/processes/command/config.js +++ b/src/processes/command/config.js @@ -27,9 +27,7 @@ const handleWrite = (config, dir, format, overwrite) => { const results = [] for (const writeConfig of modules) { - process.stdout.write( - `\r Writing configs ${results.length + 1}/${modules.length}` - ) + process.stdout.write(`\r Writing configs ${results.length + 1}/${modules.length}`) results.push(writeConfig(dir, format, overwrite)) } process.stdout.clearLine() @@ -37,24 +35,14 @@ const handleWrite = (config, dir, format, overwrite) => { const existed = results.filter(({ isExisted }) => isExisted) const overwritten = results.filter(({ isOverwritten }) => isOverwritten) - const cleanlyInitialized = results.filter( - ({ isExisted, isOverwritten }) => !isOverwritten && !isExisted - ) + const cleanlyInitialized = results.filter(({ isExisted, isOverwritten }) => !isOverwritten && !isExisted) if (cleanlyInitialized.length || overwritten.length) { - console.log( - `\nInitialized ${cleanlyInitialized.length + - overwritten.length} config(s) successfully:\n` - ) - for (const { filename, isOverwritten } of [ - ...cleanlyInitialized, - ...overwritten - ]) { + console.log(`\nInitialized ${cleanlyInitialized.length + overwritten.length} config(s) successfully:\n`) + for (const { filename, isOverwritten } of [...cleanlyInitialized, ...overwritten]) { console.log( ` ${chalk.green(figures.tick)} ${filename}${ - isOverwritten - ? ` ${chalk.yellow(`${figures.warning} overwritten`)}` - : '' + isOverwritten ? ` ${chalk.yellow(`${figures.warning} overwritten`)}` : '' }` ) } @@ -62,15 +50,11 @@ const handleWrite = (config, dir, format, overwrite) => { if (!overwrite && existed.length) { console.log('\n') - process.stdout.write( - `\rSkipped ${existed.length} already existing config(s):\n` - ) + process.stdout.write(`\rSkipped ${existed.length} already existing config(s):\n`) for (const { filename } of existed) { console.log(` ${chalk.blue(figures.line)} ${filename}`) } - console.log( - '\nUse -o/--overwrite to force re-initialization of an already existing file.' - ) + console.log('\nUse -o/--overwrite to force re-initialization of an already existing file.') } } @@ -87,57 +71,48 @@ const handlePrint = (config, dir, format) => { const fetchConfigs = (config = []) => { const glob = require('glob') const globStr = config.length ? `*(${config.join('|')})` : '*' - return glob.sync( - path.resolve(__dirname, '../../configs/', globStr) + path.sep - ) + return glob.sync(path.resolve(__dirname, '../../configs/', globStr) + path.sep) } const fetchWriters = (config = []) => { const glob = require('glob') - const globStr = config.length - ? `*(${config.join('|')})/write.js` - : '*/write.js' + const globStr = config.length ? `*(${config.join('|')})/write.js` : '*/write.js' return glob.sync(path.resolve(__dirname, '../../configs/', globStr)) } export default () => { - yargs - .command( - ['config', 'c'], - 'write out to cwd all available configs (shorthand to --init)' - ) - .command( - ['config [config...]', 'c [config...]'], - 'init/print out specified configs only', - yargs => { - yargs - .positional('config', { - describe: 'config file to load', - type: 'string' - }) - .option('--dir', { - alias: 'd', - default: process.cwd(), - description: 'Output directory' - }) - .option('--init', { - alias: 'i', - default: false, - description: 'Output directory', - choices: [false, true, 'vscode'] - }) - .option('--overwrite', { - alias: 'o', - default: false, - description: 'Overwrite existing files' - }) - .option('--format', { - alias: 'f', - default: undefined, - description: 'Output format', - choices: Object.values(FileTypes) - }) - }, - commandHandler - ) + yargs.command(['config', 'c'], 'write out to cwd all available configs (shorthand to --init)').command( + ['config [config...]', 'c [config...]'], + 'init/print out specified configs only', + yargs => { + yargs + .positional('config', { + describe: 'config file to load', + type: 'string' + }) + .option('--dir', { + alias: 'd', + default: process.cwd(), + description: 'Output directory' + }) + .option('--init', { + alias: 'i', + default: false, + description: 'Output directory', + choices: [false, true, 'vscode'] + }) + .option('--overwrite', { + alias: 'o', + default: false, + description: 'Overwrite existing files' + }) + .option('--format', { + alias: 'f', + default: undefined, + description: 'Output format', + choices: Object.values(FileTypes) + }) + }, + commandHandler + ) } diff --git a/src/processes/command/eslint.js b/src/processes/command/eslint.js index 0b7be92..dd8fb4d 100644 --- a/src/processes/command/eslint.js +++ b/src/processes/command/eslint.js @@ -9,12 +9,7 @@ const commandHandler = argv => { export default () => { yargs - .command( - 'eslint', - 'run eslint once for all files', - () => {}, - commandHandler - ) + .command('eslint', 'run eslint once for all files', () => {}, commandHandler) .command( 'eslint [...pattern]', 'run eslint once for files with matching pattern', diff --git a/src/processes/command/prettier.js b/src/processes/command/prettier.js index 15dfe21..81bf584 100644 --- a/src/processes/command/prettier.js +++ b/src/processes/command/prettier.js @@ -9,12 +9,7 @@ const commandHandler = argv => { export default () => { yargs - .command( - 'prettier', - 'run prettier once for supported files', - () => {}, - commandHandler - ) + .command('prettier', 'run prettier once for supported files', () => {}, commandHandler) .command( 'prettier [pattern...]', 'run prettier once for the matching pattern', diff --git a/src/processes/command/ui.js b/src/processes/command/ui.js index d117b68..9770c12 100644 --- a/src/processes/command/ui.js +++ b/src/processes/command/ui.js @@ -8,11 +8,7 @@ const commandHandler = argv => { argv.process = argv.process || [] if (!argv.process.length && argv._.length) { - console.error( - `Unknown process '${argv._[0]}' for the environment of '${ - process.env.NODE_ENV - }'!` - ) + console.error(`Unknown process '${argv._[0]}' for the environment of '${process.env.NODE_ENV}'!`) process.exit(0) } @@ -44,11 +40,7 @@ const commandHandler = argv => { export default () => { yargs .command('$0', 'alias to `ui`', f => f, commandHandler) - .command( - 'ui', - 'start all default processes with-in UI using current NODE_ENV', - commandHandler - ) + .command('ui', 'start all default processes with-in UI using current NODE_ENV', commandHandler) .command( 'ui [process...]', 'run specific process(es) with-in UI', diff --git a/src/processes/command/webpack-dev-server.js b/src/processes/command/webpack-dev-server.js index 0ff0c93..1320d3a 100644 --- a/src/processes/command/webpack-dev-server.js +++ b/src/processes/command/webpack-dev-server.js @@ -8,10 +8,5 @@ const commandHandler = argv => { } export default () => { - yargs.command( - ['webpack-dev-server', 'wds'], - 'run webpack-dev-server', - () => {}, - commandHandler - ) + yargs.command(['webpack-dev-server', 'wds'], 'run webpack-dev-server', () => {}, commandHandler) } diff --git a/src/processes/command/webpack.js b/src/processes/command/webpack.js index 1aca5bb..88c52e9 100644 --- a/src/processes/command/webpack.js +++ b/src/processes/command/webpack.js @@ -8,10 +8,5 @@ const commandHandler = argv => { } export default () => { - yargs.command( - ['webpack', 'wp'], - 'compile src using Webpack', - () => {}, - commandHandler - ) + yargs.command(['webpack', 'wp'], 'compile src using Webpack', () => {}, commandHandler) } diff --git a/src/processes/ecosystem/development/eslint.js b/src/processes/ecosystem/development/eslint.js index 4539b0b..bdc0df8 100644 --- a/src/processes/ecosystem/development/eslint.js +++ b/src/processes/ecosystem/development/eslint.js @@ -9,16 +9,9 @@ const getEslintCLICmd = args => { // It's a file/path, use that if (!pattern.length) { - pattern.push( - `"${path.resolve(process.cwd(), 'src/**/*.{js,jsx,ts,tsx}')}"` - ) + pattern.push(`"${path.resolve(process.cwd(), 'src/**/*.{js,jsx,ts,tsx}')}"`) } - return [ - 'node', - require.resolve('eslint/bin/eslint.js'), - ...flags, - ...pattern - ] + return ['node', require.resolve('eslint/bin/eslint.js'), ...flags, ...pattern] } class Eslint extends Process { diff --git a/src/processes/ecosystem/development/jest.js b/src/processes/ecosystem/development/jest.js index 42e9956..5374af5 100644 --- a/src/processes/ecosystem/development/jest.js +++ b/src/processes/ecosystem/development/jest.js @@ -23,17 +23,11 @@ class Jest extends Process { this.run(defaultAction, { ...rest }) } - onStart = ({ name }, { flags = [] }) => - this.spawn( - name, - getJestCLICmd([ - ...flags, - process.env.MHY_ENV === 'ui' ? watchFlag : '' - ]) - ) - - onWatchAll = ({ name }, { flags = [] }) => - this.spawn(name, getJestCLICmd([...flags, watchAllFlag])) + onStart = ({ name }, { flags = [] }) => { + this.spawn(name, getJestCLICmd([...flags, process.env.MHY_ENV === 'ui' ? watchFlag : ''])) + } + + onWatchAll = ({ name }, { flags = [] }) => this.spawn(name, getJestCLICmd([...flags, watchAllFlag])) actions = [ { diff --git a/src/processes/ecosystem/development/prettier.js b/src/processes/ecosystem/development/prettier.js index 50299de..6a9c815 100644 --- a/src/processes/ecosystem/development/prettier.js +++ b/src/processes/ecosystem/development/prettier.js @@ -9,9 +9,7 @@ const getPrettierCLICmd = args => { // It's a file/path, use that if (!pattern.length) { - pattern.push( - `"${path.resolve(process.cwd(), 'src/**/*.{js,jsx,ts,tsx}')}"` - ) + pattern.push(`"${path.resolve(process.cwd(), 'src/**/*.{js,jsx,ts,tsx}')}"`) } return [ 'node', @@ -39,9 +37,7 @@ const getPrettierServeCLICmd = flags => [ class Prettier extends Process { get commandToUse() { - return process.env.MHY_ENV === 'ui' - ? getPrettierServeCLICmd - : getPrettierCLICmd + return process.env.MHY_ENV === 'ui' ? getPrettierServeCLICmd : getPrettierCLICmd } constructor(args) { diff --git a/src/processes/ecosystem/development/storybook-start.js b/src/processes/ecosystem/development/storybook-start.js index 9bcf67b..3fcf24a 100644 --- a/src/processes/ecosystem/development/storybook-start.js +++ b/src/processes/ecosystem/development/storybook-start.js @@ -2,20 +2,14 @@ import fs from 'fs' import path from 'path' import Process from '@/processes' -const CmdStorybookStartCLI = [ - 'node', - require.resolve('@storybook/react/bin/index.js') -] +const CmdStorybookStartCLI = ['node', require.resolve('@storybook/react/bin/index.js')] class StorybookStart extends Process { constructor(args) { const storybookConfigPath = require.resolve('@/configs/storybook') const storybookConfig = require(storybookConfigPath) const babelRcPath = path.resolve( - storybookConfigPath.substring( - 0, - storybookConfigPath.lastIndexOf(path.sep) - ), + storybookConfigPath.substring(0, storybookConfigPath.lastIndexOf(path.sep)), '.storybook' ) if (!fs.existsSync(path.resolve(babelRcPath, '.babelrc'))) { diff --git a/src/processes/index.js b/src/processes/index.js index f9ded31..9e8172d 100644 --- a/src/processes/index.js +++ b/src/processes/index.js @@ -32,25 +32,14 @@ export const loadProcess = (module, env = process.env.NODE_ENV) => { if (processLocalExists) return require(processLocal) else if (processMhyExists) return require(processMhy) else { - console.error( - `Unknown process '${module}' for the environment of '${env}'!` - ) + console.error(`Unknown process '${module}' for the environment of '${env}'!`) process.exit(0) } } export const loadCommands = () => { applyEntries({}, path.join(__dirname, 'command'), '**/*.js') - applyEntries( - {}, - path.join( - process.cwd(), - process.env.MHY_LOCAL_DIR, - 'processes', - 'command' - ), - '**/*.js' - ) + applyEntries({}, path.join(process.cwd(), process.env.MHY_LOCAL_DIR, 'processes', 'command'), '**/*.js') } const mhyArgvList = ['$0', '_', 'mhy-verbose', 'mhy-debug', 'mhy-prod'] @@ -78,24 +67,27 @@ export const buildMhyArgv = (argv, noFlags = []) => { const returnObj = { mhyArgv, argv, - flags: argvToFlags(argv, noFlags) + flags: argvToFlags(argv, mhyArgv, noFlags) } return returnObj } -const argvToFlags = (argv, noFlags = []) => { - return Object.keys(argv).reduce((acc, k) => { - if (noFlags.includes(k)) return acc - acc.push(`--${k}`) - if (argv[k] !== true) { - acc.push(argv[k]) - } - return acc - }, []) +const argvToFlags = (argv, mhyArgv, noFlags = []) => { + const [, ...names] = mhyArgv._ + return [ + ...Object.keys(argv).reduce((acc, k) => { + if (noFlags.includes(k)) return acc + acc.push(`--${k}`) + if (argv[k] !== true) { + acc.push(argv[k]) + } + return acc + }, []), + ...names + ] } -const toCamelCase = str => - str.replace(/\b-([a-z])/g, (_, char) => char.toUpperCase()) +const toCamelCase = str => str.replace(/\b-([a-z])/g, (_, char) => char.toUpperCase()) export default class Process extends EventEmitter { processes = new Map() diff --git a/src/utils/applyEntries.test.js b/src/utils/applyEntries.test.js index 09020d9..2e9abd4 100644 --- a/src/utils/applyEntries.test.js +++ b/src/utils/applyEntries.test.js @@ -4,13 +4,7 @@ import { applyEntries } from '@/utils' describe('applyEntries', () => { it('should load core root processes', () => { const entries = {} - const globPath = path.join( - __dirname, - '..', - 'processes', - 'ecosystem', - 'root' - ) + const globPath = path.join(__dirname, '..', 'processes', 'ecosystem', 'root') applyEntries(entries, globPath, '**/*.js') expect(entries).toHaveProperty('config') }) diff --git a/src/utils/formatSource.js b/src/utils/formatSource.js index 442e89f..c478443 100644 --- a/src/utils/formatSource.js +++ b/src/utils/formatSource.js @@ -9,11 +9,7 @@ const formatSource = (source, format) => { case FileTypes.TSX: return `export default ${JSON.stringify(source, null, 4)}` case FileTypes.JS: - return `module.exports = module.exports.default = ${JSON.stringify( - source, - null, - 4 - )}` + return `module.exports = module.exports.default = ${JSON.stringify(source, null, 4)}` case FileTypes.JSON: case FileTypes.JSON_NO_EXT: return JSON.stringify(source, null, 2) diff --git a/src/utils/loadConfig.js b/src/utils/loadConfig.js index 45d99f5..a5538d0 100644 --- a/src/utils/loadConfig.js +++ b/src/utils/loadConfig.js @@ -3,45 +3,21 @@ import { applyJson, applyEntries } from '@/utils' const loadConfig = (module, defaults = {}) => { // 1. MHY root - applyEntries( - defaults, - path.join(__dirname, '../configs', module, 'root'), - '**/*.js' - ) + applyEntries(defaults, path.join(__dirname, '../configs', module, 'root'), '**/*.js') // 2. LOCAL root - applyEntries( - defaults, - path.join( - process.cwd(), - process.env.MHY_LOCAL_DIR, - 'configs', - module, - 'root' - ), - '**/*.js' - ) + applyEntries(defaults, path.join(process.cwd(), process.env.MHY_LOCAL_DIR, 'configs', module, 'root'), '**/*.js') // 3. JSON root defaults = applyJson(module, 'root', defaults) // 4. MHY env - applyEntries( - defaults, - path.join(__dirname, '../configs', module, process.env.NODE_ENV), - '**/*.js' - ) + applyEntries(defaults, path.join(__dirname, '../configs', module, process.env.NODE_ENV), '**/*.js') // 5. LOCAL env applyEntries( defaults, - path.join( - process.cwd(), - process.env.MHY_LOCAL_DIR, - 'configs', - module, - process.env.NODE_ENV - ), + path.join(process.cwd(), process.env.MHY_LOCAL_DIR, 'configs', module, process.env.NODE_ENV), '**/*.js' ) diff --git a/src/utils/writeFile.js b/src/utils/writeFile.js index 74aa305..68fe4a6 100644 --- a/src/utils/writeFile.js +++ b/src/utils/writeFile.js @@ -4,13 +4,7 @@ import formatSource from '@/utils/formatSource' import formatFilename from '@/utils/formatFilename' import FileTypes from '@/utils/fileTypes' -const writeFile = ( - dir, - filename, - source, - format = FileTypes.JS, - overwrite = true -) => { +const writeFile = (dir, filename, source, format = FileTypes.JS, overwrite = true) => { filename = formatFilename(filename, format) source = formatSource(source, format)