Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

feat(nativescript): v7 updates and compatibility to target es2017+ #1640

Merged
merged 14 commits into from
Oct 31, 2020
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package-lock.json
*.js
!src/*-hooks.js
build/
*.tgz
*.log.*
src/**/*.d.ts
src/**/*.map
src/platforms/ios_lib/TNSMLKitCamera/TNSMLKitCamera.xcodeproj/project.xcworkspace
src/platforms/ios_lib/TNSMLKitCamera/TNSMLKitCamera.xcodeproj/xcuserdata
src/platforms/ios/Podfile
Expand Down
10 changes: 4 additions & 6 deletions demo/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import "./bundle-config";
import * as application from "tns-core-modules/application";
import { UnhandledErrorEventData } from "tns-core-modules/application";
import { Application, UnhandledErrorEventData } from "@nativescript/core";

// added this here so we can do some wiring
require("nativescript-plugin-firebase");
require("@nativescript/firebase");

// testing this.. we may be able to hook that up to Crashlytics. Either via docs, or automatically.
application.on(application.uncaughtErrorEvent, (args: UnhandledErrorEventData) => {
Application.on(Application.uncaughtErrorEvent, (args: UnhandledErrorEventData) => {
console.log("[app.js]: Uncaught NativeScript Error: " + args.error);
});

application.run({ moduleName: "main-page" });
Application.run({ moduleName: "main-page" });
9 changes: 0 additions & 9 deletions demo/app/bundle-config.ts

This file was deleted.

7 changes: 3 additions & 4 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as observable from "tns-core-modules/data/observable";
import * as pages from "tns-core-modules/ui/page";
import { EventData, Page } from "@nativescript/core";
import { HelloWorldModel } from "./main-view-model";

const model = new HelloWorldModel();

// Event handler for Page 'loaded' event attached in main-page.xml
export function pageLoaded(args: observable.EventData) {
export function pageLoaded(args: EventData) {
// Get the event sender
let page = <pages.Page>args.object;
let page = <Page>args.object;
page.bindingContext = model;
}
26 changes: 11 additions & 15 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import * as firebase from "nativescript-plugin-firebase";
import { AddEventListenerResult, admob as firebaseAdMob, crashlytics as firebaseCrashlytics, GetRemoteConfigResult, IdTokenResult, LogComplexEventTypeParameter, performance as firebasePerformance, storage as firebaseStorage, User } from "nativescript-plugin-firebase";
import { RewardedVideoAdReward } from "nativescript-plugin-firebase/admob/admob";
import { FirebaseTrace } from "nativescript-plugin-firebase/performance/performance";
import { Observable } from "tns-core-modules/data/observable";
import * as fs from "tns-core-modules/file-system";
import { isAndroid, isIOS } from "tns-core-modules/platform";
import { alert, prompt } from "tns-core-modules/ui/dialogs";
import { firebase, AddEventListenerResult, admob as firebaseAdMob, crashlytics as firebaseCrashlytics, GetRemoteConfigResult, IdTokenResult, LogComplexEventTypeParameter, performance as firebasePerformance, storage as firebaseStorage, User } from "@nativescript/firebase";
import { RewardedVideoAdReward } from "@nativescript/firebase/admob/admob";
import { FirebaseTrace } from "@nativescript/firebase/performance/performance";
import { Observable, isAndroid, isIOS, Dialogs, knownFolders, File } from "@nativescript/core";
import { UploadMetadata } from "../../src/storage/storage";
import { MessagingViewModel } from "./messaging-view-model";

const firebaseWebApi = require("nativescript-plugin-firebase/app");
const firebaseWebApi = require("@nativescript/firebase/app");

declare const Crashlytics: any;

Expand Down Expand Up @@ -309,7 +305,7 @@ export class HelloWorldModel extends Observable {

public doWebUploadFile(): void {
// let's first create a File object using the tns file module
const appPath = fs.knownFolders.currentApp().path;
const appPath = knownFolders.currentApp().path;
const logoPath = appPath + "/images/telerik-logo.png";

const storageRef = firebaseWebApi.storage().ref();
Expand All @@ -324,7 +320,7 @@ export class HelloWorldModel extends Observable {
}
};

childRef.put(fs.File.fromPath(logoPath), metadata).then(
childRef.put(File.fromPath(logoPath), metadata).then(
uploadedFile => {
console.log("Uploaded! " + JSON.stringify(uploadedFile));
this.set("storageFeedback", "Uploaded!");
Expand All @@ -341,7 +337,7 @@ export class HelloWorldModel extends Observable {
const childRef = storageRef.child("uploads/images/telerik-logo-uploaded.png");

// let's first determine where we'll create the file using the 'file-system' module
const documents = fs.knownFolders.documents();
const documents = knownFolders.documents();
const logoPath = documents.path + "/telerik-logo-downloaded.png";

childRef.download(logoPath)
Expand Down Expand Up @@ -1666,7 +1662,7 @@ export class HelloWorldModel extends Observable {

public doUploadFile(): void {
// let's first create a File object using the tns file module
const appPath = fs.knownFolders.currentApp().path;
const appPath = knownFolders.currentApp().path;
const logoPath = appPath + "/images/telerik-logo.png";

const metadata: UploadMetadata = {
Expand All @@ -1680,7 +1676,7 @@ export class HelloWorldModel extends Observable {

firebaseStorage.uploadFile({
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
localFile: fs.File.fromPath(logoPath), // use this (a file-system module File object)
localFile: File.fromPath(logoPath), // use this (a file-system module File object)
// localFullPath: logoPath, // or this, a full file path
onProgress: status => {
console.log("Uploaded fraction: " + status.fractionCompleted + " (" + status.percentageCompleted + "%)");
Expand All @@ -1702,7 +1698,7 @@ export class HelloWorldModel extends Observable {

public doDownloadFile(): void {
// let's first determine where we'll create the file using the 'file-system' module
const documents = fs.knownFolders.documents();
const documents = knownFolders.documents();
const logoPath = documents.path + "/telerik-logo-downloaded.png";

// this will create or overwrite a local file in the app's documents folder
Expand Down
11 changes: 5 additions & 6 deletions demo/app/messaging-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { alert } from "tns-core-modules/ui/dialogs";
import * as platform from "tns-core-modules/platform";
import * as firebase from "nativescript-plugin-firebase";
import { messaging } from "nativescript-plugin-firebase/messaging";
import { Dialogs } from "@nativescript/core";
import { firebase } from "@nativescript/firebase";
import { messaging } from "@nativescript/firebase/messaging";

const getCircularReplacer = () => {
const seen = new WeakSet;
Expand All @@ -21,7 +20,7 @@ export class MessagingViewModel {
firebase.getCurrentPushToken().then(token => {
// may be null if not known yet
console.log("Current push token: " + token);
alert({
Dialogs.alert({
title: "Current Push Token",
message: (token === null ? "Not received yet" : token + ("\n\nSee the console log if you want to copy-paste it.")),
okButtonText: "OK, thx"
Expand All @@ -30,7 +29,7 @@ export class MessagingViewModel {
}

public doRegisterForInteractivePush(): void {
if (platform.isIOS) {
if (global.isIOS) {
const model = new messaging.PushNotificationModel();
model.iosSettings = new messaging.IosPushSettings();
model.iosSettings.badge = false;
Expand Down
110 changes: 0 additions & 110 deletions demo/app/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion demo/app/tests/tests.native-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const firebase = require("nativescript-plugin-firebase");
const firebase = require("@nativescript/firebase");

// TODO make this slightly more useful :P

Expand Down
2 changes: 1 addition & 1 deletion demo/app/tests/tests.web-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const firebaseWebApi = require("nativescript-plugin-firebase/app");
const firebaseWebApi = require("@nativescript/firebase/app");

// TODO make this slightly more useful :P

Expand Down
12 changes: 12 additions & 0 deletions demo/nativescript.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NativeScriptConfig } from '@nativescript/core'

export default {
id: 'org.nativescript.firebasedemo',
appResourcesPath: 'app_resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
},
discardUncaughtJsExceptions: false,
appPath: 'app',
} as NativeScriptConfig
4 changes: 0 additions & 4 deletions demo/nsconfig.json

This file was deleted.

25 changes: 9 additions & 16 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
"nativescript": {
"id": "org.nativescript.firebasedemo",
"tns-ios": {
"version": "6.5.3"
},
"tns-android": {
"version": "6.5.3"
}
},
"dependencies": {
"firebase-functions": "^2.0.5",
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-10.6.0.tgz",
"@nativescript/firebase": "file:../src",
"nativescript-theme-core": "^1.0.4",
"nativescript-unit-test-runner": "0.7.0",
"tns-core-modules": "~6.5.3"
"@nativescript/unit-test-runner": "~1.0.2",
"@nativescript/core": "7.0.0",
"@nativescript/webpack": "~3.0.0"
},
"devDependencies": {
"@nativescript/ios": "7.0.4",
"@nativescript/types": "~7.0.0",
"@types/jasmine": "~2.8.0",
"babel-traverse": "6.12.0",
"babel-types": "6.11.1",
Expand All @@ -28,13 +22,12 @@
"karma-webpack": "3.0.5",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-webpack": "1.0.1",
"tns-platform-declarations": "~6.5.3",
"tslint": "~5.4.3",
"typescript": "3.4.5"
"typescript": "~4.0.0"
},
"scripts": {
"build.plugin": "cd ../src && npm run build",
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**' --exclude '**/typings/**'"
}
},
"main": "app.js"
}
4 changes: 1 addition & 3 deletions demo/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

/// <reference path="./node_modules/@nativescript/types/index.d.ts" />
/// <reference path="./node_modules/@types/jasmine/index.d.ts" />
16 changes: 7 additions & 9 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "es2017",
"module": "esnext",
"declaration": false,
"removeComments": true,
"removeComments": false,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"lib": [
"es6",
"dom",
"es2015.iterable"
"es2015.iterable",
"es2017"
],
"pretty": true,
"allowUnreachableCode": false,
Expand All @@ -29,14 +30,11 @@
"types": [],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
],
"~/*": [
"app/*"
]
}
},
"moduleResolution": "node"
},
"exclude": [
"node_modules",
Expand Down
Loading