Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Add ability to install globally and execute as command line app #372

Merged
merged 4 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ node_modules

# IDEs
.idea/
/ts2dart.iml
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
ts2dart is a TypeScript to Dart transpiler. It's mainly used to translate Angular 2 from TypeScript
to Dart for its Dart user base.

## Usage

- To install as Command Line Tool execute: `npm i -g ts2dart`
- Once installed you could run it doing: `ts2dart inputFile.ts`

## Installation

- execute `npm i` to install the dependencies,
Expand Down
3 changes: 2 additions & 1 deletion lib/declaration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';
import {FacadeConverter} from './facade_converter';
import {Transpiler} from './main';

export default class DeclarationTranspiler extends base.TranspilerBase {
constructor(
Expand Down
3 changes: 2 additions & 1 deletion lib/expression.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';
import {FacadeConverter} from './facade_converter';
import {Transpiler} from './main';

export default class ExpressionTranspiler extends base.TranspilerBase {
constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); }
Expand Down
8 changes: 5 additions & 3 deletions lib/facade_converter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as base from './base';
import * as ts from 'typescript';
import * as path from 'path';
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';

type CallHandler = (c: ts.CallExpression, context: ts.Expression) => void;
Expand Down Expand Up @@ -384,7 +385,8 @@ export class FacadeConverter extends base.TranspilerBase {

private reportMissingType(n: ts.Node, ident: string) {
this.reportError(
n, `Untyped property access to "${ident}" which could be ` + `a special ts2dart builtin. ` +
n, `Untyped property access to "${ident}" which could be ` +
`a special ts2dart builtin. ` +
`Please add type declarations to disambiguate.`);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/literal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';
import {FacadeConverter} from './facade_converter';
import {Transpiler} from './main';

export default class LiteralTranspiler extends base.TranspilerBase {
constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); }
Expand Down
30 changes: 30 additions & 0 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /usr/bin/env node

require('source-map-support').install();
import {SourceMapGenerator} from 'source-map';
import * as fs from 'fs';
Expand Down Expand Up @@ -405,9 +407,37 @@ class Output {
}
}

function showHelp() {
console.log(`
Usage: ts2dart [input-files] [arguments]

--help show this dialog

--failFast Fail on the first error, do not collect multiple. Allows easier debugging
as stack traces lead directly to the offending line

--generateLibraryName Whether to generate 'library a.b.c;' names from relative file paths.

--generateSourceMap Whether to generate source maps.

--tsconfig A tsconfig.json to use to configure TypeScript compilation.

--basePath A base path to relativize absolute file paths against. This
is useful for library name generation (see above) and nicer
file names in error messages.

--translateBuiltins Translate calls to builtins, i.e. seemlessly convert from \` Array\` to \` List\`,
and convert the corresponding methods. Requires type checking.

--enforceUnderscoreConventions Enforce conventions of public/private keyword and underscore prefix
`);
process.exit(0);
}

// CLI entry point
if (require.main === module) {
let args = require('minimist')(process.argv.slice(2), {base: 'string'});
if (args.help) showHelp();
try {
let transpiler = new Transpiler(args);
console.error('Transpiling', args._, 'to', args.destination);
Expand Down
3 changes: 2 additions & 1 deletion lib/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';
import {FacadeConverter} from './facade_converter';
import {Transpiler} from './main';

export default class ModuleTranspiler extends base.TranspilerBase {
constructor(tr: Transpiler, private fc: FacadeConverter, private generateLibraryName: boolean) {
Expand Down
3 changes: 2 additions & 1 deletion lib/type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ts from 'typescript';

import * as base from './base';
import {Transpiler} from './main';
import {FacadeConverter} from './facade_converter';
import {Transpiler} from './main';

export default class TypeTranspiler extends base.TranspilerBase {
constructor(tr: Transpiler, private fc: FacadeConverter) { super(tr); }
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.9.10",
"description": "Transpile TypeScript code to Dart",
"main": "build/lib/main.js",
"bin": "build/lib/main.js",
"typings": "build/definitions/main.d.ts",
"directories": {
"test": "test"
Expand Down
2 changes: 1 addition & 1 deletion test/call_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

describe('calls', () => {
it('translates destructuring parameters', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/declaration_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

describe('variables', () => {
it('should print variable declaration with initializer',
Expand Down
2 changes: 1 addition & 1 deletion test/decorator_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

describe('decorators', () => {
it('translates plain decorators', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: e2e
description: Transpiled end-to-end tests for ts2dart.

dependencies:
test: 0.12.13
test: 0.12.15+3
2 changes: 1 addition & 1 deletion test/expression_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

function expectTranslates(cases: any) {
for (let tsCode of Object.keys(cases)) {
Expand Down
3 changes: 2 additions & 1 deletion test/facade_converter_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, FAKE_MAIN, translateSource} from './test_support';
import {FAKE_MAIN, expectTranslate, translateSource} from './test_support';

import chai = require('chai');

function getSources(str: string): {[k: string]: string} {
Expand Down
2 changes: 1 addition & 1 deletion test/function_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

describe('functions', () => {
it('supports declarations', () => { expectTranslate('function x() {}').to.equal('x() {}'); });
Expand Down
2 changes: 1 addition & 1 deletion test/literal_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference path="../typings/mocha/mocha.d.ts"/>
import {expectTranslate, expectErroneousCode} from './test_support';
import {expectErroneousCode, expectTranslate} from './test_support';

describe('literals', () => {
it('translates string literals', () => {
Expand Down