Skip to content

Commit

Permalink
fileOrFolder execution moved to file
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Feb 7, 2021
1 parent 54ba743 commit 6fa2f2e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
26 changes: 4 additions & 22 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import fs from 'fs/promises';
import chalk from 'chalk';
import displayHelpOutput from './lib/commands/help.js';
import parseCliFlags from './lib/parse-cli-flags.js';
import run from './lib/commands/run.js';
import parseCliInputs from './lib/parse-cli-inputs.js';

process.title = 'qunitx';

Expand All @@ -13,27 +14,8 @@ process.title = 'qunitx';
return await displayHelpOutput();
}

let config = await parseCliFlags();
let config = await parseCliInputs();

const fileOrFolder = process.argv[2]; // then turn this to array of remaining args
try {
const entry = await fs.stat(fileOrFolder);

if (entry.isDirectory()) {
console.log('entry', entry, ' is directory');
} else if (entry.isFile()) { // what to do when its .ts
const QUnit = (await import('./lib/setup-node-js-environment.js')).default;

console.log(fileOrFolder);
await import(`${process.cwd()}/${fileOrFolder}`);

QUnit.start();
}
} catch (error) {
console.log(error);

return process.exit(1);
}
// if file execute file
return await run(config);
})();

36 changes: 36 additions & 0 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import fs from 'fs/promises';
import chalk from 'chalk';

export default async function(config) {
const { browser, fileOrFolderInputs } = fileOrFolderInputs;

if (!browser) {
const QUnit = (await import('./lib/setup-node-js-environment.js')).default;
}

fileOrFolderInputs.forEach((fileOrFolder) => {
// TODO: handle/format globs

try {
const entry = await fs.stat(fileOrFolder);

if (entry.isDirectory()) {
console.log(entry, ' is directory');
} else if (entry.isFile()) { // what to do when its .ts
const QUnit = (await import('./lib/setup-node-js-environment.js')).default;

console.log(fileOrFolder, 'if file');
await import(`${process.cwd()}/${fileOrFolder}`);

}
} catch (error) {
console.log(error);

return process.exit(1);
}
});

if (!browser) {
QUnit.start();
}
}
6 changes: 4 additions & 2 deletions lib/utils/parse-cli-flags.js → lib/utils/parse-cli-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default async function() {
const packageJSON = await fs.readFile(`${projectRoot}/package.json`);
const projectConfig = JSON.parse(packageJSON.toString()).qunitx;
const defaultValues = {...projectConfig, projectRoot };
const providedFlags = process.argv.slice(3).reduce((result, arg) => {
const providedFlags = process.argv.slice(2).reduce((result, arg) => {
if (arg.startsWith('--browser')) {
return Object.assign(result, { browser: parseBoolean(arg.split('=')[1]) });
} else if (args.startsWith('--debug')) {
Expand All @@ -21,8 +21,10 @@ export default async function() {
return Object.assign(result, { coverageDist: arg.split('=')[1] || './dist' });
}

result.fileOrFolderInputs.push(arg);

return result;
}, {});
}, { fileOrFolderInputs: [] });

return Object.assign(defaultValues, projectConfig, providedFlags);
}
Expand Down

0 comments on commit 6fa2f2e

Please sign in to comment.