├── .github ├── issue_template.md └── pull_request_template.md ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── publish ├── pack.sh ├── package.json └── publish.sh ├── screenshots └── demo.png ├── seed-tests ├── e2e │ ├── config │ │ ├── appium.capabilities.json │ │ └── mocha.opts │ ├── setup.ts │ ├── tests.e2e.ts │ └── tsconfig.json ├── jasmine.config.json ├── package.json ├── postclone.tests.js ├── tests.constants.js └── tests.utils.js ├── src ├── .npmignore ├── .travis.yml ├── README.md ├── index.d.ts ├── package.json ├── platforms │ ├── android │ │ ├── AndroidManifest.xml │ │ ├── README.md │ │ └── include.gradle │ └── ios │ │ ├── Info.plist │ │ ├── README.md │ │ └── build.xcconfig ├── references.d.ts ├── scripts │ ├── build-native.js │ └── postclone.js ├── tsconfig.json ├── yourplugin.android.d.ts ├── yourplugin.android.ts ├── yourplugin.common.d.ts ├── yourplugin.common.ts ├── yourplugin.ios.d.ts └── yourplugin.ios.ts └── tslint.json /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Make sure to check the demo app(s) for sample usage 2 | 3 | ### Make sure to check the existing issues in this repository 4 | 5 | ### If the demo apps cannot help and there is no issue for your problem, tell us about it 6 | Please, ensure your title is less than 63 characters long and starts with a capital 7 | letter. 8 | 9 | ### Which platform(s) does your issue occur on? 10 | - iOS/Android/Both 11 | - iOS/Android versions 12 | - emulator or device. What type of device? 13 | 14 | ### Please, provide the following version numbers that your issue occurs with: 15 | 16 | - CLI: (run `tns --version` to fetch it) 17 | - Cross-platform modules: (check the 'version' attribute in the 18 | `node_modules/tns-core-modules/package.json` file in your project) 19 | - Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project) 20 | - Plugin(s): (look for the version numbers in the `package.json` file of your 21 | project and paste your dependencies and devDependencies here) 22 | 23 | ### Please, tell us how to recreate the issue in as much detail as possible. 24 | Describe the steps to reproduce it. 25 | 26 | ### Is there any code involved? 27 | - provide a code example to recreate the problem 28 | - (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible. 29 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | .DS_Store 4 | *.esm.json 5 | *.js 6 | *.js.map 7 | *.log 8 | src/*.d.ts 9 | !src/index.d.ts 10 | !src/references.d.ts 11 | !src/scripts/*.js 12 | !seed-tests/*.js 13 | seed-tests/seed-copy 14 | seed-tests/seed-copy-new-git-repo/**/*.* 15 | !demo/karma.conf.js 16 | !demo/app/tests/*.js 17 | demo/*.d.ts 18 | !demo/references.d.ts 19 | demo/lib 20 | demo/platforms 21 | node_modules 22 | publish/src 23 | publish/package 24 | demo/report/report.html 25 | demo/report/stats.json 26 | !demo-vue/app/app.js -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | env: 5 | global: 6 | - ANDROID_PACKAGE_JS='seed-js.apk' 7 | - ANDROID_PACKAGE_FOLDER_JS=$TRAVIS_BUILD_DIR/demo/outputs 8 | - ANDROID_PACKAGE_NG='seed-ng.apk' 9 | - ANDROID_PACKAGE_FOLDER_NG=$TRAVIS_BUILD_DIR/demo-angular/outputs 10 | - ANDROID_SAUCE_STORAGE="https://saucelabs.com/rest/v1/storage/$SAUCE_USER" 11 | - IOS_PACKAGE_JS='seed-js.zip' 12 | - IOS_PACKAGE_FOLDER_JS=$TRAVIS_BUILD_DIR/demo/outputs 13 | - IOS_PACKAGE_NG='seed-ng.zip' 14 | - IOS_PACKAGE_FOLDER_NG=$TRAVIS_BUILD_DIR/demo-angular/outputs 15 | - IOS_SAUCE_STORAGE="https://saucelabs.com/rest/v1/storage/$SAUCE_USER" 16 | 17 | matrix: 18 | include: 19 | - stage: "Lint" 20 | language: node_js 21 | os: linux 22 | node_js: "10" 23 | script: cd src && npm run ci.tslint 24 | - stage: "Build and Test" 25 | env: 26 | - BuildAndroid="29" 27 | - NodeJs="8" 28 | - Type="TypeScript" 29 | language: android 30 | dist: trusty 31 | os: linux 32 | jdk: oraclejdk8 33 | before_install: nvm install 8 34 | script: 35 | - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n 36 | - npm run build 37 | - cd ../demo 38 | - tns build android 39 | - env: 40 | - BuildAndroid="29" 41 | - Type="TypeScript" 42 | language: android 43 | dist: trusty 44 | os: linux 45 | jdk: oraclejdk8 46 | before_install: nvm install 10 47 | script: 48 | - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n 49 | - npm run tsc 50 | - cd ../demo 51 | - travis_wait travis_retry tns build android --copy-to "$ANDROID_PACKAGE_FOLDER_JS/$ANDROID_PACKAGE_JS" 52 | - "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" 53 | - os: osx 54 | env: 55 | - BuildiOS="12.0" 56 | - Type="TypeScript" 57 | osx_image: xcode11.2 58 | language: node_js 59 | node_js: "10" 60 | jdk: oraclejdk8 61 | script: 62 | - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=y includeAngularDemo=n 63 | - npm run tsc 64 | - cd ../demo 65 | - travis_wait travis_retry tns build ios --copy-to "./outputs/demo.app" 66 | - cd $IOS_PACKAGE_FOLDER_JS && zip -r $IOS_PACKAGE_JS demo.app 67 | - "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" 68 | - os: linux 69 | env: 70 | - BuildAndroid="29" 71 | - Type="Angular" 72 | language: android 73 | dist: trusty 74 | jdk: oraclejdk8 75 | before_install: nvm install 10 76 | script: 77 | - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=n includeAngularDemo=y 78 | - npm run tsc 79 | - cd ../demo-angular 80 | - travis_wait travis_retry tns build android --copy-to "$ANDROID_PACKAGE_FOLDER_NG/$ANDROID_PACKAGE_NG" 81 | - "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" 82 | - os: osx 83 | env: 84 | - BuildiOS="12.0" 85 | - Type="Angular" 86 | osx_image: xcode11.2 87 | language: node_js 88 | node_js: "10" 89 | jdk: oraclejdk8 90 | script: 91 | - cd src && npm run postclone gitHubUsername=TheGitHubUser pluginName=ThePlugin initGit=y includeTypeScriptDemo=n includeAngularDemo=y 92 | - npm run tsc 93 | - cd ../demo-angular 94 | - travis_wait travis_retry tns build ios --copy-to "./outputs/demo-angular.app" 95 | - cd $IOS_PACKAGE_FOLDER_NG && zip -r $IOS_PACKAGE_NG demo-angular.app 96 | - "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" 97 | - os: linux 98 | language: android 99 | dist: trusty 100 | env: 101 | - UnitTests="Android" 102 | - TestVersion="latest" 103 | jdk: oraclejdk8 104 | before_install: 105 | - nvm install 10 106 | before_script: 107 | - cd seed-tests && npm i 108 | - android list targets 109 | - echo no | android create avd --force -n test -t android-21 -b armeabi-v7a 110 | - emulator -avd test -no-audio -no-window & 111 | - android-wait-for-emulator 112 | script: 113 | - travis_wait travis_retry npm run test.android 114 | - os: osx 115 | env: 116 | - UnitTests="iOS" 117 | - TestVersion="latest" 118 | language: node_js 119 | node_js: "10" 120 | jdk: oraclejdk8 121 | osx_image: xcode11.2 122 | before_script: 123 | - cd seed-tests && npm i 124 | script: 125 | - travis_wait travis_retry npm run test.ios 126 | - stage: "UI Tests" 127 | env: 128 | - Android="24" 129 | - Type="TypeScript" 130 | language: node_js 131 | os: linux 132 | node_js: "10" 133 | script: 134 | - npm i -g appium 135 | - cd seed-tests && npm i 136 | - travis_wait travis_retry npm run e2e -- --runType android24 --sauceLab --appPath $ANDROID_PACKAGE_JS 137 | - os: linux 138 | env: 139 | - Android="24" 140 | - Type="Angular" 141 | language: node_js 142 | os: linux 143 | node_js: "10" 144 | script: 145 | - npm i -g appium 146 | - cd seed-tests && npm i 147 | - travis_wait travis_retry npm run e2e -- --runType android24 --sauceLab --appPath $ANDROID_PACKAGE_NG 148 | - os: linux 149 | env: 150 | - iOS="12.0" 151 | - Type="TypeScript" 152 | language: node_js 153 | node_js: "10" 154 | script: 155 | - npm i -g appium 156 | - cd seed-tests && npm i 157 | - travis_wait travis_retry npm run e2e -- --runType sim12iPhoneX --sauceLab --appPath $IOS_PACKAGE_JS 158 | - os: linux 159 | env: 160 | - iOS="12.0" 161 | - Type="Angular" 162 | language: node_js 163 | node_js: "10" 164 | script: 165 | - npm i -g appium 166 | - cd seed-tests && npm i 167 | - travis_wait travis_retry npm run e2e -- --runType sim12iPhoneX --sauceLab --appPath $IOS_PACKAGE_NG 168 | 169 | 170 | android: 171 | components: 172 | - tools 173 | - platform-tools 174 | - build-tools-29.0.2 175 | - android-21 176 | - android-29 177 | - extra-android-m2repository 178 | - sys-img-armeabi-v7a-android-21 179 | 180 | before_install: 181 | - sudo pip install --upgrade pip 182 | - sudo pip install six 183 | 184 | install: 185 | - echo no | npm install -g nativescript 186 | - tns usage-reporting disable 187 | - tns error-reporting disable 188 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to NativeScript Plugin Seed 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 | * Make sure there is an issue for the bug or feature you will be working on. 37 | 38 | Following these steps is the best way to get your code included in the project: 39 | 40 | 1. Fork and clone the nativescript-plugin-seed repo: 41 | ```bash 42 | git clone https://github.com//nativescript-plugin-seed.git 43 | # Navigate to the newly cloned directory 44 | cd nativescript-plugin-seed 45 | # Add an "upstream" remote pointing to the original repo. 46 | git remote add upstream https://github.com/NativeScript/nativescript-plugin-seed.git 47 | ``` 48 | 2. Create a branch for your PR 49 | ```bash 50 | git checkout -b master 51 | ``` 52 | 53 | 3. The fun part! Make your code changes. Make sure you: 54 | - Follow the [code conventions guide](https://github.com/NativeScript/NativeScript/blob/master/CodingConvention.md). 55 | - Follow the [commit message guidelines](https://github.com/NativeScript/NativeScript/blob/pr-template/CONTRIBUTING.md#commit-messages) 56 | - 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. 57 | - Write unit tests for your fix or feature. If this is not possible, explain how your change can be tested. 58 | > NOTE: For changes in the postclone step, make sure you create tests in `seed-tests/postclone.tests.js`! 59 | 60 | 4. Before you submit your PR: 61 | - Rebase your changes to the latest master: `git pull --rebase upstream master`. 62 | - Ensure all unit test are green. How? 63 | - Go to `seed-tests` 64 | - Run `npm install` 65 | - Run `npm run test.ios` or `npm run test.android` 66 | - Ensure your changes pass tslint validation. (run `npm run tslint` in the root of the repo). 67 | 68 | 6. Push your fork. If you have rebased you might have to use force-push your branch: 69 | ``` 70 | git push origin --force 71 | ``` 72 | 73 | 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. 74 | 75 | It's our turn from there on! We will review the PR and discuss changes you might have to make before merging it! Thanks! 76 | 77 | ## Where to Start 78 | 79 | 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). 80 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 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) 2 | 3 | > This repo is heavily based on [@NathanWalker](https://github.com/NathanWalker)'s [Plugin Seed](https://github.com/NathanWalker/nativescript-plugin-seed). Thanks, Nathan! 4 | 5 | 6 | 7 | - [TL;DR](#tldr) 8 | - [Long Description](#long-description) 9 | - [What is NativeScript plugin seed?](#what-is-nativescript-plugin-seed) 10 | - [Plugin folder structure](#plugin-folder-structure) 11 | - [Getting started](#getting-started) 12 | - [Development setup](#development-setup) 13 | - [Linking to CocoaPod or Android Arsenal plugins](#linking-to-cocoapod-or-android-arsenal-plugins) 14 | - [Generating typings for iOS](#generating-typings-for-ios) 15 | - [Generating typings for Android](#generating-typings-for-android) 16 | - [Clean plugin and demo files](#clean-plugin-and-demo-files) 17 | - [Unittesting](#unittesting) 18 | - [Publish to NPM](#publish-to-npm) 19 | - [TravisCI](#travisci) 20 | - [Referring tns-core-modules in the Plugin](#referring-tns-core-modules-in-the-plugin) 21 | - [Contribute](#contribute) 22 | - [Get Help](#get-help) 23 | 24 | 25 | 26 | ## TL;DR 27 | 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: 28 | 29 | 1. `git clone https://github.com/NativeScript/nativescript-plugin-seed nativescript-yourplugin` where `nativescript-yourplugin` is the name of your plugin. 30 | 2. `cd nativescript-yourplugin/src` 31 | 3. `npm run postclone` 32 | 4. `npm run demo.ios` or `npm run demo.android` to run the demo. 33 | 34 | ## Long Description 35 | 36 | ### What is NativeScript plugin seed? 37 | 38 | The NativeScript plugin seed is built to be used as a starting point by NativeScript plugin developers. 39 | What does the seed give you out of the box? 40 | * the plugin structure with option for easy development and debugging (see [Development setup section](#Developmentsetup) below) 41 | * a simple working plugin 42 | * a demo project working with the plugin. It is useful during development and for running tests via Travis CI 43 | * a guideline how to structure your plugin README file that will be published to NPM 44 | * a shell script to create your plugin package 45 | * a proper `.gitignore` to keep GitHub tidy 46 | * a proper `.npmignore` to ensure everyone is happy when you publish your plugin to NPM. 47 | 48 | ![Plugin seed demo](https://github.com/NativeScript/nativescript-plugin-seed/blob/master/screenshots/demo.png?raw=true) 49 | 50 | ### Plugin folder structure 51 | 52 | |Folder/File name| Description 53 | |---|---| 54 | |demo| The plugin demo source code (optional during __postclone__ setup)| 55 | |demo-angular| The plugin demo source code (optional during __postclone__ setup)| 56 | |src| The plugin source code| 57 | |src/platform/android| Plugin Android specific configuration| 58 | |src/platform/ios|Plugin ios specific configuration| 59 | |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.| 60 | |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| 61 | |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| 62 | 63 | ### Getting started 64 | 65 | 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.. 66 | 2. Open a command prompt/terminal and navigate to `nativescript-yourplugin/src` folder using `cd nativescript-yourplugin/src` 67 | 3. Execute `npm run postclone` to: 68 | * configure your github username - it will be changed in the package.json for you 69 | * configure your plugin name - all files and classes in the seed will be renamed for you 70 | * stub your plugin README.md file 71 | * add TypeScript NativeScript application which is setup to use your plugin from its local `src` folder 72 | * add Angular NativeScript application which is setup to use your plugin from its local `src` folder 73 | * create a new repository for your plugin 74 | 75 | Now you can continue with the development of your plugin by using the [Development setup](#Developmentsetup) described below. 76 | 77 | **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. 78 | 79 | #### Development setup 80 | For easier development and debugging purposes continue with the following: 81 | 82 | 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`. 83 | 84 | Now go and make a change to your plugin. It will be automatically applied to the demo project. 85 | 86 | **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. 87 | 88 | ### Linking to CocoaPod or Android Arsenal plugins 89 | 90 | You will want to create these folders and files in the `src` folder in order to use native APIs: 91 | 92 | ``` 93 | platforms -- 94 | ios -- 95 | Podfile 96 | android -- 97 | include.gradle 98 | ``` 99 | 100 | Doing so will open up those native apis to your plugin :) 101 | 102 | Take a look at these existing plugins for how that can be done very simply: 103 | 104 | * [nativescript-cardview](https://github.com/bradmartin/nativescript-cardview/tree/master/platforms) 105 | * [nativescript-floatingactionbutton](https://github.com/bradmartin/nativescript-floatingactionbutton/tree/master/src/platforms) 106 | 107 | 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 108 | 109 | #### Generating typings for iOS 110 | 111 | - Run the command for typings generation as explained in the [documentation](https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#troubleshooting) 112 | - Open `demo/typings/x86_64` and copy the `d.ts` files that you plan to use in your plugin to `src/platforms/ios/typings` 113 | - Open `src/references.d.ts` and add a reference to each of the files added to `src/platforms/ios/typings` 114 | 115 | **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). 116 | 117 | #### Generating typings for Android 118 | 119 | - Clone [Android DTS Generator repo](https://github.com/NativeScript/android-dts-generator) 120 | - Follow the steps in the [README](https://github.com/NativeScript/android-dts-generator/blob/master/README.md) 121 | - Copy the generated d.ts files in `src/platforms/android/typings`. Feel free to rename the generated files for readablity. 122 | - Open `src/references.d.ts` and add a reference to each of the files added to `src/platforms/android/typings` 123 | 124 | ### Clean plugin and demo files 125 | 126 | Sometimes you may need to wipe away the `src/node_modules`, `demo/node_modules` and `demo/platforms` folders to reinstall them fresh. 127 | 128 | * Run `npm run clean` to wipe those clean then you can can run `npm i` to install fresh dependencies. 129 | 130 | Sometimes you just need to wipe out the demo's `platforms` directory only: 131 | 132 | * Run `npm run demo.reset` or `npm run demo-angular.reset` to delete the application's `platforms` directory only. 133 | 134 | Sometimes you may need to ensure plugin files are updated in the demo: 135 | 136 | * 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. 137 | 138 | ### Unit testing 139 | 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). 140 | 141 | ### Publish to NPM 142 | 143 | When you have everything ready to publish: 144 | 145 | * Bump the version number in `src/package.json` 146 | * Go to `publish` and execute `publish.sh` (run `chmod +x *.sh` if the file isn't executable) 147 | 148 | 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. 149 | 150 | **NOTE**: To run bash script on Windows you can install [GIT SCM](https://git-for-windows.github.io/) and use Git Bash. 151 | 152 | ### TravisCI 153 | 154 | 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. 155 | 156 | 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. 157 | 158 | ## Contribute 159 | 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). 160 | 161 | ## Get Help 162 | 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). 163 | -------------------------------------------------------------------------------- /publish/pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SOURCE_DIR=../src; 4 | TO_SOURCE_DIR=src; 5 | PACK_DIR=package; 6 | ROOT_DIR=..; 7 | PUBLISH=--publish 8 | 9 | install(){ 10 | npm i 11 | } 12 | 13 | pack() { 14 | 15 | echo 'Clearing /src and /package...' 16 | node_modules/.bin/rimraf "$TO_SOURCE_DIR" 17 | node_modules/.bin/rimraf "$PACK_DIR" 18 | 19 | # copy src 20 | echo 'Copying src...' 21 | node_modules/.bin/ncp "$SOURCE_DIR" "$TO_SOURCE_DIR" 22 | 23 | # copy README & LICENSE to src 24 | echo 'Copying README and LICENSE to /src...' 25 | node_modules/.bin/ncp "$ROOT_DIR"/LICENSE "$TO_SOURCE_DIR"/LICENSE 26 | node_modules/.bin/ncp "$ROOT_DIR"/README.md "$TO_SOURCE_DIR"/README.md 27 | 28 | # compile package and copy files required by npm 29 | echo 'Building /src...' 30 | cd "$TO_SOURCE_DIR" 31 | node_modules/.bin/tsc 32 | cd .. 33 | 34 | echo 'Creating package...' 35 | # create package dir 36 | mkdir "$PACK_DIR" 37 | 38 | # create the package 39 | cd "$PACK_DIR" 40 | npm pack ../"$TO_SOURCE_DIR" 41 | 42 | # delete source directory used to create the package 43 | cd .. 44 | node_modules/.bin/rimraf "$TO_SOURCE_DIR" 45 | } 46 | 47 | install && pack -------------------------------------------------------------------------------- /publish/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nativescript-publish", 3 | "version": "1.0.0", 4 | "description": "Publish helper", 5 | "devDependencies": { 6 | "ncp": "^2.0.0", 7 | "rimraf": "^2.5.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /publish/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PACK_DIR=package; 4 | 5 | publish() { 6 | cd $PACK_DIR 7 | echo 'Publishing to npm...' 8 | npm publish *.tgz 9 | } 10 | 11 | ./pack.sh && publish -------------------------------------------------------------------------------- /screenshots/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NativeScript/nativescript-plugin-seed/dafc5c851f97ee4c797ba2ecc32275e30ed1c1a4/screenshots/demo.png -------------------------------------------------------------------------------- /seed-tests/e2e/config/appium.capabilities.json: -------------------------------------------------------------------------------- 1 | { 2 | "android19": { 3 | "platformName": "Android", 4 | "platformVersion": "4.4", 5 | "deviceName": "Emulator-Api19-Default", 6 | "avd": "Emulator-Api19-Default", 7 | "lt": 60000, 8 | "newCommandTimeout": 720, 9 | "noReset": false, 10 | "fullReset": false, 11 | "app": "" 12 | }, 13 | "android21": { 14 | "platformName": "Android", 15 | "platformVersion": "5.0", 16 | "deviceName": "Emulator-Api21-Default", 17 | "avd": "Emulator-Api21-Default", 18 | "lt": 60000, 19 | "newCommandTimeout": 720, 20 | "noReset": false, 21 | "fullReset": false, 22 | "app": "" 23 | }, 24 | "android23": { 25 | "platformName": "Android", 26 | "platformVersion": "6.0", 27 | "deviceName": "Emulator-Api23-Default", 28 | "avd": "Emulator-Api23-Default", 29 | "lt": 60000, 30 | "newCommandTimeout": 720, 31 | "noReset": false, 32 | "fullReset": false, 33 | "app": "" 34 | }, 35 | "android24": { 36 | "platformName": "Android", 37 | "platformVersion": "7.0", 38 | "deviceName": "Android GoogleAPI Emulator", 39 | "lt": 60000, 40 | "newCommandTimeout": 720, 41 | "noReset": true, 42 | "fullReset": false, 43 | "app": "", 44 | "idleTimeout": 120, 45 | "automationName": "Appium" 46 | }, 47 | "android25": { 48 | "platformName": "Android", 49 | "platformVersion": "7.1", 50 | "deviceName": "Emulator-Api25-Google", 51 | "avd": "Emulator-Api25-Google", 52 | "lt": 60000, 53 | "newCommandTimeout": 720, 54 | "noReset": false, 55 | "fullReset": false, 56 | "app": "" 57 | }, 58 | "android26": { 59 | "platformName": "Android", 60 | "platformVersion": "8.0", 61 | "deviceName": "Emulator-Api26-Google", 62 | "avd": "Emulator-Api26-Google", 63 | "lt": 60000, 64 | "newCommandTimeout": 720, 65 | "noReset": false, 66 | "fullReset": false, 67 | "app": "" 68 | }, 69 | "android27": { 70 | "platformName": "Android", 71 | "platformVersion": "27", 72 | "deviceName": "Emulator-Api27-Google", 73 | "avd": "Emulator-Api27-Google", 74 | "lt": 60000, 75 | "newCommandTimeout": 720, 76 | "noReset": false, 77 | "fullReset": false, 78 | "app": "" 79 | }, 80 | "android28": { 81 | "platformName": "Android", 82 | "platformVersion": "28", 83 | "deviceName": "Emulator-Api28-Google", 84 | "avd": "Emulator-Api28-Google", 85 | "lt": 60000, 86 | "newCommandTimeout": 720, 87 | "noReset": false, 88 | "fullReset": false, 89 | "app": "" 90 | }, 91 | "sim.iPhone7": { 92 | "platformName": "iOS", 93 | "platformVersion": "/12.*/", 94 | "deviceName": "iPhone 7", 95 | "noReset": false, 96 | "fullReset": false, 97 | "app": "" 98 | }, 99 | "sim.iPhone8": { 100 | "platformName": "iOS", 101 | "platformVersion": "/12*/", 102 | "deviceName": "iPhone 8", 103 | "noReset": false, 104 | "fullReset": false, 105 | "app": "" 106 | }, 107 | "sim12iPhoneX": { 108 | "platformName": "iOS", 109 | "platformVersion": "12.0", 110 | "deviceName": "iPhone X", 111 | "appium-version": "1.9.1", 112 | "app": "", 113 | "noReset": true, 114 | "fullReset": false, 115 | "density": 3, 116 | "offsetPixels": 87, 117 | "idleTimeout": 120, 118 | "automationName": "Appium" 119 | }, 120 | "sim.iPhoneXS": { 121 | "platformName": "ios", 122 | "platformVersion": "/12*/", 123 | "deviceName": "iPhone XS", 124 | "noReset": false, 125 | "fullReset": false, 126 | "app": "" 127 | } 128 | } -------------------------------------------------------------------------------- /seed-tests/e2e/config/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 800000 2 | --recursive e2e 3 | --reporter mocha-multi 4 | --reporter-options mochawesome=-,mocha-junit-reporter=test-results.xml 5 | --exit -------------------------------------------------------------------------------- /seed-tests/e2e/setup.ts: -------------------------------------------------------------------------------- 1 | import { startServer, stopServer, ITestReporter, nsCapabilities, LogImageType } from "nativescript-dev-appium"; 2 | const addContext = require('mochawesome/addContext'); 3 | 4 | const testReporterContext = {}; 5 | testReporterContext.name = "mochawesome"; 6 | /** 7 | * This folder should be the one provided in mocha.opts. 8 | * If omitted the default one is "mochawesome-report". 9 | * This is necessary because we need the logged images to be relatively 10 | * positioned according to mochawesome.html in the same folder 11 | */ 12 | testReporterContext.reportDir = "mochawesome-report"; 13 | testReporterContext.log = addContext; 14 | testReporterContext.logImageTypes = [LogImageType.screenshots]; 15 | nsCapabilities.testReporter = testReporterContext; 16 | 17 | before("start server", async function () { 18 | nsCapabilities.testReporter.context = this; 19 | await startServer(); 20 | }); 21 | 22 | after("stop server", async function () { 23 | await stopServer(); 24 | }); 25 | -------------------------------------------------------------------------------- /seed-tests/e2e/tests.e2e.ts: -------------------------------------------------------------------------------- 1 | import { AppiumDriver, createDriver, SearchOptions, nsCapabilities } from "nativescript-dev-appium"; 2 | import { isSauceLab } from "nativescript-dev-appium/lib/parser"; 3 | import { expect } from "chai"; 4 | import "mocha"; 5 | 6 | const fs = require('fs'); 7 | const addContext = require('mochawesome/addContext'); 8 | const rimraf = require('rimraf'); 9 | const isSauceRun = isSauceLab; 10 | 11 | describe("sample scenario", () => { 12 | let driver: AppiumDriver; 13 | 14 | before(async function() { 15 | nsCapabilities.testReporter.context = this; 16 | driver = await createDriver(); 17 | driver.defaultWaitTime = 20000; 18 | let dir = "mochawesome-report"; 19 | if (!fs.existsSync(dir)) { 20 | fs.mkdirSync(dir); 21 | } 22 | rimraf('mochawesome-report/*', function () { }); 23 | }); 24 | 25 | after(async function () { 26 | if (isSauceRun) { 27 | driver.sessionId().then(function (sessionId) { 28 | console.log("Report: https://saucelabs.com/beta/tests/" + sessionId); 29 | }); 30 | } 31 | await driver.quit(); 32 | console.log("Driver successfully quit"); 33 | }); 34 | 35 | afterEach(async function () { 36 | if (this.currentTest.state && this.currentTest.state === "failed") { 37 | let png = await driver.logScreenshot(this.currentTest.title); 38 | fs.copyFile(png, './mochawesome-report/' + this.currentTest.title + '.png', function (err) { 39 | if (err) { 40 | throw err; 41 | } 42 | console.log('Screenshot saved.'); 43 | }); 44 | addContext(this, './' + this.currentTest.title + '.png'); 45 | } 46 | }); 47 | 48 | it("should find an element by text", async function () { 49 | const alertTitle = await driver.findElementByText("Alert", SearchOptions.contains); 50 | expect(alertTitle).to.exist; 51 | 52 | const okBtn = await driver.findElementByText("OK", SearchOptions.contains); 53 | await okBtn.click(); 54 | }); 55 | }); -------------------------------------------------------------------------------- /seed-tests/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "experimentalDecorators": true, 6 | "emitDecoratorMetadata": true, 7 | "importHelpers": false, 8 | "types": [ 9 | "mocha", 10 | "chai", 11 | "node" 12 | ], 13 | "lib": [ 14 | "es2015", 15 | "dom" 16 | ], 17 | "baseUrl": "." 18 | } 19 | } -------------------------------------------------------------------------------- /seed-tests/jasmine.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": ".", 3 | "spec_files": ["./*tests.js"], 4 | "stopSpecOnExpectationFailure": false, 5 | "random": false 6 | } -------------------------------------------------------------------------------- /seed-tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "async": "^2.4.1", 4 | "cross-env": "^5.1.3", 5 | "glob": "^7.1.2", 6 | "jasmine": "^2.6.0", 7 | "ncp": "^2.0.0", 8 | "rimraf": "^2.6.1", 9 | "@types/chai": "~4.1.7", 10 | "@types/mocha": "~5.2.5", 11 | "@types/node": "~10.12.18", 12 | "chai": "^4.1.2", 13 | "mocha": "^5.2.0", 14 | "mocha-junit-reporter": "~1.18.0", 15 | "mocha-multi": "~1.0.1", 16 | "mochawesome": "~3.1.2", 17 | "nativescript-dev-appium": "^5.3.0", 18 | "nativescript-dev-typescript": "~0.10.0", 19 | "nativescript-dev-webpack": "~0.24.0" 20 | }, 21 | "scripts": { 22 | "test.android": "cross-env ANDROID=true jasmine --config=jasmine.config.json", 23 | "test.ios": "cross-env IOS=true jasmine --config=jasmine.config.json", 24 | "e2e": "node ./node_modules/nativescript-dev-appium/check-dev-deps.js && tsc -p e2e && mocha --opts ./e2e/config/mocha.opts", 25 | "e2e-watch": "tsc -p e2e --watch" 26 | }, 27 | "dependencies": {} 28 | } 29 | -------------------------------------------------------------------------------- /seed-tests/postclone.tests.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec; 2 | var fs = require('fs'); 3 | var glob = require("glob"); 4 | var testUtils = require("./tests.utils"); 5 | var constants = require("./tests.constants"); 6 | var path = require("path"); 7 | 8 | var _srcReadmeContent = ""; 9 | 10 | describe('postclone', function () { 11 | 12 | // keep before 'should not init new git repo' 13 | // in order to avoid getting new files in the git repo 14 | it('should init new git repo', function (done) { 15 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 16 | if (err) { 17 | done.fail(err); 18 | } 19 | 20 | testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "y", "n", "n", function (error) { 21 | if (error) { 22 | done.fail(error); 23 | } else { 24 | exec("cd " + constants.SEED_COPY_LOCATION + "/src && git config --get remote.origin.url", function (error, stdout, stderr) { 25 | expect(stdout).toEqual(""); 26 | done(); 27 | }); 28 | } 29 | }); 30 | }); 31 | }); 32 | 33 | it('should not init new git repo', function (done) { 34 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 35 | if (err) { 36 | done.fail(err); 37 | } 38 | 39 | _srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md"); 40 | testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "n", "n", function (error, stdout) { 41 | if (error) { 42 | done.fail(error); 43 | } else { 44 | exec("cd " + constants.SEED_COPY_LOCATION + " && git config --get remote.origin.url", function (execError, stdout, stderr) { 45 | expect(stdout).toContain("NativeScript/nativescript-plugin-seed.git"); 46 | done(); 47 | }); 48 | } 49 | }); 50 | }); 51 | }); 52 | 53 | it('should create only TypeScript app (demo)', function (done) { 54 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 55 | if (err) { 56 | done.fail(err); 57 | } 58 | 59 | _srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md"); 60 | testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "y", "n", function (error, stdout) { 61 | if (error) { 62 | done.fail(error); 63 | } else { 64 | var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); 65 | let tsConfigContents = fs.readFileSync(seedCopyPath + "/demo/tsconfig.json").toString('utf-8'); 66 | 67 | expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true); 68 | expect(stdout.includes("Updating ../demo/")).toBe(true); 69 | expect(tsConfigContents.includes("app/*")).toBe(true); 70 | 71 | expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(false); 72 | expect(stdout.includes("Updating ../demo-angular/")).toBe(false); 73 | 74 | done(); 75 | } 76 | }); 77 | }); 78 | }); 79 | 80 | it('should create only TypeScript app (demo) for Release branch', function (done) { 81 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 82 | if (err) { 83 | done.fail(err);x 84 | } 85 | 86 | _srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md"); 87 | testUtils.callPostcloneForBranch(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "y", "n", function (error, stdout) { 88 | if (error) { 89 | done.fail(error); 90 | } else { 91 | var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); 92 | let tsConfigContents = fs.readFileSync(seedCopyPath + "/demo/tsconfig.json").toString('utf-8'); 93 | 94 | expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true); 95 | expect(stdout.includes("Updating ../demo/")).toBe(true); 96 | expect(stdout.includes("Creating 'TypeScript' application from branch release...")).toBe(true); 97 | expect(tsConfigContents.includes("app/*")).toBe(true); 98 | 99 | expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(false); 100 | expect(stdout.includes("Updating ../demo-angular/")).toBe(false); 101 | 102 | done(); 103 | } 104 | }); 105 | }); 106 | }); 107 | 108 | it('should create only Angular app (demo-angular)', function (done) { 109 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 110 | if (err) { 111 | done.fail(err); 112 | } 113 | 114 | _srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md"); 115 | testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "n", "y", function (error, stdout) { 116 | if (error) { 117 | done.fail(error); 118 | } else { 119 | var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); 120 | expect(fs.existsSync(seedCopyPath + "/demo")).toBe(false); 121 | expect(stdout.includes("Updating ../demo/")).toBe(false); 122 | 123 | let angularTsConfigContents = fs.readFileSync(seedCopyPath + "/demo-angular/tsconfig.json").toString('utf-8'); 124 | 125 | expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true); 126 | expect(stdout.includes("Updating ../demo-angular/")).toBe(true); 127 | expect(angularTsConfigContents.includes("src/*")).toBe(true); 128 | 129 | done(); 130 | } 131 | }); 132 | }); 133 | }); 134 | 135 | it('should create both TypeScript & Angular app (demo & demo-angular)', function (done) { 136 | testUtils.copySeedDir(constants.SEED_LOCATION, constants.SEED_COPY_LOCATION, function (err) { 137 | if (err) { 138 | done.fail(err); 139 | } 140 | 141 | _srcReadmeContent = fs.readFileSync(constants.SEED_LOCATION + "/src/README.md"); 142 | testUtils.callPostclone(constants.SEED_COPY_LOCATION, constants.TEST_GITHUB_USERNAME, constants.TEST_PLUGIN_NAME, "n", "y", "y", function (error, stdout) { 143 | if (error) { 144 | done.fail(error); 145 | } else { 146 | var seedCopyPath = path.resolve(__dirname, constants.SEED_COPY_LOCATION); 147 | let tsConfigContents = fs.readFileSync(seedCopyPath + "/demo/tsconfig.json").toString('utf-8'); 148 | 149 | expect(fs.existsSync(seedCopyPath + "/demo")).toBe(true); 150 | expect(stdout.includes("Updating ../demo/")).toBe(true); 151 | expect(tsConfigContents.includes("app/*")).toBe(true); 152 | 153 | let angularTsConfigContents = fs.readFileSync(seedCopyPath + "/demo-angular/tsconfig.json").toString('utf-8'); 154 | 155 | expect(fs.existsSync(seedCopyPath + "/demo-angular")).toBe(true); 156 | expect(stdout.includes("Updating ../demo-angular/")).toBe(true); 157 | expect(angularTsConfigContents.includes("src/*")).toBe(true); 158 | 159 | done(); 160 | } 161 | }); 162 | }); 163 | }); 164 | 165 | it('should delete the seed screenshots folder', function () { 166 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/screenshots")).toBeFalsy(); 167 | }); 168 | 169 | it('should delete the seed CONTRIBUTING.md', function () { 170 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/CONTRIBUTING.md")).toBeFalsy(); 171 | }); 172 | 173 | it('should delete the seed CODE_OF_CONDUCT.md', function () { 174 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/CODE_OF_CONDUCT.md")).toBeFalsy(); 175 | }); 176 | 177 | it('should delete the postclone.js', function () { 178 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/src/scripts/postclone.js")).toBeFalsy(); 179 | }); 180 | 181 | it('should delete the postclone script', function () { 182 | let packageJsonContents = fs.readFileSync(constants.SEED_COPY_LOCATION + "/src/package.json").toString('utf-8'); 183 | expect(packageJsonContents.includes("postclone")).toBeFalsy(); 184 | }); 185 | 186 | it('should delete the seed tests folder', function () { 187 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/seed-tests")).toBeFalsy(); 188 | }); 189 | 190 | it('should rename each yourplugin file with the new plugin name in README', function () { 191 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/README.md")).toBeTruthy(); 192 | 193 | var readmeContent = fs.readFileSync(constants.SEED_COPY_LOCATION + "/README.md"); 194 | expect(readmeContent).toContain("nativescript-" + constants.TEST_PLUGIN_NAME); 195 | expect(readmeContent).toContain("tns plugin add nativescript-" + constants.TEST_PLUGIN_NAME); 196 | }); 197 | 198 | it('should remove old src/README and create a new /README', function() { 199 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/README.md")).toBeTruthy(); 200 | expect(fs.existsSync(constants.SEED_COPY_LOCATION + "/src/README.md")).toBeFalsy(); 201 | }); 202 | 203 | it('should rename each yourplugin file', function (done) { 204 | glob(constants.SEED_COPY_LOCATION + "/**/yourplugin*.*", function (er, files) { 205 | expect(files.length).toEqual(0); 206 | done(); 207 | }); 208 | }); 209 | 210 | it('should rename each yourplugin file with the new plugin name', function (done) { 211 | glob(constants.SEED_COPY_LOCATION + "/**/" + constants.TEST_PLUGIN_NAME + "*.*", function (er, files) { 212 | expect(files.length).toBeGreaterThan(0); 213 | done(); 214 | }); 215 | }); 216 | 217 | it('should replace each yourplugin string', function (done) { 218 | testUtils.findInFiles("yourplugin", constants.SEED_COPY_LOCATION, function (resultsCount) { 219 | expect(resultsCount).toEqual(0); 220 | done(); 221 | }); 222 | }); 223 | 224 | it('should replace each YourPlugin string', function (done) { 225 | testUtils.findInFiles("YourPlugin", constants.SEED_COPY_LOCATION, function (resultsCount) { 226 | expect(resultsCount).toEqual(0); 227 | done(); 228 | }); 229 | }); 230 | 231 | it('should replace each yourPlugin string', function (done) { 232 | testUtils.findInFiles("yourPlugin", constants.SEED_COPY_LOCATION, function (resultsCount) { 233 | expect(resultsCount).toEqual(0); 234 | done(); 235 | }); 236 | }); 237 | 238 | it('should replace each YourName string', function (done) { 239 | testUtils.findInFiles("YourName", constants.SEED_COPY_LOCATION, function (resultsCount) { 240 | expect(resultsCount).toEqual(0); 241 | done(); 242 | }); 243 | }); 244 | 245 | it('should replace each YourName string with the test github username', function (done) { 246 | testUtils.findInFiles(constants.TEST_GITHUB_USERNAME, constants.SEED_COPY_LOCATION, function (resultsCount) { 247 | // plugin author in the package json 248 | expect(resultsCount).toEqual(1); 249 | done(); 250 | }); 251 | }); 252 | 253 | it('should replace each YourPlugin string with ThePlugin', function (done) { 254 | testUtils.findInFiles(constants.TEST_PLUGIN_NAME, constants.SEED_COPY_LOCATION, function (resultsCount) { 255 | expect(resultsCount).toBeGreaterThan(0); 256 | done(); 257 | }); 258 | }); 259 | 260 | it('should replace each nativescript-YourPlugin string with nativescript-ThePlugin', function (done) { 261 | testUtils.findInFiles("nativescript-" + constants.TEST_PLUGIN_NAME, constants.SEED_COPY_LOCATION, function (resultsCount) { 262 | expect(resultsCount).toBeGreaterThan(0); 263 | done(); 264 | }); 265 | }); 266 | }); -------------------------------------------------------------------------------- /seed-tests/tests.constants.js: -------------------------------------------------------------------------------- 1 | exports.SEED_LOCATION = "../"; 2 | exports.SEED_COPY_LOCATION = "seed-copy"; 3 | exports.SEED_TESTS_LOCATION = "seed-tests"; 4 | exports.DEFAULT_PLUGIN_NAME = "nativescript-yourplugin"; 5 | exports.TEST_PLUGIN_NAME = "ThePlugin"; 6 | exports.TEST_GITHUB_USERNAME = "TheGitHubUser"; 7 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 1200000; // 20 mins -------------------------------------------------------------------------------- /seed-tests/tests.utils.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec; 2 | var rimraf = require('rimraf'); 3 | var ncp = require('ncp').ncp; 4 | var fs = require('fs'); 5 | var async = require("async"); 6 | var os = require('os'); 7 | var constants = require('./tests.constants'); 8 | 9 | exports.findInFiles = function findInFiles(string, dir, callback) { 10 | var _resultsCount = 0; 11 | var _excludedPaths = ["node_modules", "src/scripts/postclone", "/seed-tests/", ".git"]; 12 | 13 | function _findInFiles(string, dir, callback) { 14 | fs.readdir(dir, function (err, entries) { 15 | entries = entries.filter(function (entry) { 16 | var fullEntry = dir + '/' + entry; 17 | var shouldBeIncluded = true; 18 | _excludedPaths.forEach(function callback(currentValue) { 19 | shouldBeIncluded = fullEntry.indexOf(currentValue) === -1 && shouldBeIncluded; 20 | }); 21 | 22 | return shouldBeIncluded; 23 | }); 24 | async.eachSeries(entries, function (entry, foreachCallback) { 25 | entry = dir + '/' + entry; 26 | fs.stat(entry, function (err, stat) { 27 | if (stat && stat.isDirectory()) { 28 | _findInFiles(string, entry, foreachCallback); 29 | } else { 30 | fs.readFile(entry, 'utf-8', function (err, contents) { 31 | if (contents.indexOf(string) > -1) { 32 | _resultsCount++; 33 | } 34 | 35 | foreachCallback(); 36 | }); 37 | } 38 | }); 39 | }, function (err) { 40 | callback(); 41 | }); 42 | }); 43 | }; 44 | 45 | _findInFiles(string, dir, function () { 46 | callback(_resultsCount); 47 | }); 48 | }; 49 | 50 | exports.copySeedDir = function copySeedDir(seedLocation, copyLocation, callback) { 51 | rimraf.sync(copyLocation); 52 | 53 | ncp(seedLocation, copyLocation, { 54 | filter: function (fileName) { 55 | if ((fileName.indexOf("seed-tests") > -1 && fileName.indexOf(constants.SEED_COPY_LOCATION) > -1) || 56 | (fileName.indexOf("seed-tests") > -1 && fileName.indexOf("node_modules") > -1) || 57 | (fileName.indexOf("src") > -1 && fileName.indexOf("node_modules") > -1)) { 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | }, function (err) { 64 | if (!err) { 65 | console.log(copyLocation + ' folder successfully created.'); 66 | } 67 | callback(err); 68 | }); 69 | }; 70 | 71 | exports.callPostclone = function callPostclone(seedLocation, githubUsername, pluginName, initGit, includeTypeScriptDemo, includeAngularDemo, callback) { 72 | var postcloneScript = getPackageJsonPostcloneScript(); 73 | postcloneScript = postcloneScript.replace("postclone.js", "postclone.js gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypeScriptDemo=" + includeTypeScriptDemo + " includeAngularDemo=" + includeAngularDemo); 74 | console.log("Executing postclone script with args: " + postcloneScript); 75 | exec("cd " + seedLocation + "/src && " + postcloneScript, function (error, stdout, stderr) { 76 | callback(error, stdout, stderr); 77 | }); 78 | }; 79 | 80 | exports.callPostcloneForBranch = function callPostcloneForBranch(seedLocation, githubUsername, pluginName, initGit, includeTypeScriptDemo, includeAngularDemo, callback) { 81 | var postcloneScript = getPackageJsonPostcloneScript(); 82 | postcloneScript = postcloneScript.replace("postclone.js", "postclone.js templatesBranch=release gitHubUsername=" + githubUsername + " pluginName=" + pluginName + " initGit=" + initGit + " includeTypeScriptDemo=" + includeTypeScriptDemo + " includeAngularDemo=" + includeAngularDemo); 83 | console.log("Executing postclone script with args: " + postcloneScript); 84 | exec("cd " + seedLocation + "/src && " + postcloneScript, function (error, stdout, stderr) { 85 | callback(error, stdout, stderr); 86 | }); 87 | }; 88 | 89 | exports.callDevelopmentSetup = function callDevelopmentSetup(seedLocation, callback) { 90 | exec("cd " + seedLocation + "/src && npm run development.setup", function (error, stdout, stderr) { 91 | callback(error, stdout, stderr); 92 | }); 93 | }; 94 | 95 | exports.getNpmLinks = function getNpmLinks(callback) { 96 | exec("npm list -g --depth=0", function (error, stdout, stderr) { 97 | var links = stdout.split(os.EOL) 98 | .map(function (item) { 99 | return item.replace("├──", "").replace("└──", "").trim(); 100 | }) 101 | .filter(function (item) { 102 | return !!item && item.indexOf("->") !== -1; 103 | }); 104 | 105 | callback(links); 106 | }); 107 | } 108 | 109 | exports.removeNpmLink = function removeNpmLink(packageName, callback) { 110 | exec("npm remove " + packageName + " -g", function (error, stdout, stderr) { 111 | callback(); 112 | }); 113 | } 114 | 115 | exports.isAndroid = function isAndroid() { 116 | return !!!process.env.IOS; 117 | } 118 | 119 | function getPackageJsonPostcloneScript() { 120 | var packageJsonFile = constants.SEED_COPY_LOCATION + "/src/package.json"; 121 | 122 | if (fs.lstatSync(packageJsonFile).isFile()) { 123 | var packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')); 124 | var packageJsonScripts = packageJson["scripts"]; 125 | 126 | if (packageJsonScripts && packageJsonScripts["postclone"]) { 127 | return packageJsonScripts["postclone"]; 128 | }; 129 | } 130 | 131 | return ""; 132 | } -------------------------------------------------------------------------------- /src/.npmignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.ts 3 | !*.d.ts 4 | tsconfig.json 5 | scripts/* 6 | platforms/android/* 7 | !platforms/android/include.gradle 8 | !platforms/android/*.aar 9 | !platforms/android/*.jar 10 | .DS_Store -------------------------------------------------------------------------------- /src/.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - stage: "Lint" 4 | language: node_js 5 | os: linux 6 | node_js: "10" 7 | script: cd src && npm run ci.tslint 8 | - stage: "WebPack, Build and Test" 9 | os: osx 10 | env: 11 | - WebPack="iOS" 12 | osx_image: xcode10.2 13 | language: node_js 14 | node_js: "10" 15 | jdk: oraclejdk8 16 | script: cd src && npm run build && cd ../demo && npm i && tns build ios --bundle --env.uglify 17 | - language: android 18 | os: linux 19 | env: 20 | - WebPack="Android" 21 | jdk: oraclejdk8 22 | before_install: nvm install 10 23 | script: cd src && npm run build && cd ../demo && npm i && tns build android --bundle --env.uglify --env.snapshot 24 | - language: android 25 | env: 26 | - BuildAndroid="28" 27 | os: linux 28 | jdk: oraclejdk8 29 | before_install: nvm install 10 30 | script: 31 | - cd src && npm i && npm run tsc && cd ../demo && tns build android 32 | - os: osx 33 | env: 34 | - BuildiOS="12" 35 | - Xcode="10.0" 36 | osx_image: xcode10.2 37 | language: node_js 38 | node_js: "10" 39 | jdk: oraclejdk8 40 | script: 41 | - cd src && npm i && npm run tsc && cd ../demo && tns build ios 42 | - os: linux 43 | language: android 44 | dist: precise 45 | sudo: required 46 | jdk: oraclejdk8 47 | before_script: 48 | - echo no | android create avd --force -n test -t android-21 -b armeabi-v7a 49 | - emulator -avd test -no-audio -no-window & 50 | - android-wait-for-emulator 51 | before_install: 52 | - nvm install 10 53 | script: cd src && npm run test.android 54 | - os: osx 55 | language: node_js 56 | node_js: "10" 57 | jdk: oraclejdk8 58 | osx_image: xcode10.2 59 | script: cd src && npm run test.ios 60 | 61 | android: 62 | components: 63 | - tools 64 | - platform-tools 65 | - build-tools-28.0.3 66 | - android-28 67 | - extra-android-m2repository 68 | - sys-img-armeabi-v7a-android-21 69 | 70 | before_install: 71 | - sudo pip install --upgrade pip 72 | - sudo pip install six 73 | 74 | install: 75 | - echo no | npm install -g nativescript 76 | - tns usage-reporting disable 77 | - tns error-reporting disable 78 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # nativescript-yourplugin 2 | 3 | Add your plugin badges here. See [nativescript-urlhandler](https://github.com/hypery2k/nativescript-urlhandler) for example. 4 | 5 | Then describe what's the purpose of your plugin. 6 | 7 | In case you develop UI plugin, this is where you can add some screenshots. 8 | 9 | ## (Optional) Prerequisites / Requirements 10 | 11 | Describe the prerequisites that the user need to have installed before using your plugin. See [nativescript-firebase plugin](https://github.com/eddyverbruggen/nativescript-plugin-firebase) for example. 12 | 13 | ## Installation 14 | 15 | Describe your plugin installation steps. Ideally it would be something like: 16 | 17 | ```javascript 18 | tns plugin add nativescript-yourplugin 19 | ``` 20 | 21 | ## Usage 22 | 23 | Describe any usage specifics for your plugin. Give examples for Android, iOS, Angular if needed. See [nativescript-drop-down](https://www.npmjs.com/package/nativescript-drop-down) for example. 24 | 25 | ```javascript 26 | Usage code snippets here 27 | ```) 28 | 29 | ## API 30 | 31 | Describe your plugin methods and properties here. See [nativescript-feedback](https://github.com/EddyVerbruggen/nativescript-feedback) for example. 32 | 33 | | Property | Default | Description | 34 | | --- | --- | --- | 35 | | some property | property default value | property description, default values, etc.. | 36 | | another property | property default value | property description, default values, etc.. | 37 | 38 | ## License 39 | 40 | Apache License Version 2.0, January 2004 41 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Common } from './yourplugin.common'; 2 | export declare class YourPlugin extends Common { 3 | // define your typings manually 4 | // or.. 5 | // take the ios or android .d.ts files and copy/paste them here 6 | } 7 | -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nativescript-yourplugin", 3 | "version": "1.0.0", 4 | "description": "Your awesome NativeScript plugin.", 5 | "main": "yourplugin", 6 | "typings": "index.d.ts", 7 | "nativescript": { 8 | "platforms": { 9 | "android": "6.0.0", 10 | "ios": "6.0.1" 11 | } 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/YourName/nativescript-yourplugin.git" 16 | }, 17 | "scripts": { 18 | "tsc": "npm i && tsc", 19 | "build": "npm run tsc && npm run build.native", 20 | "build.native": "node scripts/build-native.js", 21 | "postclone": "npm i && node scripts/postclone.js", 22 | "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", 23 | "ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", 24 | "prepack": "npm run build.native" 25 | }, 26 | "keywords": [ 27 | "NativeScript", 28 | "JavaScript", 29 | "Android", 30 | "iOS" 31 | ], 32 | "author": { 33 | "name": "Your Name", 34 | "email": "youremail@yourdomain.com" 35 | }, 36 | "bugs": { 37 | "url": "https://github.com/YourName/nativescript-yourplugin/issues" 38 | }, 39 | "license": "Apache-2.0", 40 | "homepage": "https://github.com/YourName/nativescript-yourplugin", 41 | "devDependencies": { 42 | "tns-core-modules": "^6.0.0", 43 | "tns-platform-declarations": "^6.0.0", 44 | "typescript": "~3.4.5", 45 | "prompt": "^1.0.0", 46 | "rimraf": "^2.6.3", 47 | "tslint": "^5.12.1", 48 | "semver": "^5.6.0" 49 | }, 50 | "dependencies": {}, 51 | "bootstrapper": "nativescript-plugin-seed" 52 | } 53 | -------------------------------------------------------------------------------- /src/platforms/android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/platforms/android/README.md: -------------------------------------------------------------------------------- 1 | # Android permissions and dependencies 2 | 3 | * (Optional) Use AndroidManifest.xml to describe any permissions, features or other configuration specifics required or used by your plugin for Android. 4 | NOTE: The NativeScript CLI will not resolve any contradicting or duplicate entries during the merge. After the plugin is installed, you need to manually resolve such issues. 5 | 6 | * (Optional) Use include.gradle configuration to describe any native dependencies. If there are no such, this file can be removed. For more information, see the [include.gradle Specification](http://docs.nativescript.org/plugins/plugins#includegradle-specification) 7 | 8 | 9 | [Read more about nativescript plugins](http://docs.nativescript.org/plugins/plugins) -------------------------------------------------------------------------------- /src/platforms/android/include.gradle: -------------------------------------------------------------------------------- 1 | /* Include.gradle configuration: http://docs.nativescript.org/plugins/plugins#includegradle-specification */ 2 | 3 | android { 4 | 5 | } 6 | 7 | dependencies { 8 | // Describe plugin native Android dependencies like 9 | // implementation "groupName:pluginName:ver" 10 | // EXAMPLE: implementation "com.facebook.fresco:fresco:0.9.0+" 11 | } -------------------------------------------------------------------------------- /src/platforms/ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/platforms/ios/README.md: -------------------------------------------------------------------------------- 1 | # iOS permissions and dependencies 2 | 3 | 4 | * (Optional) Use Info.plist to describe any permissions, features or other configuration specifics required or used by your plugin for iOS. 5 | NOTE: The NativeScript CLI will not resolve any contradicting or duplicate entries during the merge. After the plugin is installed, you need to manually resolve such issues. 6 | * (Optional) Use build.xcconfig configuration to describe any plugin the native dependencies. If there are no such, this file can be removed. For more information, see the [build.xcconfig Specification section](http://docs.nativescript.org/plugins/plugins#buildxcconfig-specification). 7 | 8 | 9 | [Read more about nativescript plugins](http://docs.nativescript.org/plugins/plugins) -------------------------------------------------------------------------------- /src/platforms/ios/build.xcconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NativeScript/nativescript-plugin-seed/dafc5c851f97ee4c797ba2ecc32275e30ed1c1a4/src/platforms/ios/build.xcconfig -------------------------------------------------------------------------------- /src/references.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /src/scripts/build-native.js: -------------------------------------------------------------------------------- 1 | const { exec } = require('child_process'); 2 | const semver = require('semver'); 3 | 4 | exec('tns --version', (err, stdout, stderr) => { 5 | if (err) { 6 | // node couldn't execute the command 7 | console.log(`tns --version err: ${err}`); 8 | return; 9 | } 10 | 11 | // In case the current Node.js version is not supported by CLI, a warning in `tns --version` output is shown. 12 | // Sample output: 13 | // 14 | /*Support for Node.js ^8.0.0 is deprecated and will be removed in one of the next releases of NativeScript. Please, upgrade to the latest Node.js LTS version. 15 | 16 | 6.0.0 17 | */ 18 | // Extract the actual version (6.0.0) from it. 19 | const tnsVersion = semver.major((stdout.match(/^(?:\d+\.){2}\d+.*?$/m) || [])[0]); 20 | 21 | // execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder. 22 | if (tnsVersion >= 4) { 23 | console.log(`executing 'tns plugin build'`); 24 | exec('tns plugin build', (err, stdout, stderr) => { 25 | if (err) { 26 | // node couldn't execute the command 27 | console.log(`${err}`); 28 | return; 29 | } 30 | }); 31 | } 32 | }); 33 | -------------------------------------------------------------------------------- /src/scripts/postclone.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var prompt = require('prompt'); 3 | var rimraf = require('rimraf'); 4 | var exec = require('child_process').exec; 5 | const spawn = require('child_process').spawn; 6 | const pathModule = require("path"); 7 | 8 | var class_name, 9 | inputParams = { 10 | plugin_name: undefined, 11 | github_username: undefined, 12 | init_git: undefined, 13 | include_javascript_demo: undefined, 14 | include_typescript_demo: undefined, 15 | include_angular_demo: undefined, 16 | include_vue_demo: undefined, 17 | templates_branch: undefined 18 | }, 19 | seed_plugin_name = "yourplugin", 20 | seed_class_name = "YourPlugin", 21 | seed_demo_property_name = "yourPlugin", 22 | seed_github_username = "YourName", 23 | tsAppName = "demo", 24 | angularAppName = "demo-angular", 25 | // vueAppName = "demo-vue", 26 | demoTsFolder = "../" + tsAppName, 27 | demoAngularFolder = "../" + angularAppName, 28 | // demoVueFolder = "../" + vueAppName, 29 | screenshots_dir = "../screenshots", 30 | templates_dir = "../nativescript-app-templates", 31 | seed_tests_dir = "../seed-tests", 32 | scripts_dir = "scripts", 33 | filesToReplace = { 34 | readmeFile: { 35 | source: "README.md", 36 | destination: "../README.md" 37 | }, 38 | travisFile: { 39 | source: ".travis.yml", 40 | destination: "../.travis.yml" 41 | } 42 | }, 43 | appsToCreate = [], 44 | appsToInstallPluginIn = [], 45 | demoTsSearchTerm = ".bindingContext =", 46 | demoAngularSearchTerm = 'templateUrl: "app.component.html"', 47 | demoVueSearchTerm = '', 48 | preDefinedInclude = [ 49 | "../src", 50 | "**/*" 51 | ], 52 | preDefinedExclude = [ 53 | "../src/node_modules", 54 | "node_modules", 55 | "platforms" 56 | ], 57 | preDefinedPaths = [ 58 | { 59 | key: "*", 60 | value: [ 61 | "./node_modules/*" 62 | ] 63 | } 64 | ], 65 | appNamePlaceholderStr = "appNamePlaceholder", 66 | pluginNamePlaceholderStr = "pluginNamePlaceholder", 67 | appPathPlaceholderStr = "appPathPlaceholder", 68 | removeAddPluginCommand = "cd appNamePlaceholder && tns plugin remove pluginNamePlaceholder && tns plugin add ../src", 69 | removeAddPluginCommandPlaceholderStr = "removeAddPluginCommandPlaceholder", 70 | cleanAppsScriptPlaceholderStr = "cleanAppsScriptPlaceholder", 71 | preDefinedAppScripts = [ 72 | { 73 | key: "appNamePlaceholder.ios", 74 | value: "npm i && cd appPathPlaceholder && tns run ios" 75 | }, 76 | { 77 | key: "appNamePlaceholder.android", 78 | value: "npm i && cd appPathPlaceholder && tns run android" 79 | }], 80 | preDefinedPrepareScript = 81 | { 82 | key: "plugin.prepare", 83 | value: "npm run build removeAddPluginCommandPlaceholder" 84 | }, 85 | preDefinedResetScript = { 86 | key: "appNamePlaceholder.reset", 87 | value: "cd appPathPlaceholder && npx rimraf -- hooks node_modules platforms package-lock.json" 88 | }, 89 | preDefinedCleanScript = { 90 | key: "clean", 91 | value: "cleanAppsScriptPlaceholder && npx rimraf -- node_modules package-lock.json && npm i", 92 | }; 93 | 94 | console.log('NativeScript Plugin Seed Configuration'); 95 | 96 | // Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypeScriptDemo` `includeAngularDemo` 97 | // Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypeScriptDemo=y includeAngularDemo=n 98 | var parseArgv = function () { 99 | var argv = Array.prototype.slice.call(process.argv, 2); 100 | var result = {}; 101 | argv.forEach(function (pairString) { 102 | var pair = pairString.split('='); 103 | result[pair[0]] = pair[1]; 104 | }); 105 | 106 | return result; 107 | }; 108 | var argv = parseArgv(); 109 | 110 | if (argv) { 111 | inputParams.github_username = argv.gitHubUsername; 112 | inputParams.plugin_name = argv.pluginName; 113 | inputParams.init_git = argv.initGit; 114 | inputParams.include_typescript_demo = argv.includeTypeScriptDemo; 115 | inputParams.include_angular_demo = argv.includeAngularDemo; 116 | // inputParams.include_vue_demo = argv.includeVueDemo; 117 | inputParams.templates_branch = argv.templatesBranch; 118 | } 119 | 120 | if (!isInteractive() && (!inputParams.github_username || !inputParams.plugin_name || !inputParams.init_git || !inputParams.include_typescript_demo || !inputParams.include_angular_demo)) { 121 | console.log("Using default values for plugin creation since your shell is not interactive."); 122 | inputParams.github_username = "PluginAuthor"; 123 | inputParams.plugin_name = "myPluginClassName"; 124 | inputParams.init_git = "y"; 125 | inputParams.include_typescript_demo = "y"; 126 | inputParams.include_angular_demo = "n"; 127 | // inputParams.include_vue_demo = "n"; 128 | } 129 | 130 | askGithubUsername(); 131 | 132 | function askGithubUsername() { 133 | if (inputParams.github_username !== undefined) { 134 | askPluginName(); 135 | } else { 136 | prompt.start(); 137 | prompt.get({ 138 | name: 'github_username', 139 | description: 'What is your GitHub username (used for updating package.json)? Example: NathanWalker' 140 | }, function (err, result) { 141 | if (err) { 142 | return console.log(err); 143 | } 144 | if (!result.github_username) { 145 | return console.log("Your GitHub username is required to configure plugin's package.json."); 146 | } 147 | inputParams.github_username = result.github_username; 148 | askPluginName(); 149 | }); 150 | } 151 | } 152 | 153 | function askPluginName() { 154 | if (inputParams.plugin_name !== undefined) { 155 | generateClassName(); 156 | } else { 157 | prompt.get({ 158 | name: 'plugin_name', 159 | description: 'What will be the name of your plugin? Use lowercase characters and dashes only. Example: yourplugin / google-maps / bluetooth' 160 | }, function (err, result) { 161 | if (err) { 162 | return console.log(err); 163 | } 164 | if (!result.plugin_name) { 165 | return console.log("Your plugin name is required to correct the file names and classes."); 166 | } 167 | 168 | inputParams.plugin_name = result.plugin_name; 169 | 170 | if (inputParams.plugin_name.startsWith("nativescript-")) { 171 | inputParams.plugin_name = inputParams.plugin_name.replace("nativescript-", ""); 172 | } 173 | 174 | generateClassName(); 175 | }); 176 | } 177 | } 178 | 179 | function askTypeScriptDemo() { 180 | if (inputParams.include_typescript_demo !== undefined) { 181 | askAngularDemo(); 182 | } else { 183 | prompt.start(); 184 | prompt.get({ 185 | name: 'include_typescript_demo', 186 | description: 'Do you want to include a "TypeScript NativeScript" application linked with your plugin to make development easier (y/n)?', 187 | default: 'y' 188 | }, function (err, result) { 189 | if (err) { 190 | return console.log(err); 191 | } 192 | 193 | inputParams.include_typescript_demo = result.include_typescript_demo; 194 | askAngularDemo(); 195 | }); 196 | } 197 | } 198 | 199 | function askAngularDemo() { 200 | if (inputParams.include_angular_demo !== undefined) { 201 | // askVueDemo(); 202 | prepareDemoAppsFromTemplates(); 203 | } else { 204 | prompt.start(); 205 | prompt.get({ 206 | name: 'include_angular_demo', 207 | description: 'Do you want to include an "Angular NativeScript" application linked with your plugin to make development easier (y/n)?', 208 | default: 'n' 209 | }, function (err, result) { 210 | if (err) { 211 | return console.log(err); 212 | } 213 | 214 | inputParams.include_angular_demo = result.include_angular_demo; 215 | // askVueDemo(); 216 | prepareDemoAppsFromTemplates(); 217 | }); 218 | } 219 | } 220 | 221 | // function askVueDemo() { 222 | // if (inputParams.include_vue_demo !== undefined) { 223 | // prepareDemoAppsFromTemplates(); 224 | // } else { 225 | // prompt.start(); 226 | // prompt.get({ 227 | // name: 'include_vue_demo', 228 | // description: 'Do you want to include a "Vue NativeScript" application linked with your plugin to make development easier (y/n)?', 229 | // default: 'n' 230 | // }, function (err, result) { 231 | // if (err) { 232 | // return console.log(err); 233 | // } 234 | 235 | // inputParams.include_vue_demo = result.include_vue_demo; 236 | // prepareDemoAppsFromTemplates(); 237 | // }); 238 | // } 239 | // } 240 | 241 | function prepareDemoAppsFromTemplates() { 242 | let templatesOrigin = inputParams.templates_branch ? 243 | "nativescript-app-templates/packages/template-blank" : 244 | "tns-template-blank"; 245 | let templatesOriginName = inputParams.templates_branch ? 246 | "branch " + inputParams.templates_branch : 247 | "latest published template"; 248 | if (inputParams.include_typescript_demo && inputParams.include_typescript_demo.toLowerCase() === "y") { 249 | appsToCreate.push({ 250 | command: "cd ../ && tns create " + tsAppName + " --template " + templatesOrigin + "-ts && cd " + tsAppName + " && cd ../src/", 251 | startMessage: "Creating 'TypeScript' application from " + templatesOriginName + "...", 252 | successMessage: "TypeScript-NativeScript application created at: " + demoTsFolder, 253 | type: "TypeScript" 254 | }); 255 | appsToInstallPluginIn.push(demoTsFolder); 256 | } 257 | 258 | if (inputParams.include_angular_demo && inputParams.include_angular_demo.toLowerCase() === "y") { 259 | appsToCreate.push({ 260 | command: "cd ../ && tns create " + angularAppName + " --template " + templatesOrigin + "-ng && cd " + angularAppName + " && cd ../src/", 261 | startMessage: "Creating 'Angular' application from " + templatesOriginName + "...", 262 | successMessage: "Angular-NativeScript application created at: " + demoAngularFolder, 263 | type: "Angular" 264 | }); 265 | appsToInstallPluginIn.push(demoAngularFolder); 266 | } 267 | 268 | // if (inputParams.include_vue_demo && inputParams.include_vue_demo.toLowerCase() === "y") { 269 | // appsToCreate.push({ 270 | // command: "cd ../ && tns create " + vueAppName + " --vue && cd " + vueAppName + " && cd ../src/", 271 | // startMessage: "Creating 'Vue' application from " + templatesOriginName + "...", 272 | // successMessage: "Vue-NativeScript application created at: /demo-vue", 273 | // type: "Vue" 274 | // }); 275 | // appsToInstallPluginIn.push(demoVueFolder); 276 | // } 277 | 278 | if (appsToCreate.length > 0 && inputParams.templates_branch) { 279 | console.log("Cloning repository NativeScript/nativescript-app-templates..."); 280 | exec('cd ../ && git clone https://github.com/NativeScript/nativescript-app-templates.git', function (err, stdout, stderr) { 281 | if (err) { 282 | console.log(err); 283 | } else { 284 | console.log("Repository cloned."); 285 | exec('cd ../nativescript-app-templates && git checkout ' + inputParams.templates_branch, function (err, stdout, stderr) { 286 | if (err) { 287 | console.log(err); 288 | } else { 289 | console.log("Checked out branch " + inputParams.templates_branch); 290 | } 291 | }); 292 | 293 | createDemoAppsFromTemplates(); 294 | } 295 | }); 296 | } else { 297 | createDemoAppsFromTemplates(); 298 | } 299 | } 300 | 301 | function createDemoAppsFromTemplates() { 302 | let appObject = appsToCreate.pop(); 303 | if (appObject) { 304 | startProcess(appObject); 305 | } else { 306 | adjustScripts(); 307 | } 308 | } 309 | 310 | function startProcess(commandAndMessage) { 311 | if (commandAndMessage.startMessage) { 312 | console.log(commandAndMessage.startMessage); 313 | } 314 | let mainChildProcess = spawn(commandAndMessage.command, [], { stdio: 'inherit', shell: true, detached: false }); 315 | mainChildProcess.on("close", function (code, signal) { 316 | if (commandAndMessage.successMessage) { 317 | console.log(commandAndMessage.successMessage); 318 | } 319 | 320 | if (appsToCreate.length == 0) { 321 | adjustScripts(); 322 | } else { 323 | let appObject = appsToCreate.pop(); 324 | startProcess(appObject); 325 | } 326 | }); 327 | } 328 | 329 | function generateClassName() { 330 | // the class_name becomes 'GoogleMaps' when plugin_name is 'google-maps' 331 | class_name = ""; 332 | var plugin_name_parts = inputParams.plugin_name.split("-"); 333 | for (var p in plugin_name_parts) { 334 | var part = plugin_name_parts[p]; 335 | class_name += (part[0].toUpperCase() + part.substr(1)); 336 | } 337 | console.log('Using ' + class_name + ' as the TypeScript Class name..'); 338 | renameFiles(); 339 | } 340 | 341 | function renameFiles() { 342 | console.log('Will now rename some files..'); 343 | var files = fs.readdirSync("."); 344 | for (var f in files) { 345 | var file = files[f]; 346 | if (file.indexOf(seed_plugin_name) === 0) { 347 | var newName = inputParams.plugin_name + file.substr(file.indexOf(".")); 348 | fs.renameSync(file, newName); 349 | } 350 | } 351 | 352 | askTypeScriptDemo(); 353 | } 354 | 355 | function adjustScripts() { 356 | console.log('Adjusting scripts..'); 357 | 358 | // add all files in the root 359 | var files = fs.readdirSync("."); 360 | 361 | // add include.gradle 362 | files.push("platforms/android/include.gradle"); 363 | 364 | // add the demo files 365 | let demoAppPath = pathModule.join(demoTsFolder + "/app/home/"); 366 | if (fs.existsSync(demoAppPath)) { 367 | files.push(demoTsFolder + "/package.json"); 368 | var demoFiles = fs.readdirSync(demoAppPath); 369 | for (var d in demoFiles) { 370 | var demoFile = demoFiles[d]; 371 | files.push(demoAppPath + demoFile); 372 | } 373 | 374 | updateAppsTsConfigFile(pathModule.resolve(__dirname, pathModule.join("../" + demoTsFolder))); 375 | } 376 | 377 | // add the demo-angular files 378 | let demoAngularAppPath = pathModule.join(demoAngularFolder + "/src/app/"); 379 | if (fs.existsSync(demoAngularAppPath)) { 380 | files.push(demoAngularFolder + "/package.json"); 381 | var demoFiles = fs.readdirSync(demoAngularAppPath); 382 | for (var d in demoFiles) { 383 | var demoFile = demoFiles[d]; 384 | files.push(demoAngularAppPath + demoFile); 385 | } 386 | 387 | updateAppsTsConfigFile(pathModule.resolve(__dirname, pathModule.join("../" + demoAngularFolder))); 388 | 389 | } 390 | 391 | // add the demo-angular files 392 | // let demoVueAppPath = path.join(demoVueFolder + "/app/components/"); 393 | // if (fs.existsSync(demoVueAppPath)) { 394 | // files.push(demoVueFolder + "/package.json"); 395 | // var demoFiles = fs.readdirSync(demoVueAppPath); 396 | // for (var d in demoFiles) { 397 | // var demoFile = demoFiles[d]; 398 | // files.push(demoVueAppPath + demoFile); 399 | // } 400 | // updateAppsTsConfigFile(path.resolve(__dirname, path.join("../" + demoVueFolder))); 401 | // } 402 | 403 | // prepare and cache a few Regexp thingies 404 | var regexp_seed_plugin_name = new RegExp(seed_plugin_name, "g"); 405 | var regexp_seed_class_name = new RegExp(seed_class_name, "g"); 406 | var regexp_seed_demo_property_name = new RegExp(seed_demo_property_name, "g"); 407 | var regexp_seed_github_username = new RegExp(seed_github_username, "g"); 408 | 409 | for (var f in files) { 410 | var file = files[f]; 411 | 412 | if (fs.lstatSync(file).isFile()) { 413 | var contents = fs.readFileSync(file, 'utf8'); 414 | 415 | // Adds an 'import' and console.log() of the 'message' filed of 'nativescript-yourplugin' to the includes apps 416 | contents = file.includes(pathModule.join(demoTsFolder)) ? updateApp(contents, file, demoTsSearchTerm) : contents; 417 | contents = file.includes(pathModule.join(demoAngularFolder)) ? updateApp(contents, file, demoAngularSearchTerm) : contents; 418 | // contents = file.includes(pathModule.join(demoVueFolder)) ? updateDemoVueApp(contents, file) : contents; 419 | 420 | var result = contents.replace(regexp_seed_plugin_name, inputParams.plugin_name); 421 | result = result.replace(regexp_seed_class_name, class_name); 422 | result = result.replace(regexp_seed_demo_property_name, class_name[0].toLowerCase() + class_name.substr(1)); 423 | result = result.replace(regexp_seed_github_username, inputParams.github_username); 424 | fs.writeFileSync(file, result); 425 | } 426 | } 427 | 428 | replaceFiles(); 429 | updateSrcJson(); 430 | } 431 | 432 | function updateAppsTsConfigFile(path) { 433 | let jsonPath = pathModule.join(path + "/tsconfig.json"); 434 | let jsonFile = fs.readFileSync(jsonPath); 435 | let jsonObject = JSON.parse(jsonFile); 436 | var jsonInclude = ensureJsonArray(jsonObject["include"]); 437 | var newInclude = updateJsonArray(preDefinedInclude, jsonInclude); 438 | jsonObject["include"] = newInclude; 439 | var jsonExclude = ensureJsonArray(jsonObject["exclude"]); 440 | var newExclude = updateJsonArray(preDefinedExclude, jsonExclude); 441 | jsonObject["exclude"] = newExclude; 442 | 443 | var jsonPaths = ensureJsonArray(jsonObject["compilerOptions"])["paths"]; 444 | var newPaths = updateObject(preDefinedPaths, jsonPaths); 445 | jsonObject["compilerOptions"]["paths"] = newPaths; 446 | 447 | fs.writeFileSync(jsonPath, JSON.stringify(jsonObject, null, "\t")); 448 | } 449 | 450 | function updateSrcJson() { 451 | let jsonPath = pathModule.join(pathModule.resolve(__dirname, "../") + "/package.json"); 452 | let jsonFile = fs.readFileSync(jsonPath); 453 | let jsonObject = JSON.parse(jsonFile); 454 | var jsonScripts = ensureJsonArray(jsonObject["scripts"]); 455 | let pluginScripts = getPluginScripts(); 456 | 457 | var newScripts = updateObject(pluginScripts, jsonScripts); 458 | delete newScripts["postclone"]; 459 | jsonObject["scripts"] = newScripts; 460 | 461 | fs.writeFileSync(jsonPath, JSON.stringify(jsonObject, null, "\t")); 462 | } 463 | 464 | function getPluginScripts() { 465 | let scripts = []; 466 | let prepareScriptCommand; 467 | let clearScriptResetCommands = []; 468 | let pluginName = `nativescript-` + inputParams.plugin_name; 469 | if (inputParams.include_typescript_demo === "y") { 470 | preDefinedAppScripts.forEach((script) => { 471 | scripts.push( 472 | { 473 | key: script.key.replace(appNamePlaceholderStr, tsAppName), 474 | value: script.value.replace(appPathPlaceholderStr, demoTsFolder) 475 | }); 476 | }); 477 | let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, tsAppName); 478 | scripts.push({ 479 | key: resetScriptKey, 480 | value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoTsFolder) 481 | }); 482 | 483 | clearScriptResetCommands.push(resetScriptKey); 484 | 485 | let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoTsFolder); 486 | prepareScriptCommand = "&& " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName); 487 | } 488 | 489 | if (inputParams.include_angular_demo === "y") { 490 | preDefinedAppScripts.forEach((script) => { 491 | scripts.push( 492 | { 493 | key: script.key.replace(appNamePlaceholderStr, angularAppName), 494 | value: script.value.replace(appPathPlaceholderStr, demoAngularFolder) 495 | }); 496 | }); 497 | 498 | let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, angularAppName); 499 | scripts.push({ 500 | key: resetScriptKey, 501 | value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoAngularFolder) 502 | }); 503 | 504 | clearScriptResetCommands.push(resetScriptKey); 505 | 506 | let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoAngularFolder); 507 | prepareScriptCommand += " && " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName); 508 | } 509 | 510 | if (inputParams.include_vue_demo) { 511 | preDefinedAppScripts.forEach((script) => { 512 | scripts.push( 513 | { 514 | key: script.key.replace(appNamePlaceholderStr, demoVueFolder), 515 | value: script.value.replace(appPathPlaceholderStr, demoVueFolder) 516 | }); 517 | }); 518 | 519 | let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, angularAppName); 520 | scripts.push({ 521 | key: resetScriptKey, 522 | value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoAngularFolder) 523 | }); 524 | 525 | clearScriptResetCommands.push(resetScriptKey); 526 | 527 | let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoVueFolder); 528 | prepareScriptCommand += " && " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName); 529 | } 530 | 531 | scripts.push({ 532 | key: preDefinedPrepareScript.key, 533 | value: preDefinedPrepareScript.value.replace(removeAddPluginCommandPlaceholderStr, prepareScriptCommand) 534 | }); 535 | 536 | let fullAppResetCommand = ""; 537 | clearScriptResetCommands.forEach((tag) => { 538 | fullAppResetCommand += fullAppResetCommand.length === 0 ? "npm run " + tag : " && npm run " + tag; 539 | }); 540 | 541 | scripts.push({ 542 | key: preDefinedCleanScript.key, 543 | value: preDefinedCleanScript.value.replace(cleanAppsScriptPlaceholderStr, fullAppResetCommand) 544 | }); 545 | 546 | 547 | 548 | return scripts; 549 | } 550 | 551 | function updateJsonArray(newValues, oldValues) { 552 | newValues.forEach((value) => { 553 | if (!oldValues.includes(value)) { 554 | oldValues.push(value); 555 | } 556 | }); 557 | 558 | return oldValues; 559 | } 560 | 561 | function updateObject(newObjects, oldObjects) { 562 | newObjects.forEach((script) => { 563 | oldObjects[script.key] = script.value; 564 | }); 565 | 566 | return oldObjects; 567 | } 568 | 569 | function ensureJsonArray(jsonSection) { 570 | if (!jsonSection) { 571 | return []; 572 | } 573 | 574 | return jsonSection; 575 | } 576 | 577 | function updateApp(contents, file, searchTerm) { 578 | if (contents.includes(searchTerm)) { 579 | let fullPluginName = `'nativescript-` + inputParams.plugin_name + `'`; 580 | console.log("Updating " + file + " with " + fullPluginName + " import ."); 581 | let typeScriptImportSnippet = `import { ` + class_name + ` } from ` + fullPluginName + `;\n`, 582 | typeScriptAlertSnippet = `console.log(new ` + class_name + `().message);\n`; 583 | contents = typeScriptAlertSnippet + contents; 584 | contents = typeScriptImportSnippet + contents; 585 | } 586 | 587 | return contents; 588 | } 589 | 590 | // function updateDemoVueApp(contents, file) { 591 | // if (contents.includes(demoVueSearchTerm)) { 592 | // let pluginName = `'nativescript-`+ inputParams.plugin_name + `'`; 593 | // console.log("Updating " + file + " with " + pluginName + " import"); 594 | // let typeScriptImportSnippet = `import { ` + class_name + ` } from ` + pluginName + `;\n`, 595 | // typeScriptAlertSnippet = `console.log(new ` + class_name + `().message);\n`; 596 | // // contents = typeScriptAlertSnippet + contents; 597 | // // contents = typeScriptImportSnippet + contents; 598 | // // TODO: insert this after the