Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,20 @@ Set up a new React, Vue, or Angular App so the new app and final package repo is

## Creating Test Apps

### React Example App
Each shim ships with a ready-to-run example under its `example/` folder. After
building the codegen (`npm run build`), the easiest way to try the shims
locally is:

```
cd build/react/example # or build/vue/v2/example, build/vue/v3/example, build/onesignal-ngx/example
vp run start
```

The `prestart` hook invokes `scripts/setup.sh`, which builds the parent shim,
packs it as a tarball, and installs it into the example before launching the
dev server on http://localhost:4000.

### React Example App (alternative)

```
cd ~/tmp
Expand All @@ -85,7 +98,7 @@ cd web-shim-test-react
npm link {YOUR_PATH_HERE}/web-shim-codegen/build/react
```

### Vue Example App
### Vue Example App (alternative)

```
cd ~/tmp
Expand Down
23 changes: 23 additions & 0 deletions outputs/onesignal-ngx/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
onesignal-ngx.tgz

# build outputs
/dist
/.angular

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*

# local HTTPS certs (mkcert)
/.certs
36 changes: 36 additions & 0 deletions outputs/onesignal-ngx/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# example-angular

A minimal Angular standalone app showcasing `onesignal-ngx`.

## Setup

Replace `<YOUR_APP_ID>` in `src/app/app.component.ts` with your OneSignal app id.

For a locally-trusted HTTPS cert (recommended; OneSignal requires HTTPS),
install [mkcert](https://github.com/FiloSottile/mkcert) once on your machine:

```bash
brew install mkcert nss
mkcert -install
```

If mkcert isn't installed the example falls back to Angular's self-signed
cert and the browser will show a security warning.

## Available Scripts

In the project directory, you can run:

### `npm start` (or `vp run start`)

Packs the parent `onesignal-ngx` package as a tarball, installs it locally,
generates a local HTTPS cert (via mkcert if available), and runs `ng serve`
on [https://localhost:4000](https://localhost:4000).

The page will reload if you make edits.

## Re-running setup

Run `vp run setup` to re-pack the parent package and re-install the freshly
packed tarball into the example. If you've changed the SDK source, rebuild it
first by running `npm run build` from the `web-shim-codegen` repo root.
72 changes: 72 additions & 0 deletions outputs/onesignal-ngx/example/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"cli": {
"analytics": false
},
"projects": {
"example-angular": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "css",
"standalone": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/example-angular",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "example-angular:build:production"
},
"development": {
"buildTarget": "example-angular:build:development"
}
},
"defaultConfiguration": "development"
}
}
}
}
}
1,890 changes: 1,890 additions & 0 deletions outputs/onesignal-ngx/example/bun.lock

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions outputs/onesignal-ngx/example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "example-angular",
"version": "0.1.0",
"private": true,
"dependencies": {
"@angular/animations": "^18.2.0",
"@angular/common": "^18.2.0",
"@angular/compiler": "^18.2.0",
"@angular/core": "^18.2.0",
"@angular/forms": "^18.2.0",
"@angular/platform-browser": "^18.2.0",
"@angular/platform-browser-dynamic": "^18.2.0",
"@angular/router": "^18.2.0",
"onesignal-ngx": "file:./onesignal-ngx.tgz",
"rxjs": "^7.8.0",
"tslib": "^2.6.0",
"zone.js": "^0.14.0"
},
"scripts": {
"setup": "./scripts/setup.sh",
"prestart": "vp run setup",
"start": "./scripts/start.sh"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.2.0",
"@angular/cli": "^18.2.0",
"@angular/compiler-cli": "^18.2.0",
"typescript": "~5.5.0"
},
"packageManager": "bun@1.3.13"
}
1 change: 1 addition & 0 deletions outputs/onesignal-ngx/example/public/OneSignalSDKWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
importScripts("https://onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
36 changes: 36 additions & 0 deletions outputs/onesignal-ngx/example/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -euo pipefail

bold=$(tput bold 2>/dev/null || true)
normal=$(tput sgr0 2>/dev/null || true)

log() {
echo -e "\n${bold}$1${normal}"
}

EXAMPLE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
PARENT_DIR="$(cd "$EXAMPLE_DIR/.." && pwd)"
TARBALL="onesignal-ngx.tgz"
CERTS_DIR="$EXAMPLE_DIR/.certs"

log "Packing onesignal-ngx from $PARENT_DIR"
cd "$PARENT_DIR"
bun pm pack --filename "$EXAMPLE_DIR/$TARBALL"

log "Installing tarball into example"
cd "$EXAMPLE_DIR"
vp install --force

log "Generating locally-trusted HTTPS cert"
if ! command -v mkcert >/dev/null 2>&1; then
echo "mkcert not found. Install it for a locally-trusted HTTPS cert:"
echo " brew install mkcert nss && mkcert -install"
echo "Falling back to Angular's self-signed cert (browser will warn)."
exit 0
fi
if [[ ! -f "$CERTS_DIR/cert.pem" || ! -f "$CERTS_DIR/key.pem" ]]; then
mkdir -p "$CERTS_DIR"
mkcert -key-file "$CERTS_DIR/key.pem" -cert-file "$CERTS_DIR/cert.pem" localhost 127.0.0.1 ::1
else
echo "Cert already present at $CERTS_DIR, skipping."
fi
14 changes: 14 additions & 0 deletions outputs/onesignal-ngx/example/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail

EXAMPLE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
CERTS_DIR="$EXAMPLE_DIR/.certs"

cd "$EXAMPLE_DIR"

if [[ -f "$CERTS_DIR/cert.pem" && -f "$CERTS_DIR/key.pem" ]]; then
exec vpx ng serve --port 4000 --open \
--ssl --ssl-cert "$CERTS_DIR/cert.pem" --ssl-key "$CERTS_DIR/key.pem"
else
exec vpx ng serve --port 4000 --open --ssl
fi
26 changes: 26 additions & 0 deletions outputs/onesignal-ngx/example/src/app/app.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.container {
font-family: Avenir, Helvetica, Arial, sans-serif;
text-align: center;
color: #2c3e50;
margin: 60px auto 0;
max-width: 720px;
padding: 0 16px;
}

h3 {
margin: 40px 0 0;
}

ul {
list-style-type: none;
padding: 0;
}

li {
display: inline-block;
margin: 0 10px;
}

a {
color: #dd0031;
}
21 changes: 21 additions & 0 deletions outputs/onesignal-ngx/example/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<main class="container">
<h1>Welcome to Your Angular OneSignal App</h1>
<p>
Edit <code>src/app/app.component.ts</code> and save to reload.<br />
Replace <code>&lt;YOUR_APP_ID&gt;</code> with your OneSignal app id.
</p>
<h3>Essential Links</h3>
<ul>
<li>
<a href="https://angular.dev" target="_blank" rel="noopener">Angular</a>
</li>
<li>
<a
href="https://documentation.onesignal.com/docs/web-push-quickstart"
target="_blank"
rel="noopener"
>OneSignal Web Push</a
>
</li>
</ul>
</main>
23 changes: 23 additions & 0 deletions outputs/onesignal-ngx/example/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, OnInit } from '@angular/core';
import { OneSignal } from 'onesignal-ngx';

@Component({
selector: 'app-root',
standalone: true,
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
constructor(private readonly oneSignal: OneSignal) {}

ngOnInit(): void {
this.oneSignal
.init({
appId: '<YOUR_APP_ID>',
allowLocalhostAsSecureOrigin: true,
})
.then(() => {
this.oneSignal.Debug.setLogLevel('trace');
});
}
}
5 changes: 5 additions & 0 deletions outputs/onesignal-ngx/example/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';

export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true })],
};
12 changes: 12 additions & 0 deletions outputs/onesignal-ngx/example/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Angular OneSignal Example</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<app-root></app-root>
</body>
</html>
8 changes: 8 additions & 0 deletions outputs/onesignal-ngx/example/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { bootstrapApplication } from '@angular/platform-browser';

import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';

bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err),
);
7 changes: 7 additions & 0 deletions outputs/onesignal-ngx/example/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
9 changes: 9 additions & 0 deletions outputs/onesignal-ngx/example/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"]
}
28 changes: 28 additions & 0 deletions outputs/onesignal-ngx/example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"esModuleInterop": true,
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": ["ES2022", "dom"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
Loading