typenative 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,152 +1,154 @@
1
- # TypeNative
2
-
3
- Build native applications using Typescript.
4
-
5
- ## PreRequisites
6
-
7
- - [Nodejs v24](https://nodejs.org/en) or newer.
8
- - [Go 1.21](https://go.dev/doc/install) or newer.
9
-
10
- ## Get Started
11
-
12
- - Write a file `test.ts` with content `console.log('Hello World!');` or any other message
13
- - Run `npx typenative --source test.ts --script`
14
-
15
- ## Typescript Syntax Support
16
-
17
- TypeNative currently supports a focused subset of TypeScript syntax elements that are transpiled to Go code. The support is grouped by topic for easier scanning.
18
-
19
- **Basic Types**
20
-
21
- | Feature | Supported | Notes |
22
- | -------------- | :-------: | ------------------------------------------------------------- |
23
- | number | ✅ | Transpiled to `float64` |
24
- | boolean | ✅ | Transpiled to `bool` |
25
- | string | ✅ | |
26
- | null | ✅ | |
27
- | any | ✅ | Used for type inference |
28
- | Nullable types | ✅ | `T \| null` / `T \| undefined` transpiled to Go pointer types |
29
-
30
- **Variables & Objects**
31
-
32
- | Feature | Supported | Notes |
33
- | --------------------- | :-------: | -------------------------------- |
34
- | Variable declarations | ✅ | `let` and `const` |
35
- | Object literals | ✅ | Transpiled to Go struct literals |
36
-
37
- **Operators**
38
-
39
- | Feature | Supported | Notes |
40
- | ------------------------ | :-------: | ------------------------------ |
41
- | Arithmetic operators | ✅ | `+`, `-`, etc. |
42
- | Comparison operators | ✅ | `==`, `!=`, `===`, `!==`, etc. |
43
- | Logical operators | ✅ | `&&`, `\|\|` |
44
- | Increment/Decrement | ✅ | `++`, `--` |
45
- | Non-null assertion (`!`) | ✅ | Stripped during transpilation |
46
- | Ternary expressions | ✅ | `condition ? a : b` |
47
- | Nullish coalescing | ✅ | `??` operator |
48
- | Optional chaining | ✅ | `obj?.prop`, `arr?.[i]` |
49
-
50
- **Control Flow**
51
-
52
- | Feature | Supported | Notes |
53
- | ------------------ | :-------: | ---------------------------------- |
54
- | If/Else statements | ✅ | Fully supported |
55
- | Switch statements | ✅ | Case and default statements |
56
- | For loops | ✅ | Standard `for` loops |
57
- | For...of loops | ✅ | Iteration over arrays |
58
- | While loops | ✅ | Transpiled to Go's `for` loops |
59
- | Do...while loops | ✅ | Implemented with conditional break |
60
-
61
- **Data Structures & Array Methods**
62
-
63
- | Feature | Supported | Notes |
64
- | -------------------------- | :-------: | ---------------------------------------------------------------- |
65
- | Arrays || Basic array operations |
66
- | Array methods | ✅ | `push`, `join`, `slice` |
67
- | Higher-order array methods | ✅ | `.map()`, `.filter()`, `.some()`, `.find()` |
68
- | Method chaining | ✅ | Chaining array methods such as `.map(...).filter(...).join(...)` |
69
-
70
- **Functions**
71
-
72
- | Feature | Supported | Notes |
73
- | ---------------------------- | :-------: | --------------------------------- |
74
- | Function declarations | ✅ | Transpiled to Go functions |
75
- | Arrow functions | ✅ | Transpiled to anonymous functions |
76
- | Generics (functions/classes) | ✅ | Type parameters via Go generics |
77
- | Default parameter values | ✅ | `function(x = defaultValue)` |
78
-
79
- **Classes & Interfaces**
80
-
81
- | Feature | Supported | Notes |
82
- | ------------------- | :-------: | -------------------------------------------------------------- |
83
- | Classes | ✅ | Transpiled to Go structs with constructor and receiver methods |
84
- | Class inheritance | ✅ | `extends` via embedded structs, `super()` supported |
85
- | Interfaces | ✅ | Transpiled to Go interfaces, supports `extends` |
86
- | Optional properties | ✅ | `prop?: Type` in interfaces/types |
87
- | Enums | ✅ | `enum` declarations and member access |
88
-
89
- **Async & Timing**
90
-
91
- | Feature | Supported | Notes |
92
- | ----------- | :-------: | ----------------------------------------------------------------- |
93
- | Async/Await | ✅ | `async` functions return Go channels, `await` reads from channels |
94
- | Promises | ✅ | `new Promise` transpiled to channel + goroutine pattern |
95
- | setTimeout | ✅ | Mapped to Go's `time.AfterFunc` |
96
-
97
- **Built-in Functions & Utilities**
98
-
99
- | Feature | Supported | Notes |
100
- | --------------------- | :-------: | ----------------------------------------------------- |
101
- | console.log | ✅ | Mapped to `fmt.Println` |
102
- | console.time/timeEnd | ✅ | Performance measurement via `time.Now` / `time.Since` |
103
- | assert | ✅ | Transpiled to `panic` on failure |
104
- | parseInt / parseFloat | ✅ | Mapped to Go's `strconv` package |
105
-
106
- **Math Methods**
107
-
108
- | Feature | Supported | Notes |
109
- | ------------------------- | :-------: | ------------------------------------------------- |
110
- | Math.random | ✅ | Mapped to `rand.Float64()` |
111
- | Math.floor / ceil / round | ✅ | Mapped to `math.Floor`, `math.Ceil`, `math.Round` |
112
- | Math.abs / sqrt / pow | ✅ | Mapped to corresponding `math` functions |
113
- | Math.min / max | ✅ | Mapped to `math.Min`, `math.Max` |
114
-
115
- **String Methods**
116
-
117
- | Feature | Supported | Notes |
118
- | -------------------------- | :-------: | --------------------------------------------- |
119
- | Template literals | ✅ | Backtick strings with `${expr}` interpolation |
120
- | toUpperCase / toLowerCase | ✅ | Via `strings` package |
121
- | trim / trimStart / trimEnd | ✅ | Via `strings` package |
122
- | split / includes / indexOf | ✅ | Via `strings` package |
123
- | startsWith / endsWith | ✅ | Via `strings` package |
124
- | replace / replaceAll | ✅ | Via `strings` package |
125
- | charAt / substring / slice | ✅ | Direct Go string indexing/slicing |
126
- | concat / repeat | ✅ | String concatenation and `strings.Repeat` |
127
-
128
- **Number / Object Methods**
129
-
130
- | Feature | Supported | Notes |
131
- | -------- | :-------: | ----------------------------------------------------- |
132
- | toString | ✅ | Universal `toString()` via `fmt.Sprintf` for any type |
133
-
134
- **RegExp**
135
-
136
- | Feature | Supported | Notes |
137
- | -------------- | :-------: | --------------------------------------------------- |
138
- | Regex literals | ✅ | `/pattern/flags` transpiled to `regexp.MustCompile` |
139
- | new RegExp() | ✅ | Constructor with optional flags |
140
- | test() | ✅ | Mapped to `regexp.MatchString` |
141
- | exec() | ✅ | Mapped to `regexp.FindStringSubmatch` |
142
-
143
- **Unsupported / Roadmap**
144
-
145
- | Feature | Supported | Notes |
146
- | --------------------------- | :-------: | ------------------------------------------------ |
147
- | Modules/Imports | ❌ | `import` / `export` declarations |
148
- | Try/Catch | ❌ | Error handling |
149
- | Map / Set | ❌ | Built-in collection types and their methods |
150
- | Closures over mutable state | ❌ | Functions capturing and mutating outer variables |
151
-
152
- TypeNative is currently in early development and new features are being added regularly. The goal for `1.0` release is for TypeNative to transpile itself.
1
+ # TypeNative
2
+
3
+ Build native applications using Typescript.
4
+
5
+ ## PreRequisites
6
+
7
+ - [Nodejs v24](https://nodejs.org/en) or newer.
8
+ - [Go 1.21](https://go.dev/doc/install) or newer.
9
+
10
+ ## Get Started
11
+
12
+ - Write a file `test.ts` with content `console.log('Hello World!');` or any other message
13
+ - Run `npx typenative --source test.ts --script`
14
+
15
+ ## Typescript Syntax Support
16
+
17
+ TypeNative currently supports a focused subset of TypeScript syntax elements that are transpiled to Go code. The support is grouped by topic for easier scanning.
18
+
19
+ **Basic Types**
20
+
21
+ | Feature | Supported | Notes |
22
+ | -------------- | :-------: | ------------------------------------------------------------- |
23
+ | number | ✅ | Transpiled to `float64` |
24
+ | boolean | ✅ | Transpiled to `bool` |
25
+ | string | ✅ | |
26
+ | null | ✅ | |
27
+ | any | ✅ | Used for type inference |
28
+ | Nullable types | ✅ | `T \| null` / `T \| undefined` transpiled to Go pointer types |
29
+
30
+ **Variables & Objects**
31
+
32
+ | Feature | Supported | Notes |
33
+ | --------------------- | :-------: | -------------------------------- |
34
+ | Variable declarations | ✅ | `let` and `const` |
35
+ | Object literals | ✅ | Transpiled to Go struct literals |
36
+
37
+ **Operators**
38
+
39
+ | Feature | Supported | Notes |
40
+ | ------------------------ | :-------: | ------------------------------ |
41
+ | Arithmetic operators | ✅ | `+`, `-`, etc. |
42
+ | Comparison operators | ✅ | `==`, `!=`, `===`, `!==`, etc. |
43
+ | Logical operators | ✅ | `&&`, `\|\|` |
44
+ | Increment/Decrement | ✅ | `++`, `--` |
45
+ | Non-null assertion (`!`) | ✅ | Stripped during transpilation |
46
+ | Ternary expressions | ✅ | `condition ? a : b` |
47
+ | Nullish coalescing | ✅ | `??` operator |
48
+ | Optional chaining | ✅ | `obj?.prop`, `arr?.[i]` |
49
+
50
+ **Control Flow**
51
+
52
+ | Feature | Supported | Notes |
53
+ | ------------------ | :-------: | ---------------------------------- |
54
+ | If/Else statements | ✅ | Fully supported |
55
+ | Switch statements | ✅ | Case and default statements |
56
+ | For loops | ✅ | Standard `for` loops |
57
+ | For...of loops | ✅ | Iteration over arrays |
58
+ | While loops | ✅ | Transpiled to Go's `for` loops |
59
+ | Do...while loops | ✅ | Implemented with conditional break |
60
+ | Try/Catch/Finally | ✅ | `throw` → `panic`; catch/finally via `defer`/`recover` |
61
+
62
+ **Data Structures & Array Methods**
63
+
64
+ | Feature | Supported | Notes |
65
+ | -------------------------- | :-------: | ---------------------------------------------------------------- |
66
+ | Arrays | ✅ | Basic array operations |
67
+ | Array methods | ✅ | `push`, `join`, `slice` |
68
+ | Higher-order array methods | ✅ | `.map()`, `.filter()`, `.some()`, `.find()` |
69
+ | Method chaining | ✅ | Chaining array methods such as `.map(...).filter(...).join(...)` |
70
+ | Map | ✅ | `Map<K, V>` → Go `map[K]V`; `.set()`, `.get()`, `.has()`, `.delete()`, `.clear()`, `.size` |
71
+ | Set | ✅ | `Set<T>` → Go `map[T]struct{}`; `.add()`, `.has()`, `.delete()`, `.clear()`, `.size` |
72
+
73
+ **Functions**
74
+
75
+ | Feature | Supported | Notes |
76
+ | ---------------------------- | :-------: | ------------------------------------------------------------ |
77
+ | Function declarations | ✅ | Transpiled to Go functions |
78
+ | Arrow functions | ✅ | Transpiled to anonymous functions |
79
+ | Closures over mutable state | ✅ | Functions capturing and mutating outer variables |
80
+ | Function types | ✅ | `() => number`, `(x: number) => string` as type annotations |
81
+ | Generics (functions/classes) | ✅ | Type parameters via Go generics |
82
+ | Default parameter values | ✅ | `function(x = defaultValue)` |
83
+
84
+ **Classes & Interfaces**
85
+
86
+ | Feature | Supported | Notes |
87
+ | ------------------- | :-------: | -------------------------------------------------------------- |
88
+ | Classes | ✅ | Transpiled to Go structs with constructor and receiver methods |
89
+ | Class inheritance | ✅ | `extends` via embedded structs, `super()` supported |
90
+ | Interfaces | ✅ | Transpiled to Go interfaces, supports `extends` |
91
+ | Optional properties | ✅ | `prop?: Type` in interfaces/types |
92
+ | Enums | ✅ | `enum` declarations and member access |
93
+
94
+ **Async & Timing**
95
+
96
+ | Feature | Supported | Notes |
97
+ | ----------- | :-------: | ----------------------------------------------------------------- |
98
+ | Async/Await | ✅ | `async` functions return Go channels, `await` reads from channels |
99
+ | Promises | ✅ | `new Promise` transpiled to channel + goroutine pattern |
100
+ | setTimeout | ✅ | Mapped to Go's `time.AfterFunc` |
101
+
102
+ **Built-in Functions & Utilities**
103
+
104
+ | Feature | Supported | Notes |
105
+ | --------------------- | :-------: | ----------------------------------------------------- |
106
+ | console.log | ✅ | Mapped to `fmt.Println` |
107
+ | console.time/timeEnd | ✅ | Performance measurement via `time.Now` / `time.Since` |
108
+ | assert | ✅ | Transpiled to `panic` on failure |
109
+ | parseInt / parseFloat | ✅ | Mapped to Go's `strconv` package |
110
+
111
+ **Math Methods**
112
+
113
+ | Feature | Supported | Notes |
114
+ | ------------------------- | :-------: | ------------------------------------------------- |
115
+ | Math.random | ✅ | Mapped to `rand.Float64()` |
116
+ | Math.floor / ceil / round | ✅ | Mapped to `math.Floor`, `math.Ceil`, `math.Round` |
117
+ | Math.abs / sqrt / pow | ✅ | Mapped to corresponding `math` functions |
118
+ | Math.min / max | ✅ | Mapped to `math.Min`, `math.Max` |
119
+
120
+ **String Methods**
121
+
122
+ | Feature | Supported | Notes |
123
+ | -------------------------- | :-------: | --------------------------------------------- |
124
+ | Template literals | ✅ | Backtick strings with `${expr}` interpolation |
125
+ | toUpperCase / toLowerCase | ✅ | Via `strings` package |
126
+ | trim / trimStart / trimEnd | ✅ | Via `strings` package |
127
+ | split / includes / indexOf | ✅ | Via `strings` package |
128
+ | startsWith / endsWith | ✅ | Via `strings` package |
129
+ | replace / replaceAll | ✅ | Via `strings` package |
130
+ | charAt / substring / slice | ✅ | Direct Go string indexing/slicing |
131
+ | concat / repeat | ✅ | String concatenation and `strings.Repeat` |
132
+
133
+ **Number / Object Methods**
134
+
135
+ | Feature | Supported | Notes |
136
+ | -------- | :-------: | ----------------------------------------------------- |
137
+ | toString | ✅ | Universal `toString()` via `fmt.Sprintf` for any type |
138
+
139
+ **RegExp**
140
+
141
+ | Feature | Supported | Notes |
142
+ | -------------- | :-------: | --------------------------------------------------- |
143
+ | Regex literals | ✅ | `/pattern/flags` transpiled to `regexp.MustCompile` |
144
+ | new RegExp() | ✅ | Constructor with optional flags |
145
+ | test() | ✅ | Mapped to `regexp.MatchString` |
146
+ | exec() | ✅ | Mapped to `regexp.FindStringSubmatch` |
147
+
148
+ **Unsupported / Roadmap**
149
+
150
+ | Feature | Supported | Notes |
151
+ | --------------- | :-------: | -------------------------------- |
152
+ | Modules/Imports | ❌ | `import` / `export` declarations |
153
+
154
+ TypeNative is currently in early development and new features are being added regularly. The goal for `1.0` release is for TypeNative to transpile itself.
package/bin/index.js CHANGED
@@ -8,143 +8,150 @@ import { fileURLToPath } from 'url';
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = path.dirname(__filename);
10
10
  (async function main() {
11
- const scriptMode = process.argv.findIndex((a) => a === '--script') > -1;
12
- const newCommand = process.argv.findIndex((a) => a === '--new') > -1;
13
- const sourceIndex = process.argv.findIndex((a) => a === '--source');
14
- const source = sourceIndex > -1 ? process.argv[sourceIndex + 1] : null;
15
- const outputIndex = process.argv.findIndex((a) => a === '--output');
16
- const output = outputIndex > -1 ? process.argv[outputIndex + 1] : null;
17
- const answers = await inquirer.prompt([
18
- {
19
- type: 'input',
20
- name: 'projectName',
21
- message: 'Enter Project Name:',
22
- when: newCommand,
23
- validate: (input) => input.trim() !== ''
24
- },
25
- {
26
- type: 'confirm',
27
- name: 'installDependencies',
28
- message: 'Do you want to install dependencies?',
29
- when: newCommand
30
- },
31
- {
32
- type: 'input',
33
- name: 'path',
34
- message: 'Enter Path to typescript main file:',
35
- when: !newCommand && !scriptMode && !source,
36
- validate: (input) => input.trim() !== ''
37
- },
38
- {
39
- type: 'input',
40
- name: 'output',
41
- message: 'Enter Output Path:',
42
- when: !newCommand && !scriptMode && !output,
43
- validate: (input) => input.trim() !== ''
44
- },
45
- {
46
- type: 'editor',
47
- name: 'tsCode',
48
- message: 'Write your typescript code here:',
49
- when: !newCommand && scriptMode && !source,
50
- default: `console.log('Hello, World!');`
51
- }
52
- ]);
53
- if (newCommand) {
54
- const projectName = answers.projectName.trim();
55
- await fs.ensureDir(projectName);
56
- await fs.writeFile(path.join(projectName, 'main.ts'), `// Write your TypeScript code here\nconsole.log('Hello, World!');\n`, { encoding: 'utf-8' });
57
- await fs.writeFile(path.join(projectName, 'tsconfig.json'), getTsConfig(), {
58
- encoding: 'utf-8'
59
- });
60
- await fs.writeFile(path.join(projectName, 'package.json'), getPackageJson(projectName), {
61
- encoding: 'utf-8'
62
- });
63
- await fs.writeFile(path.join(projectName, '.gitignore'), getGitIgnore(), {
64
- encoding: 'utf-8'
65
- });
66
- await fs.writeFile(path.join(projectName, 'README.md'), getReadMe(projectName), {
67
- encoding: 'utf-8'
68
- });
69
- console.log(`Project "${projectName}" created successfully!`);
70
- if (answers.installDependencies) {
71
- console.log('Installing dependencies...');
72
- await execa('npm install', { cwd: projectName, stdio: 'inherit' });
73
- console.log('Dependencies installed successfully!');
74
- }
75
- return;
11
+ const scriptMode = process.argv.findIndex((a) => a === '--script') > -1;
12
+ const newCommand = process.argv.findIndex((a) => a === '--new') > -1;
13
+ const sourceIndex = process.argv.findIndex((a) => a === '--source');
14
+ const source = sourceIndex > -1 ? process.argv[sourceIndex + 1] : null;
15
+ const outputIndex = process.argv.findIndex((a) => a === '--output');
16
+ const output = outputIndex > -1 ? process.argv[outputIndex + 1] : null;
17
+ const answers = await inquirer.prompt([
18
+ {
19
+ type: 'input',
20
+ name: 'projectName',
21
+ message: 'Enter Project Name:',
22
+ when: newCommand,
23
+ validate: (input) => input.trim() !== ''
24
+ },
25
+ {
26
+ type: 'confirm',
27
+ name: 'installDependencies',
28
+ message: 'Do you want to install dependencies?',
29
+ when: newCommand
30
+ },
31
+ {
32
+ type: 'input',
33
+ name: 'path',
34
+ message: 'Enter Path to typescript main file:',
35
+ when: !newCommand && !scriptMode && !source,
36
+ validate: (input) => input.trim() !== ''
37
+ },
38
+ {
39
+ type: 'input',
40
+ name: 'output',
41
+ message: 'Enter Output Path:',
42
+ when: !newCommand && !scriptMode && !output,
43
+ validate: (input) => input.trim() !== ''
44
+ },
45
+ {
46
+ type: 'editor',
47
+ name: 'tsCode',
48
+ message: 'Write your typescript code here:',
49
+ when: !newCommand && scriptMode && !source,
50
+ default: `console.log('Hello, World!');`
76
51
  }
77
- const tsCode = answers.tsCode
78
- ? answers.tsCode
79
- : await fs.readFile(source ?? answers.path, { encoding: 'utf-8' });
80
- const nativeCode = transpileToNative(tsCode);
81
- await fs.ensureDir('dist');
82
- await fs.writeFile('dist/code.go', nativeCode, { encoding: 'utf-8' });
83
- await execa('go build -o dist/native.exe dist/code.go', {
84
- stdio: 'inherit'
52
+ ]);
53
+ if (newCommand) {
54
+ const projectName = answers.projectName.trim();
55
+ await fs.ensureDir(projectName);
56
+ await fs.writeFile(
57
+ path.join(projectName, 'main.ts'),
58
+ `// Write your TypeScript code here\nconsole.log('Hello, World!');\n`,
59
+ { encoding: 'utf-8' }
60
+ );
61
+ await fs.writeFile(path.join(projectName, 'tsconfig.json'), getTsConfig(), {
62
+ encoding: 'utf-8'
85
63
  });
86
- // await fs.remove('dist/code.go');
87
- if (scriptMode) {
88
- await execa('dist/native.exe', {
89
- stdio: 'inherit'
90
- });
91
- //await fs.remove('dist/native.exe');
92
- }
93
- else if (output || answers.output) {
94
- await fs.copy('dist/native.exe', output ?? answers.output, { overwrite: true });
95
- //await fs.remove('dist/native.exe');
96
- console.log(`Created native executable at: ${output ?? answers.output}`);
64
+ await fs.writeFile(path.join(projectName, 'package.json'), getPackageJson(projectName), {
65
+ encoding: 'utf-8'
66
+ });
67
+ await fs.writeFile(path.join(projectName, '.gitignore'), getGitIgnore(), {
68
+ encoding: 'utf-8'
69
+ });
70
+ await fs.writeFile(path.join(projectName, 'README.md'), getReadMe(projectName), {
71
+ encoding: 'utf-8'
72
+ });
73
+ console.log(`Project "${projectName}" created successfully!`);
74
+ if (answers.installDependencies) {
75
+ console.log('Installing dependencies...');
76
+ await execa('npm', ['install'], { cwd: projectName, stdio: 'inherit' });
77
+ console.log('Dependencies installed successfully!');
97
78
  }
79
+ return;
80
+ }
81
+ const tsCode = answers.tsCode
82
+ ? answers.tsCode
83
+ : await fs.readFile(source ?? answers.path, { encoding: 'utf-8' });
84
+ const nativeCode = transpileToNative(tsCode);
85
+ const exeName = process.platform === 'win32' ? 'native.exe' : 'native';
86
+ const exePath = `dist/${exeName}`;
87
+ await fs.ensureDir('dist');
88
+ await fs.writeFile('dist/code.go', nativeCode, { encoding: 'utf-8' });
89
+ await execa('go', ['build', '-o', exePath, 'dist/code.go'], {
90
+ stdio: 'inherit'
91
+ });
92
+ // await fs.remove('dist/code.go');
93
+ if (scriptMode) {
94
+ await execa(exePath, {
95
+ stdio: 'inherit'
96
+ });
97
+ //await fs.remove(exePath);
98
+ } else if (output || answers.output) {
99
+ await fs.copy(exePath, output ?? answers.output, { overwrite: true });
100
+ //await fs.remove(exePath);
101
+ console.log(`Created native executable at: ${output ?? answers.output}`);
102
+ }
98
103
  })();
99
104
  function getPackageJson(projectName) {
100
- const pckg = {
101
- name: projectName,
102
- version: '1.0.0',
103
- scripts: {
104
- execute: 'npx typenative --source main.ts --script',
105
- build: `npx typenative --source main.ts --output bin/${projectName}.exe`
106
- },
107
- devDependencies: {
108
- typenative: '^0.0.16'
109
- }
110
- };
111
- return JSON.stringify(pckg, null, 2);
105
+ const exeName = process.platform === 'win32' ? `${projectName}.exe` : projectName;
106
+ const pckg = {
107
+ name: projectName,
108
+ version: '1.0.0',
109
+ scripts: {
110
+ execute: 'npx typenative --source main.ts --script',
111
+ build: `npx typenative --source main.ts --output bin/${exeName}`
112
+ },
113
+ devDependencies: {
114
+ typenative: '^0.0.16'
115
+ }
116
+ };
117
+ return JSON.stringify(pckg, null, 2);
112
118
  }
113
119
  function getTsConfig() {
114
- const tsConfig = {
115
- include: ['**/*.ts'],
116
- compilerOptions: {
117
- target: 'es2020',
118
- lib: [],
119
- types: ['./node_modules/typenative/types/typenative.d.ts'],
120
- rootDir: '.',
121
- strict: true,
122
- noImplicitAny: true
123
- }
124
- };
125
- return JSON.stringify(tsConfig, null, 2);
120
+ const tsConfig = {
121
+ include: ['**/*.ts'],
122
+ compilerOptions: {
123
+ target: 'es2020',
124
+ lib: [],
125
+ types: ['./node_modules/typenative/types/typenative.d.ts'],
126
+ rootDir: '.',
127
+ strict: true,
128
+ noImplicitAny: true
129
+ }
130
+ };
131
+ return JSON.stringify(tsConfig, null, 2);
126
132
  }
127
133
  function getGitIgnore() {
128
- return `# TypeNative generated files
129
- node_modules/
130
- dist/
131
- bin/
134
+ return `# TypeNative generated files
135
+ node_modules/
136
+ dist/
137
+ bin/
132
138
  `;
133
139
  }
134
140
  function getReadMe(projectName) {
135
- return `# ${projectName}
136
-
137
- This project was created using TypeNative, a tool to transpile TypeScript code to native Go code.
138
-
139
- ## How to Run
140
-
141
- You can write your TypeScript code in the \`main.ts\` file. The code will be transpiled to Go and compiled into a native executable.
142
- You can also run the code directly in script mode using \`npm run execute\`.
143
-
144
- ## How to Build
145
-
146
- 1. Install dependencies: \`npm install\` (if not done already)
147
- 2. Build the project: \`npm run build\`
148
- 3. Run the executable: \`./bin/${projectName}.exe\`
141
+ const exeName = process.platform === 'win32' ? `${projectName}.exe` : projectName;
142
+ return `# ${projectName}
143
+
144
+ This project was created using TypeNative, a tool to transpile TypeScript code to native Go code.
145
+
146
+ ## How to Run
147
+
148
+ You can write your TypeScript code in the \`main.ts\` file. The code will be transpiled to Go and compiled into a native executable.
149
+ You can also run the code directly in script mode using \`npm run execute\`.
150
+
151
+ ## How to Build
152
+
153
+ 1. Install dependencies: \`npm install\` (if not done already)
154
+ 2. Build the project: \`npm run build\`
155
+ 3. Run the executable: \`./bin/${exeName}\`
149
156
  `;
150
157
  }