Skip to content

Commit

Permalink
preparing for github publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ODuzhar committed Mar 29, 2020
1 parent c729379 commit 7de4f4e
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/build
/node_modules
/typings
/__out
package-lock.json
ipch
__build_debug
__build_mingw32_debug
Expand All @@ -26,3 +28,6 @@ __build_win32_release
*.bin
out
out1
/packages/tsc-cxx/lib
/packages/tsc-cxx/cpplib
/packages/tsc-cxx/node_modules
142 changes: 142 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
TypeScript to C++
===========================

License
-------

TypeScriptCxx is licensed under the MIT license.

Chat Room
---------

Want to chat with other members of the TypeScript to C++ community?

[![Join the chat at https://gitter.im/ASDAlexander77/TypeScript2Cxx](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/TypeScriptCpp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


Quick Start
-----------

0) install

```
node -i typescript-cxx
```


1) Compile test.ts

create file test.ts

```TypeScript
class Person {
protected name: string;
constructor(name: string) { this.name = name; }
}

class Employee extends Person {
private department: string;

constructor(name: string, department: string) {
super(name);
this.department = department;
}

public get ElevatorPitch() {
return `Hello, my name is ${this.name} and I work in ${this.department}.`;
}
}

let howard = new Employee("Howard", "Sales");
console.log(howard.ElevatorPitch);
```

```
node __out\maian.js test.ts
```

Now you have test.cpp and test.h

test.h:
```
#ifndef TEST_H
#define TEST_H
#include "core.h"
using namespace js;
class Person;
class Employee;
class Person : public object {
public:
string name;
Person(string name);
};
class Employee : public Person {
public:
string department;
Employee(string name, string department);
virtual any get_ElevatorPitch();
Employee(string name);
};
extern Employee* howard;
#endif
```

test.cpp:
```
#include "test.h"
using namespace js;
Person::Person(string name) {
this->name = name;
}
Employee::Employee(string name, string department) : Person(name) {
this->department = department;
}
any Employee::get_ElevatorPitch()
{
return cast<any>("Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S);
}
Employee::Employee(string name) : Person(name) {
}
Employee* howard = new Employee("Howard"_S, "Sales"_S);
void Main(void)
{
console->log(howard->get_ElevatorPitch());
}
int main(int argc, char** argv)
{
Main();
return 0;
}
```

2) Compile it.

cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp

3) Run it.

```
test.exe
```

Result:
```
Hello, my name is Howard and I work in Sales.
```

Enjoy it.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"watch": "tsc -w -p ./",
"lint": "tslint src/**/*.ts -t verbose",
"build": "tsc -p tsconfig.json",
"exec": "ts-node src/main.ts"
"exec": "ts-node src/main.ts",
"prepublish": "prepublish_npm.cmd"
},
"bin": {
"tsc-cxx": "./__out/main.js"
Expand Down
134 changes: 134 additions & 0 deletions packages/tsc-cxx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
TypeScript to C++
===========================

License
-------

TypeScriptCxx is licensed under the MIT license.

Quick Start
-----------

0) install

```
node -i typescript-cxx
```


1) Compile test.ts

create file test.ts

```TypeScript
class Person {
protected name: string;
constructor(name: string) { this.name = name; }
}

class Employee extends Person {
private department: string;

constructor(name: string, department: string) {
super(name);
this.department = department;
}

public get ElevatorPitch() {
return `Hello, my name is ${this.name} and I work in ${this.department}.`;
}
}

let howard = new Employee("Howard", "Sales");
console.log(howard.ElevatorPitch);
```

```
tsc-cxx test.ts
```

Now you have test.cpp and test.h

test.h:
```
#ifndef TEST_H
#define TEST_H
#include "core.h"
using namespace js;
class Person;
class Employee;
class Person : public object {
public:
string name;
Person(string name);
};
class Employee : public Person {
public:
string department;
Employee(string name, string department);
virtual any get_ElevatorPitch();
Employee(string name);
};
extern Employee* howard;
#endif
```

test.cpp:
```
#include "test.h"
using namespace js;
Person::Person(string name) {
this->name = name;
}
Employee::Employee(string name, string department) : Person(name) {
this->department = department;
}
any Employee::get_ElevatorPitch()
{
return cast<any>("Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S);
}
Employee::Employee(string name) : Person(name) {
}
Employee* howard = new Employee("Howard"_S, "Sales"_S);
void Main(void)
{
console->log(howard->get_ElevatorPitch());
}
int main(int argc, char** argv)
{
Main();
return 0;
}
```

2) Compile it.

cl /W3 /GR /EHsc /std:c++latest /Fe:test.exe /I ../cpplib ../cpplib/core.cpp test.cpp

3) Run it.

```
test.exe
```

Result:
```
Hello, my name is Howard and I work in Sales.
```

Enjoy it.
2 changes: 2 additions & 0 deletions packages/tsc-cxx/bin/tsc-cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/main.js')
39 changes: 39 additions & 0 deletions packages/tsc-cxx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "typescript-cxx",
"version": "1.0.0",
"description": "TypeScript to C++ transpiler",
"keywords": [
"typescript",
"c++",
"tsc-cxx",
"transpiler"
],
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"tsc-cxx": "./bin/tsc-cxx"
},
"dependencies": {
"cross-spawn": "^6.0.5",
"fs-extra": "^7.0.1",
"path": "^0.12.7",
"source-map": "^0.7.3",
"typescript": "^3.3.3333"
},
"engines": {
"node": ">=4.2.0"
},
"files": [
"bin/",
"lib/",
"README.md"
],
"author": "Alexander Duzhar",
"license": "ISC",
"bugs": {
"url": "https://github.com/ASDAlexander77/TypeScriptCxx/issues"
},
"homepage": "https://github.com/ASDAlexander77/TypeScriptCxx/#readme"
}
32 changes: 32 additions & 0 deletions prepublish_npm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if exist packages goto :skip
md packages
:skip
cd packages
if exist tsc-cxx goto :skip2
md tsc-cxx
:skip2
cd tsc-cxx
if exist lib goto :skip3
md lib
if exist bin goto :skip3
md bin
if exist cpplib goto :skip3
md cpplib
:skip3

cd ..\..

del "packages\tsc-cxx\lib\*.js"
del "packages\tsc-cxx\lib\*.js.map"

del "packages\tsc-cxx\cpplib\*.cpp"
del "packages\tsc-cxx\cpplib\*.h"

@call tsc -p ./
copy __out\*.js "packages\tsc-cxx\lib"
copy __out\*.js.map "packages\tsc-cxx\lib"

copy Playground\core.h "packages\tsc-cxx\cpplib"
copy Playground\core.cpp "packages\tsc-cxx\cpplib"

cd ..\..
Loading

0 comments on commit 7de4f4e

Please sign in to comment.