Skip to content

Commit

Permalink
fix: config error throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasan Farrokh committed Jul 2, 2021
1 parent e103a91 commit b425991
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ To use it, simply build your project with this structure: `dist/DEVICE` then run
## Configuration
```ts
// multidevice.config.js

module.exports = {
devices: ['desktop', 'mobile'],
devices: {
mobile: /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/,
},
fallback: 'desktop',

// returns the identifiers that should be replaced. by default these two are considered
replacement: (device) => ['DEVICE.' + device, 'window.DEVICE.' + device],
Expand Down
6 changes: 2 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ export function loadConfig(): MultiDeviceConfig {
let config: Partial<MultiDeviceConfig> = {};
try {
config = require(path.resolve(process.cwd(), CONFIG_FILE));
} catch (err) {
console.error(err);
} // eslint-disable-line no-empty
} catch (err) {} // eslint-disable-line no-empty
return {
...defaultConfig,
...config,
};
}

export function getDevicesArray(config: Pick<MultiDeviceConfig, 'devices' | 'fallback'>) {
export function getDevicesArray(config: Pick<MultiDeviceConfig, 'devices' | 'fallback'>): string[] {
return [...new Set([config.fallback, ...(Array.isArray(config.devices) ? config.devices : Object.keys(config.devices))])];
}

0 comments on commit b425991

Please sign in to comment.