This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
143 lines (124 loc) · 4.21 KB
/
deploy.js
File metadata and controls
143 lines (124 loc) · 4.21 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env node
// Deploy Eagles demo site to Run402
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { join, relative } from 'path';
import { execSync } from 'child_process';
import { readdirSync } from 'fs';
const ROOT = new URL('.', import.meta.url).pathname;
function readText(path) {
return readFileSync(join(ROOT, path), 'utf-8');
}
function collectFiles(dir, base = dir) {
const files = [];
if (!existsSync(join(ROOT, dir))) return files;
for (const entry of readdirSync(join(ROOT, dir), { withFileTypes: true })) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...collectFiles(full, base));
} else {
// Use "path" reference — CLI auto-detects and base64-encodes binary files
files.push({ file: relative(base, full), path: './' + full });
}
}
return files;
}
function collectFunctions(dir) {
if (!existsSync(join(ROOT, dir))) return [];
return readdirSync(join(ROOT, dir))
.filter(f => f.endsWith('.js'))
.map(f => {
const name = f.replace('.js', '');
const code = readText(join(dir, f));
const scheduleMatch = code.match(/\/\/\s*schedule:\s*"([^"]+)"/);
const fn = { name, code };
if (scheduleMatch) fn.schedule = scheduleMatch[1];
return fn;
});
}
// Project ID — override with EAGLES_PROJECT_ID env var
const projectId = process.env.EAGLES_PROJECT_ID || 'prj_1774878751490_0301';
const subdomain = process.env.SUBDOMAIN || 'eagles';
console.log(`\n=== Eagles Demo Deploy ===`);
console.log(`Project: ${projectId}`);
console.log(`Subdomain: ${subdomain}\n`);
// Resolve anon_key
let anonKey = process.env.ANON_KEY || '';
if (!anonKey) {
try {
const keysOut = execSync(`run402 projects keys ${projectId}`, { encoding: 'utf-8' });
const keys = JSON.parse(keysOut);
anonKey = keys.anon_key || '';
} catch {}
}
if (!anonKey) {
console.error('Could not resolve anon_key. Set ANON_KEY env var or ensure project has keys.');
process.exit(1);
}
// Generate env.js
const envJsPath = join(ROOT, 'site', 'js', 'env.js');
writeFileSync(envJsPath, `// env.js — Runtime config (auto-generated by deploy.js)\nwindow.__WILDLYCHEE_API = 'https://api.run402.com';\nwindow.__WILDLYCHEE_ANON_KEY = '${anonKey}';\n`);
// Read schema + seed as combined migrations
const schema = readText('schema.sql');
const seed = readText('seed.sql');
const migrations = schema + '\n\n' + seed;
const migrationsPath = join(ROOT, '.migrations.sql');
writeFileSync(migrationsPath, migrations);
// Collect site files
const siteFiles = collectFiles('site', 'site');
// Collect functions
const functions = collectFunctions('functions');
// RLS configuration
const rls = {
template: 'public_read',
tables: [
{ table: 'site_config' },
{ table: 'pages' },
{ table: 'sections' },
{ table: 'membership_tiers' },
{ table: 'member_custom_fields' },
{ table: 'announcements' },
{ table: 'activity_log' },
{ table: 'members' },
{ table: 'events' },
{ table: 'event_rsvps' },
{ table: 'resources' },
{ table: 'forum_categories' },
{ table: 'forum_topics' },
{ table: 'forum_replies' },
{ table: 'committees' },
{ table: 'committee_members' },
{ table: 'content_translations' },
{ table: 'moderation_log' },
{ table: 'member_insights' },
{ table: 'newsletter_drafts' },
],
};
// Assemble manifest
const manifest = {
project_id: projectId,
migrations_file: '.migrations.sql',
rls,
files: siteFiles,
subdomain,
};
if (functions.length > 0) {
manifest.functions = functions;
}
const manifestPath = join(ROOT, 'app.json');
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
console.log(` ${siteFiles.length} site files`);
console.log(` ${functions.length} functions`);
console.log(` Migrations: schema.sql + seed.sql\n`);
try {
const result = execSync(`run402 deploy --manifest "${manifestPath}"`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
});
const parsed = JSON.parse(result);
console.log('Deploy successful!');
console.log(`Live at: https://${subdomain}.run402.com`);
console.log(JSON.stringify(parsed, null, 2));
} catch (err) {
console.error('Deploy failed:', err.stderr || err.message);
process.exit(1);
}