@straitlink/cli 0.2.1 → 0.2.2
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 +1 -1
- package/package.json +1 -1
- package/src/detect.mjs +2 -0
- package/src/templates.mjs +10 -7
- package/src/version.mjs +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npx @straitlink/cli links create summer https://acme.com/s # create a link (sec
|
|
|
26
26
|
| App | File written |
|
|
27
27
|
|---|---|
|
|
28
28
|
| React Native | `links.ts` (or `links.js`) |
|
|
29
|
-
| Expo | `links.ts`, plus `app/+native-intent.tsx` with Expo Router |
|
|
29
|
+
| Expo | `links.ts`, plus `app/+native-intent.tsx` with Expo Router (`src/links.ts` and `src/app/+native-intent.tsx` when your routes live in `src/app`) |
|
|
30
30
|
| Flutter | `lib/links.dart` |
|
|
31
31
|
| Android | `app/src/main/java/<package>/StraitLinks.kt` |
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@straitlink/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Strait deep links from the terminal: init sets them up in a React Native, Expo, Flutter or Android app, doctor checks your link host, links creates and lists links and saves QR codes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strait",
|
package/src/detect.mjs
CHANGED
|
@@ -73,6 +73,8 @@ export function detectProject(dir) {
|
|
|
73
73
|
framework: 'expo',
|
|
74
74
|
typescript: existsSync(join(dir, 'tsconfig.json')),
|
|
75
75
|
expoRouter: Boolean(deps['expo-router']),
|
|
76
|
+
// Expo Router's root: src/app when it exists, else app (@expo/metro-config getRouterDirectory).
|
|
77
|
+
routerDir: deps['expo-router'] && existsSync(join(dir, 'src', 'app')) ? 'src/app' : 'app',
|
|
76
78
|
appName: expo.name ?? pkg.name ?? null,
|
|
77
79
|
androidPackage: expo.android?.package ?? null,
|
|
78
80
|
iosBundleId: expo.ios?.bundleIdentifier ?? null,
|
package/src/templates.mjs
CHANGED
|
@@ -8,7 +8,7 @@ const HEADER = (pkg, version) => `Created by \`strait init\` (${pkg} ${version})
|
|
|
8
8
|
|
|
9
9
|
// ---------- integration files ----------
|
|
10
10
|
|
|
11
|
-
function rnLinks({ key, host }, { withRouting }) {
|
|
11
|
+
function rnLinks({ key, host }, { withRouting, routerDir = 'app' }) {
|
|
12
12
|
return `// ${HEADER(PACKAGES.reactNative, VERSIONS.rnVersion)}
|
|
13
13
|
// Import this file once from your entry file (index.js) so the launch link is caught.
|
|
14
14
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
@@ -36,7 +36,7 @@ links.onLink((e) => {
|
|
|
36
36
|
});
|
|
37
37
|
`
|
|
38
38
|
: `
|
|
39
|
-
// Routing lives in
|
|
39
|
+
// Routing lives in ${routerDir}/_layout.tsx (links.onLink). This log helps while you set up.
|
|
40
40
|
links.onLink((e) => console.log('Strait link:', e.kind, e.route, e.matched, e.path));
|
|
41
41
|
`
|
|
42
42
|
}
|
|
@@ -44,8 +44,8 @@ links.start();
|
|
|
44
44
|
`;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
// Links reach the app through Strait's onLink (
|
|
47
|
+
const nativeIntent = (routerDir) => `// ${HEADER(PACKAGES.reactNative, VERSIONS.rnVersion)}
|
|
48
|
+
// Links reach the app through Strait's onLink (${routerDir}/_layout.tsx), which knows the
|
|
49
49
|
// real destination. Keep Expo Router from routing the raw link URL.
|
|
50
50
|
// If your app has other deep links of its own (a sign-in callback), return \`path\` for those.
|
|
51
51
|
export function redirectSystemPath({ path }: { path: string; initial: boolean }) {
|
|
@@ -223,8 +223,11 @@ export function integrationFiles(project, opts) {
|
|
|
223
223
|
case 'react-native':
|
|
224
224
|
return [{ path: `links.${ext}`, contents: rnLinks(opts, { withRouting: true }), why: 'creates the client and handles every link' }];
|
|
225
225
|
case 'expo': {
|
|
226
|
-
const
|
|
227
|
-
|
|
226
|
+
const routerDir = project.routerDir ?? 'app';
|
|
227
|
+
// links.ts sits next to the router folder, so the layout's `../links` import finds it.
|
|
228
|
+
const linksPath = project.expoRouter && routerDir === 'src/app' ? `src/links.${ext}` : `links.${ext}`;
|
|
229
|
+
const files = [{ path: linksPath, contents: rnLinks(opts, { withRouting: !project.expoRouter, routerDir }), why: 'creates the client' }];
|
|
230
|
+
if (project.expoRouter) files.push({ path: `${routerDir}/+native-intent.tsx`, contents: nativeIntent(routerDir), why: 'stops Expo Router routing the raw link URL' });
|
|
228
231
|
return files;
|
|
229
232
|
}
|
|
230
233
|
case 'flutter':
|
|
@@ -333,7 +336,7 @@ export function nextSteps(project, opts, installSrc) {
|
|
|
333
336
|
if (fw === 'react-native') steps.push({ title: 'Load links at startup', body: `Add \`import './links';\` to the top of index.js, then rebuild (npx react-native run-android). The SDK adds a native module, so a Metro reload is not enough.` });
|
|
334
337
|
if (fw === 'expo') {
|
|
335
338
|
steps.push({ title: 'Add link settings to app.json (merge with what you have)', code: expoAppJson(opts, project), lang: 'json', body: `${project.dynamicConfig ? 'Your config is app.config.js/ts, so copy these keys into it by hand. ' : ''}associatedDomains opens links in your iPhone app. ${IPHONE_INSTALLS}` });
|
|
336
|
-
if (project.expoRouter) steps.push({ title:
|
|
339
|
+
if (project.expoRouter) steps.push({ title: `Route links in ${project.routerDir ?? 'app'}/_layout.tsx`, code: EXPO_LAYOUT, lang: 'tsx' });
|
|
337
340
|
else steps.push({ title: 'Load links at startup', body: "Add `import './links';` to your entry file." });
|
|
338
341
|
steps.push({ title: 'Make a development build (Expo Go cannot load the native module)', code: 'npx expo run:android # or: eas build --profile development --platform android', lang: 'bash' });
|
|
339
342
|
}
|
package/src/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Kept equal to package.json version (test/links.test.mjs checks it). Sent as the API User-Agent.
|
|
2
|
-
export const CLI_VERSION = '0.2.
|
|
2
|
+
export const CLI_VERSION = '0.2.2';
|