-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.plugin.js
More file actions
89 lines (79 loc) Β· 2.58 KB
/
app.plugin.js
File metadata and controls
89 lines (79 loc) Β· 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// app.plugin.js
const {
withAndroidManifest,
withStringsXml,
withProjectBuildGradle,
createRunOncePlugin,
} = require("expo/config-plugins");
const PLUGIN_NAME = "withKakaoLogin";
const KAKAO_MAVEN_URL =
"https://devrepo.kakao.com/nexus/content/groups/public/";
function addKakaoMaven(buildGradle) {
if (!buildGradle.includes(KAKAO_MAVEN_URL)) {
return buildGradle.replace(
/repositories\s*{/,
(m) => `${m}\n maven { url '${KAKAO_MAVEN_URL}' }`
);
}
return buildGradle;
}
const withKakaoProjectBuildGradle = (config) =>
withProjectBuildGradle(config, (cfg) => {
cfg.modResults.contents = addKakaoMaven(cfg.modResults.contents);
return cfg;
});
const withKakaoStrings = (config, appKey) =>
withStringsXml(config, (cfg) => {
const items = cfg.modResults.resources?.string ?? [];
const hasKey = items.some((s) => s.$?.name === "kakao_app_key");
if (!hasKey) {
items.push({ _: appKey, $: { name: "kakao_app_key" } });
}
cfg.modResults.resources = cfg.modResults.resources || {};
cfg.modResults.resources.string = items;
return cfg;
});
const withKakaoManifest = (config) =>
withAndroidManifest(config, (cfg) => {
const app = cfg.modResults.manifest.application?.[0];
if (!app) return cfg;
// meta-data: com.kakao.sdk.AppKey -> @string/kakao_app_key
app["meta-data"] = app["meta-data"] || [];
const hasMeta = app["meta-data"].some(
(m) => m.$["android:name"] === "com.kakao.sdk.AppKey"
);
if (!hasMeta) {
app["meta-data"].push({
$: {
"android:name": "com.kakao.sdk.AppKey",
"android:value": "@string/kakao_app_key",
},
});
}
// KakaoTalk ν¨ν€μ§ μ‘°ν νμ© (Android 11+ queries)
cfg.modResults.manifest.queries = cfg.modResults.manifest.queries || [];
const queries = cfg.modResults.manifest.queries;
const hasQuery = queries.some(
(q) =>
q.package &&
q.package.some((p) => p.$["android:name"] === "com.kakao.talk")
);
if (!hasQuery) {
queries.push({
package: [{ $: { "android:name": "com.kakao.talk" } }],
});
}
return cfg;
});
const withKakao = (config, { kakaoAppKey }) => {
if (!kakaoAppKey) {
throw new Error(
"[withKakaoLogin] kakaoAppKeyκ° μμ΅λλ€. app.jsonμ extra.kakaoAppKeyμ κ°μ λ£μ΄μ£ΌμΈμ."
);
}
config = withKakaoProjectBuildGradle(config);
config = withKakaoStrings(config, kakaoAppKey);
config = withKakaoManifest(config);
return config;
};
module.exports = createRunOncePlugin(withKakao, PLUGIN_NAME, "1.0.0");