Skip to content

Commit 1d93ca9

Browse files
committed
feat: publish examples to GitHub-backed StackBlitz branches
Saved StackBlitz projects can lose their files (the Angular and Svelte battery examples did after a StackBlitz storage migration), so examples now publish to per-flavor branches that StackBlitz loads straight from GitHub: https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/<example>-<flavor> Pipeline (.github/workflows/publish-examples.yml, replaces extract-templates.yml): - tools/scripts/extract-example.mjs makes apps/<example>/<flavor> standalone, copying in referenced libs and rewriting ../../../ paths - tools/scripts/verify-example.sh installs and bundles it for iOS and Android - on main, pushes the result to the <example>-<flavor> branch with plain git (git-publish-subdir-action v2.6.0 runs on retired node16) - pull requests verify without publishing Shared lib is resolved through a webpack alias instead of a file: dependency (@nativescript/webpack does not apply tsconfig paths), so the monorepo and the published projects resolve it the same way. Battery flavors: - @nativescript/core ~8.9.0 everywhere; Preview does not support v9 yet - Vue: NativeScript-Vue 3 (createApp, <script setup>, src/ layout) - Angular: v20, standalone components, zoneless with signals; @nativescript/angular ~20.0.0 since 20.1.x needs core 9 (SplitView) - React: battery state in useState/useEffect so the UI updates; drop obsolete @types/react 16 patch - Svelte: @nativescript-community/svelte-native + Svelte 4; drop svelte-native-preprocessor (Svelte 3 peer only) - JavaScript: now the battery example instead of the tap counter - Solid: new flavor, linked from nativescript.org - Tailwind with one shared app.css; logos use Wikimedia standard 500px thumbnails (previous sizes now return 400/404) - lib: globalThis instead of Node's global so it type-checks without @types/node
1 parent 59aa644 commit 1d93ca9

91 files changed

Lines changed: 1582 additions & 1124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/extract-templates.yml‎

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish Examples
2+
3+
# Each apps/<example>/<flavor> is extracted into a standalone project and pushed
4+
# to the <example>-<flavor> branch, which StackBlitz opens directly from GitHub:
5+
# https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/<example>-<flavor>
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
workflow_dispatch:
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
example: [battery]
22+
flavor: [angular, javascript, react, solid, svelte, typescript, vue]
23+
env:
24+
OUT_DIR: dist/${{ matrix.example }}-${{ matrix.flavor }}
25+
steps:
26+
- uses: actions/checkout@v7
27+
28+
- uses: actions/setup-node@v7
29+
with:
30+
node-version: 22
31+
32+
- name: Extract
33+
run: node tools/scripts/extract-example.mjs ${{ matrix.example }} ${{ matrix.flavor }} "$OUT_DIR"
34+
35+
- name: Install and bundle for iOS and Android
36+
run: tools/scripts/verify-example.sh "$OUT_DIR"
37+
38+
- name: Publish to ${{ matrix.example }}-${{ matrix.flavor }}
39+
if: github.ref == 'refs/heads/main'
40+
env:
41+
BRANCH: ${{ matrix.example }}-${{ matrix.flavor }}
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
remote="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
45+
if ! git clone --quiet --depth 1 --branch "$BRANCH" "$remote" publish; then
46+
git init --quiet --initial-branch "$BRANCH" publish
47+
fi
48+
find publish -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
49+
cp -R "$OUT_DIR"/. publish/
50+
cd publish
51+
git add --all
52+
if git diff --cached --quiet; then
53+
echo "$BRANCH is already up to date"
54+
exit 0
55+
fi
56+
git -c user.name='github-actions[bot]' \
57+
-c user.email='41898282+github-actions[bot]@users.noreply.github.com' \
58+
commit --quiet -m "chore(update): $BRANCH to $GITHUB_SHA"
59+
git push --quiet "$remote" "HEAD:refs/heads/$BRANCH"

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ package-lock.json
4646
# System Files
4747
.DS_Store
4848
Thumbs.db
49+
50+
.nx/cache
51+
.nx/workspace-data

‎.prettierignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
/dist
44
/coverage
5+
6+
/.nx/cache
7+
/.nx/workspace-data

‎README.md‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
11
# StackBlitz Examples
22

3-
The examples are managed on the `main` branch only - the individual flavor branches are automatically updated when pushing to `main`
4-
5-
Each example is split into it's own folder within apps, for example:
3+
Examples are edited on `main` only. Each one lives in its own folder:
64

75
```
86
apps/{example}/{flavor}
97
```
108

11-
Each example can utilize shared `libs` for their examples to reuse across flavors, for example:
9+
Code shared across the flavors of an example lives in `libs`, e.g. `libs/nativescript-battery` is used by every `apps/battery/*` flavor. Apps import it by package name (`@stackblitz/nativescript-battery`), which each app's `webpack.config.js` aliases to the lib's `src` folder.
1210

13-
```
14-
libs/nativescript-battery
15-
```
11+
## How examples reach StackBlitz
1612

17-
^ is used across all `apps/battery` examples.
13+
Every push to `main` runs [`publish-examples.yml`](.github/workflows/publish-examples.yml), which for each `{example}/{flavor}`:
1814

19-
## Test them out locally
15+
1. extracts it into a standalone project ([`tools/scripts/extract-example.mjs`](tools/scripts/extract-example.mjs)), copying in the libs it uses and rewriting `../../../` paths;
16+
2. installs it and bundles it for iOS and Android ([`tools/scripts/verify-example.sh`](tools/scripts/verify-example.sh)), the same build `ns preview` runs;
17+
3. pushes it to the `{example}-{flavor}` branch.
2018

21-
Since each flavor utilizes it's own node_modules dependencies you want to clean each example before running it, for example:
19+
Pull requests run steps 1 and 2 without publishing.
20+
21+
StackBlitz opens those branches straight from GitHub, so links always show what is on `main`:
2222

2323
```
24-
npx nx run battery-angular:clean
24+
https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/{example}-{flavor}?file={path}
2525
```
2626

27-
You can now try out the example:
27+
> **Warning:** Do not edit the `{example}-{flavor}` branches; they are overwritten on every publish.
28+
29+
### Battery example links
30+
31+
| Flavor | Link |
32+
| ---------- | ---- |
33+
| TypeScript | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-typescript?file=app%2Fmain-page.xml |
34+
| JavaScript | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-javascript?file=app%2Fmain-page.xml |
35+
| Angular | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-angular?file=src%2Fapp%2Fhome.component.html |
36+
| React | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-react?file=src%2Fcomponents%2FHomeScreen.tsx |
37+
| Solid | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-solid?file=src%2Fcomponents%2Fhome.jsx |
38+
| Svelte | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-svelte?file=app%2Fcomponents%2FHome.svelte |
39+
| Vue | https://stackblitz.com/github/NativeScript/stackblitz-examples/tree/battery-vue?file=src%2Fcomponents%2FHome.vue |
40+
41+
## Check an example locally
42+
43+
Run what CI runs:
2844

2945
```
30-
npx nx run battery-angular:ios
46+
node tools/scripts/extract-example.mjs battery vue dist/battery-vue
47+
tools/scripts/verify-example.sh dist/battery-vue
3148
```
3249

33-
> **Warning:** Do not edit the individual flavor branches manually!.
50+
`dist/battery-vue` is then the exact project StackBlitz will load.
51+
52+
`@nativescript/core` stays on 8.9.x until NativeScript Preview supports v9.
3453

3554
# Templates
3655

‎apps/battery/angular/package.json‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
"version": "1.0.0",
55
"private": true,
66
"dependencies": {
7-
"@angular/animations": "~14.1.0",
8-
"@angular/common": "~14.1.0",
9-
"@angular/compiler": "~14.1.0",
10-
"@angular/core": "~14.1.0",
11-
"@angular/forms": "~14.1.0",
12-
"@angular/platform-browser": "~14.1.0",
13-
"@angular/platform-browser-dynamic": "~14.1.0",
14-
"@angular/router": "~14.1.0",
15-
"@nativescript/angular": "^14.0.0",
16-
"@nativescript/core": "~8.3.0",
17-
"@nativescript/theme": "~3.0.2",
18-
"rxjs": "~7.5.0",
19-
"zone.js": "~0.11.5"
7+
"@angular/animations": "~20.0.0",
8+
"@angular/common": "~20.0.0",
9+
"@angular/compiler": "~20.0.0",
10+
"@angular/core": "~20.0.0",
11+
"@angular/forms": "~20.0.0",
12+
"@angular/platform-browser": "~20.0.0",
13+
"@angular/platform-browser-dynamic": "~20.0.0",
14+
"@angular/router": "~20.0.0",
15+
"@nativescript/angular": "~20.0.0",
16+
"@nativescript/core": "~8.9.0",
17+
"rxjs": "~7.8.0",
18+
"zone.js": "~0.15.0"
2019
},
2120
"devDependencies": {
22-
"@angular-devkit/build-angular": "~14.1.0",
23-
"@angular/compiler-cli": "~14.1.0",
24-
"@nativescript/ios": "8.3.3",
25-
"@nativescript/preview-cli": "1.0.0-beta.18",
26-
"@nativescript/stackblitz": "0.0.5",
27-
"@nativescript/types-minimal": "~8.3.0",
28-
"@nativescript/webpack": "~5.0.0",
29-
"@ngtools/webpack": "~14.1.0",
30-
"typescript": "~4.7.0"
21+
"@angular-devkit/build-angular": "~20.0.0",
22+
"@angular/compiler-cli": "~20.0.0",
23+
"@nativescript/preview-cli": "^1.0.14",
24+
"@nativescript/stackblitz": "^0.0.8",
25+
"@nativescript/tailwind": "^2.1.0",
26+
"@nativescript/types": "~8.9.0",
27+
"@nativescript/webpack": "~5.0.27",
28+
"@ngtools/webpack": "~20.0.0",
29+
"tailwindcss": "~3.4.0",
30+
"typescript": "~5.8.0"
3131
}
3232
}

‎apps/battery/angular/project.json‎

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,41 @@
33
"sourceRoot": "apps/battery/angular/src",
44
"projectType": "application",
55
"targets": {
6-
"ios": {
6+
"build": {
77
"executor": "@nativescript/nx:build",
88
"options": {
9-
"platform": "ios"
9+
"noHmr": true,
10+
"production": true,
11+
"uglify": true,
12+
"release": true,
13+
"forDevice": true
1014
},
11-
"configurations": {
12-
"build": {
13-
"copyTo": "./dist/build.ipa"
14-
},
15-
"prod": {
16-
"combineWithConfig": "build:prod"
17-
}
18-
}
15+
"configurations": {}
1916
},
20-
"android": {
21-
"executor": "@nativescript/nx:build",
17+
"debug": {
18+
"executor": "@nativescript/nx:debug",
2219
"options": {
23-
"platform": "android"
20+
"noHmr": true,
21+
"uglify": false,
22+
"release": false,
23+
"forDevice": false,
24+
"prepare": false
2425
},
25-
"configurations": {
26-
"build": {
27-
"copyTo": "./dist/build.apk"
28-
},
29-
"prod": {
30-
"combineWithConfig": "build:prod"
31-
}
32-
}
26+
"configurations": {}
3327
},
3428
"clean": {
35-
"executor": "@nativescript/nx:build",
36-
"options": {
37-
"clean": true
38-
}
29+
"executor": "@nativescript/nx:clean",
30+
"options": {}
3931
},
4032
"lint": {
41-
"executor": "@nrwl/linter:eslint",
33+
"executor": "@nx/eslint:lint",
4234
"options": {
4335
"lintFilePatterns": [
4436
"apps/battery/angular/**/*.ts",
4537
"apps/battery/angular/src/**/*.html"
4638
]
4739
}
4840
}
49-
}
41+
},
42+
"name": "angular"
5043
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/// <reference path="./node_modules/@nativescript/types-minimal/index.d.ts" />
1+
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />

‎apps/battery/angular/src/app.css‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
@import '@nativescript/theme/css/core.css';
2-
@import '@nativescript/theme/css/default.css';
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
ActionBar {
6+
background-color: #65adf1;
7+
color: white;
8+
}
39

410
Button.action-btn {
511
border-radius: 25;

‎apps/battery/angular/src/app/app-routing.module.ts‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)