UNPKG

1.37 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4var path = require("path");
5var ms = require("minimist");
6var main_1 = require("./main");
7var utils_1 = require("./utils");
8if (require && require.main === module) {
9 var args = ms(process.argv.slice(2));
10 var project = args.project || args.p || process.cwd();
11 if (!utils_1.isString(project)) {
12 throw new Error('Project argument is invalid');
13 }
14 var projectPath = project.replace(/['"]/g, '');
15 var projectConfigPath = '';
16 if (!path.isAbsolute(project)) {
17 projectPath = path.resolve(process.cwd(), projectPath);
18 }
19 if (utils_1.isFile(projectPath)) {
20 projectConfigPath = path.resolve(projectPath);
21 projectPath = path.dirname(project);
22 }
23 else if (utils_1.isDirectory(projectPath)) {
24 projectConfigPath = path.resolve(projectPath, 'tsconfig.json');
25 }
26 else {
27 throw new Error('A valid path is required to project directory or tsconfig!');
28 }
29 main_1.main(projectPath, projectConfigPath)
30 .then(function () {
31 console.log('Bundle completed successfully!');
32 process.exit(0);
33 })
34 .catch(function (err) {
35 var message = (err.stack || err).toString();
36 console.error('Bundle halted!\n' + message);
37 process.exit(1);
38 });
39}