@capgo/capacitor-social-login 7.19.1 → 7.20.0-beta.1

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.
@@ -0,0 +1,352 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Capacitor Hook Script: Configure Dynamic Provider Dependencies
5
+ *
6
+ * This script runs after `npx cap sync` and configures which providers
7
+ * to include based on capacitor.config.ts settings.
8
+ *
9
+ * Environment variables provided by Capacitor:
10
+ * - CAPACITOR_ROOT_DIR: Root directory of the consuming app
11
+ * - CAPACITOR_CONFIG: JSON stringified config object
12
+ * - CAPACITOR_PLATFORM_NAME: Platform name (android, ios, web)
13
+ * - process.cwd(): Plugin root directory
14
+ */
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28
+ }) : function(o, v) {
29
+ o["default"] = v;
30
+ });
31
+ var __importStar = (this && this.__importStar) || (function () {
32
+ var ownKeys = function(o) {
33
+ ownKeys = Object.getOwnPropertyNames || function (o) {
34
+ var ar = [];
35
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
36
+ return ar;
37
+ };
38
+ return ownKeys(o);
39
+ };
40
+ return function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
47
+ })();
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.getProviderConfig = getProviderConfig;
50
+ exports.configureAndroid = configureAndroid;
51
+ exports.configureIOS = configureIOS;
52
+ exports.configureWeb = configureWeb;
53
+ const fs = __importStar(require("fs"));
54
+ const path = __importStar(require("path"));
55
+ // Get environment variables
56
+ const PLUGIN_ROOT = process.cwd();
57
+ // Not used for now
58
+ // const APP_ROOT = process.env.CAPACITOR_ROOT_DIR;
59
+ const CONFIG_JSON = process.env.CAPACITOR_CONFIG;
60
+ const PLATFORM = process.env.CAPACITOR_PLATFORM_NAME;
61
+ // File paths
62
+ // Not used for now
63
+ // const androidGradlePath = path.join(PLUGIN_ROOT, 'android', 'build.gradle');
64
+ const gradlePropertiesPath = path.join(PLUGIN_ROOT, 'android', 'gradle.properties');
65
+ const podspecPath = path.join(PLUGIN_ROOT, 'CapgoCapacitorSocialLogin.podspec');
66
+ // Default provider configuration (backward compatible)
67
+ const defaultProviders = {
68
+ google: 'implementation',
69
+ facebook: 'implementation',
70
+ apple: 'implementation',
71
+ twitter: 'implementation',
72
+ };
73
+ // ============================================================================
74
+ // Common: Logging Utilities
75
+ // ============================================================================
76
+ /**
77
+ * ANSI color codes for terminal output
78
+ */
79
+ const colors = {
80
+ reset: '\x1b[0m',
81
+ bright: '\x1b[1m',
82
+ green: '\x1b[32m',
83
+ red: '\x1b[31m',
84
+ yellow: '\x1b[33m',
85
+ blue: '\x1b[34m',
86
+ cyan: '\x1b[36m',
87
+ gray: '\x1b[90m',
88
+ };
89
+ /**
90
+ * Capacitor-style colored logging with emojis
91
+ */
92
+ function log(message, emoji = '', color = '') {
93
+ const emojiPart = emoji ? `${emoji} ` : '';
94
+ const colorCode = color || colors.reset;
95
+ const resetCode = color ? colors.reset : '';
96
+ console.log(`${colorCode}${emojiPart}${message}${resetCode}`);
97
+ }
98
+ function logSuccess(message) {
99
+ log(message, '✔', colors.green);
100
+ }
101
+ function logError(message) {
102
+ log(message, '✖', colors.red);
103
+ }
104
+ function logInfo(message) {
105
+ log(message, 'ℹ', colors.blue);
106
+ }
107
+ function logWarning(message) {
108
+ log(message, '⚠', colors.yellow);
109
+ }
110
+ /**
111
+ * Log provider configuration status
112
+ */
113
+ function logProviderConfig(providerConfig) {
114
+ log('\nProvider configuration:', '', colors.bright);
115
+ const providers = ['google', 'facebook', 'apple', 'twitter'];
116
+ for (const provider of providers) {
117
+ const config = providerConfig[provider];
118
+ const isEnabled = config === 'implementation';
119
+ const providerName = provider.charAt(0).toUpperCase() + provider.slice(1);
120
+ if (isEnabled) {
121
+ // Enabled - green checkmark
122
+ console.log(` ${colors.green}✔${colors.reset} ${colors.bright}${providerName}${colors.reset}: ${colors.green}enabled${colors.reset}`);
123
+ }
124
+ else {
125
+ // Disabled - red cross
126
+ console.log(` ${colors.red}✖${colors.reset} ${colors.bright}${providerName}${colors.reset}: ${colors.red}disabled${colors.reset}`);
127
+ }
128
+ }
129
+ console.log('');
130
+ }
131
+ // ============================================================================
132
+ // Common: Configuration Parsing
133
+ // ============================================================================
134
+ /**
135
+ * Parse provider configuration from Capacitor config
136
+ * Supports: true = implementation, false = compileOnly
137
+ */
138
+ function getProviderConfig() {
139
+ try {
140
+ if (!CONFIG_JSON) {
141
+ logInfo('No CAPACITOR_CONFIG found, using defaults');
142
+ return defaultProviders;
143
+ }
144
+ const config = JSON.parse(CONFIG_JSON);
145
+ const providerConfig = config.plugins?.SocialLogin?.providers || defaultProviders;
146
+ // Normalize config: convert true to 'implementation', false to 'compileOnly'
147
+ const normalized = {};
148
+ for (const [provider, value] of Object.entries(providerConfig)) {
149
+ if (value === true) {
150
+ normalized[provider] = 'implementation';
151
+ }
152
+ else if (value === false) {
153
+ normalized[provider] = 'compileOnly';
154
+ }
155
+ else {
156
+ // Legacy support: if someone passes a string, use it as-is
157
+ normalized[provider] = value;
158
+ }
159
+ }
160
+ // Merge with defaults for missing providers
161
+ return { ...defaultProviders, ...normalized };
162
+ }
163
+ catch (error) {
164
+ logError(`Error parsing config: ${error.message}`);
165
+ return defaultProviders;
166
+ }
167
+ }
168
+ // ============================================================================
169
+ // Android: Gradle Configuration
170
+ // ============================================================================
171
+ /**
172
+ * Write gradle.properties file for Android
173
+ * Injects SocialLogin properties while preserving existing content
174
+ */
175
+ function configureAndroid(providerConfig) {
176
+ logInfo('Configuring Android dependencies...');
177
+ try {
178
+ // Read existing gradle.properties if it exists
179
+ let existingContent = '';
180
+ if (fs.existsSync(gradlePropertiesPath)) {
181
+ existingContent = fs.readFileSync(gradlePropertiesPath, 'utf8');
182
+ }
183
+ // Remove existing SocialLogin properties (if any)
184
+ const lines = existingContent.split('\n');
185
+ const filteredLines = [];
186
+ let inSocialLoginSection = false;
187
+ let lastWasEmpty = false;
188
+ for (const line of lines) {
189
+ // Check if this is a SocialLogin property or comment
190
+ if (line.trim().startsWith('# SocialLogin') ||
191
+ line.trim().startsWith('socialLogin.') ||
192
+ line.trim() === '# Generated by SocialLogin hook script') {
193
+ inSocialLoginSection = true;
194
+ continue; // Skip this line
195
+ }
196
+ // If we were in SocialLogin section and hit a non-empty line, we're done
197
+ if (inSocialLoginSection && line.trim() !== '') {
198
+ inSocialLoginSection = false;
199
+ }
200
+ // Add non-SocialLogin lines, but avoid multiple consecutive empty lines
201
+ if (!inSocialLoginSection) {
202
+ if (line.trim() === '') {
203
+ if (!lastWasEmpty) {
204
+ filteredLines.push(line);
205
+ lastWasEmpty = true;
206
+ }
207
+ }
208
+ else {
209
+ filteredLines.push(line);
210
+ lastWasEmpty = false;
211
+ }
212
+ }
213
+ }
214
+ // Build new SocialLogin properties section
215
+ const socialLoginProperties = [];
216
+ socialLoginProperties.push('');
217
+ socialLoginProperties.push('# SocialLogin Provider Dependencies (auto-generated)');
218
+ socialLoginProperties.push('# Generated by SocialLogin hook script');
219
+ for (const [provider, value] of Object.entries(providerConfig)) {
220
+ const dependencyType = value === 'compileOnly' ? 'compileOnly' : 'implementation';
221
+ const include = dependencyType === 'compileOnly' ? 'false' : 'true';
222
+ socialLoginProperties.push(`socialLogin.${provider}.include=${include}`);
223
+ socialLoginProperties.push(`socialLogin.${provider}.dependencyType=${dependencyType}`);
224
+ }
225
+ // Combine: existing content + new SocialLogin properties
226
+ const newContent = filteredLines.join('\n') + '\n' + socialLoginProperties.join('\n') + '\n';
227
+ fs.writeFileSync(gradlePropertiesPath, newContent, 'utf8');
228
+ logSuccess('Updated gradle.properties');
229
+ }
230
+ catch (error) {
231
+ logError(`Error updating gradle.properties: ${error.message}`);
232
+ }
233
+ }
234
+ // ============================================================================
235
+ // iOS: Podspec Configuration
236
+ // ============================================================================
237
+ /**
238
+ * Modify Podspec for iOS conditional dependencies
239
+ */
240
+ function configureIOS(providerConfig) {
241
+ logInfo('Configuring iOS dependencies...');
242
+ try {
243
+ let podspecContent = fs.readFileSync(podspecPath, 'utf8');
244
+ // Replace dependency declarations with conditional ones
245
+ // Handle both active and commented-out dependencies (including existing disabled comments)
246
+ const replacements = [
247
+ {
248
+ // Google SignIn - handle both active and commented (including existing disabled comments)
249
+ old: /(#\s*)?s\.dependency\s+'GoogleSignIn',\s*'~>\s*9\.0\.0'(\s*#.*)?/,
250
+ new: providerConfig.google === 'implementation'
251
+ ? `s.dependency 'GoogleSignIn', '~> 9.0.0'`
252
+ : `# s.dependency 'GoogleSignIn', '~> 9.0.0' # Disabled via config (compileOnly)`,
253
+ },
254
+ {
255
+ // Facebook Core - handle both active and commented (including existing disabled comments)
256
+ old: /(#\s*)?s\.dependency\s+'FBSDKCoreKit',\s*'18\.0\.0'(\s*#.*)?/,
257
+ new: providerConfig.facebook === 'implementation'
258
+ ? `s.dependency 'FBSDKCoreKit', '18.0.0'`
259
+ : `# s.dependency 'FBSDKCoreKit', '18.0.0' # Disabled via config (compileOnly)`,
260
+ },
261
+ {
262
+ // Facebook Login - handle both active and commented (including existing disabled comments)
263
+ old: /(#\s*)?s\.dependency\s+'FBSDKLoginKit',\s*'18\.0\.0'(\s*#.*)?/,
264
+ new: providerConfig.facebook === 'implementation'
265
+ ? `s.dependency 'FBSDKLoginKit', '18.0.0'`
266
+ : `# s.dependency 'FBSDKLoginKit', '18.0.0' # Disabled via config (compileOnly)`,
267
+ },
268
+ {
269
+ // Alamofire (for Apple) - handle both active and commented (including existing disabled comments)
270
+ old: /(#\s*)?s\.dependency\s+'Alamofire',\s*'~>\s*5\.10\.2'(\s*#.*)?/,
271
+ new: providerConfig.apple === 'implementation'
272
+ ? `s.dependency 'Alamofire', '~> 5.10.2'`
273
+ : `# s.dependency 'Alamofire', '~> 5.10.2' # Disabled via config (compileOnly)`,
274
+ },
275
+ ];
276
+ let modified = false;
277
+ for (const replacement of replacements) {
278
+ if (replacement.old.test(podspecContent)) {
279
+ const before = podspecContent;
280
+ podspecContent = podspecContent.replace(replacement.old, replacement.new);
281
+ if (before !== podspecContent) {
282
+ modified = true;
283
+ }
284
+ }
285
+ }
286
+ if (modified) {
287
+ fs.writeFileSync(podspecPath, podspecContent, 'utf8');
288
+ logSuccess('Modified podspec');
289
+ }
290
+ else {
291
+ logInfo('Podspec already up to date');
292
+ }
293
+ }
294
+ catch (error) {
295
+ logError(`Error modifying podspec: ${error.message}`);
296
+ }
297
+ }
298
+ // ============================================================================
299
+ // Web: No Configuration Needed
300
+ // ============================================================================
301
+ /**
302
+ * Web platform doesn't need native dependency configuration
303
+ */
304
+ function configureWeb() {
305
+ logInfo('Skipping conditional dependency compilation for web platform');
306
+ logInfo('Web platform uses JavaScript dependencies managed by npm/bundler');
307
+ }
308
+ // ============================================================================
309
+ // Main Execution
310
+ // ============================================================================
311
+ /**
312
+ * Main execution
313
+ */
314
+ function main() {
315
+ // Route to platform-specific configuration
316
+ switch (PLATFORM) {
317
+ case 'android':
318
+ log('Configuring dynamic provider dependencies for SocialLogin', '🔧', colors.cyan);
319
+ // eslint-disable-next-line no-case-declarations
320
+ const androidConfig = getProviderConfig();
321
+ logProviderConfig(androidConfig);
322
+ configureAndroid(androidConfig);
323
+ logSuccess('Configuration complete\n');
324
+ break;
325
+ case 'ios':
326
+ log('Configuring dynamic provider dependencies for SocialLogin', '🔧', colors.cyan);
327
+ // eslint-disable-next-line no-case-declarations
328
+ const iosConfig = getProviderConfig();
329
+ logProviderConfig(iosConfig);
330
+ configureIOS(iosConfig);
331
+ logSuccess('Configuration complete\n');
332
+ break;
333
+ case 'web':
334
+ configureWeb();
335
+ break;
336
+ default:
337
+ // If platform is not specified, configure all platforms (backward compatibility)
338
+ log('Configuring dynamic provider dependencies for SocialLogin', '🔧', colors.blue);
339
+ // eslint-disable-next-line no-case-declarations
340
+ const defaultConfig = getProviderConfig();
341
+ logProviderConfig(defaultConfig);
342
+ logWarning(`Unknown platform: ${PLATFORM || 'undefined'}, configuring all platforms`);
343
+ configureAndroid(defaultConfig);
344
+ configureIOS(defaultConfig);
345
+ logSuccess('Configuration complete\n');
346
+ break;
347
+ }
348
+ }
349
+ // Run if executed directly
350
+ if (require.main === module) {
351
+ main();
352
+ }