├── bin
├── ns-upgrade-tsconfig.cmd
└── ns-upgrade-tsconfig
├── preuninstall.js
├── lib
├── after-watch.js
├── before-watchPatterns.js
├── watch.js
├── before-prepare.js
└── compiler.js
├── .gitignore
├── .github
├── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
└── pull_request_template.md
├── postinstall.js
├── package.json
├── CHANGELOG.md
├── README.md
├── tsconfig-upgrader.js
├── CONTRIBUTING.md
├── CODE_OF_CONDUCT.md
└── LICENSE
/bin/ns-upgrade-tsconfig.cmd:
--------------------------------------------------------------------------------
1 | @node %~dp0\ns-upgrade-tsconfig %*
2 |
--------------------------------------------------------------------------------
/preuninstall.js:
--------------------------------------------------------------------------------
1 | require('nativescript-hook')(__dirname).preuninstall();
2 |
--------------------------------------------------------------------------------
/lib/after-watch.js:
--------------------------------------------------------------------------------
1 | var compiler = require('./compiler');
2 |
3 | module.exports = function ($logger) {
4 | var tsc = compiler.getTscProcess();
5 | if (tsc) {
6 | $logger.trace("Stopping tsc watch");
7 | tsc.kill("SIGINT")
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/bin/ns-upgrade-tsconfig:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var path = require("path");
3 | var upgrader = require("../tsconfig-upgrader");
4 |
5 | var projectDir = path.dirname(path.dirname(path.dirname(__dirname)));
6 | var tsConfigPath = path.join(projectDir, "tsconfig.json");
7 | upgrader.migrateTsConfig(tsConfigPath, projectDir);
8 |
--------------------------------------------------------------------------------
/lib/before-watchPatterns.js:
--------------------------------------------------------------------------------
1 | module.exports = function (hookArgs) {
2 | if (hookArgs.liveSyncData && !hookArgs.liveSyncData.bundle) {
3 | return (args, originalMethod) => {
4 | return originalMethod(...args).then(originalPatterns => {
5 | originalPatterns.push("!**/*.ts");
6 |
7 | return originalPatterns;
8 | });
9 | };
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 | *.js.map
4 |
5 | coverage
6 | lib-cov
7 | *.seed
8 | *.log
9 | *.csv
10 | *.dat
11 | *.out
12 | *.pid
13 | *.gz
14 | *.tgz
15 | *.tmp
16 | *.sublime-workspace
17 | tscommand*.tmp.txt
18 | .tscache/
19 | /lib/.d.ts
20 |
21 | pids
22 | logs
23 | results
24 | scratch/
25 | .idea/
26 | .settings/
27 | .vscode/
28 | test-reports.xml
29 |
30 | npm-debug.log
31 | node_modules
32 | docs/html
--------------------------------------------------------------------------------
/lib/watch.js:
--------------------------------------------------------------------------------
1 | var compiler = require('./compiler');
2 |
3 | module.exports = function ($logger, $projectData, $errors, hookArgs) {
4 | if (hookArgs.config) {
5 | const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
6 | if (appFilesUpdaterOptions.bundle) {
7 | $logger.trace("Hook skipped because bundling is in progress.")
8 | return;
9 | }
10 | }
11 |
12 | return compiler.runTypeScriptCompiler($logger, $projectData.projectDir, { watch: true, release: $projectData.$options.release });
13 | }
14 |
--------------------------------------------------------------------------------
/lib/before-prepare.js:
--------------------------------------------------------------------------------
1 | var compiler = require('./compiler');
2 |
3 | module.exports = function ($logger, $projectData, $options, hookArgs) {
4 | var liveSync = !!compiler.getTscProcess();
5 | var appFilesUpdaterOptions = (hookArgs && hookArgs.appFilesUpdaterOptions) || {};
6 | var bundle = $options.bundle || appFilesUpdaterOptions.bundle;
7 |
8 | if (liveSync || bundle) {
9 | $logger.trace("Hook skipped because either bundling or livesync is in progress.")
10 | return;
11 | }
12 |
13 | var release = $options.release || appFilesUpdaterOptions.release;
14 | return compiler.runTypeScriptCompiler($logger, $projectData.projectDir, { release });
15 | }
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 |
9 |
10 | **Describe the solution you'd like**
11 |
12 |
13 | **Describe alternatives you've considered**
14 |
15 |
16 | **Additional context**
17 |
18 |
--------------------------------------------------------------------------------
/postinstall.js:
--------------------------------------------------------------------------------
1 | var hook = require("nativescript-hook")(__dirname);
2 | hook.postinstall();
3 |
4 | var fs = require("fs");
5 | var path = require("path");
6 | var upgrader = require("./tsconfig-upgrader");
7 |
8 | var projectDir = hook.findProjectDir();
9 | if (projectDir) {
10 | const tsconfigPath = path.join(projectDir, "tsconfig.json");
11 | if (fs.existsSync(tsconfigPath)) {
12 | upgrader.migrateTsConfig(tsconfigPath, projectDir);
13 | } else {
14 | createTsconfig(tsconfigPath);
15 | }
16 | }
17 |
18 | function createTsconfig(tsconfigPath) {
19 | var tsconfig = {};
20 |
21 | tsconfig.compilerOptions = {
22 | module: "commonjs",
23 | target: "es5",
24 | experimentalDecorators: true,
25 | emitDecoratorMetadata: true,
26 | noEmitHelpers: true,
27 | noEmitOnError: true,
28 | };
29 | upgrader.migrateProject(tsconfig, tsconfigPath, projectDir);
30 |
31 | tsconfig.exclude = ["node_modules", "platforms"];
32 |
33 | fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
34 | }
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativescript-dev-typescript",
3 | "version": "0.10.0",
4 | "description": "TypeScript support for NativeScript projects. Install using `tns install typescript`.",
5 | "scripts": {
6 | "test": "exit 0",
7 | "postinstall": "node postinstall.js",
8 | "preuninstall": "node preuninstall.js"
9 | },
10 | "bin": {
11 | "ns-upgrade-tsconfig": "./bin/ns-upgrade-tsconfig"
12 | },
13 | "nativescript": {
14 | "hooks": [
15 | {
16 | "type": "before-prepare",
17 | "script": "lib/before-prepare.js",
18 | "inject": true
19 | },
20 | {
21 | "type": "before-watchPatterns",
22 | "script": "lib/before-watchPatterns.js",
23 | "inject": true
24 | },
25 | {
26 | "type": "before-watch",
27 | "script": "lib/watch.js",
28 | "inject": true
29 | },
30 | {
31 | "type": "after-watch",
32 | "script": "lib/after-watch.js",
33 | "inject": true
34 | }
35 | ]
36 | },
37 | "license": "Apache-2.0",
38 | "repository": {
39 | "type": "git",
40 | "url": "https://github.com/NativeScript/nativescript-dev-typescript.git"
41 | },
42 | "dependencies": {
43 | "nativescript-hook": "^0.2.0",
44 | "semver": "5.5.0",
45 | "typescript": "~3.4.5"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 | ## PR Checklist
11 |
12 | - [ ] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages.
13 | - [ ] There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
14 | - [ ] All existing tests are passing
15 | - [ ] Tests for the changes are included
16 |
17 | ## What is the current behavior?
18 |
19 |
20 | ## What is the new behavior?
21 |
22 |
23 | Fixes/Implements/Closes #[Issue Number].
24 |
25 |
26 |
27 |
36 |
37 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: 'We really appreciate your effort to provide feedback. Before opening a new
4 | issue, please make sure that this case is not already reported in GitHub as an
5 | issue or in StackOverflow as a question.'
6 |
7 | ---
8 |
9 | **Environment**
10 | Provide version numbers for the following components (information can be retrieved by running `tns info` in your project folder or by inspecting the `package.json` of the project):
11 | - CLI:
12 | - Cross-platform modules:
13 | - Android Runtime:
14 | - iOS Runtime:
15 | - Plugin(s):
16 |
17 | **Describe the bug**
18 |
19 |
20 | **To Reproduce**
21 |
22 |
23 | **Expected behavior**
24 |
25 | **Sample project**
26 |
27 |
28 | **Additional context**
29 |
30 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### Bug Fixes
2 |
3 | * Non-meaningful messages are printed in the default output(https://github.com/NativeScript/nativescript-dev-typescript/issues/79))
4 |
5 | ## [0.8.0](https://github.com/NativeScript/nativescript-dev-typescript/compare/v0.7.4...v0.8.0) (2019-03-12)
6 |
7 |
8 | ## [0.7.4](https://github.com/NativeScript/nativescript-dev-typescript/compare/v0.7.3...v0.7.4) (2018-09-18)
9 |
10 |
11 | ### Bug Fixes
12 |
13 | * stop syncing TS files outside the app folder (e.g. plugins in node_modules)([0936a03](https://github.com/NativeScript/nativescript-dev-typescript/commit/0936a03)),
14 |
15 |
16 |
17 | ## [0.7.3](https://github.com/NativeScript/nativescript-dev-typescript/compare/v0.7.2...v0.7.3) (2018-08-21)
18 |
19 |
20 | ### Bug Fixes
21 |
22 | * respect nsconfig options when updating tsconfig on postinstall ([#61](https://github.com/NativeScript/nativescript-dev-typescript/issues/61)) ([396180c](https://github.com/NativeScript/nativescript-dev-typescript/commit/396180c)), closes [#60](https://github.com/NativeScript/nativescript-dev-typescript/issues/60)
23 |
24 |
25 |
26 |
27 | ## [0.7.2](https://github.com/NativeScript/nativescript-dev-typescript/compare/v0.7.1...v0.7.2) (2018-08-21)
28 |
29 | ### Bug Fixes
30 |
31 | * **watch:** add support for ts 2.9 ([8449614](https://github.com/NativeScript/nativescript-dev-typescript/commit/8449614))
32 |
33 |
34 |
35 | ## [0.7.1](https://github.com/NativeScript/nativescript-dev-typescript/compare/v0.7.0...v0.7.1) (2018-04-13)
36 |
37 | ### Bug Fixes
38 | * Console output is cleared when the TypeScript watcher is started.
39 |
40 |
41 | ## [0.4.5](https://github.com/NativeScript/nativescript-dev-typescript/compare/0.4.4...0.4.5) (2017-05-17)
42 |
43 |
44 | ### Bug Fixes
45 |
46 | * **postinstall:** upgrader respects existing tsconfig paths ([#33](https://github.com/NativeScript/nativescript-dev-typescript/issues/33)) ([b6fbcaa](https://github.com/NativeScript/nativescript-dev-typescript/commit/b6fbcaa)), closes [#32](https://github.com/NativeScript/nativescript-dev-typescript/issues/32)
47 |
48 |
49 |
50 |
51 | ## [0.4.4](https://github.com/NativeScript/nativescript-dev-typescript/compare/0.4.3...0.4.4) (2017-05-10)
52 |
53 |
54 | ### Bug Fixes
55 |
56 | * **postinstall:** update TS version on NS3 only if <2.2 ([#31](https://github.com/NativeScript/nativescript-dev-typescript/issues/31)) ([95bd5e8](https://github.com/NativeScript/nativescript-dev-typescript/commit/95bd5e8))
57 |
58 |
59 |
60 |
61 | ## 0.4.3 (2017-05-09)
62 |
63 | ### Features
64 |
65 | * **postinstall:** force update TypeScript if you use NS 3.0 ([#29](https://github.com/NativeScript/nativescript-dev-typescript/issues/29)) ([cd7e8a5](https://github.com/NativeScript/nativescript-dev-typescript/commit/cd7e8a5))
66 |
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NativeScript TypeScript
2 |
3 | ## `nativescript-dev-typescript` is deprecated in favour of `bundle` workflow, which will be introduced with CLI v6.0. More info about the upcoming new approach can be found [here](https://www.nativescript.org/blog/the-future-of-building-nativescript-apps).
4 |
5 | A package providing TypeScript support for NativeScript.
6 |
7 | [NativeScript](https://www.nativescript.org/) is a framework which enables developers to write truly native mobile applications for Android and iOS using JavaScript and CSS. [Angular](https://angular.io/) is one of the most popular open source JavaScript frameworks for application development. We [worked closely with developers at Google](http://angularjs.blogspot.bg/2015/12/building-mobile-apps-with-angular-2-and.html) to make Angular in NativeScript a reality. The result is a software architecture that allows you to build mobile apps using the same framework—and in some cases the same code—that you use to build Angular web apps, with the performance you’d expect from native code. [Read more about building truly native mobile apps with NativeScript and Angular](https://docs.nativescript.org/tutorial/ng-chapter-0).
8 |
9 | ## How to use in NativeScript projects
10 |
11 | ```
12 | $ npm install -D nativescript-dev-typescript
13 | ```
14 |
15 | The above command adds `nativescript-dev-typescript` package as dev dependency and installs the necessary hooks. TypeScript compilation happens when the project is prepared for build. A file named `tsconfig.json` that specifies compilation options will be created in the project folder and should be committed to source control. [Read more about tsconfig.json options](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
16 |
17 | ## How it works
18 |
19 | When the plugin installed what it will do out of the box is to add
20 | - `tsconfig.json` file to the project (if it doesn't exist),
21 | - `typescript` as dev dependency
22 | - `before-prepare` hook which takes care to transpile all files before preparing your project
23 | - `before-watch` hook to start the typescript watcher and transpile on every typescript change during project livesync
24 | - `after-watch` hook to stop the typescript watcher after the livesync is stopped
25 |
26 | ## How to use in NativeScript plugins
27 |
28 | This package is not meant to be used in plugins. It's applicable for NativeScript projects only.
29 |
30 | ## Contribute
31 | We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/nativescript-dev-typescript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
32 |
33 | ## Get Help
34 | Please, use [github issues](https://github.com/NativeScript/nativescript-dev-typescript/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-features). For general questions and support, check out the [NativeScript community forum](https://discourse.nativescript.org/) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation).
35 |
36 | 
37 |
--------------------------------------------------------------------------------
/tsconfig-upgrader.js:
--------------------------------------------------------------------------------
1 | var fs = require("fs");
2 | var path = require("path");
3 |
4 | var __migrations = [
5 | inlineSourceMapMigration,
6 | addDomLibs,
7 | addIterableToAngularProjects,
8 | addTnsCoreModulesPathMappings,
9 | ];
10 |
11 | function migrateProject(tsConfig, tsconfigPath, projectDir) {
12 | var displayableTsconfigPath = path.relative(projectDir, tsconfigPath);
13 | __migrations.forEach(function (migration) {
14 | migration(tsConfig, displayableTsconfigPath, projectDir);
15 | });
16 | }
17 | exports.migrateProject = migrateProject;
18 |
19 | function migrateTsConfig(tsconfigPath, projectDir) {
20 | var displayableTsconfigPath = path.relative(projectDir, tsconfigPath);
21 |
22 | function withTsConfig(action) {
23 | var existingConfig = null;
24 | try {
25 | var existingConfigContents = fs.readFileSync(tsconfigPath);
26 | existingConfig = JSON.parse(existingConfigContents);
27 | } catch (e) {
28 | console.error("Invalid " + displayableTsconfigPath + ": " + e);
29 | return;
30 | }
31 | action(existingConfig);
32 | fs.writeFileSync(tsconfigPath, JSON.stringify(existingConfig, null, 4));
33 | }
34 |
35 | withTsConfig(function (existingConfig) {
36 | migrateProject(existingConfig, displayableTsconfigPath, projectDir);
37 | });
38 | }
39 | exports.migrateTsConfig = migrateTsConfig;
40 |
41 | function inlineSourceMapMigration(existingConfig, displayableTsconfigPath) {
42 | if (existingConfig.compilerOptions) {
43 | if ("sourceMap" in existingConfig["compilerOptions"]) {
44 | delete existingConfig["compilerOptions"]["sourceMap"];
45 | console.warn("> Deleted \"compilerOptions.sourceMap\" setting in \"" + displayableTsconfigPath + "\".");
46 | console.warn("> Inline source maps will be used when building in Debug configuration from now on.");
47 | }
48 | }
49 | }
50 |
51 | function addIterableToAngularProjects(existingConfig, displayableTsconfigPath, projectDir) {
52 | var packageJsonPath = path.join(projectDir, "package.json");
53 | var packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
54 | var dependencies = packageJson.dependencies || [];
55 |
56 | var hasAngular = Object.keys(dependencies).includes("nativescript-angular");
57 | if (hasAngular) {
58 | console.log("Adding 'es2015.iterable' lib to tsconfig.json...");
59 | addTsLib(existingConfig, "es2015.iterable");
60 | }
61 | }
62 |
63 | function addDomLibs(existingConfig, displayableTsconfigPath, projectDir) {
64 | console.log("Adding 'es6' lib to tsconfig.json...");
65 | addTsLib(existingConfig, "es6");
66 | console.log("Adding 'dom' lib to tsconfig.json...");
67 | addTsLib(existingConfig, "dom");
68 | }
69 |
70 | function addTsLib(existingConfig, libName) {
71 | if (existingConfig.compilerOptions) {
72 | var options = existingConfig.compilerOptions;
73 | if (!options.lib) {
74 | options.lib = [];
75 | }
76 | if (!options.lib.find(function (l) {
77 | return libName.toLowerCase() === l.toLowerCase();
78 | })) {
79 | options.lib.push(libName);
80 | }
81 | }
82 | }
83 |
84 | function addTnsCoreModulesPathMappings(existingConfig, displayableTsconfigPath, projectDir) {
85 | console.log("Adding tns-core-modules path mappings lib to tsconfig.json...");
86 | existingConfig["compilerOptions"] = existingConfig["compilerOptions"] || {};
87 | var compilerOptions = existingConfig["compilerOptions"];
88 | compilerOptions["baseUrl"] = ".";
89 | compilerOptions["paths"] = compilerOptions["paths"] || {};
90 |
91 | const appPath = getAppPath(projectDir);
92 | compilerOptions["paths"]["~/*"] = compilerOptions["paths"]["~/*"] || [
93 | `${appPath}/*`
94 | ];
95 | }
96 |
97 | function getAppPath(projectDir) {
98 | const DEFAULT_PATH = "app";
99 | const nsConfigPath = path.join(projectDir, "nsconfig.json");
100 |
101 | try {
102 | const nsConfig = JSON.parse(fs.readFileSync(nsConfigPath));
103 | const appPath = nsConfig && nsConfig.appPath;
104 | return appPath || DEFAULT_PATH;
105 | } catch (_) {
106 | return DEFAULT_PATH;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to nativescript-dev-typescript
2 |
3 | :+1: First of all, thank you for taking the time to contribute! :+1:
4 |
5 | Here are some guides on how to do that:
6 |
7 |
8 |
9 | - [Code of Conduct](#code-of-conduct)
10 | - [Reporting Bugs](#reporting-bugs)
11 | - [Requesting Features](#requesting-features)
12 | - [Submitting a PR](#submitting-a-pr)
13 | - [Where to Start](#where-to-start)
14 |
15 |
16 |
17 | ## Code of Conduct
18 | Help us keep a healthy and open community. We expect all participants in this project to adhere to the [NativeScript Code Of Conduct](https://github.com/NativeScript/codeofconduct).
19 |
20 |
21 | ## Reporting Bugs
22 |
23 | 1. Always update to the most recent master release; the bug may already be resolved.
24 | 2. Search for similar issues in the issues list for this repo; it may already be an identified problem.
25 | 3. If this is a bug or problem that is clear, simple, and is unlikely to require any discussion -- it is OK to open an issue on GitHub with a reproduction of the bug including workflows and screenshots. If possible, submit a Pull Request with a failing test, entire application or module. If you'd rather take matters into your own hands, fix the bug yourself (jump down to the [Submitting a PR](#submitting-a-pr) section).
26 |
27 | ## Requesting Features
28 |
29 | 1. Use Github Issues to submit feature requests.
30 | 2. First, search for a similar request and extend it if applicable. This way it would be easier for the community to track the features.
31 | 3. When requesting a new feature, please provide as much detail as possible about why you need the feature in your apps. We prefer that you explain a need rather than explain a technical solution for it. That might trigger a nice conversation on finding the best and broadest technical solution to a specific need.
32 |
33 | ## Submitting a PR
34 |
35 | Before you begin:
36 | * Read and sign the [NativeScript Contribution License Agreement](http://www.nativescript.org/cla).
37 | * Make sure there is an issue for the bug or feature you will be working on.
38 |
39 | Following these steps is the best way to get you code included in the project:
40 |
41 | 1. Fork and clone the nativescript-dev-typescript repo:
42 | ```bash
43 | git clone https://github.com//nativescript-dev-typescript.git
44 | # Navigate to the newly cloned directory
45 | cd nativescript-dev-typescript
46 | # Add an "upstream" remote pointing to the original {N} repo.
47 | git remote add upstream https://github.com/NativeScript/nativescript-dev-typescript.git
48 | ```
49 |
50 | 2. Set up the project:
51 |
52 | ```bash
53 | # In the repo root
54 | npm install --ignore-scripts
55 | ```
56 |
57 | 3. Create a branch for your PR
58 | ```bash
59 | git checkout -b master
60 | ```
61 |
62 | 4. The fun part! Make your code changes. Make sure you:
63 | - Follow the [NativeScript code conventions guide](https://github.com/NativeScript/NativeScript/blob/master/CodingConvention.md).
64 | - Follow the [commit message guidelines](https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#-commit-message-guidelines).
65 |
66 | 5. Before you submit your PR:
67 | - Rebase your changes to the latest master: `git pull --rebase upstream master`.
68 | - Ensure your changes pass tslint validation. (run `npm run tslint` in the root of the repo).
69 |
70 | 6. Push your fork. If you have rebased you might have to use force-push your branch:
71 | ```
72 | git push origin --force
73 | ```
74 |
75 | 7. [Submit your pull request](https://github.com/NativeScript/nativescript-dev-typescript/compare). Please, fill in the Pull Request template - it will help us better understand the PR and increase the chances of it getting merged quickly.
76 |
77 | It's our turn from there on! We will review the PR and discuss changes you might have to make before merging it! Thanks!
78 |
79 |
80 | ## Where to Start
81 |
82 | If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/nativescript-dev-typescript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
83 |
--------------------------------------------------------------------------------
/lib/compiler.js:
--------------------------------------------------------------------------------
1 | exports.runTypeScriptCompiler = runTypeScriptCompiler;
2 | exports.getTscProcess = getTscProcess;
3 |
4 | var spawn = require('child_process').spawn;
5 | var fs = require('fs');
6 | var path = require('path');
7 | var semver = require('semver');
8 | var tsc = null;
9 | var TscCompilationCompleteMessage = "watching for file changes";
10 | var TscWatcherInfoMessages = [
11 | "file change detected",
12 | "starting incremental compilation",
13 | TscCompilationCompleteMessage
14 | ];
15 |
16 | function getTypeScriptVersion(typeScriptPath) {
17 | try {
18 | return require(path.join(typeScriptPath, 'package.json')).version;
19 | } catch (err) { }
20 |
21 | return null;
22 | }
23 |
24 | function shouldPreserveWatchOutput(typeScriptVersion) {
25 | try {
26 | return semver.gte(typeScriptVersion, "2.8.1");
27 | } catch (err) { }
28 |
29 | return false;
30 | }
31 |
32 | function runTypeScriptCompiler(logger, projectDir, options) {
33 | return new Promise(function (resolve, reject) {
34 | options = options || {};
35 |
36 | var peerTypescriptPath = path.join(__dirname, '../../typescript');
37 | var tscPath = path.join(peerTypescriptPath, 'lib/tsc.js');
38 | var typeScriptVersion = getTypeScriptVersion(peerTypescriptPath);
39 |
40 | if (fs.existsSync(tscPath)) {
41 | logger.info(`Found peer TypeScript ${typeScriptVersion}`);
42 | } else {
43 | throw Error('TypeScript installation local to project was not found. Install by executing `npm install typescript`.');
44 | }
45 |
46 | var tsconfigPath = path.join(projectDir, 'tsconfig.json');
47 | if (!fs.existsSync(tsconfigPath)) {
48 | throw Error('No tsconfig.json file found in project.');
49 | }
50 |
51 | var nodeArgs = ['--max_old_space_size=4096', tscPath, '--project', projectDir];
52 | if (options.watch) {
53 | nodeArgs.push('--watch');
54 | }
55 |
56 | if (!options.release) {
57 | // For debugging in Chrome DevTools
58 | nodeArgs.push('--inlineSourceMap', '--inlineSources');
59 | }
60 |
61 | if (shouldPreserveWatchOutput(typeScriptVersion)) {
62 | nodeArgs.push('--preserveWatchOutput');
63 | }
64 |
65 | const logLevel = logger.getLevel();
66 | const isTraceLogLevel = logLevel && /trace/i.test(logLevel);
67 | if (isTraceLogLevel) {
68 | nodeArgs.push("--listEmittedFiles");
69 | }
70 |
71 | logger.trace(process.execPath, nodeArgs.join(' '));
72 | tsc = spawn(process.execPath, nodeArgs);
73 |
74 | var isResolved = false;
75 | tsc.stdout.on('data', function (data) {
76 | var stringData = data.toString();
77 | // Prevent console clear. Fixed the behaviour for typescript 2.7.1 and 2.7.2. Should be deleted after dropping support for 2.7.x version.
78 | // https://github.com/Microsoft/TypeScript/blob/master/src/compiler/sys.ts#L623
79 | let filteredData = stringData
80 | .split("\n")
81 | .map(row => row.replace("\x1Bc", ""))
82 | .filter(r => !!r)
83 | .join("\n");
84 |
85 | if (filteredData) {
86 | var infoMessage = TscWatcherInfoMessages.find((info) => filteredData.toLowerCase().indexOf(info) !== -1);
87 | if (infoMessage) {
88 | if (options.watch && !isResolved && infoMessage === TscCompilationCompleteMessage) {
89 | isResolved = true;
90 | resolve();
91 | }
92 |
93 | // ignore these info messages as they are spamming the CLI output
94 | // on each file generated in the platforms folder during prepare
95 | return;
96 | }
97 |
98 | if (isTraceLogLevel) {
99 | logger.trace(filteredData);
100 | }
101 |
102 | // https://github.com/Microsoft/TypeScript/blob/e53e56cf8212e45d0ebdd6affe462d161c7e0dc5/src/compiler/watch.ts#L160
103 | if (!isTraceLogLevel && filteredData.indexOf("error") !== -1) {
104 | logger.info(filteredData);
105 | }
106 | }
107 |
108 | });
109 |
110 | tsc.stderr.on('data', function (data) {
111 | logger.info(data.toString());
112 | });
113 |
114 | tsc.on('error', function (err) {
115 | logger.info(err.message);
116 | if (!isResolved) {
117 | isResolved = true;
118 | reject(err);
119 | }
120 | });
121 |
122 | // TODO: Consider using close event instead of exit
123 | tsc.on('exit', function (code, signal) {
124 | tsc = null;
125 | if (!isResolved) {
126 | isResolved = true;
127 | // ExitStatus enum in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L2620
128 | if (code === 0 || code === 2) {
129 | resolve();
130 | } else {
131 | reject(new Error('TypeScript compiler failed with exit code ' + code));
132 | }
133 | }
134 | });
135 | });
136 | }
137 |
138 | function getTscProcess() {
139 | return tsc;
140 | }
141 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # NativeScript Community Code of Conduct
2 |
3 | Our community members come from all walks of life and are all at different stages of their personal and professional journeys. To support everyone, we've prepared a short code of conduct. Our mission is best served in an environment that is friendly, safe, and accepting; free from intimidation or harassment.
4 |
5 | Towards this end, certain behaviors and practices will not be tolerated.
6 |
7 | ## tl;dr
8 |
9 | - Be respectful.
10 | - We're here to help.
11 | - Abusive behavior is never tolerated.
12 | - Violations of this code may result in swift and permanent expulsion from the NativeScript community channels.
13 |
14 | ## Administrators
15 |
16 | - Dan Wilson (@DanWilson on Slack)
17 | - Jen Looper (@jen.looper on Slack)
18 | - TJ VanToll (@tjvantoll on Slack)
19 |
20 | ## Scope
21 |
22 | We expect all members of the NativeScript community, including administrators, users, facilitators, and vendors to abide by this Code of Conduct at all times in our community venues, online and in person, and in one-on-one communications pertaining to NativeScript affairs.
23 |
24 | This policy covers the usage of the NativeScript Slack community, as well as the NativeScript support forums, NativeScript GitHub repositories, the NativeScript website, and any NativeScript-related events. This Code of Conduct is in addition to, and does not in any way nullify or invalidate, any other terms or conditions related to use of NativeScript.
25 |
26 | The definitions of various subjective terms such as "discriminatory", "hateful", or "confusing" will be decided at the sole discretion of the NativeScript administrators.
27 |
28 | ## Friendly, Harassment-Free Space
29 |
30 | We are committed to providing a friendly, safe, and welcoming environment for all, regardless of gender identity, sexual orientation, disability, ethnicity, religion, age, physical appearance, body size, race, or similar personal characteristics.
31 |
32 | We ask that you please respect that people have differences of opinion regarding technical choices, and acknowledge that every design or implementation choice carries a trade-off and numerous costs. There is seldom a single right answer. A difference of technology preferences is never a license to be rude.
33 |
34 | Any spamming, trolling, flaming, baiting, or other attention-stealing behaviour is not welcome, and will not be tolerated.
35 |
36 | Harassing other users of NativeScript is never tolerated, whether via public or private media.
37 |
38 | Avoid using offensive or harassing package names, nicknames, or other identifiers that might detract from a friendly, safe, and welcoming environment for all.
39 |
40 | Harassment includes, but is not limited to: harmful or prejudicial verbal or written comments related to gender identity, sexual orientation, disability, ethnicity, religion, age, physical appearance, body size, race, or similar personal characteristics; inappropriate use of nudity, sexual images, and/or sexually explicit language in public spaces; threats of physical or non-physical harm; deliberate intimidation, stalking or following; harassing photography or recording; sustained disruption of talks or other events; inappropriate physical contact; and unwelcome sexual attention.
41 |
42 | ## Acceptable Content
43 |
44 | The NativeScript administrators reserve the right to make judgement calls about what is and isn't appropriate in published content. These are guidelines to help you be successful in our community.
45 |
46 | Content must contain something applicable to the previously stated goals of the NativeScript community. "Spamming", that is, publishing any form of content that is not applicable, is not allowed.
47 |
48 | Content must not contain illegal or infringing content. You should only publish content to NativeScript properties if you have the right to do so. This includes complying with all software license agreements or other intellectual property restrictions. For example, redistributing an MIT-licensed module with the copyright notice removed, would not be allowed. You will be responsible for any violation of laws or others’ intellectual property rights.
49 |
50 | Content must not be malware. For example, content (code, video, pictures, words, etc.) which is designed to maliciously exploit or damage computer systems, is not allowed.
51 |
52 | Content name, description, and other visible metadata must not include abusive, inappropriate, or harassing content.
53 |
54 | ## Reporting Violations of this Code of Conduct
55 |
56 | If you believe someone is harassing you or has otherwise violated this Code of Conduct, please contact the administrators and send us an abuse report. If this is the initial report of a problem, please include as much detail as possible. It is easiest for us to address issues when we have more context.
57 |
58 | ## Consequences
59 |
60 | All content published to the NativeScript community channels is hosted at the sole discretion of the NativeScript administrators.
61 |
62 | Unacceptable behavior from any community member, including sponsors, employees, customers, or others with decision-making authority, will not be tolerated.
63 |
64 | Anyone asked to stop unacceptable behavior is expected to comply immediately.
65 |
66 | If a community member engages in unacceptable behavior, the NativeScript administrators may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event or service).
67 |
68 | ## Addressing Grievances
69 |
70 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify the administrators. We will do our best to ensure that your grievance is handled appropriately.
71 |
72 | In general, we will choose the course of action that we judge as being most in the interest of fostering a safe and friendly community.
73 |
74 | ## Contact Info
75 | Please contact Dan Wilson @DanWilson if you need to report a problem or address a grievance related to an abuse report.
76 |
77 | You are also encouraged to contact us if you are curious about something that might be "on the line" between appropriate and inappropriate content. We are happy to provide guidance to help you be a successful part of our community.
78 |
79 | ## Credit and License
80 |
81 | This Code of Conduct borrows heavily from the WADE Code of Conduct, which is derived from the NodeBots Code of Conduct, which in turn borrows from the npm Code of Conduct, which was derived from the Stumptown Syndicate Citizen's Code of Conduct, and the Rust Project Code of Conduct.
82 |
83 | This document may be reused under a Creative Commons Attribution-ShareAlike License.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright (c) 2015-2019 Progress Software Corporation
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------