@gurulu/cli 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 +66 -0
- package/bin/gurulu.js +2 -0
- package/dist/api-client.d.ts +27 -0
- package/dist/api-client.js +150 -0
- package/dist/commands/add-server.d.ts +9 -0
- package/dist/commands/add-server.js +155 -0
- package/dist/commands/alerts.d.ts +22 -0
- package/dist/commands/alerts.js +281 -0
- package/dist/commands/api-keys.d.ts +20 -0
- package/dist/commands/api-keys.js +130 -0
- package/dist/commands/audiences.d.ts +16 -0
- package/dist/commands/audiences.js +180 -0
- package/dist/commands/audit.d.ts +20 -0
- package/dist/commands/audit.js +130 -0
- package/dist/commands/auth.d.ts +20 -0
- package/dist/commands/auth.js +214 -0
- package/dist/commands/chat.d.ts +18 -0
- package/dist/commands/chat.js +117 -0
- package/dist/commands/config.d.ts +10 -0
- package/dist/commands/config.js +92 -0
- package/dist/commands/db.d.ts +25 -0
- package/dist/commands/db.js +322 -0
- package/dist/commands/destinations.d.ts +20 -0
- package/dist/commands/destinations.js +191 -0
- package/dist/commands/doctor.d.ts +7 -0
- package/dist/commands/doctor.js +318 -0
- package/dist/commands/events.d.ts +27 -0
- package/dist/commands/events.js +147 -0
- package/dist/commands/experiments.d.ts +18 -0
- package/dist/commands/experiments.js +233 -0
- package/dist/commands/identity.d.ts +13 -0
- package/dist/commands/identity.js +107 -0
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.js +215 -0
- package/dist/commands/insights.d.ts +10 -0
- package/dist/commands/insights.js +65 -0
- package/dist/commands/install.d.ts +233 -0
- package/dist/commands/install.js +920 -0
- package/dist/commands/login.d.ts +20 -0
- package/dist/commands/login.js +170 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.js +41 -0
- package/dist/commands/playground.d.ts +11 -0
- package/dist/commands/playground.js +47 -0
- package/dist/commands/sites.d.ts +18 -0
- package/dist/commands/sites.js +139 -0
- package/dist/commands/sourcemap.d.ts +21 -0
- package/dist/commands/sourcemap.js +137 -0
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +136 -0
- package/dist/commands/warehouse.d.ts +20 -0
- package/dist/commands/warehouse.js +65 -0
- package/dist/commands/warehouses.d.ts +17 -0
- package/dist/commands/warehouses.js +182 -0
- package/dist/commands/whoami.d.ts +9 -0
- package/dist/commands/whoami.js +47 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +329 -0
- package/dist/frameworks/detect.d.ts +8 -0
- package/dist/frameworks/detect.js +362 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +429 -0
- package/dist/install-intent-proposal.d.ts +99 -0
- package/dist/install-intent-proposal.js +202 -0
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +47 -0
- package/dist/utils/config.d.ts +13 -0
- package/dist/utils/config.js +30 -0
- package/dist/utils/confirm.d.ts +17 -0
- package/dist/utils/confirm.js +40 -0
- package/dist/utils/dry-run.d.ts +20 -0
- package/dist/utils/dry-run.js +67 -0
- package/dist/utils/from-file.d.ts +9 -0
- package/dist/utils/from-file.js +72 -0
- package/dist/utils/ui.d.ts +14 -0
- package/dist/utils/ui.js +59 -0
- package/package.json +26 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 18.5 W2 — Multi-profile CLI config.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the single-profile `~/.gurulu/config.json` used by earlier phases
|
|
6
|
+
* with a profile-aware store, while keeping backward compatibility for
|
|
7
|
+
* commands that still call `utils/config.ts` (they now read from the
|
|
8
|
+
* currently-active profile).
|
|
9
|
+
*
|
|
10
|
+
* Resolution order for a live session:
|
|
11
|
+
* 1. GURULU_SECRET_KEY (env-var override — bypasses the file entirely)
|
|
12
|
+
* 2. --profile <name> (CLI flag)
|
|
13
|
+
* 3. GURULU_PROFILE (env)
|
|
14
|
+
* 4. default_profile (from file)
|
|
15
|
+
* 5. 'personal' (final fallback)
|
|
16
|
+
*
|
|
17
|
+
* Optional macOS keychain integration: if `keytar` is available at runtime,
|
|
18
|
+
* secrets can be stored there under service 'io.gurulu.cli' account
|
|
19
|
+
* `<profile>`. If unavailable, secrets fall back to the plaintext file.
|
|
20
|
+
* Keytar is a **soft runtime require** — never a hard dependency, because
|
|
21
|
+
* it's a native module and we don't want to force its install.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ProfileNotFoundError = void 0;
|
|
58
|
+
exports.configPath = configPath;
|
|
59
|
+
exports.readKeychainSecret = readKeychainSecret;
|
|
60
|
+
exports.writeKeychainSecret = writeKeychainSecret;
|
|
61
|
+
exports.deleteKeychainSecret = deleteKeychainSecret;
|
|
62
|
+
exports.isKeychainAvailable = isKeychainAvailable;
|
|
63
|
+
exports.listProfiles = listProfiles;
|
|
64
|
+
exports.getStoredProfile = getStoredProfile;
|
|
65
|
+
exports.getDefaultProfileName = getDefaultProfileName;
|
|
66
|
+
exports.setDefaultProfile = setDefaultProfile;
|
|
67
|
+
exports.saveProfile = saveProfile;
|
|
68
|
+
exports.deleteProfile = deleteProfile;
|
|
69
|
+
exports.deleteAllProfiles = deleteAllProfiles;
|
|
70
|
+
exports.loadActiveProfile = loadActiveProfile;
|
|
71
|
+
exports.getActiveProfile = getActiveProfile;
|
|
72
|
+
exports.defaultApiBase = defaultApiBase;
|
|
73
|
+
const fs = __importStar(require("fs"));
|
|
74
|
+
const path = __importStar(require("path"));
|
|
75
|
+
const os = __importStar(require("os"));
|
|
76
|
+
const DEFAULT_API_BASE = 'https://gurulu.io';
|
|
77
|
+
const KEYCHAIN_SERVICE = 'io.gurulu.cli';
|
|
78
|
+
function configHome() {
|
|
79
|
+
if (process.env.GURULU_CONFIG_HOME)
|
|
80
|
+
return process.env.GURULU_CONFIG_HOME;
|
|
81
|
+
return path.join(os.homedir(), '.gurulu');
|
|
82
|
+
}
|
|
83
|
+
function configPath() {
|
|
84
|
+
return path.join(configHome(), 'config.json');
|
|
85
|
+
}
|
|
86
|
+
function emptyFile() {
|
|
87
|
+
return { default_profile: 'personal', profiles: {} };
|
|
88
|
+
}
|
|
89
|
+
function readFileRaw() {
|
|
90
|
+
const p = configPath();
|
|
91
|
+
if (!fs.existsSync(p))
|
|
92
|
+
return emptyFile();
|
|
93
|
+
try {
|
|
94
|
+
const txt = fs.readFileSync(p, 'utf8');
|
|
95
|
+
const parsed = JSON.parse(txt);
|
|
96
|
+
if (parsed && typeof parsed === 'object' && parsed.profiles) {
|
|
97
|
+
return parsed;
|
|
98
|
+
}
|
|
99
|
+
// Migrate legacy `{ apiKey, email }` single-profile config.
|
|
100
|
+
if (parsed && typeof parsed === 'object' && parsed.apiKey) {
|
|
101
|
+
const migrated = {
|
|
102
|
+
default_profile: 'personal',
|
|
103
|
+
profiles: {
|
|
104
|
+
personal: {
|
|
105
|
+
email: parsed.email || '',
|
|
106
|
+
secret_key: parsed.apiKey,
|
|
107
|
+
api_base: DEFAULT_API_BASE,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return migrated;
|
|
112
|
+
}
|
|
113
|
+
return emptyFile();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return emptyFile();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function writeFileRaw(cfg) {
|
|
120
|
+
const home = configHome();
|
|
121
|
+
if (!fs.existsSync(home)) {
|
|
122
|
+
fs.mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
try {
|
|
126
|
+
fs.chmodSync(home, 0o700);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
/* ignore */
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const p = configPath();
|
|
133
|
+
fs.writeFileSync(p, JSON.stringify(cfg, null, 2));
|
|
134
|
+
try {
|
|
135
|
+
fs.chmodSync(p, 0o600);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
/* ignore on non-unix */
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function warnBadPermissions() {
|
|
142
|
+
const p = configPath();
|
|
143
|
+
if (!fs.existsSync(p))
|
|
144
|
+
return;
|
|
145
|
+
try {
|
|
146
|
+
const stat = fs.statSync(p);
|
|
147
|
+
const mode = stat.mode & 0o777;
|
|
148
|
+
if (mode & 0o077) {
|
|
149
|
+
// Group/world readable — warn on stderr only.
|
|
150
|
+
process.stderr.write(`[warn] ${p} has insecure permissions (${mode.toString(8)}). Run: chmod 600 ${p}\n`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
/* ignore */
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function tryRequireKeytar() {
|
|
158
|
+
if (process.env.GURULU_DISABLE_KEYCHAIN === '1')
|
|
159
|
+
return null;
|
|
160
|
+
try {
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
162
|
+
return require('keytar');
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function readKeychainSecret(profile) {
|
|
169
|
+
const kt = tryRequireKeytar();
|
|
170
|
+
if (!kt)
|
|
171
|
+
return null;
|
|
172
|
+
try {
|
|
173
|
+
return await kt.getPassword(KEYCHAIN_SERVICE, profile);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function writeKeychainSecret(profile, secret) {
|
|
180
|
+
const kt = tryRequireKeytar();
|
|
181
|
+
if (!kt)
|
|
182
|
+
return false;
|
|
183
|
+
try {
|
|
184
|
+
await kt.setPassword(KEYCHAIN_SERVICE, profile, secret);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function deleteKeychainSecret(profile) {
|
|
192
|
+
const kt = tryRequireKeytar();
|
|
193
|
+
if (!kt)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
await kt.deletePassword(KEYCHAIN_SERVICE, profile);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
/* ignore */
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function isKeychainAvailable() {
|
|
203
|
+
return tryRequireKeytar() !== null;
|
|
204
|
+
}
|
|
205
|
+
// --- public API --------------------------------------------------------------
|
|
206
|
+
function listProfiles() {
|
|
207
|
+
const cfg = readFileRaw();
|
|
208
|
+
return Object.entries(cfg.profiles).map(([name, p]) => ({
|
|
209
|
+
name,
|
|
210
|
+
email: p.email,
|
|
211
|
+
api_base: p.api_base,
|
|
212
|
+
isDefault: name === cfg.default_profile,
|
|
213
|
+
keychain: !!p.keychain,
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
function getStoredProfile(name) {
|
|
217
|
+
const cfg = readFileRaw();
|
|
218
|
+
return cfg.profiles[name] || null;
|
|
219
|
+
}
|
|
220
|
+
function getDefaultProfileName() {
|
|
221
|
+
const cfg = readFileRaw();
|
|
222
|
+
return cfg.default_profile || 'personal';
|
|
223
|
+
}
|
|
224
|
+
function setDefaultProfile(name) {
|
|
225
|
+
const cfg = readFileRaw();
|
|
226
|
+
if (!cfg.profiles[name]) {
|
|
227
|
+
throw new Error(`Profile '${name}' does not exist.`);
|
|
228
|
+
}
|
|
229
|
+
cfg.default_profile = name;
|
|
230
|
+
writeFileRaw(cfg);
|
|
231
|
+
}
|
|
232
|
+
async function saveProfile(name, profile, opts = {}) {
|
|
233
|
+
const cfg = readFileRaw();
|
|
234
|
+
const wantKeychain = !!opts.useKeychain && isKeychainAvailable();
|
|
235
|
+
let storedInKeychain = false;
|
|
236
|
+
if (wantKeychain) {
|
|
237
|
+
storedInKeychain = await writeKeychainSecret(name, profile.secret_key);
|
|
238
|
+
}
|
|
239
|
+
cfg.profiles[name] = storedInKeychain
|
|
240
|
+
? { email: profile.email, api_base: profile.api_base, keychain: true }
|
|
241
|
+
: { email: profile.email, api_base: profile.api_base, secret_key: profile.secret_key };
|
|
242
|
+
if (!cfg.default_profile || !cfg.profiles[cfg.default_profile]) {
|
|
243
|
+
cfg.default_profile = name;
|
|
244
|
+
}
|
|
245
|
+
writeFileRaw(cfg);
|
|
246
|
+
return { storedInKeychain };
|
|
247
|
+
}
|
|
248
|
+
async function deleteProfile(name) {
|
|
249
|
+
const cfg = readFileRaw();
|
|
250
|
+
if (!cfg.profiles[name])
|
|
251
|
+
return false;
|
|
252
|
+
delete cfg.profiles[name];
|
|
253
|
+
if (cfg.default_profile === name) {
|
|
254
|
+
const remaining = Object.keys(cfg.profiles);
|
|
255
|
+
cfg.default_profile = remaining[0] || 'personal';
|
|
256
|
+
}
|
|
257
|
+
writeFileRaw(cfg);
|
|
258
|
+
await deleteKeychainSecret(name);
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
async function deleteAllProfiles() {
|
|
262
|
+
const cfg = readFileRaw();
|
|
263
|
+
const names = Object.keys(cfg.profiles);
|
|
264
|
+
for (const n of names)
|
|
265
|
+
await deleteKeychainSecret(n);
|
|
266
|
+
writeFileRaw({ default_profile: 'personal', profiles: {} });
|
|
267
|
+
return names;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Resolve the active profile given CLI flags. Throws if no usable profile.
|
|
271
|
+
* Accepts the `GURULU_SECRET_KEY` env var as an override for CI.
|
|
272
|
+
*/
|
|
273
|
+
async function loadActiveProfile(flags = {}) {
|
|
274
|
+
// 1. Environment override (bypasses file entirely — used by CI)
|
|
275
|
+
const envKey = process.env.GURULU_SECRET_KEY;
|
|
276
|
+
if (envKey) {
|
|
277
|
+
return {
|
|
278
|
+
name: flags.profile || process.env.GURULU_PROFILE || 'env',
|
|
279
|
+
email: process.env.GURULU_EMAIL || 'env@gurulu.local',
|
|
280
|
+
secret_key: envKey,
|
|
281
|
+
api_base: process.env.GURULU_API_BASE || DEFAULT_API_BASE,
|
|
282
|
+
source: 'env',
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
warnBadPermissions();
|
|
286
|
+
const cfg = readFileRaw();
|
|
287
|
+
const name = flags.profile || process.env.GURULU_PROFILE || cfg.default_profile || 'personal';
|
|
288
|
+
const stored = cfg.profiles[name];
|
|
289
|
+
if (!stored) {
|
|
290
|
+
throw new ProfileNotFoundError(name);
|
|
291
|
+
}
|
|
292
|
+
let secret = stored.secret_key || '';
|
|
293
|
+
let source = 'file';
|
|
294
|
+
if (stored.keychain) {
|
|
295
|
+
const kc = await readKeychainSecret(name);
|
|
296
|
+
if (kc) {
|
|
297
|
+
secret = kc;
|
|
298
|
+
source = 'keychain';
|
|
299
|
+
}
|
|
300
|
+
else if (!secret) {
|
|
301
|
+
throw new Error(`Profile '${name}' is marked as keychain-stored but the secret is missing. Run 'gurulu login --profile ${name}' again.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
name,
|
|
306
|
+
email: stored.email,
|
|
307
|
+
secret_key: secret,
|
|
308
|
+
api_base: stored.api_base || DEFAULT_API_BASE,
|
|
309
|
+
source,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
async function getActiveProfile(flags = {}) {
|
|
313
|
+
try {
|
|
314
|
+
return await loadActiveProfile(flags);
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
class ProfileNotFoundError extends Error {
|
|
321
|
+
constructor(name) {
|
|
322
|
+
super(`Profile '${name}' not found. Run 'gurulu login' first.`);
|
|
323
|
+
this.name = 'ProfileNotFoundError';
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.ProfileNotFoundError = ProfileNotFoundError;
|
|
327
|
+
function defaultApiBase() {
|
|
328
|
+
return process.env.GURULU_API_BASE || DEFAULT_API_BASE;
|
|
329
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Framework = 'nextjs-app' | 'nextjs-pages' | 'react-vite' | 'react-cra' | 'vue3' | 'nuxt3' | 'svelte' | 'sveltekit' | 'astro' | 'express' | 'nestjs' | 'html' | 'react-native' | 'ios-swift' | 'android-kotlin' | 'flutter' | 'unknown';
|
|
2
|
+
export declare function detectFramework(projectDir: string): Framework;
|
|
3
|
+
export declare function getSetupSnippet(framework: Framework, siteId: string, token: string): {
|
|
4
|
+
file: string;
|
|
5
|
+
code: string;
|
|
6
|
+
instruction: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function getFrameworkDisplayName(fw: Framework): string;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.detectFramework = detectFramework;
|
|
7
|
+
exports.getSetupSnippet = getSetupSnippet;
|
|
8
|
+
exports.getFrameworkDisplayName = getFrameworkDisplayName;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
function detectFramework(projectDir) {
|
|
12
|
+
const pkgPath = path_1.default.join(projectDir, 'package.json');
|
|
13
|
+
const hasPkgJson = fs_1.default.existsSync(pkgPath);
|
|
14
|
+
// Mobile framework detection (non-package.json based)
|
|
15
|
+
if (fs_1.default.existsSync(path_1.default.join(projectDir, 'pubspec.yaml')))
|
|
16
|
+
return 'flutter';
|
|
17
|
+
const hasSwiftPkg = fs_1.default.existsSync(path_1.default.join(projectDir, 'Package.swift'));
|
|
18
|
+
const hasXcodeProj = fs_1.default.readdirSync(projectDir).some(f => f.endsWith('.xcodeproj'));
|
|
19
|
+
if (hasSwiftPkg || hasXcodeProj)
|
|
20
|
+
return 'ios-swift';
|
|
21
|
+
if (!hasPkgJson) {
|
|
22
|
+
// Android detection (no package.json means no RN false positive)
|
|
23
|
+
if (fs_1.default.existsSync(path_1.default.join(projectDir, 'build.gradle.kts')) || fs_1.default.existsSync(path_1.default.join(projectDir, 'build.gradle'))) {
|
|
24
|
+
return 'android-kotlin';
|
|
25
|
+
}
|
|
26
|
+
return 'html';
|
|
27
|
+
}
|
|
28
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
|
|
29
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
30
|
+
// React Native (must check before other React frameworks)
|
|
31
|
+
if (deps['react-native'])
|
|
32
|
+
return 'react-native';
|
|
33
|
+
if (deps['next']) {
|
|
34
|
+
// Check for app router
|
|
35
|
+
if (fs_1.default.existsSync(path_1.default.join(projectDir, 'src', 'app')) || fs_1.default.existsSync(path_1.default.join(projectDir, 'app'))) {
|
|
36
|
+
return 'nextjs-app';
|
|
37
|
+
}
|
|
38
|
+
return 'nextjs-pages';
|
|
39
|
+
}
|
|
40
|
+
if (deps['@nestjs/core'])
|
|
41
|
+
return 'nestjs';
|
|
42
|
+
if (deps['nuxt'])
|
|
43
|
+
return 'nuxt3';
|
|
44
|
+
if (deps['@sveltejs/kit'])
|
|
45
|
+
return 'sveltekit';
|
|
46
|
+
if (deps['svelte'])
|
|
47
|
+
return 'svelte';
|
|
48
|
+
if (deps['astro'])
|
|
49
|
+
return 'astro';
|
|
50
|
+
if (deps['vue'])
|
|
51
|
+
return 'vue3';
|
|
52
|
+
if (deps['@vitejs/plugin-react'])
|
|
53
|
+
return 'react-vite';
|
|
54
|
+
if (deps['react-scripts'])
|
|
55
|
+
return 'react-cra';
|
|
56
|
+
if (deps['express'])
|
|
57
|
+
return 'express';
|
|
58
|
+
return 'unknown';
|
|
59
|
+
}
|
|
60
|
+
function getSetupSnippet(framework, siteId, token) {
|
|
61
|
+
switch (framework) {
|
|
62
|
+
case 'nextjs-app':
|
|
63
|
+
return {
|
|
64
|
+
file: 'src/lib/gurulu.tsx',
|
|
65
|
+
code: `'use client';
|
|
66
|
+
import { useEffect } from 'react';
|
|
67
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
68
|
+
|
|
69
|
+
export function GuruluProvider() {
|
|
70
|
+
const pathname = usePathname();
|
|
71
|
+
const searchParams = useSearchParams();
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const script = document.createElement('script');
|
|
75
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
76
|
+
script.async = true;
|
|
77
|
+
script.dataset.siteId = '${siteId}';
|
|
78
|
+
script.dataset.token = '${token}';
|
|
79
|
+
document.head.appendChild(script);
|
|
80
|
+
return () => { document.head.removeChild(script); };
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (typeof window !== 'undefined' && (window as any).gurulu) {
|
|
85
|
+
(window as any).gurulu.track('pageview', {
|
|
86
|
+
page_url: pathname + (searchParams?.toString() ? '?' + searchParams.toString() : ''),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}, [pathname, searchParams]);
|
|
90
|
+
|
|
91
|
+
return null;
|
|
92
|
+
}`,
|
|
93
|
+
instruction: 'Add <GuruluProvider /> inside <body> in your root layout.tsx',
|
|
94
|
+
};
|
|
95
|
+
case 'nextjs-pages':
|
|
96
|
+
return {
|
|
97
|
+
file: 'src/lib/gurulu.tsx',
|
|
98
|
+
code: `import Script from 'next/script';
|
|
99
|
+
|
|
100
|
+
export function GuruluScript() {
|
|
101
|
+
return (
|
|
102
|
+
<Script
|
|
103
|
+
src="https://cdn.gurulu.io/t.js"
|
|
104
|
+
data-site-id="${siteId}"
|
|
105
|
+
data-token="${token}"
|
|
106
|
+
strategy="afterInteractive"
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}`,
|
|
110
|
+
instruction: 'Add <GuruluScript /> in your _app.tsx',
|
|
111
|
+
};
|
|
112
|
+
case 'react-vite':
|
|
113
|
+
case 'react-cra':
|
|
114
|
+
return {
|
|
115
|
+
file: 'src/gurulu.ts',
|
|
116
|
+
code: `// Gurulu.io Analytics
|
|
117
|
+
export function initGurulu() {
|
|
118
|
+
if (typeof document === 'undefined') return;
|
|
119
|
+
const script = document.createElement('script');
|
|
120
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
121
|
+
script.async = true;
|
|
122
|
+
script.dataset.siteId = '${siteId}';
|
|
123
|
+
script.dataset.token = '${token}';
|
|
124
|
+
document.head.appendChild(script);
|
|
125
|
+
}`,
|
|
126
|
+
instruction: 'Call initGurulu() in your main.tsx or index.tsx entry point',
|
|
127
|
+
};
|
|
128
|
+
case 'vue3':
|
|
129
|
+
return {
|
|
130
|
+
file: 'src/plugins/gurulu.ts',
|
|
131
|
+
code: `// Gurulu.io Analytics Plugin
|
|
132
|
+
import type { App } from 'vue';
|
|
133
|
+
|
|
134
|
+
export const guruluPlugin = {
|
|
135
|
+
install(app: App) {
|
|
136
|
+
if (typeof document === 'undefined') return;
|
|
137
|
+
const script = document.createElement('script');
|
|
138
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
139
|
+
script.async = true;
|
|
140
|
+
script.dataset.siteId = '${siteId}';
|
|
141
|
+
script.dataset.token = '${token}';
|
|
142
|
+
document.head.appendChild(script);
|
|
143
|
+
},
|
|
144
|
+
};`,
|
|
145
|
+
instruction: 'Add app.use(guruluPlugin) in your main.ts',
|
|
146
|
+
};
|
|
147
|
+
case 'nuxt3':
|
|
148
|
+
return {
|
|
149
|
+
file: 'plugins/gurulu.client.ts',
|
|
150
|
+
code: `// Gurulu.io Analytics Plugin
|
|
151
|
+
export default defineNuxtPlugin(() => {
|
|
152
|
+
if (typeof document === 'undefined') return;
|
|
153
|
+
const script = document.createElement('script');
|
|
154
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
155
|
+
script.async = true;
|
|
156
|
+
script.dataset.siteId = '${siteId}';
|
|
157
|
+
script.dataset.token = '${token}';
|
|
158
|
+
document.head.appendChild(script);
|
|
159
|
+
});`,
|
|
160
|
+
instruction: 'Plugin auto-registered via plugins/ directory',
|
|
161
|
+
};
|
|
162
|
+
case 'svelte':
|
|
163
|
+
return {
|
|
164
|
+
file: 'src/lib/gurulu.ts',
|
|
165
|
+
code: `// Gurulu.io Analytics
|
|
166
|
+
import { onMount } from 'svelte';
|
|
167
|
+
|
|
168
|
+
export function initGurulu() {
|
|
169
|
+
onMount(() => {
|
|
170
|
+
const script = document.createElement('script');
|
|
171
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
172
|
+
script.async = true;
|
|
173
|
+
script.dataset.siteId = '${siteId}';
|
|
174
|
+
script.dataset.token = '${token}';
|
|
175
|
+
document.head.appendChild(script);
|
|
176
|
+
});
|
|
177
|
+
}`,
|
|
178
|
+
instruction: 'Call initGurulu() in your root +layout.svelte or App.svelte',
|
|
179
|
+
};
|
|
180
|
+
case 'sveltekit':
|
|
181
|
+
return {
|
|
182
|
+
file: 'src/lib/gurulu.ts',
|
|
183
|
+
code: `// Gurulu.io Analytics
|
|
184
|
+
import { browser } from '$app/environment';
|
|
185
|
+
|
|
186
|
+
export function initGurulu() {
|
|
187
|
+
if (!browser) return;
|
|
188
|
+
const script = document.createElement('script');
|
|
189
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
190
|
+
script.async = true;
|
|
191
|
+
script.dataset.siteId = '${siteId}';
|
|
192
|
+
script.dataset.token = '${token}';
|
|
193
|
+
document.head.appendChild(script);
|
|
194
|
+
}`,
|
|
195
|
+
instruction: 'Call initGurulu() in your root +layout.svelte onMount',
|
|
196
|
+
};
|
|
197
|
+
case 'astro':
|
|
198
|
+
return {
|
|
199
|
+
file: 'src/components/Gurulu.astro',
|
|
200
|
+
code: `---
|
|
201
|
+
// Gurulu.io Analytics
|
|
202
|
+
---
|
|
203
|
+
<script src="https://cdn.gurulu.io/t.js" data-site-id="${siteId}" data-token="${token}" async></script>`,
|
|
204
|
+
instruction: 'Add <Gurulu /> in your Layout.astro <head>',
|
|
205
|
+
};
|
|
206
|
+
case 'express':
|
|
207
|
+
return {
|
|
208
|
+
file: 'src/gurulu.ts',
|
|
209
|
+
code: `// Gurulu.io Server Analytics
|
|
210
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
211
|
+
|
|
212
|
+
const SITE_ID = '${siteId}';
|
|
213
|
+
const TOKEN = '${token}';
|
|
214
|
+
|
|
215
|
+
export function guruluMiddleware(req: Request, res: Response, next: NextFunction) {
|
|
216
|
+
// Track server-side pageview
|
|
217
|
+
fetch('https://ingest.gurulu.io/api/events', {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + TOKEN },
|
|
220
|
+
body: JSON.stringify({
|
|
221
|
+
site_id: SITE_ID,
|
|
222
|
+
event: 'pageview',
|
|
223
|
+
url: req.originalUrl,
|
|
224
|
+
referrer: req.headers.referer || '',
|
|
225
|
+
user_agent: req.headers['user-agent'] || '',
|
|
226
|
+
ip: req.ip,
|
|
227
|
+
timestamp: new Date().toISOString(),
|
|
228
|
+
}),
|
|
229
|
+
}).catch(() => {});
|
|
230
|
+
next();
|
|
231
|
+
}`,
|
|
232
|
+
instruction: 'Add app.use(guruluMiddleware) in your Express app',
|
|
233
|
+
};
|
|
234
|
+
case 'nestjs':
|
|
235
|
+
return {
|
|
236
|
+
file: 'src/gurulu.middleware.ts',
|
|
237
|
+
code: `// Gurulu.io Server Analytics Middleware
|
|
238
|
+
import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
239
|
+
import { Request, Response, NextFunction } from 'express';
|
|
240
|
+
|
|
241
|
+
const SITE_ID = '${siteId}';
|
|
242
|
+
const TOKEN = '${token}';
|
|
243
|
+
|
|
244
|
+
@Injectable()
|
|
245
|
+
export class GuruluMiddleware implements NestMiddleware {
|
|
246
|
+
use(req: Request, res: Response, next: NextFunction) {
|
|
247
|
+
fetch('https://ingest.gurulu.io/api/events', {
|
|
248
|
+
method: 'POST',
|
|
249
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + TOKEN },
|
|
250
|
+
body: JSON.stringify({
|
|
251
|
+
site_id: SITE_ID,
|
|
252
|
+
event: 'pageview',
|
|
253
|
+
url: req.originalUrl,
|
|
254
|
+
referrer: req.headers.referer || '',
|
|
255
|
+
user_agent: req.headers['user-agent'] || '',
|
|
256
|
+
ip: req.ip,
|
|
257
|
+
timestamp: new Date().toISOString(),
|
|
258
|
+
}),
|
|
259
|
+
}).catch(() => {});
|
|
260
|
+
next();
|
|
261
|
+
}
|
|
262
|
+
}`,
|
|
263
|
+
instruction: 'Apply GuruluMiddleware in your AppModule configure()',
|
|
264
|
+
};
|
|
265
|
+
case 'react-native':
|
|
266
|
+
return {
|
|
267
|
+
file: '',
|
|
268
|
+
code: `// npm install @gurulu/react-native
|
|
269
|
+
import Gurulu from '@gurulu/react-native';
|
|
270
|
+
|
|
271
|
+
Gurulu.initialize({
|
|
272
|
+
siteId: '${siteId}',
|
|
273
|
+
token: '${token}',
|
|
274
|
+
endpoint: 'https://ingest.gurulu.io/api/ingest/v1/collect',
|
|
275
|
+
});`,
|
|
276
|
+
instruction: 'Run "npm install @gurulu/react-native" and add initialization to your App entry point',
|
|
277
|
+
};
|
|
278
|
+
case 'ios-swift':
|
|
279
|
+
return {
|
|
280
|
+
file: '',
|
|
281
|
+
code: `// Package.swift: add .package(url: "https://github.com/Preatan/gurulu-ios-sdk", from: "0.1.0")
|
|
282
|
+
// AppDelegate.swift or @main App:
|
|
283
|
+
import GuruluSDK
|
|
284
|
+
|
|
285
|
+
GuruluSDK.shared.initialize(config: GuruluConfig(
|
|
286
|
+
siteId: "${siteId}",
|
|
287
|
+
token: "${token}",
|
|
288
|
+
endpoint: URL(string: "https://ingest.gurulu.io/api/ingest/v1/collect")!
|
|
289
|
+
))`,
|
|
290
|
+
instruction: 'Add the SPM dependency and initialize in your AppDelegate or @main App struct',
|
|
291
|
+
};
|
|
292
|
+
case 'android-kotlin':
|
|
293
|
+
return {
|
|
294
|
+
file: '',
|
|
295
|
+
code: `// build.gradle.kts: implementation("com.github.Preatan:gurulu.io:android-sdk-0.1.0")
|
|
296
|
+
// repositories: maven { url = uri("https://jitpack.io") }
|
|
297
|
+
// Application.onCreate():
|
|
298
|
+
import io.gurulu.sdk.GuruluSdk
|
|
299
|
+
import io.gurulu.sdk.GuruluConfig
|
|
300
|
+
|
|
301
|
+
GuruluSdk.initialize(GuruluConfig(
|
|
302
|
+
siteId = "${siteId}",
|
|
303
|
+
token = "${token}",
|
|
304
|
+
endpoint = "https://ingest.gurulu.io/api/ingest/v1/collect"
|
|
305
|
+
))`,
|
|
306
|
+
instruction: 'Add JitPack repository and dependency, then initialize in your Application.onCreate()',
|
|
307
|
+
};
|
|
308
|
+
case 'flutter':
|
|
309
|
+
return {
|
|
310
|
+
file: '',
|
|
311
|
+
code: `// pubspec.yaml: gurulu_flutter: ^0.1.0
|
|
312
|
+
import 'package:gurulu_flutter/gurulu_flutter.dart';
|
|
313
|
+
|
|
314
|
+
await GuruluFlutter.initialize(config: {
|
|
315
|
+
'siteId': '${siteId}',
|
|
316
|
+
'token': '${token}',
|
|
317
|
+
'endpoint': 'https://ingest.gurulu.io/api/ingest/v1/collect',
|
|
318
|
+
});`,
|
|
319
|
+
instruction: 'Add gurulu_flutter to pubspec.yaml and initialize in your main() function',
|
|
320
|
+
};
|
|
321
|
+
case 'html':
|
|
322
|
+
return {
|
|
323
|
+
file: '',
|
|
324
|
+
code: `<script src="https://cdn.gurulu.io/t.js" data-site-id="${siteId}" data-token="${token}" async></script>`,
|
|
325
|
+
instruction: 'Add this script tag before </head> in your HTML',
|
|
326
|
+
};
|
|
327
|
+
default:
|
|
328
|
+
return {
|
|
329
|
+
file: 'src/gurulu.ts',
|
|
330
|
+
code: `// Gurulu.io Analytics
|
|
331
|
+
const script = document.createElement('script');
|
|
332
|
+
script.src = 'https://cdn.gurulu.io/t.js';
|
|
333
|
+
script.async = true;
|
|
334
|
+
script.dataset.siteId = '${siteId}';
|
|
335
|
+
script.dataset.token = '${token}';
|
|
336
|
+
document.head.appendChild(script);`,
|
|
337
|
+
instruction: 'Import this file in your app entry point',
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function getFrameworkDisplayName(fw) {
|
|
342
|
+
const names = {
|
|
343
|
+
'nextjs-app': 'Next.js (App Router)',
|
|
344
|
+
'nextjs-pages': 'Next.js (Pages Router)',
|
|
345
|
+
'react-vite': 'React (Vite)',
|
|
346
|
+
'react-cra': 'React (CRA)',
|
|
347
|
+
'vue3': 'Vue 3',
|
|
348
|
+
'nuxt3': 'Nuxt 3',
|
|
349
|
+
'svelte': 'Svelte',
|
|
350
|
+
'sveltekit': 'SvelteKit',
|
|
351
|
+
'astro': 'Astro',
|
|
352
|
+
'express': 'Express',
|
|
353
|
+
'nestjs': 'NestJS',
|
|
354
|
+
'html': 'HTML',
|
|
355
|
+
'react-native': 'React Native',
|
|
356
|
+
'ios-swift': 'iOS (Swift)',
|
|
357
|
+
'android-kotlin': 'Android (Kotlin)',
|
|
358
|
+
'flutter': 'Flutter',
|
|
359
|
+
'unknown': 'Unknown',
|
|
360
|
+
};
|
|
361
|
+
return names[fw];
|
|
362
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|