fix: config file support
This commit is contained in:
parent
3f54ca11a1
commit
9917425cc8
23
README.md
23
README.md
|
|
@ -40,18 +40,19 @@ Check out the example of [**standalone version running here**](https://codecrumb
|
|||
2) Run ```codecrumbs -d project-src-dir -e project-src-dir/index.js```. Change parameters to match your project:```-d``` is *directory with source code*, ```-e``` is *entry point file* .
|
||||
3) Go to [http://localhost:2018](http://localhost:2018/#) in the browser to check it out.
|
||||
|
||||
### CLI
|
||||
Parameter | Description | Example
|
||||
--- | --- | ---
|
||||
```-d```, ```--dir``` | Relative path to project source code directory | ```-d src```
|
||||
```-e```, ```--entry``` | Relative path to project source entry point file (must be inside ```dir```) | ```-e src/app.js```
|
||||
```-x```, ```--excludeDir``` | Relative path(or paths separated by ```,```) to directories for exclusion | ```-x src/doc,src/thirdparty```
|
||||
```-i```, ```--ideCmd``` | command to open file in IDE from bash (default 'webstorm') | ```-i code```
|
||||
```-p```, ```--port``` | Port for Codecrumbs client (optional, default *2018*) | ```-p 2019```
|
||||
```-n```, ```--projectName``` | Project name alias (optional, default same as ```-d``` value) | ```-n my-hello-world```
|
||||
```-D```, ```--debugModeEnabled``` | Enable debug mode for logs (optional, default is ```false```) | ```-D```
|
||||
### Configuration
|
||||
Run codecrumbs with CLI params or specify static config file `codecrumbs.config.js` (see example [here](/example-project/codecrumbs.config.js))
|
||||
|
||||
Parameters could be specified in `codecrumbs.config.js`
|
||||
CLI | Config file | Description | Example
|
||||
--- | --- | --- | ---
|
||||
```-d``` | ```projectDir``` | Relative path to project source code directory | ```-d src```
|
||||
```-e``` | ```entryPoint``` | Relative path to project source entry point file (must be inside ```dir```) | ```-e src/app.js```
|
||||
```-x``` | ```excludeDir``` | Relative path(or paths separated by ```,```) to directories for exclusion | ```-x src/doc,src/thirdparty```
|
||||
```-i``` | ```ideCmd``` | command to open file in IDE from bash (default 'webstorm') | ```-i code```
|
||||
```-p``` | ```clientPort``` | Port for Codecrumbs client (optional, default *2018*) | ```-p 2019```
|
||||
```-n``` | ```projectNameAlias``` | Project name alias (optional, default same as ```-d``` value) | ```-n my-hello-world```
|
||||
```-C``` | - | Path to codecrumbs.config.js (optional, by default will try to find the file in PWD) | ```-C config/codecrumbs.config.js```
|
||||
```-D``` | ```debugModeEnabled``` | Enable debug mode for logs (optional, default is ```false```) | ```-D```
|
||||
|
||||
## Features
|
||||
### Breadcrumbs and trails
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const colors = require('colors');
|
||||
const _ = require('lodash');
|
||||
|
|
@ -7,8 +8,10 @@ const _ = require('lodash');
|
|||
const showUpdatesInfo = require('./updatesInfo');
|
||||
const server = require('../src/server');
|
||||
|
||||
showUpdatesInfo();
|
||||
|
||||
program
|
||||
.option('-e, --entry [entryFile]', 'Specify path to entry point file. E.g. `src/app.js`')
|
||||
.option('-e, --entry [entryPoint]', 'Specify path to entry point file. E.g. `src/app.js`')
|
||||
.option('-d, --dir [projectDir]', 'Specify path to project source code directory. E.g. `src`', '')
|
||||
.option(
|
||||
'-w, --webpack [webpackConfigFile]',
|
||||
|
|
@ -22,22 +25,24 @@ program
|
|||
.option('-i, --ideCmd [ideCmd]', 'IDE command to open file')
|
||||
.option('-x, --excludeDir [excludeDirectories]', 'Exclude directories')
|
||||
.option('-n, --projectName [projectNameAlias]', 'Project name alias')
|
||||
.option('-C, --configFile [pathToConfigFile]', 'Path to codecrumbs.config.js')
|
||||
.option('-D, --debugModeEnabled [debugModeEnabled]', 'Enable debug mode for logs.')
|
||||
.parse(process.argv);
|
||||
|
||||
if (!program.entry || !program.dir) {
|
||||
const pathToConfigFile = program.configFile || 'codecrumbs.config.js';
|
||||
const configFileExists = server.checkIfPathExists(pathToConfigFile);
|
||||
if ((!program.entry || !program.dir) && !configFileExists) {
|
||||
console.log(
|
||||
colors.magenta(
|
||||
'Please specify `entry` and `dir` params. E.g. `codecrumbs -e src/app.js -d src`'
|
||||
'Please specify `entryPoint` and `projectDir` params (e.g. `codecrumbs -e src/app.js -d src`). Or use `-C codecrumbs.config.js` instead.'
|
||||
)
|
||||
);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
showUpdatesInfo();
|
||||
const configFromFile = configFileExists ? require(path.resolve(pathToConfigFile)) : {};
|
||||
|
||||
const config = require('codecrumbs.config.js');
|
||||
const environmentConfig = {
|
||||
const configFromCLI = {
|
||||
projectNameAlias: program.projectName,
|
||||
entryPoint: program.entry,
|
||||
projectDir: program.dir,
|
||||
|
|
@ -47,9 +52,6 @@ const environmentConfig = {
|
|||
excludeDir: program.excludeDir,
|
||||
ideCmd: program.ideCmd,
|
||||
debugModeEnabled: program.debugModeEnabled
|
||||
}
|
||||
};
|
||||
|
||||
server.setup(
|
||||
_.merge(config, environmentConfig),
|
||||
{ isDev: false }
|
||||
);
|
||||
server.setup(_.merge(configFromCLI, configFromFile), { isDev: false });
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
module.exports = {
|
||||
"entryPoint": 'src/index.js',
|
||||
"projectDir": 'src',
|
||||
"webpackConfigFile": 'webpack.config.js',
|
||||
"tsConfigFile": 'tsconfig.js',
|
||||
"defaultPort": 1234,
|
||||
"ideCmd": 'webstorm',
|
||||
"excludeDirectories": ['build'],
|
||||
"projectNameAlias": 'my-hello-world'
|
||||
entryPoint: 'example-project/src-client/index.js',
|
||||
projectDir: 'example-project/src-client',
|
||||
clientPort: 1234,
|
||||
projectNameAlias: 'example-project-for-client',
|
||||
debugModeEnabled: true
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import dataBus from '../dataBus/reducer';
|
|||
import namespaceIntegration from '../namespaceIntegration/reducer';
|
||||
import rootSaga from './sagas';
|
||||
|
||||
export default ({ extraReducers, extraPersistWhiteList } = {}) => {
|
||||
export default ({ extraReducers = {}, extraPersistWhiteList = [] } = {}) => {
|
||||
const sagaMiddleware = createSagaMiddleware();
|
||||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||
|
||||
|
|
|
|||
|
|
@ -97,11 +97,11 @@ const alignPlatformPath = (p = '') =>
|
|||
|
||||
const validateProjectPath = (pDir, ePoint) => {
|
||||
const paths = [];
|
||||
if (!fs.existsSync(alignPlatformPath(pDir))) {
|
||||
if (!checkIfPathExists(pDir)) {
|
||||
paths.push(pDir);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(alignPlatformPath(ePoint))) {
|
||||
if (!checkIfPathExists(ePoint)) {
|
||||
paths.push(ePoint);
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +113,9 @@ const validateProjectPath = (pDir, ePoint) => {
|
|||
}
|
||||
};
|
||||
|
||||
const checkIfPathExists = path => fs.existsSync(alignPlatformPath(path));
|
||||
|
||||
module.exports = {
|
||||
checkIfPathExists,
|
||||
setup
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue