|
1 |
| -import { hideBin } from 'yargs/helpers'; |
2 |
| -import Yargs from 'yargs'; |
3 |
| -Yargs(hideBin(process.argv)) |
4 |
| - .command('* [testfolder]', false, function (yargs) { |
5 |
| - return yargs.positional('testfolder', { |
6 |
| - default: 'tests/', |
7 |
| - description: 'Path to the tests' |
| 1 | +/* * |
| 2 | + * |
| 3 | + * Imports |
| 4 | + * |
| 5 | + * */ |
| 6 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 7 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 8 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 9 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 10 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 11 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 12 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
8 | 13 | });
|
9 |
| -}, function (argv) { |
10 |
| - console.log('CLI', argv); |
11 |
| -}) |
12 |
| - .parse(); |
| 14 | +}; |
| 15 | +import * as Path from 'path'; |
| 16 | +import System from './System.js'; |
| 17 | +import Tester from './Tester.js'; |
| 18 | +import TSConfig from './TSConfig.js'; |
| 19 | +/* * |
| 20 | + * |
| 21 | + * Class |
| 22 | + * |
| 23 | + * */ |
| 24 | +export class CLI { |
| 25 | + /* * |
| 26 | + * |
| 27 | + * Constructor |
| 28 | + * |
| 29 | + * */ |
| 30 | + constructor(argv, system) { |
| 31 | + this.argv = argv; |
| 32 | + this.source = argv[argv.length - 1] || './'; |
| 33 | + this.system = system; |
| 34 | + } |
| 35 | + /* * |
| 36 | + * |
| 37 | + * Functions |
| 38 | + * |
| 39 | + * */ |
| 40 | + run() { |
| 41 | + return __awaiter(this, void 0, void 0, function* () { |
| 42 | + const system = this.system; |
| 43 | + if (this.argv.includes('-h') || |
| 44 | + this.argv.includes('--help')) { |
| 45 | + console.info(CLI.HELP.join(system.EOL)); |
| 46 | + return; |
| 47 | + } |
| 48 | + if (this.argv.includes('-v') || |
| 49 | + this.argv.includes('--version')) { |
| 50 | + console.info(CLI.VERSION); |
| 51 | + return; |
| 52 | + } |
| 53 | + let source = this.source; |
| 54 | + if (!source.endsWith('.json')) { |
| 55 | + source = Path.join(source, 'tsconfig.json'); |
| 56 | + } |
| 57 | + if (!system.fileExits(source)) { |
| 58 | + throw new Error(`TSConfig not found. (${source})`); |
| 59 | + } |
| 60 | + const target = TSConfig.extractOutDir(source) || source; |
| 61 | + try { |
| 62 | + console.info(`Testing ${this.source}...`); |
| 63 | + const result = yield System.exec(`npx tsc -p ${source}`); |
| 64 | + console.info(result); |
| 65 | + const files = System.getFiles(target, /\.js$/); |
| 66 | + for (const file of files) { |
| 67 | + yield import(System.join(System.CWD, target, file)); |
| 68 | + } |
| 69 | + const tester = Tester.default; |
| 70 | + yield tester.start(); |
| 71 | + for (const success of tester.successes) { |
| 72 | + console.log('✅', success); |
| 73 | + } |
| 74 | + for (const error of tester.errors) { |
| 75 | + console.log('🛑', error[0]); |
| 76 | + console.error(error[1]); |
| 77 | + } |
| 78 | + } |
| 79 | + catch (error) { |
| 80 | + console.error(error); |
| 81 | + process.exit(1); |
| 82 | + } |
| 83 | + }); |
| 84 | + } |
| 85 | +} |
| 86 | +/* * |
| 87 | + * |
| 88 | + * Class Namespace |
| 89 | + * |
| 90 | + * */ |
| 91 | +(function (CLI) { |
| 92 | + /* * |
| 93 | + * |
| 94 | + * Declarations |
| 95 | + * |
| 96 | + * */ |
| 97 | + /* * |
| 98 | + * |
| 99 | + * Constants |
| 100 | + * |
| 101 | + * */ |
| 102 | + CLI.VERSION = `Version ${System.extractPackageVersion()}`; |
| 103 | + CLI.HELP = [ |
| 104 | + `tst: The TypeScript Tester - ${CLI.VERSION}`, |
| 105 | + '', |
| 106 | + `tst [options] [source]`, |
| 107 | + '', |
| 108 | + 'ARGUMENTS:', |
| 109 | + '', |
| 110 | + ' [options] Optional flags explained in the section below.', |
| 111 | + '', |
| 112 | + ' [source] Source folder with TypeScript tests.', |
| 113 | + '', |
| 114 | + 'OPTIONS:', |
| 115 | + '', |
| 116 | + ' --help, -h Prints this help text.', |
| 117 | + '', |
| 118 | + ' --verbose Prints this help text.', |
| 119 | + '', |
| 120 | + ' --version, -v Prints the version string.', |
| 121 | + '', |
| 122 | + 'EXAMPLES:', |
| 123 | + '', |
| 124 | + ' tst tests/', |
| 125 | + ' Compiles, loads and runs assertion tests in the "tests" folder.', |
| 126 | + ]; |
| 127 | + /* * |
| 128 | + * |
| 129 | + * Functions |
| 130 | + * |
| 131 | + * */ |
| 132 | + function run(argv) { |
| 133 | + return __awaiter(this, void 0, void 0, function* () { |
| 134 | + return new CLI(argv, System).run(); |
| 135 | + }); |
| 136 | + } |
| 137 | + CLI.run = run; |
| 138 | +})(CLI || (CLI = {})); |
| 139 | +/* * |
| 140 | + * |
| 141 | + * Default Export |
| 142 | + * |
| 143 | + * */ |
| 144 | +export default CLI; |
0 commit comments