diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6e87a00 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..3856c8c --- /dev/null +++ b/.eslintrc @@ -0,0 +1,41 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "module", + "project": "./tsconfig.base.json" + }, + "ignorePatterns": ["**/*"], + "plugins": ["@typescript-eslint", "@nrwl/nx"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/@typescript-eslint" + ], + "rules": { + "@typescript-eslint/explicit-member-accessibility": "off", + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-parameter-properties": "off", + "@nrwl/nx/enforce-module-boundaries": [ + "error", + { + "enforceBuildableLibDependency": true, + "allow": [], + "depConstraints": [ + { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] } + ] + } + ] + }, + "overrides": [ + { + "files": ["*.tsx"], + "rules": { + "@typescript-eslint/no-unused-vars": "off" + } + } + ] +} diff --git a/.github/issue_template.md b/.github/issue_template.md deleted file mode 100644 index d103b9f..0000000 --- a/.github/issue_template.md +++ /dev/null @@ -1,28 +0,0 @@ -### Make sure to check the demo app(s) for sample usage - -### Make sure to check the existing issues in this repository - -### If the demo apps cannot help and there is no issue for your problem, tell us about it -Please, ensure your title is less than 63 characters long and starts with a capital -letter. - -### Which platform(s) does your issue occur on? -- iOS/Android/Both -- iOS/Android versions -- emulator or device. What type of device? - -### Please, provide the following version numbers that your issue occurs with: - -- CLI: (run `tns --version` to fetch it) -- Cross-platform modules: (check the 'version' attribute in the -`node_modules/tns-core-modules/package.json` file in your project) -- Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project) -- Plugin(s): (look for the version numbers in the `package.json` file of your -project and paste your dependencies and devDependencies here) - -### Please, tell us how to recreate the issue in as much detail as possible. -Describe the steps to reproduce it. - -### Is there any code involved? - - provide a code example to recreate the problem - - (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index e1becd3..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,36 +0,0 @@ - - - - - -## PR Checklist - -- [ ] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages. -- [ ] 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. -- [ ] All existing tests are passing -- [ ] Tests for the changes are included - -## What is the current behavior? - - -## What is the new behavior? - - -Fixes/Implements/Closes #[Issue Number]. - - - - - diff --git a/.gitignore b/.gitignore index 5f5c757..ea0c923 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,44 @@ -.vscode -.idea -.DS_Store -*.esm.json -*.js -*.js.map -*.log -src/*.d.ts -!src/index.d.ts -!src/references.d.ts -!src/scripts/*.js -!seed-tests/*.js -seed-tests/seed-copy -seed-tests/seed-copy-new-git-repo/**/*.* -!demo/karma.conf.js -!demo/app/tests/*.js -demo/*.d.ts -!demo/references.d.ts -demo/lib -demo/platforms +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc + +# dependencies node_modules -publish/src -publish/package -demo/report/report.html -demo/report/stats.json -!demo-vue/app/app.js \ No newline at end of file +package-lock.json +yarn.lock + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db + +*.tgz +packages/**/angular/dist diff --git a/.npsrc b/.npsrc new file mode 100644 index 0000000..12f87dc --- /dev/null +++ b/.npsrc @@ -0,0 +1,3 @@ +{ + "config": "./tools/workspace-scripts.js" +} \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..413ca14 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +# Add files here to ignore them from prettier formatting + +/dist +/coverage +native-src diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4a9f8e0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "useTabs": true, + "printWidth": 600, + "tabWidth": 2, + "singleQuote": true +} diff --git a/.travis.yml b/.travis.yml index abe28a9..8c3d1ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,187 +1,6 @@ -branches: - only: - - master -env: - global: - - ANDROID_PACKAGE_JS='seed-js.apk' - - ANDROID_PACKAGE_FOLDER_JS=$TRAVIS_BUILD_DIR/demo/outputs - - ANDROID_PACKAGE_NG='seed-ng.apk' - - ANDROID_PACKAGE_FOLDER_NG=$TRAVIS_BUILD_DIR/demo-angular/outputs - - ANDROID_SAUCE_STORAGE="https://saucelabs.com/rest/v1/storage/$SAUCE_USER" - - IOS_PACKAGE_JS='seed-js.zip' - - IOS_PACKAGE_FOLDER_JS=$TRAVIS_BUILD_DIR/demo/outputs - - IOS_PACKAGE_NG='seed-ng.zip' - - IOS_PACKAGE_FOLDER_NG=$TRAVIS_BUILD_DIR/demo-angular/outputs - - IOS_SAUCE_STORAGE="https://saucelabs.com/rest/v1/storage/$SAUCE_USER" - -matrix: - include: - - stage: "Lint" - language: node_js - os: linux - node_js: "10" - script: cd src && npm run ci.tslint - - stage: "Build and Test" - env: - - BuildAndroid="29" - - NodeJs="8" - - Type="TypeScript" - language: android - dist: trusty - os: linux - jdk: oraclejdk8 - before_install: nvm install 8 - script: - - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n - - npm run build - - cd ../demo - - tns build android - - env: - - BuildAndroid="29" - - Type="TypeScript" - language: android - dist: trusty - os: linux - jdk: oraclejdk8 - before_install: nvm install 10 - script: - - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n - - npm run tsc - - cd ../demo - - travis_wait travis_retry tns build android --copy-to "$ANDROID_PACKAGE_FOLDER_JS/$ANDROID_PACKAGE_JS" - - "curl -u $SAUCE_USER:$SAUCE_KEY -X POST -H 'Content-Type: application/octet-stream' $ANDROID_SAUCE_STORAGE/$ANDROID_PACKAGE_JS?overwrite=true --data-binary @$ANDROID_PACKAGE_FOLDER_JS/$ANDROID_PACKAGE_JS" - - os: osx - env: - - BuildiOS="12.0" - - Type="TypeScript" - osx_image: xcode11.2 - language: node_js - node_js: "10" - jdk: oraclejdk8 - script: - - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n - - npm run tsc - - cd ../demo - - travis_wait travis_retry tns build ios --copy-to "./outputs/demo.app" - - cd $IOS_PACKAGE_FOLDER_JS && zip -r $IOS_PACKAGE_JS demo.app - - "curl -u $SAUCE_USER:$SAUCE_KEY -X POST -H 'Content-Type: application/octet-stream' $IOS_SAUCE_STORAGE/$IOS_PACKAGE_JS?overwrite=true --data-binary @$IOS_PACKAGE_FOLDER_JS/$IOS_PACKAGE_JS" - - os: linux - env: - - BuildAndroid="29" - - Type="Angular" - language: android - dist: trusty - jdk: oraclejdk8 - before_install: nvm install 10 - script: - - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=n includeAngularDemo=y - - npm run tsc - - cd ../demo-angular - - travis_wait travis_retry tns build android --copy-to "$ANDROID_PACKAGE_FOLDER_NG/$ANDROID_PACKAGE_NG" - - "curl -u $SAUCE_USER:$SAUCE_KEY -X POST -H 'Content-Type: application/octet-stream' $ANDROID_SAUCE_STORAGE/$ANDROID_PACKAGE_NG?overwrite=true --data-binary @$ANDROID_PACKAGE_FOLDER_NG/$ANDROID_PACKAGE_NG" - - os: osx - env: - - BuildiOS="12.0" - - Type="Angular" - osx_image: xcode11.2 - language: node_js - node_js: "10" - jdk: oraclejdk8 - script: - - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=n includeAngularDemo=y - - npm run tsc - - cd ../demo-angular - - travis_wait travis_retry tns build ios --copy-to "./outputs/demo-angular.app" - - cd $IOS_PACKAGE_FOLDER_NG && zip -r $IOS_PACKAGE_NG demo-angular.app - - "curl -u $SAUCE_USER:$SAUCE_KEY -X POST -H 'Content-Type: application/octet-stream' $IOS_SAUCE_STORAGE/$IOS_PACKAGE_NG?overwrite=true --data-binary @$IOS_PACKAGE_FOLDER_NG/$IOS_PACKAGE_NG" - - os: linux - language: android - dist: trusty - env: - - UnitTests="Android" - - TestVersion="latest" - jdk: oraclejdk8 - before_install: - - nvm install 10 - before_script: - - cd seed-tests && npm i - - android list targets - - echo no | android create avd --force -n test -t android-21 -b armeabi-v7a - - emulator -avd test -no-audio -no-window & - - android-wait-for-emulator - script: - - travis_wait travis_retry npm run test.android - - os: osx - env: - - UnitTests="iOS" - - TestVersion="latest" - language: node_js - node_js: "10" - jdk: oraclejdk8 - osx_image: xcode11.2 - before_script: - - cd seed-tests && npm i - script: - - travis_wait travis_retry npm run test.ios - - stage: "UI Tests" - env: - - Android="24" - - Type="TypeScript" - language: node_js - os: linux - node_js: "10" - script: - - npm i -g appium - - cd seed-tests && npm i - - travis_wait travis_retry npm run e2e -- --runType android24 --sauceLab --appPath $ANDROID_PACKAGE_JS - - os: linux - env: - - Android="24" - - Type="Angular" - language: node_js - os: linux - node_js: "10" - script: - - npm i -g appium - - cd seed-tests && npm i - - travis_wait travis_retry npm run e2e -- --runType android24 --sauceLab --appPath $ANDROID_PACKAGE_NG - - os: linux - env: - - iOS="12.0" - - Type="TypeScript" - language: node_js - node_js: "10" - script: - - npm i -g appium - - cd seed-tests && npm i - - travis_wait travis_retry npm run e2e -- --runType sim12iPhoneX --sauceLab --appPath $IOS_PACKAGE_JS - - os: linux - env: - - iOS="12.0" - - Type="Angular" - language: node_js - node_js: "10" - script: - - npm i -g appium - - cd seed-tests && npm i - - travis_wait travis_retry npm run e2e -- --runType sim12iPhoneX --sauceLab --appPath $IOS_PACKAGE_NG - - -android: - components: - - tools - - platform-tools - - build-tools-29.0.2 - - android-21 - - android-29 - - extra-android-m2repository - - sys-img-armeabi-v7a-android-21 - -before_install: - - sudo pip install --upgrade pip - - sudo pip install six - -install: - - echo no | npm install -g nativescript - - tns usage-reporting disable - - tns error-reporting disable +language: node_js +node_js: + - "node" +script: +- npm run setup +- npm start @nativescript.build-all diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 1c845d0..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,83 +0,0 @@ -# NativeScript Community Code of Conduct - -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. - -Towards this end, certain behaviors and practices will not be tolerated. - -## tl;dr - -- Be respectful. -- We're here to help. -- Abusive behavior is never tolerated. -- Violations of this code may result in swift and permanent expulsion from the NativeScript community channels. - -## Administrators - -- Dan Wilson (@DanWilson on Slack) -- Jen Looper (@jen.looper on Slack) -- TJ VanToll (@tjvantoll on Slack) - -## Scope - -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. - -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. - -The definitions of various subjective terms such as "discriminatory", "hateful", or "confusing" will be decided at the sole discretion of the NativeScript administrators. - -## Friendly, Harassment-Free Space - -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. - -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. - -Any spamming, trolling, flaming, baiting, or other attention-stealing behaviour is not welcome, and will not be tolerated. - -Harassing other users of NativeScript is never tolerated, whether via public or private media. - -Avoid using offensive or harassing package names, nicknames, or other identifiers that might detract from a friendly, safe, and welcoming environment for all. - -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. - -## Acceptable Content - -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. - -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. - -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. - -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. - -Content name, description, and other visible metadata must not include abusive, inappropriate, or harassing content. - -## Reporting Violations of this Code of Conduct - -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. - -## Consequences - -All content published to the NativeScript community channels is hosted at the sole discretion of the NativeScript administrators. - -Unacceptable behavior from any community member, including sponsors, employees, customers, or others with decision-making authority, will not be tolerated. - -Anyone asked to stop unacceptable behavior is expected to comply immediately. - -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). - -## Addressing Grievances - -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. - -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. - -## Contact Info -Please contact Dan Wilson @DanWilson if you need to report a problem or address a grievance related to an abuse report. - -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. - -## Credit and License - -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. - -This document may be reused under a Creative Commons Attribution-ShareAlike License. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 6637ee7..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,79 +0,0 @@ -# Contributing to NativeScript Plugin Seed - -:+1: First of all, thank you for taking the time to contribute! :+1: - -Here are some guides on how to do that: - - - -- [Code of Conduct](#code-of-conduct) -- [Reporting Bugs](#reporting-bugs) -- [Requesting Features](#requesting-features) -- [Submitting a PR](#submitting-a-pr) -- [Where to Start](#where-to-start) - - - -## Code of Conduct -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). - - -## Reporting Bugs - -1. Always update to the most recent master release; the bug may already be resolved. -2. Search for similar issues in the issues list for this repo; it may already be an identified problem. -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). - -## Requesting Features - -1. Use Github Issues to submit feature requests. -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. -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. - -## Submitting a PR - -Before you begin: -* Make sure there is an issue for the bug or feature you will be working on. - -Following these steps is the best way to get your code included in the project: - -1. Fork and clone the nativescript-plugin-seed repo: -```bash -git clone https://github.com//nativescript-plugin-seed.git -# Navigate to the newly cloned directory -cd nativescript-plugin-seed -# Add an "upstream" remote pointing to the original repo. -git remote add upstream https://github.com/NativeScript/nativescript-plugin-seed.git -``` -2. Create a branch for your PR -```bash -git checkout -b master -``` - -3. The fun part! Make your code changes. Make sure you: - - Follow the [code conventions guide](https://github.com/NativeScript/NativeScript/blob/master/CodingConvention.md). - - Follow the [commit message guidelines](https://github.com/NativeScript/NativeScript/blob/pr-template/CONTRIBUTING.md#commit-messages) - - Setup your development workflow. The seed itself is a plugin so you can follow the [development setup][https://github.com/NativeScript/nativescript-plugin-seed#development-setup] described in the README. - - Write unit tests for your fix or feature. If this is not possible, explain how your change can be tested. - > NOTE: For changes in the postclone step, make sure you create tests in `seed-tests/postclone.tests.js`! - -4. Before you submit your PR: - - Rebase your changes to the latest master: `git pull --rebase upstream master`. - - Ensure all unit test are green. How? - - Go to `seed-tests` - - Run `npm install` - - Run `npm run test.ios` or `npm run test.android` - - Ensure your changes pass tslint validation. (run `npm run tslint` in the root of the repo). - -6. Push your fork. If you have rebased you might have to use force-push your branch: -``` -git push origin --force -``` - -7. [Submit your pull request](https://github.com/NativeScript/nativescript-plugin-seed/compare) and compare to `NativeScript/nativescript-plugin-seed`. Please, fill in the Pull Request template - it will help us better understand the PR and increase the chances of it getting merged quickly. - -It's our turn from there on! We will review the PR and discuss changes you might have to make before merging it! Thanks! - -## Where to Start - -If you want to contribute, but you are not sure where to start - look for issues labeled [`help wanted`](https://github.com/NativeScript/nativescript-plugin-seed/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22). diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 34236ee..fb9d57d 100644 --- a/README.md +++ b/README.md @@ -1,162 +1,71 @@ -# Develop a NativeScript plugin [![Build Status](https://travis-ci.org/NativeScript/nativescript-plugin-seed.svg?branch=master)](https://travis-ci.org/NativeScript/nativescript-plugin-seed) +**=== IMPORTANT** -> This repo is heavily based on [@NathanWalker](https://github.com/NathanWalker)'s [Plugin Seed](https://github.com/NathanWalker/nativescript-plugin-seed). Thanks, Nathan! +**Download and Configure first:** - +1. Download a zip of this repo +2. Unzip and name the folder appropriately (perhaps the name of the npm scope you intend to manage here) +3. Setup workspace: `npm run setup` +4. Configure your npm scope: `npm run config` -- [TL;DR](#tldr) -- [Long Description](#long-description) - - [What is NativeScript plugin seed?](#what-is-nativescript-plugin-seed) - - [Plugin folder structure](#plugin-folder-structure) - - [Getting started](#getting-started) - - [Development setup](#development-setup) - - [Linking to CocoaPod or Android Arsenal plugins](#linking-to-cocoapod-or-android-arsenal-plugins) - - [Generating typings for iOS](#generating-typings-for-ios) - - [Generating typings for Android](#generating-typings-for-android) - - [Clean plugin and demo files](#clean-plugin-and-demo-files) - - [Unittesting](#unittesting) - - [Publish to NPM](#publish-to-npm) - - [TravisCI](#travisci) - - [Referring tns-core-modules in the Plugin](#referring-tns-core-modules-in-the-plugin) -- [Contribute](#contribute) -- [Get Help](#get-help) +=== - - -## TL;DR -The NativeScript plugin seed is built to be used as a starting point by NativeScript plugin developers. To bootstrap your plugin development execute the following: - -1. `git clone https://github.com/NativeScript/nativescript-plugin-seed nativescript-yourplugin` where `nativescript-yourplugin` is the name of your plugin. -2. `cd nativescript-yourplugin/src` -3. `npm run postclone` -4. `npm run demo.ios` or `npm run demo.android` to run the demo. - -## Long Description - -### What is NativeScript plugin seed? - -The NativeScript plugin seed is built to be used as a starting point by NativeScript plugin developers. -What does the seed give you out of the box? -* the plugin structure with option for easy development and debugging (see [Development setup section](#Developmentsetup) below) -* a simple working plugin -* a demo project working with the plugin. It is useful during development and for running tests via Travis CI -* a guideline how to structure your plugin README file that will be published to NPM -* a shell script to create your plugin package -* a proper `.gitignore` to keep GitHub tidy -* a proper `.npmignore` to ensure everyone is happy when you publish your plugin to NPM. - -![Plugin seed demo](https://github.com/NativeScript/nativescript-plugin-seed/blob/master/screenshots/demo.png?raw=true) - -### Plugin folder structure - -|Folder/File name| Description -|---|---| -|demo| The plugin demo source code (optional during __postclone__ setup)| -|demo-angular| The plugin demo source code (optional during __postclone__ setup)| -|src| The plugin source code| -|src/platform/android| Plugin Android specific configuration| -|src/platform/ios|Plugin ios specific configuration| -|src/README|Your plugin README stub explaining how other developers can use your plugin in their applications. Used when you publish your plugin to NPM. On postclone step, the README in the root is replaced with this one.| -|src/scripts|The postclone script run when you execute `npm run postclone`. Feel free to delete it after you have executed the postclone step from the [Getting started](#Gettingstarted) section| -|publish|Contains a shell script to create and publish your package. Read more on creating a package and publishing in the [Publish to NPM](#Publishtonpm) section| - -### Getting started - -1. Open a command prompt/terminal and execute `git clone https://github.com/NativeScript/nativescript-plugin-seed nativescript-yourplugin` to clone the plugin seed repository into the `nativescript-yourplugin` folder where `nativescript-yourplugin` is the name of your plugin.. -2. Open a command prompt/terminal and navigate to `nativescript-yourplugin/src` folder using `cd nativescript-yourplugin/src` -3. Execute `npm run postclone` to: - * configure your github username - it will be changed in the package.json for you - * configure your plugin name - all files and classes in the seed will be renamed for you - * stub your plugin README.md file - * add TypeScript NativeScript application which is setup to use your plugin from its local `src` folder - * add Angular NativeScript application which is setup to use your plugin from its local `src` folder - * create a new repository for your plugin - -Now you can continue with the development of your plugin by using the [Development setup](#Developmentsetup) described below. - -**NOTE**: The plugin seed is updated to use the latest version of NativeScript. If you are not ready to upgrade, you can checkout a [tagged version](https://github.com/NativeScript/nativescript-plugin-seed/tags) that is compatible with your NativeScript version. - -#### Development setup -For easier development and debugging purposes continue with the following: - -Open a command prompt/terminal, navigate to `src` folder and run `npm run demo.ios`, `npm run demo.android`, `npm run demo-angular.ios`, `npm run demo-angular.android` to run the demo applications created during `postclone`. - -Now go and make a change to your plugin. It will be automatically applied to the demo project. - -**NOTE**: Any changes that you need to make in a native library used in your plugin or in any other files inside `src/platforms` directory such as Info.plist or AndroidManifest.xml can't be directly reflected in the demo applications. You need to use `npm run demo.reset` or `npm run demo-angular.reset` and run the application again. - -### Linking to CocoaPod or Android Arsenal plugins - -You will want to create these folders and files in the `src` folder in order to use native APIs: +# @nativescript/\* plugins ``` -platforms -- - ios -- - Podfile - android -- - include.gradle +npm run setup +npm start ``` -Doing so will open up those native apis to your plugin :) - -Take a look at these existing plugins for how that can be done very simply: - -* [nativescript-cardview](https://github.com/bradmartin/nativescript-cardview/tree/master/platforms) -* [nativescript-floatingactionbutton](https://github.com/bradmartin/nativescript-floatingactionbutton/tree/master/src/platforms) - -It's highly recommended to generate typings for the native libraries used in your plugin. By generating typings you'll be able to see what APIs exactly are exposed to Javascript and use them easily in your plugin code - -#### Generating typings for iOS - -- Run the command for typings generation as explained in the [documentation](https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#troubleshooting) -- Open `demo/typings/x86_64` and copy the `d.ts` files that you plan to use in your plugin to `src/platforms/ios/typings` -- Open `src/references.d.ts` and add a reference to each of the files added to `src/platforms/ios/typings` - -**NOTE**: Swift APIs that are not exported to Objective-C are not supported. This means that you can only call APIs from JavaScript that are visible to the Objective-C runtime. This include all Objective-C APIs and only the subset of all Swift APIs that are exposed to Objective-C. So, to use a Swift API (class/function/method etc.) from NativeScript, first make sure that it can be used from Objective-C code. For more information which Swfit APIs can be exposed to Objective-C, see [here](https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID53). - -#### Generating typings for Android - -- Clone [Android DTS Generator repo](https://github.com/NativeScript/android-dts-generator) -- Follow the steps in the [README](https://github.com/NativeScript/android-dts-generator/blob/master/README.md) -- Copy the generated d.ts files in `src/platforms/android/typings`. Feel free to rename the generated files for readablity. -- Open `src/references.d.ts` and add a reference to each of the files added to `src/platforms/android/typings` +- @nativescript/yourplugin -### Clean plugin and demo files +# How to use? -Sometimes you may need to wipe away the `src/node_modules`, `demo/node_modules` and `demo/platforms` folders to reinstall them fresh. +This workspace manages the suite of plugins listed above. -* Run `npm run clean` to wipe those clean then you can can run `npm i` to install fresh dependencies. +In general, when in doubt with what to do, just `npm start`. -Sometimes you just need to wipe out the demo's `platforms` directory only: +## How to add a new package to workspace? -* Run `npm run demo.reset` or `npm run demo-angular.reset` to delete the application's `platforms` directory only. +``` +npm run add +``` -Sometimes you may need to ensure plugin files are updated in the demo: +At the prompt, enter the name of the new package. -* Run `npm run plugin.prepare` will do a fresh build of the plugin then remove itself from the demo and add it back for assurance. +- This adds a plugin harness in `packages` with the necessary boilerplate to just start developing +- Updates all demo app flavors to support demoing the new package +- Adds shared code in `tools/demo` where you can write demo code **once** and share across all demo flavors +- Updates build tooling to support the new package +- Updates the `npm start` interactive display +- Updates the README here to list the new package -### Unit testing -In order to add unit testing to the demo applications and in relation to test your plugin inside of them you should follow our latest guide [here](https://docs.nativescript.org/tooling/testing/testing). +## How to add Angular compatibility to a package -### Publish to NPM +``` +npm run add-angular +``` -When you have everything ready to publish: +At the prompt, enter the name of the package to add an `angular` folder to it with the necessary boilerplate to provide Angular support to the package. -* Bump the version number in `src/package.json` -* Go to `publish` and execute `publish.sh` (run `chmod +x *.sh` if the file isn't executable) +## How to focus on just 1 package to develop in isolation -If you just want to create a package, go to `publish` folder and execute `pack.sh`. The package will be created in `publish/package` folder. +``` +npm start +``` -**NOTE**: To run bash script on Windows you can install [GIT SCM](https://git-for-windows.github.io/) and use Git Bash. +- Choose the focus commands for the package you wish to focus on and hit enter. +- All the demo app's will be updated to isolate that 1 package and for supported IDE's (currently VS Code), the source code will also become isolated in the workspace. -### TravisCI +Note: _good to always clean the demo you plan to run after focusing. (You can clean any demo from `npm start` as well)_ -The plugin structure comes with a fully functional .travis.yml file that deploys the testing app on Android emulator and iOS simulator to make sure that those apps start correctly while your plugin is linked to them. All you have to do, after cloning the repo and implementing your plugin and tests, is to sign up at [https://travis-ci.org/](https://travis-ci.org/). Then enable your plugin's repo on "https://travis-ci.org/profile/" and that's it. Next time a PR is opened or change is committed to a branch TravisCI will trigger a build testing the code. +## How to publish packages? -To properly show current build status you will have to edit the badge at the start of the README.md file so it matches your repo, user and branch. +``` +npm run publish-packages +``` -## Contribute -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/tns-core-modules-widgets/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22). +- You will be prompted for the package names to publish. Leaving blank and hitting enter will publish them all. +- You will then be prompted for the version to use. Leaving blank will auto bump the patch version (it also handles prerelease types like alpha, beta, rc, etc. - It even auto tags the corresponding prelease type on npm). +- You will then be given a brief sanity check 🧠😊 -## Get Help -Please, use [github issues](https://github.com/NativeScript/tns-core-modules-widgets/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation). +

Made with ❀️

diff --git a/apps/demo-angular/.gitignore b/apps/demo-angular/.gitignore new file mode 100644 index 0000000..74ba2bc --- /dev/null +++ b/apps/demo-angular/.gitignore @@ -0,0 +1,3 @@ +hooks +platforms +!webpack.config.js \ No newline at end of file diff --git a/apps/demo-angular/nativescript.config.ts b/apps/demo-angular/nativescript.config.ts new file mode 100644 index 0000000..395e275 --- /dev/null +++ b/apps/demo-angular/nativescript.config.ts @@ -0,0 +1,11 @@ +import { NativeScriptConfig } from '@nativescript/core'; + +export default { + id: 'org.nativescript.plugindemoangular', + appResourcesPath: '../../tools/assets/App_Resources', + android: { + v8Flags: '--expose_gc', + markingMode: 'none', + }, + appPath: 'src', +} as NativeScriptConfig; diff --git a/apps/demo-angular/package.json b/apps/demo-angular/package.json new file mode 100644 index 0000000..3f2f0f2 --- /dev/null +++ b/apps/demo-angular/package.json @@ -0,0 +1,28 @@ +{ + "main": "main.js", + "dependencies": { + "@angular/animations": "file:../../node_modules/@angular/animations", + "@angular/common": "file:../../node_modules/@angular/common", + "@angular/compiler": "file:../../node_modules/@angular/compiler", + "@angular/core": "file:../../node_modules/@angular/core", + "@angular/forms": "file:../../node_modules/@angular/forms", + "@angular/platform-browser": "file:../../node_modules/@angular/platform-browser", + "@angular/platform-browser-dynamic": "file:../../node_modules/@angular/platform-browser-dynamic", + "@angular/router": "file:../../node_modules/@angular/router", + "@nativescript/angular": "file:../../node_modules/@nativescript/angular", + "@nativescript/core": "file:../../node_modules/@nativescript/core", + "nativescript-theme-core": "file:../../node_modules/nativescript-theme-core", + "reflect-metadata": "file:../../node_modules/reflect-metadata", + "rxjs": "file:../../node_modules/rxjs", + "zone.js": "file:../../node_modules/zone.js", + "@nativescript/yourplugin": "file:../../dist/packages/yourplugin" + }, + "devDependencies": { + "@angular/compiler-cli": "file:../../node_modules/@angular/compiler-cli", + "@nativescript/android": "~7.0.0", + "@nativescript/ios": "7.0.0", + "@nativescript/webpack": "~3.0.0", + "@ngtools/webpack": "file:../../node_modules/@ngtools/webpack", + "typescript": "file:../../node_modules/typescript" + } +} diff --git a/apps/demo-angular/references.d.ts b/apps/demo-angular/references.d.ts new file mode 100644 index 0000000..22bac92 --- /dev/null +++ b/apps/demo-angular/references.d.ts @@ -0,0 +1 @@ +/// diff --git a/apps/demo-angular/src/app-routing.module.ts b/apps/demo-angular/src/app-routing.module.ts new file mode 100644 index 0000000..cad2265 --- /dev/null +++ b/apps/demo-angular/src/app-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes } from '@angular/router'; +import { NativeScriptRouterModule } from '@nativescript/angular'; + +import { HomeComponent } from './home.component'; + +const routes: Routes = [ + { path: '', redirectTo: '/home', pathMatch: 'full' }, + { path: 'home', component: HomeComponent }, + { path: 'yourplugin', loadChildren: () => import('./plugin-demos/yourplugin.module').then((m) => m.YourpluginModule) }, +]; + +@NgModule({ + imports: [NativeScriptRouterModule.forRoot(routes)], + exports: [NativeScriptRouterModule], +}) +export class AppRoutingModule {} diff --git a/apps/demo-angular/src/app.component.ts b/apps/demo-angular/src/app.component.ts new file mode 100644 index 0000000..e37a75f --- /dev/null +++ b/apps/demo-angular/src/app.component.ts @@ -0,0 +1,9 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'demo-app', + template: ` + + `, +}) +export class AppComponent {} diff --git a/apps/demo-angular/src/app.css b/apps/demo-angular/src/app.css new file mode 100644 index 0000000..386a8ee --- /dev/null +++ b/apps/demo-angular/src/app.css @@ -0,0 +1,21 @@ +ο»Ώ@import '~nativescript-theme-core/css/core.light.css'; + +button, label, stack-layout { + horizontal-align: center; +} + +button { + font-size: 36; +} + +.title { + font-size: 30; + margin: 20; +} + +.message { + font-size: 20; + color: #284848; + text-align: center; + margin: 0 20; +} diff --git a/apps/demo-angular/src/app.module.ts b/apps/demo-angular/src/app.module.ts new file mode 100644 index 0000000..c869e4d --- /dev/null +++ b/apps/demo-angular/src/app.module.ts @@ -0,0 +1,14 @@ +import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; +import { NativeScriptModule } from '@nativescript/angular'; + +import { AppComponent } from './app.component'; +import { AppRoutingModule } from './app-routing.module'; +import { HomeComponent } from './home.component'; + +@NgModule({ + schemas: [NO_ERRORS_SCHEMA], + declarations: [AppComponent, HomeComponent], + bootstrap: [AppComponent], + imports: [NativeScriptModule, AppRoutingModule], +}) +export class AppModule {} diff --git a/apps/demo-angular/src/home.component.html b/apps/demo-angular/src/home.component.html new file mode 100644 index 0000000..b6ad279 --- /dev/null +++ b/apps/demo-angular/src/home.component.html @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/apps/demo-angular/src/home.component.ts b/apps/demo-angular/src/home.component.ts new file mode 100644 index 0000000..0f1e46d --- /dev/null +++ b/apps/demo-angular/src/home.component.ts @@ -0,0 +1,13 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'demo-home', + templateUrl: 'home.component.html', +}) +export class HomeComponent { + demos = [ + { + name: 'yourplugin', + }, + ]; +} diff --git a/apps/demo-angular/src/main.ts b/apps/demo-angular/src/main.ts new file mode 100644 index 0000000..b6b1db3 --- /dev/null +++ b/apps/demo-angular/src/main.ts @@ -0,0 +1,4 @@ +import { platformNativeScriptDynamic } from "@nativescript/angular"; +import { AppModule } from "./app.module"; + +platformNativeScriptDynamic().bootstrapModule(AppModule); \ No newline at end of file diff --git a/src/platforms/ios/build.xcconfig b/apps/demo-angular/src/plugin-demos/.gitkeep similarity index 100% rename from src/platforms/ios/build.xcconfig rename to apps/demo-angular/src/plugin-demos/.gitkeep diff --git a/apps/demo-angular/src/plugin-demos/yourplugin.component.html b/apps/demo-angular/src/plugin-demos/yourplugin.component.html new file mode 100644 index 0000000..f70630f --- /dev/null +++ b/apps/demo-angular/src/plugin-demos/yourplugin.component.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/apps/demo-angular/src/plugin-demos/yourplugin.component.ts b/apps/demo-angular/src/plugin-demos/yourplugin.component.ts new file mode 100644 index 0000000..bae2f60 --- /dev/null +++ b/apps/demo-angular/src/plugin-demos/yourplugin.component.ts @@ -0,0 +1,17 @@ +import { Component, NgZone } from '@angular/core'; +import { DemoSharedYourplugin } from '@demo/shared'; +import {} from '@nativescript/yourplugin'; + +@Component({ + selector: 'demo-yourplugin', + templateUrl: 'yourplugin.component.html', +}) +export class YourpluginComponent { + demoShared: DemoSharedYourplugin; + + constructor(private _ngZone: NgZone) {} + + ngOnInit() { + this.demoShared = new DemoSharedYourplugin(); + } +} diff --git a/apps/demo-angular/src/plugin-demos/yourplugin.module.ts b/apps/demo-angular/src/plugin-demos/yourplugin.module.ts new file mode 100644 index 0000000..d96de1a --- /dev/null +++ b/apps/demo-angular/src/plugin-demos/yourplugin.module.ts @@ -0,0 +1,10 @@ +import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; +import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'; +import { YourpluginComponent } from './yourplugin.component'; + +@NgModule({ + imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: YourpluginComponent }])], + declarations: [YourpluginComponent], + schemas: [NO_ERRORS_SCHEMA], +}) +export class YourpluginModule {} diff --git a/apps/demo-angular/tsconfig.json b/apps/demo-angular/tsconfig.json new file mode 100644 index 0000000..0ba046a --- /dev/null +++ b/apps/demo-angular/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDirs": [ + ".", + "../.." + ], + "baseUrl": ".", + "paths": { + "~/*": [ + "src/*" + ], + "@nativescript/*": [ + "../../dist/packages/*" + ], + "@demo/shared": [ + "../../tools/demo/index.ts" + ] + } + }, + "files": [ + "./references.d.ts", + "./src/main.ts" + ] +} \ No newline at end of file diff --git a/apps/demo-angular/webpack.config.js b/apps/demo-angular/webpack.config.js new file mode 100644 index 0000000..fe48a43 --- /dev/null +++ b/apps/demo-angular/webpack.config.js @@ -0,0 +1,436 @@ +const { join, relative, resolve, sep, dirname } = require('path'); +const fs = require('fs'); + +const webpack = require('webpack'); +const nsWebpack = require('@nativescript/webpack'); +const nativescriptTarget = require('@nativescript/webpack/nativescript-target'); +const { + nsSupportHmrNg +} = require('@nativescript/webpack/transformers/ns-support-hmr-ng'); +const { nsTransformNativeClassesNg } = require("@nativescript/webpack/transformers/ns-transform-native-classes-ng"); +const { + getMainModulePath +} = require('@nativescript/webpack/utils/ast-utils'); +const { getNoEmitOnErrorFromTSConfig, getCompilerOptionsFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils"); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); +const { + NativeScriptWorkerPlugin +} = require('nativescript-worker-loader/NativeScriptWorkerPlugin'); +const TerserPlugin = require('terser-webpack-plugin'); +const { + getAngularCompilerPlugin +} = require('@nativescript/webpack/plugins/NativeScriptAngularCompilerPlugin'); +const hashSalt = Date.now().toString(); + +module.exports = env => { + // Add your custom Activities, Services and other Android app components here. + const appComponents = [ + "@nativescript/core/ui/frame", "@nativescript/core/ui/frame/activity" + ]; + + const platform = env && ((env.android && 'android') || (env.ios && 'ios')); + if (!platform) { + throw new Error('You need to provide a target platform!'); + } + + const AngularCompilerPlugin = getAngularCompilerPlugin(platform); + const projectRoot = __dirname; + + // Default destination inside platforms//... + const dist = resolve( + projectRoot, + nsWebpack.getAppPath(platform, projectRoot) + ); + + const { + // The 'appPath' and 'appResourcesPath' values are fetched from + // the nsconfig.json configuration file + // when bundling with `tns run android|ios --bundle`. + appPath = 'src', + appResourcesPath = 'App_Resources', + + // You can provide the following flags when running 'tns run android|ios' + snapshot, // --env.snapshot, + production, // --env.production + uglify, // --env.uglify + report, // --env.report + sourceMap, // --env.sourceMap + hiddenSourceMap, // --env.hiddenSourceMap + hmr, // --env.hmr, + unitTesting, // --env.unitTesting + testing, // --env.testing + verbose, // --env.verbose + ci, // --env.ci + snapshotInDocker, // --env.snapshotInDocker + skipSnapshotTools, // --env.skipSnapshotTools + compileSnapshot // --env.compileSnapshot + } = env; + + const useLibs = compileSnapshot; + const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; + const externals = nsWebpack.getConvertedExternals(env.externals); + const appFullPath = resolve(projectRoot, appPath); + const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + let tsConfigName = 'tsconfig.json'; + let tsConfigTnsName = 'tsconfig.tns.json'; + let tsConfigPath = resolve(projectRoot, tsConfigName); + const tsConfigTnsPath = resolve(projectRoot, tsConfigTnsName); + if (fs.existsSync(tsConfigTnsPath)) { + // still support shared angular app configurations + tsConfigName = tsConfigTnsName; + tsConfigPath = tsConfigTnsPath; + } + const entryModule = `${nsWebpack.getEntryModule(appFullPath, platform)}.ts`; + const entryPath = `.${sep}${entryModule}`; + const entries = { bundle: entryPath }; + const areCoreModulesExternal = + Array.isArray(env.externals) && + env.externals.some(e => e.indexOf('@nativescript') > -1); + if (platform === 'ios' && !areCoreModulesExternal && !testing) { + entries['tns_modules/@nativescript/core/inspector_modules'] = + 'inspector_modules'; + } + + const compilerOptions = getCompilerOptionsFromTSConfig(tsConfigPath); + nsWebpack.processTsPathsForScopedModules({ compilerOptions }); + nsWebpack.processTsPathsForScopedAngular({ compilerOptions }); + + const ngCompilerTransformers = [nsTransformNativeClassesNg]; + const additionalLazyModuleResources = []; + + const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; + const copyTargets = [ + { from: 'assets/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + { from: 'fonts/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + ]; + + if (!production) { + // for development purposes only + // for example, include mock json folder + // copyTargets.push({ from: 'tools/mockdata', to: 'assets/mockdata' }); + + if (hmr) { + ngCompilerTransformers.push(nsSupportHmrNg); + } + } + + // when "@angular/core" is external, it's not included in the bundles. In this way, it will be used + // directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes + // fixes https://github.com/NativeScript/nativescript-cli/issues/4024 + if (env.externals && env.externals.indexOf('@angular/core') > -1) { + const appModuleRelativePath = getMainModulePath( + resolve(appFullPath, entryModule), + tsConfigName + ); + if (appModuleRelativePath) { + const appModuleFolderPath = dirname( + resolve(appFullPath, appModuleRelativePath) + ); + // include the new lazy loader path in the allowed ones + additionalLazyModuleResources.push(appModuleFolderPath); + } + } + + const ngCompilerPlugin = new AngularCompilerPlugin({ + hostReplacementPaths: nsWebpack.getResolver([platform, 'tns']), + platformTransformers: ngCompilerTransformers.map(t => + t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot) + ), + mainPath: join(appFullPath, entryModule), + tsConfigPath, + skipCodeGeneration: false, + sourceMap: !!isAnySourceMapEnabled, + additionalLazyModuleResources: additionalLazyModuleResources, + compilerOptions: { paths: compilerOptions.paths } + }); + + let sourceMapFilename = nsWebpack.getSourceMapFilename( + hiddenSourceMap, + __dirname, + dist + ); + + const itemsToClean = [`${dist}/**/*`]; + if (platform === 'android') { + itemsToClean.push( + `${join( + projectRoot, + 'platforms', + 'android', + 'app', + 'src', + 'main', + 'assets', + 'snapshots' + )}` + ); + itemsToClean.push( + `${join( + projectRoot, + 'platforms', + 'android', + 'app', + 'build', + 'configurations', + 'nativescript-android-snapshot' + )}` + ); + } + + const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigName); + + nsWebpack.processAppComponents(appComponents, platform); + const config = { + mode: production ? 'production' : 'development', + context: appFullPath, + externals, + watchOptions: { + ignored: [ + appResourcesFullPath, + // Don't watch hidden files + '**/.*' + ] + }, + target: nativescriptTarget, + entry: entries, + output: { + pathinfo: false, + path: dist, + sourceMapFilename, + libraryTarget: 'commonjs2', + filename: '[name].js', + globalObject: 'global', + hashSalt + }, + resolve: { + extensions: ['.ts', '.js', '.scss', '.css'], + // Resolve {N} system modules from @nativescript/core + modules: [ + resolve(__dirname, 'node_modules/@nativescript/core'), + resolve(__dirname, 'node_modules'), + 'node_modules/@nativescript/core', + 'node_modules' + ], + alias: { + '~/package.json': resolve(projectRoot, 'package.json'), + '~': appFullPath, + "tns-core-modules": "@nativescript/core", + "nativescript-angular": "@nativescript/angular", + '@demo/shared': resolve(projectRoot, '..', '..', 'tools', 'demo') + }, + symlinks: true + }, + resolveLoader: { + symlinks: false + }, + node: { + // Disable node shims that conflict with NativeScript + http: false, + timers: false, + setImmediate: false, + fs: 'empty', + __dirname: false + }, + devtool: hiddenSourceMap + ? 'hidden-source-map' + : sourceMap + ? 'inline-source-map' + : 'none', + optimization: { + runtimeChunk: 'single', + noEmitOnErrors: noEmitOnErrorFromTSConfig, + splitChunks: { + cacheGroups: { + vendor: { + name: 'vendor', + chunks: 'all', + test: (module, chunks) => { + const moduleName = module.nameForCondition + ? module.nameForCondition() + : ''; + return ( + /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName) + ); + }, + enforce: true + } + } + }, + minimize: !!uglify, + minimizer: [ + new TerserPlugin({ + parallel: true, + cache: !ci, + sourceMap: isAnySourceMapEnabled, + terserOptions: { + output: { + comments: false, + semicolons: !isAnySourceMapEnabled + }, + compress: { + // The Android SBG has problems parsing the output + // when these options are enabled + collapse_vars: platform !== 'android', + sequences: platform !== 'android', + // custom + drop_console: true, + drop_debugger: true, + ecma: 6, + keep_infinity: platform === 'android', // for Chrome/V8 + reduce_funcs: platform !== 'android', // for Chrome/V8 + global_defs: { + __UGLIFIED__: true + } + }, + // custom + ecma: 6, + safari10: platform !== 'android' + } + }) + ] + }, + module: { + rules: [ + { + include: join(appFullPath, entryPath), + use: [ + // Require all Android app components + platform === 'android' && { + loader: '@nativescript/webpack/helpers/android-app-components-loader', + options: { modules: appComponents } + }, + + { + loader: '@nativescript/webpack/bundle-config-loader', + options: { + angular: true, + loadCss: !snapshot, // load the application css if in debug mode + unitTesting, + appFullPath, + projectRoot, + ignoredFiles: nsWebpack.getUserDefinedEntries(entries, platform) + } + } + ].filter(loader => !!loader) + }, + + { test: /\.html$|\.xml$/, use: 'raw-loader' }, + + { + test: /[\/|\\]app\.css$/, + use: [ + '@nativescript/webpack/helpers/style-hot-loader', + { + loader: "@nativescript/webpack/helpers/css2json-loader", + options: { useForImports: true } + }, + ], + }, + { + test: /[\/|\\]app\.scss$/, + use: [ + '@nativescript/webpack/helpers/style-hot-loader', + { + loader: "@nativescript/webpack/helpers/css2json-loader", + options: { useForImports: true } + }, + 'sass-loader', + ], + }, + + // Angular components reference css files and their imports using raw-loader + { test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: 'raw-loader' }, + { + test: /\.scss$/, + exclude: /[\/|\\]app\.scss$/, + use: ['raw-loader', 'resolve-url-loader', 'sass-loader'] + }, + + { + test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, + use: [ + '@nativescript/webpack/helpers/moduleid-compat-loader', + '@nativescript/webpack/helpers/lazy-ngmodule-hot-loader', + '@ngtools/webpack' + ] + }, + + // Mark files inside `@angular/core` as using SystemJS style dynamic imports. + // Removing this will cause deprecation warnings to appear. + { + test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, + parser: { system: true } + } + ] + }, + plugins: [ + // Define useful constants like TNS_WEBPACK + new webpack.DefinePlugin({ + 'global.TNS_WEBPACK': 'true', + 'global.isAndroid': platform === 'android', + 'global.isIOS': platform === 'ios', + process: 'global.process' + }), + // Remove all files from the out dir. + new CleanWebpackPlugin({ + cleanOnceBeforeBuildPatterns: itemsToClean, + verbose: !!verbose + }), + // Copy assets + new CopyWebpackPlugin({ + patterns: copyTargets, + }), + new nsWebpack.GenerateNativeScriptEntryPointsPlugin('bundle'), + // For instructions on how to set up workers with webpack + // check out https://github.com/nativescript/worker-loader + new NativeScriptWorkerPlugin(), + ngCompilerPlugin, + // Does IPC communication with the {N} CLI to notify events when running in watch mode. + new nsWebpack.WatchStateLoggerPlugin() + ] + }; + + if (report) { + // Generate report files for bundles content + config.plugins.push( + new BundleAnalyzerPlugin({ + analyzerMode: 'static', + openAnalyzer: false, + generateStatsFile: true, + reportFilename: resolve(projectRoot, 'report', `report.html`), + statsFilename: resolve(projectRoot, 'report', `stats.json`) + }) + ); + } + + if (snapshot) { + config.plugins.push( + new nsWebpack.NativeScriptSnapshotPlugin({ + chunk: 'vendor', + angular: true, + requireModules: [ + 'reflect-metadata', + '@angular/platform-browser', + '@angular/core', + '@angular/common', + '@angular/router', + '@nativescript/angular' + ], + projectRoot, + webpackConfig: config, + snapshotInDocker, + skipSnapshotTools, + useLibs + }) + ); + } + + if (!production && hmr) { + config.plugins.push(new webpack.HotModuleReplacementPlugin()); + } + + return config; +}; \ No newline at end of file diff --git a/apps/demo/.gitignore b/apps/demo/.gitignore new file mode 100644 index 0000000..407ded9 --- /dev/null +++ b/apps/demo/.gitignore @@ -0,0 +1,42 @@ +# NativeScript +hooks/ +node_modules/ +platforms/ + +# NativeScript Template +*.js.map +*.js +!webpack.config.js + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# General +.DS_Store +.AppleDouble +.LSOverride +.idea +.cloud +.project +tmp/ +typings/ + +# misc +npm-debug.log + +# app +!*.d.ts +!src/assets/fontawesome.min.css +/report/ +.nsbuildinfo +/temp/ +/src/tns_modules/ + +# app uses platform specific scss which can inadvertently get renamed which will cause problems +app/app.scss + +package-lock.json diff --git a/apps/demo/nativescript.config.ts b/apps/demo/nativescript.config.ts new file mode 100644 index 0000000..411ac72 --- /dev/null +++ b/apps/demo/nativescript.config.ts @@ -0,0 +1,11 @@ +import { NativeScriptConfig } from '@nativescript/core'; + +export default { + id: 'org.nativescript.plugindemo', + appResourcesPath: '../../tools/assets/App_Resources', + android: { + v8Flags: '--expose_gc', + markingMode: 'none', + }, + appPath: 'src', +} as NativeScriptConfig; diff --git a/apps/demo/package.json b/apps/demo/package.json new file mode 100644 index 0000000..c5159d1 --- /dev/null +++ b/apps/demo/package.json @@ -0,0 +1,17 @@ +{ + "main": "app.js", + "description": "NativeScript Application", + "license": "SEE LICENSE IN ", + "repository": "", + "dependencies": { + "nativescript-theme-core": "file:../../node_modules/nativescript-theme-core", + "@nativescript/core": "file:../../node_modules/@nativescript/core", + "@nativescript/yourplugin": "file:../../packages/yourplugin" + }, + "devDependencies": { + "@nativescript/android": "~7.0.0", + "@nativescript/ios": "7.0.0", + "@nativescript/webpack": "3.0.0", + "typescript": "file:../../node_modules/typescript" + } +} diff --git a/apps/demo/references.d.ts b/apps/demo/references.d.ts new file mode 100644 index 0000000..22bac92 --- /dev/null +++ b/apps/demo/references.d.ts @@ -0,0 +1 @@ +/// diff --git a/apps/demo/src/app-root.xml b/apps/demo/src/app-root.xml new file mode 100644 index 0000000..54e70d9 --- /dev/null +++ b/apps/demo/src/app-root.xml @@ -0,0 +1,2 @@ + + diff --git a/apps/demo/src/app.css b/apps/demo/src/app.css new file mode 100644 index 0000000..50170bd --- /dev/null +++ b/apps/demo/src/app.css @@ -0,0 +1 @@ +@import '~nativescript-theme-core/css/core.light.css'; \ No newline at end of file diff --git a/apps/demo/src/app.ts b/apps/demo/src/app.ts new file mode 100644 index 0000000..a4c5c52 --- /dev/null +++ b/apps/demo/src/app.ts @@ -0,0 +1,3 @@ +import { Application } from '@nativescript/core'; + +Application.run({ moduleName: 'app-root' }); diff --git a/apps/demo/src/main-page.ts b/apps/demo/src/main-page.ts new file mode 100644 index 0000000..89e6b7a --- /dev/null +++ b/apps/demo/src/main-page.ts @@ -0,0 +1,7 @@ +import { EventData, Page } from '@nativescript/core'; +import { MainViewModel } from "./main-view-model"; + +export function navigatingTo(args: EventData) { + const page = args.object; + page.bindingContext = new MainViewModel(); +} diff --git a/apps/demo/src/main-page.xml b/apps/demo/src/main-page.xml new file mode 100644 index 0000000..b1f6cb1 --- /dev/null +++ b/apps/demo/src/main-page.xml @@ -0,0 +1,13 @@ + + + + + + + +