1 | #!/usr/bin/env node
|
2 | (function (factory) {
|
3 | if (typeof module === "object" && typeof module.exports === "object") {
|
4 | var v = factory(require, exports);
|
5 | if (v !== undefined) module.exports = v;
|
6 | }
|
7 | else if (typeof define === "function" && define.amd) {
|
8 | define(["require", "exports", "child_process", "@theintern/common", "../lib/node/util", "../lib/common/util", "../index", "../lib/common/console"], factory);
|
9 | }
|
10 | })(function (require, exports) {
|
11 | "use strict";
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var child_process_1 = require("child_process");
|
14 | var common_1 = require("@theintern/common");
|
15 | var util_1 = require("../lib/node/util");
|
16 | var util_2 = require("../lib/common/util");
|
17 | var index_1 = require("../index");
|
18 | var console = require("../lib/common/console");
|
19 | util_1.getConfig()
|
20 | .then(function (_a) {
|
21 | var config = _a.config, file = _a.file;
|
22 | if (config.help) {
|
23 | printHelp(config, file);
|
24 | }
|
25 | else if (config.showConfigs) {
|
26 | console.log(util_2.getConfigDescription(config));
|
27 | }
|
28 | else {
|
29 | if (!file) {
|
30 | console.warn('No config file was loaded');
|
31 | }
|
32 | index_1.default.configure({ reporters: 'runner' });
|
33 | index_1.default.configure(config);
|
34 | return index_1.default.run();
|
35 | }
|
36 | })
|
37 | .catch(function (error) {
|
38 | if (!error.reported) {
|
39 | try {
|
40 | console.error(index_1.default.formatError(error));
|
41 | }
|
42 | catch (e) {
|
43 | console.error(error);
|
44 | }
|
45 | }
|
46 | common_1.global.process.exitCode = 1;
|
47 | });
|
48 | function printHelp(config, file) {
|
49 | var $ = function (cmd) { return child_process_1.execSync(cmd, { encoding: 'utf8' }).trim(); };
|
50 | var pkg = require('../package.json');
|
51 | var npmVersion = $('npm -v');
|
52 | var nodeVersion = $('node -v');
|
53 | console.log("intern version " + pkg.version);
|
54 | console.log("npm version " + npmVersion);
|
55 | console.log("node version " + nodeVersion);
|
56 | console.log();
|
57 | console.log('Usage: intern [config=<file>] [showConfig|showConfigs] [options]');
|
58 | console.log();
|
59 | console.log(' config - path to a config file');
|
60 | console.log(' showConfig - show the resolved config');
|
61 | console.log(' showConfigs - show information about configFile');
|
62 | console.log();
|
63 | console.log("Options (set with 'option=value' or 'option'):\n");
|
64 | var internConfig = index_1.default._config;
|
65 | var opts = Object.keys(internConfig)
|
66 | .map(function (key) {
|
67 | return { name: key, value: JSON.stringify(internConfig[key]) };
|
68 | })
|
69 | .sort(function (a, b) {
|
70 | if (a.name < b.name) {
|
71 | return -1;
|
72 | }
|
73 | if (a.name > b.name) {
|
74 | return 1;
|
75 | }
|
76 | return 0;
|
77 | });
|
78 | var width = opts.reduce(function (max, opt) { return Math.max(opt.name.length, max); }, 0);
|
79 | for (var _i = 0, opts_1 = opts; _i < opts_1.length; _i++) {
|
80 | var _a = opts_1[_i], name_1 = _a.name, value = _a.value;
|
81 | var pad = Array(width - name_1.length + 1).join(' ');
|
82 | console.log(" " + name_1 + pad + " - " + value);
|
83 | }
|
84 | if (file) {
|
85 | console.log();
|
86 | var description = util_2.getConfigDescription(config, ' ');
|
87 | if (description) {
|
88 | console.log("Using config file '" + file + "':\n");
|
89 | console.log(description);
|
90 | }
|
91 | else {
|
92 | console.log("Using config file '" + file + "'");
|
93 | }
|
94 | }
|
95 | }
|
96 | });
|
97 |
|
\ | No newline at end of file |