1 | 'use strict';
|
2 |
|
3 | const Path = require('path');
|
4 | const Fs = require('fs');
|
5 |
|
6 | module.exports = async function (argument, required) {
|
7 | const data = {};
|
8 |
|
9 | data.input = argument ? argument.split(/\s+/)[0] : '';
|
10 | data.output = argument ? argument.split(/\s+/)[1] : '';
|
11 |
|
12 | data.input = Path.resolve(process.cwd(), data.input);
|
13 |
|
14 | if (!Fs.existsSync(data.input)) {
|
15 | throw new Error(`Input path does not exist ${data.input}`);
|
16 | }
|
17 |
|
18 | if (data.output) {
|
19 | data.output = Path.resolve(process.cwd(), data.output);
|
20 | }
|
21 |
|
22 | if (required !== false && !Path.extname(data.output) && !Fs.existsSync(data.output)) {
|
23 | throw new Error(`Output path does not exist ${data.output}`);
|
24 | }
|
25 |
|
26 | return data;
|
27 | };
|