create-mithril-lynx 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -12
- package/package.json +3 -5
- package/src/index.js +536 -7
- package/templates/android/app-scripts/android.mjs +232 -0
- package/templates/android/font/AssetFontFaceLoader.kt +39 -0
- package/templates/android/host/app/build.gradle.kts +103 -0
- package/templates/android/host/app/proguard-rules.pro +51 -0
- package/templates/android/host/app/src/main/AndroidManifest.xml +28 -0
- package/templates/android/host/app/src/main/java/package-path/App.kt +23 -0
- package/templates/android/host/app/src/main/java/package-path/AssetTemplateProvider.kt +27 -0
- package/templates/android/host/app/src/main/java/package-path/MainActivity.kt +37 -0
- package/templates/android/host/app/src/main/res/drawable/ic_launcher_background.xml +6 -0
- package/templates/android/host/app/src/main/res/drawable/ic_launcher_foreground.xml +11 -0
- package/templates/android/host/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
- package/templates/android/host/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
- package/templates/android/host/app/src/main/res/values/strings.xml +3 -0
- package/templates/android/host/app/src/main/res/values/themes.xml +17 -0
- package/templates/android/host/build.gradle.kts +4 -0
- package/templates/android/host/gitignore +16 -0
- package/templates/android/host/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/templates/android/host/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/templates/android/host/gradle.properties +3 -0
- package/templates/android/host/gradlew +251 -0
- package/templates/android/host/gradlew.bat +94 -0
- package/templates/android/host/keystore.properties.example +15 -0
- package/templates/android/host/local.properties +4 -0
- package/templates/android/host/settings.gradle.kts +18 -0
- package/templates/basic-activity/common/src/style.css +59 -0
- package/templates/basic-activity/js/src/index.js +43 -0
- package/templates/basic-activity/ts/src/index.ts +48 -0
- package/templates/blank/common/src/style.css +16 -0
- package/templates/blank/js/src/index.js +11 -0
- package/templates/blank/ts/src/index.ts +11 -0
- /package/{template-js → templates/hello-world/js}/src/index.js +0 -0
- /package/{template-common → templates/_shared/common}/README.md +0 -0
- /package/{template-common → templates/_shared/common}/gitignore +0 -0
- /package/{template-js → templates/_shared/js}/lynx.config.js +0 -0
- /package/{template-js → templates/_shared/js}/package.json +0 -0
- /package/{template-js → templates/_shared/js}/src/main-thread.js +0 -0
- /package/{template-ts → templates/_shared/ts}/lynx.config.ts +0 -0
- /package/{template-ts → templates/_shared/ts}/package.json +0 -0
- /package/{template-ts → templates/_shared/ts}/src/main-thread.ts +0 -0
- /package/{template-ts → templates/_shared/ts}/src/rspeedy-env.d.ts +0 -0
- /package/{template-ts → templates/_shared/ts}/src/tsconfig.json +0 -0
- /package/{template-ts → templates/_shared/ts}/tsconfig.json +0 -0
- /package/{template-ts → templates/_shared/ts}/tsconfig.node.json +0 -0
- /package/{template-common → templates/hello-world/common}/src/assets/arrow.png +0 -0
- /package/{template-common → templates/hello-world/common}/src/assets/lynx-logo.png +0 -0
- /package/{template-common → templates/hello-world/common}/src/assets/mithril-logo.png +0 -0
- /package/{template-common → templates/hello-world/common}/src/style.css +0 -0
- /package/{template-ts → templates/hello-world/ts}/src/index.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# create-mithril-lynx
|
|
2
2
|
|
|
3
|
-
Scaffolds a new [`mithril-lynx`](https://github.com/carlos-sweb/mithril-lynx) app
|
|
3
|
+
Scaffolds a new [`mithril-lynx`](https://github.com/carlos-sweb/mithril-lynx) app. Three templates, matching the "Hello World" / "Blank" / "Basic Activity" naming most native app scaffolds already use, each available in TypeScript or JavaScript.
|
|
4
|
+
|
|
5
|
+
It can also generate the **native Android host** — the whole Gradle project that wraps the bundle into an installable APK — so you never hand-write the ~20 Kotlin/Gradle/XML files that takes. That path automates [`mithril-lynx`'s ANDROID_APK_GUIDE.md](https://github.com/carlos-sweb/mithril-lynx/blob/main/ANDROID_APK_GUIDE.md).
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
6
8
|
|
|
@@ -8,35 +10,118 @@ Scaffolds a new [`mithril-lynx`](https://github.com/carlos-sweb/mithril-lynx) ap
|
|
|
8
10
|
npm create mithril-lynx@latest
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
Prompts for a project name and a variant (TypeScript or JavaScript), scaffolds it, and offers to install dependencies for you.
|
|
13
|
+
Prompts for a project name, a template, and a variant (TypeScript or JavaScript), scaffolds it, and offers to install dependencies for you.
|
|
12
14
|
|
|
13
15
|
### Non-interactive
|
|
14
16
|
|
|
15
17
|
```bash
|
|
16
|
-
npx create-mithril-lynx my-app --ts
|
|
17
|
-
npx create-mithril-lynx my-app --js --no-install
|
|
18
|
+
npx create-mithril-lynx my-app --hello-world --ts
|
|
19
|
+
npx create-mithril-lynx my-app --basic-activity --js --no-install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### With the Android host
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Scaffold the JS app plus a sibling my-app-android/ Gradle project:
|
|
26
|
+
npx create-mithril-lynx my-app --ts --blank --android
|
|
27
|
+
|
|
28
|
+
cd my-app
|
|
29
|
+
npm install
|
|
30
|
+
npm run android # bundle -> assets -> installDebug -> launch on the device
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The interactive prompt offers it too, and the literal `target=android` form works as well:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm create mithril-lynx@latest my-app target=android
|
|
18
37
|
```
|
|
19
38
|
|
|
20
|
-
|
|
39
|
+
Every flag, in one table — `npx create-mithril-lynx --help` prints the same list:
|
|
40
|
+
|
|
41
|
+
| Flag | Effect |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `<name>` (positional) | Project name, and the directory to create. Omit it and you're prompted. |
|
|
44
|
+
| `--hello-world` / `--blank` / `--basic-activity` | Template to scaffold. Omit it and you're prompted. |
|
|
45
|
+
| `--ts` / `--js` | TypeScript or JavaScript variant. Omit it and you're prompted. |
|
|
46
|
+
| `--no-install` | Don't install dependencies (also skips that prompt). |
|
|
47
|
+
| `-h`, `--help` | Print usage and exit. |
|
|
48
|
+
| `--android` / `--target android` / `--target=android` / `target=android` | Also scaffold the sibling `<name>-android/` Gradle project. |
|
|
49
|
+
| `--android-id <id>` | `applicationId` / `namespace` (default `com.example.<name>`). |
|
|
50
|
+
| `--app-name <name>` | Launcher label (default: the project name). |
|
|
51
|
+
| `--with-font <file.ttf>` | Copy the font into the host's assets, generate `AssetFontFaceLoader.kt`, and wire the cold-start `prefetchFont()` hack (Part D of the guide). |
|
|
52
|
+
| `--font-family <name>` | Override the family name derived from the font's file name. Only meaningful with `--with-font`. |
|
|
53
|
+
|
|
54
|
+
Anything not listed — in particular the four Android flags — requires `--android`
|
|
55
|
+
(or one of its aliases); `--with-font` implies it on its own.
|
|
56
|
+
|
|
57
|
+
### What the generated Android host gives you
|
|
58
|
+
|
|
59
|
+
The sibling `<name>-android/` project is a complete, no-Android-Studio Gradle CLI project pinned to the versions in the guide (AGP 8.5.2, Kotlin 1.9.24, Gradle 8.14.2, Lynx `4.1.0`, `compileSdk`/`targetSdk` 34, `minSdk` 24), including:
|
|
60
|
+
|
|
61
|
+
- the Gradle wrapper (`gradlew`, `gradlew.bat`, `gradle-wrapper.jar`), so nothing needs to be installed besides a JDK 17 and the Android SDK;
|
|
62
|
+
- `local.properties` with `sdk.dir` auto-detected from `ANDROID_HOME`/`ANDROID_SDK_ROOT` (with a written warning if it can't be found);
|
|
63
|
+
- the Kotlin host: the `Application` (log service registered), `MainActivity` (async `AssetTemplateProvider`, splash screen, `XElementBehaviors`), and the font loader when `--with-font` is used;
|
|
64
|
+
- resource files that compile as-is (theme, splash theme, adaptive launcher icon);
|
|
65
|
+
- an opt-in release signing setup driven by a gitignored `keystore.properties`.
|
|
66
|
+
|
|
67
|
+
And in the JS project, a `scripts/android.mjs` bridge plus npm scripts:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm run android # build + sync + installDebug + launch, printing TotalTime
|
|
71
|
+
npm run android:apk # build + sync + assembleDebug
|
|
72
|
+
npm run android:release # build + sync + assembleRelease (signed if keystore.properties exists)
|
|
73
|
+
npm run android:sync # build + sync bundle into app/src/main/assets/, no Gradle
|
|
74
|
+
npm run android:keystore # generate release.keystore + keystore.properties (KEYSTORE_PASSWORD=...)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Templates
|
|
78
|
+
|
|
79
|
+
| Template | What it is |
|
|
80
|
+
|---|---|
|
|
81
|
+
| **Hello World** (recommended) | The Mithril.js analog of Lynx's official React hello-world ([`lynx-examples/examples/hello-world`](https://github.com/lynx-family/lynx-examples/tree/main/examples/hello-world)) — same layout, same "tap the logo" interaction, running through Mithril hyperscript instead of JSX. |
|
|
82
|
+
| **Blank** | A single centered line of text. Nothing else — the starting point when you don't want any of Hello World's styling/assets in your way. |
|
|
83
|
+
| **Basic Activity** | Two screens (Main → Details) wired with [`mithril-lynx/navigation`](https://github.com/carlos-sweb/mithril-lynx#navigation) — a stack-based, in-memory navigator (deliberately not `m.route`; see that package's README for why Lynx pages can't use URL-based routing). Includes a reusable app-bar-with-back-button pattern. Confirmed working end to end on a real device: `push()` with data, the back button, and `pop()` all round-trip correctly. |
|
|
84
|
+
|
|
85
|
+
## Variants
|
|
21
86
|
|
|
22
87
|
| Variant | Adds over the base template |
|
|
23
88
|
|---|---|
|
|
24
89
|
| **TypeScript** (recommended) | `.ts` source files, `tsconfig.json` (project references, matching `@lynx-js/rspeedy`'s own generated config), `@rsbuild/plugin-type-check`, `@types/mithril` for real editor autocomplete on `m()` calls. |
|
|
25
90
|
| **JavaScript** | Same app, plain `.js` with ES module `import`/`export` — no type-checking, no `tsconfig.json`. |
|
|
26
91
|
|
|
27
|
-
Both variants share `template-common/`: the logo/arrow image assets, `style.css`, `.gitignore`, and the project's own `README.md`.
|
|
28
|
-
|
|
29
92
|
## Package structure
|
|
30
93
|
|
|
31
94
|
```
|
|
32
95
|
create-mithril-lynx/
|
|
33
|
-
src/index.js
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
96
|
+
src/index.js the CLI itself
|
|
97
|
+
templates/
|
|
98
|
+
_shared/
|
|
99
|
+
common/ gitignore, project README — shared by every template
|
|
100
|
+
js/ lynx.config.js, package.json, main-thread.js — shared by every JS variant
|
|
101
|
+
ts/ lynx.config.ts, tsconfig*, package.json, main-thread.ts — shared by every TS variant
|
|
102
|
+
hello-world/
|
|
103
|
+
common/src/ logo/arrow assets, style.css
|
|
104
|
+
js/src/index.js
|
|
105
|
+
ts/src/index.ts
|
|
106
|
+
blank/
|
|
107
|
+
common/src/style.css
|
|
108
|
+
js/src/index.js
|
|
109
|
+
ts/src/index.ts
|
|
110
|
+
basic-activity/
|
|
111
|
+
common/src/style.css
|
|
112
|
+
js/src/index.js
|
|
113
|
+
ts/src/index.ts
|
|
114
|
+
android/ only used with --android
|
|
115
|
+
host/ the Gradle project -> <name>-android/
|
|
116
|
+
font/AssetFontFaceLoader.kt copied only when --with-font is used
|
|
117
|
+
app-scripts/android.mjs the bridge -> <name>/scripts/android.mjs
|
|
37
118
|
```
|
|
38
119
|
|
|
39
|
-
`src/index.js` copies `template
|
|
120
|
+
`src/index.js` copies, in order, `templates/_shared/common` → `templates/_shared/<variant>` → `templates/<template>/common` → `templates/<template>/<variant>` into the target directory (later copies never need to overwrite earlier ones — each layer contributes different files), renames `gitignore` to `.gitignore` (npm doesn't publish dotfiles reliably otherwise), and replaces `{{PROJECT_NAME}}`/`{{MITHRIL_LYNX_VERSION}}` placeholders in `package.json` and `README.md`.
|
|
121
|
+
|
|
122
|
+
With `--android` it then copies `templates/android/host` into a sibling `<name>-android/` (renaming `package-path` to the real package directory and `App.kt` to the Application class), substitutes `{{PACKAGE_NAME}}`, `{{APP_CLASS}}`, `{{APP_NAME}}`, `{{ANDROID_DIR}}` and `{{SDK_DIR}}` across the tree, and fills in the four font-hack hooks (`{{FONT_LOADER_IMPORT}}`, `{{FONT_LOADER_REGISTRATION}}`, `{{FONT_IMPORT}}`, `{{FONT_PREFETCH}}`) with either the real code or nothing at all. Binary files (the Gradle wrapper jar, the `.ttf`) are never text-substituted.
|
|
123
|
+
|
|
124
|
+
Every template's `src/index.{js,ts}` exports the same shape (`{ root }`), so `_shared/{js,ts}/src/main-thread.{js,ts}` — the actual `__RenderPage` wiring — is 100% shared and never duplicated per template.
|
|
40
125
|
|
|
41
126
|
## License
|
|
42
127
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mithril-lynx",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Scaffolds a new mithril-lynx app — the
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffolds a new mithril-lynx app — Hello World, Blank, or Basic Activity (with navigation), in JavaScript or TypeScript — and optionally the native Android host that packages it into an APK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -17,9 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"src",
|
|
20
|
-
"
|
|
21
|
-
"template-js",
|
|
22
|
-
"template-ts"
|
|
20
|
+
"templates"
|
|
23
21
|
],
|
|
24
22
|
"engines": {
|
|
25
23
|
"node": "^20.19.0 || >=22.12.0"
|