shared-hosting-sync 0.0.0-stage → 0.1.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.
- package/.env.example +23 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/PHASES.md +147 -0
- package/PRODUCT.md +90 -0
- package/README.md +398 -2
- package/RELEASING.md +79 -0
- package/package.json +68 -4
- package/src/arguments.js +30 -0
- package/src/bin.js +8 -0
- package/src/checksum.js +18 -0
- package/src/cli.js +511 -0
- package/src/config.js +98 -0
- package/src/core/db.js +61 -0
- package/src/core/deployment.js +22 -0
- package/src/core/envResolver.js +98 -0
- package/src/core/envSchema.js +160 -0
- package/src/core/migrate.js +75 -0
- package/src/core/migrations/001_init.sql +67 -0
- package/src/core/migrations/002_operation_locks.sql +9 -0
- package/src/core/operationLock.js +54 -0
- package/src/core/projects.js +261 -0
- package/src/core/secrets.js +75 -0
- package/src/core/v1Migrate.js +82 -0
- package/src/ignore.js +148 -0
- package/src/metadata.js +3 -0
- package/src/onboarding.js +117 -0
- package/src/paths.js +23 -0
- package/src/prompt.js +54 -0
- package/src/server/browse.js +46 -0
- package/src/server/deployments.js +209 -0
- package/src/server/index.js +79 -0
- package/src/server/local.js +23 -0
- package/src/server/onboarding.js +203 -0
- package/src/server/routes.js +307 -0
- package/src/server/session.js +58 -0
- package/src/transport/ftp.js +100 -0
- package/src/transport/index.js +12 -0
- package/src/transport/reliable.js +50 -0
- package/src/transport/sftp.js +99 -0
- package/src/ui/deployments.js +129 -0
- package/src/ui/index.html +17 -0
- package/src/ui/style.css +129 -0
- package/src/ui/ui.js +289 -0
- package/src/uploader.js +160 -0
- package/src/watcher.js +122 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
|
2
|
+
const bytes = (value = 0) => value < 1024 ? `${value} B` : value < 1024 * 1024 ? `${(value / 1024).toFixed(1)} KB` : `${(value / 1024 / 1024).toFixed(2)} MB`
|
|
3
|
+
|
|
4
|
+
export class DeploymentPanel {
|
|
5
|
+
constructor({ api, run, isBusy, message }) {
|
|
6
|
+
this.api = api
|
|
7
|
+
this.run = run
|
|
8
|
+
this.isBusy = isBusy
|
|
9
|
+
this.message = message
|
|
10
|
+
this.generation = 0
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
close() {
|
|
14
|
+
clearTimeout(this.timer)
|
|
15
|
+
this.generation++
|
|
16
|
+
this.projectId = null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async open(projectId, configuration) {
|
|
20
|
+
this.close()
|
|
21
|
+
this.projectId = projectId
|
|
22
|
+
this.lastPlan = null
|
|
23
|
+
this.lastLogs = null
|
|
24
|
+
this.settingsDryRun = ['true', '1', true].includes(configuration.values.DEVSYNC_DRY_RUN)
|
|
25
|
+
this.configured = !Object.keys(configuration.errors).length
|
|
26
|
+
const element = document.querySelector('#deploymentPanel')
|
|
27
|
+
element.innerHTML = `<h2>Deploy your project</h2><p class="muted">Deploy uploads all eligible files. Sync uploads only changed files. Server files are never deleted.</p><div class="operation-options"><div class="field"><label for="previewMode">Preview mode</label><select id="previewMode"><option value="sync">Changed files (sync)</option><option value="deploy">All eligible files (deploy)</option></select></div><label class="check"><input id="operationDryRun" type="checkbox" ${this.settingsDryRun ? 'checked disabled' : ''}>Preview only for deploy, sync and watch</label></div>${this.settingsDryRun ? '<p class="help">Preview-only mode is enabled in this project’s settings.</p>' : ''}<div class="operation-actions"><button class="secondary" id="previewUploads">Preview uploads</button><button class="primary" id="deployFiles">Deploy all files</button><button class="secondary" id="syncFiles">Sync changes</button><button class="secondary" id="startWatching">Start watching</button><button class="danger" id="stopWatching" hidden>Stop watching</button></div><p class="help">Watch syncs current files first, then follows saves while devsync is running. Stop waits for the current batch to finish.</p><div id="operationStatus" class="notice" role="status"></div><div class="operation-progress"><progress id="uploadProgress" max="1" value="0" aria-label="Operation progress"></progress><span id="progressText" class="help"></span></div><div id="operationResult"></div><div id="operationPlan"></div><details id="activityDetails"><summary>Activity log</summary><ol class="operation-log" id="operationLogs"><li>No operations yet.</li></ol></details><p id="lastSync" class="help"></p>`
|
|
28
|
+
document.querySelector('#previewUploads').onclick = () => this.start('preview')
|
|
29
|
+
document.querySelector('#deployFiles').onclick = () => this.start('deploy')
|
|
30
|
+
document.querySelector('#syncFiles').onclick = () => this.start('sync')
|
|
31
|
+
document.querySelector('#startWatching').onclick = () => this.start('watch')
|
|
32
|
+
document.querySelector('#stopWatching').onclick = () => this.run(async () => {
|
|
33
|
+
this.message('')
|
|
34
|
+
this.render(await this.api('POST', `/api/projects/${this.projectId}/watch/stop`, {}))
|
|
35
|
+
this.schedule(250)
|
|
36
|
+
})
|
|
37
|
+
await this.poll(this.generation)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
start(kind) {
|
|
41
|
+
this.run(async () => {
|
|
42
|
+
this.message('')
|
|
43
|
+
const options = {
|
|
44
|
+
dryRun: document.querySelector('#operationDryRun').checked,
|
|
45
|
+
...(kind === 'preview' ? { mode: document.querySelector('#previewMode').value } : {})
|
|
46
|
+
}
|
|
47
|
+
const result = await this.api('POST', `/api/projects/${this.projectId}/${kind}`, options)
|
|
48
|
+
document.querySelector('#activityDetails').open = true
|
|
49
|
+
this.render(result)
|
|
50
|
+
this.schedule(250)
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
schedule(delay) {
|
|
55
|
+
clearTimeout(this.timer)
|
|
56
|
+
const generation = this.generation
|
|
57
|
+
this.timer = setTimeout(() => this.poll(generation), delay)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async poll(generation) {
|
|
61
|
+
if (!this.projectId || generation !== this.generation) return
|
|
62
|
+
try {
|
|
63
|
+
const result = await this.api('GET', `/api/projects/${this.projectId}/activity`)
|
|
64
|
+
if (generation !== this.generation || !document.querySelector('#deploymentPanel')) return
|
|
65
|
+
this.render(result)
|
|
66
|
+
this.schedule(result.active ? 700 : 2500)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (generation !== this.generation) return
|
|
69
|
+
const status = document.querySelector('#operationStatus')
|
|
70
|
+
if (status) { status.textContent = `Could not refresh activity: ${error.message}`; status.className = 'notice error' }
|
|
71
|
+
this.schedule(2500)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
disable(id, disabled) {
|
|
76
|
+
const element = document.querySelector(`#${id}`)
|
|
77
|
+
if (!element) return
|
|
78
|
+
if (this.isBusy()) { element.dataset.beforeBusy = String(disabled); element.disabled = true }
|
|
79
|
+
else element.disabled = disabled
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
render(activity) {
|
|
83
|
+
if (!this.projectId || activity.projectId !== this.projectId) return
|
|
84
|
+
const busy = activity.active || !!activity.externalOperation
|
|
85
|
+
for (const id of ['previewUploads', 'deployFiles', 'syncFiles', 'startWatching', 'previewMode']) this.disable(id, busy || !this.configured)
|
|
86
|
+
this.disable('operationDryRun', busy || this.settingsDryRun || !this.configured)
|
|
87
|
+
for (const id of ['editProject', 'testProject', 'deleteProject']) this.disable(id, busy)
|
|
88
|
+
const startingWatch = activity.kind === 'watch' && busy
|
|
89
|
+
document.querySelector('#startWatching').hidden = startingWatch
|
|
90
|
+
document.querySelector('#stopWatching').hidden = !startingWatch
|
|
91
|
+
this.disable('stopWatching', !startingWatch || activity.stopping)
|
|
92
|
+
const status = document.querySelector('#operationStatus')
|
|
93
|
+
const phases = { connecting: 'Connecting to hosting…', planning: 'Comparing local and server files…', uploading: activity.dryRun ? 'Building the preview…' : 'Uploading files…', watching: 'Watching for local saves.', stopping: 'Stopping watching — finishing the current batch…', complete: 'Operation complete.', error: 'Operation needs attention.', idle: 'Preview uploads before deploying, or start a sync when you are ready.' }
|
|
94
|
+
let text = activity.stopping ? phases.stopping : phases[activity.phase] || phases.idle
|
|
95
|
+
if (activity.state === 'success') text = activity.dryRun ? 'Preview complete. No files were uploaded.' : 'Upload complete.'
|
|
96
|
+
if (activity.state === 'stopped') text = 'Watching stopped. No further saves will be uploaded.'
|
|
97
|
+
if (activity.externalOperation) text = 'An operation is running in another CLI or dashboard. Stop it there or wait for it to finish.'
|
|
98
|
+
if (activity.lastError) text = `${activity.watching && !activity.stopping ? 'Watching is still active; the last sync failed. ' : ''}${activity.lastError} Check the connection and server folder permissions, then retry.`
|
|
99
|
+
if (!this.configured && !busy) text = 'Complete project setup before previewing or uploading.'
|
|
100
|
+
if (status.textContent !== text) status.textContent = text
|
|
101
|
+
status.className = `notice ${activity.lastError ? 'error' : activity.state === 'success' || activity.state === 'watching' || activity.state === 'stopped' ? 'success' : 'info'}`
|
|
102
|
+
const progress = activity.progress
|
|
103
|
+
const meter = document.querySelector('#uploadProgress')
|
|
104
|
+
meter.max = Math.max(1, progress?.total || 0)
|
|
105
|
+
meter.value = progress?.current || 0
|
|
106
|
+
document.querySelector('#progressText').textContent = progress ? `${progress.current} / ${progress.total} files${progress.file ? ' · ' + progress.file : ''}${progress.bytes ? ' · ' + bytes(progress.bytes) : ''}` : ''
|
|
107
|
+
const result = activity.result
|
|
108
|
+
document.querySelector('#operationResult').innerHTML = result ? `<div class="operation-metrics"><div><strong>${result.dryRun ? result.planned : result.uploaded}</strong><span>${result.dryRun ? 'would upload' : 'uploaded'}</span></div><div><strong>${result.failedCount ?? result.failed.length}</strong><span>failed</span></div><div><strong>${bytes(result.bytes)}</strong><span>uploaded</span></div></div>${result.failed.length ? `<details open><summary>Files needing attention</summary><ul class="errors">${result.failed.map((file) => `<li>${esc(file.rel)} — ${esc(file.error)}</li>`).join('')}</ul></details>` : ''}` : ''
|
|
109
|
+
this.renderPlan(activity.plan)
|
|
110
|
+
const logSignature = JSON.stringify(activity.logs)
|
|
111
|
+
if (logSignature !== this.lastLogs) {
|
|
112
|
+
const log = document.querySelector('#operationLogs')
|
|
113
|
+
const atBottom = log.scrollHeight - log.scrollTop - log.clientHeight < 30
|
|
114
|
+
log.innerHTML = activity.logs.length ? activity.logs.map((entry) => `<li class="log-${esc(entry.level)}"><time>${esc(new Date(entry.at).toLocaleTimeString())}</time> ${esc(entry.message)}</li>`).join('') : '<li>No operations yet.</li>'
|
|
115
|
+
if (atBottom) log.scrollTop = log.scrollHeight
|
|
116
|
+
this.lastLogs = logSignature
|
|
117
|
+
}
|
|
118
|
+
document.querySelector('#lastSync').textContent = activity.lastSyncAt ? `Last successful sync: ${new Date(activity.lastSyncAt).toLocaleString()} · ${bytes(activity.lastUploadBytes)}` : 'No successful sync recorded yet.'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
renderPlan(plan) {
|
|
122
|
+
const signature = JSON.stringify(plan)
|
|
123
|
+
if (signature === this.lastPlan) return
|
|
124
|
+
this.lastPlan = signature
|
|
125
|
+
const element = document.querySelector('#operationPlan')
|
|
126
|
+
if (!plan) { element.innerHTML = ''; return }
|
|
127
|
+
element.innerHTML = `<div class="operation-metrics"><div><strong>${plan.considered}</strong><span>eligible files</span></div><div><strong>${plan.uploadCount}</strong><span>selected to upload</span></div><div><strong>${plan.skippedCount}</strong><span>unchanged</span></div><div><strong>${bytes(plan.bytes)}</strong><span>selected size</span></div></div><details open><summary>Selected files (${plan.uploadCount})</summary>${plan.uploads.length ? `<div class="plan-table-wrap"><table class="plan-table"><thead><tr><th>File</th><th>Server destination</th><th>Size</th></tr></thead><tbody>${plan.uploads.map((file) => `<tr><td>${esc(file.rel)}</td><td>${esc(file.remote)}</td><td>${bytes(file.bytes)}</td></tr>`).join('')}</tbody></table></div>` : '<p class="help">No files need uploading.</p>'}${plan.uploadCount > plan.uploads.length ? '<p class="help">Showing the first 200 selected files.</p>' : ''}</details><details><summary>Unchanged files (${plan.skippedCount})</summary><ul class="file-list">${plan.skipped.map((file) => `<li>${esc(file.rel)} <span class="muted">· ${esc(file.reason)}</span></li>`).join('') || '<li>No unchanged files.</li>'}</ul>${plan.skippedCount > plan.skipped.length ? '<p class="help">Showing the first 200 unchanged files.</p>' : ''}</details><details><summary>Excluded entries (${plan.excludedCount})</summary><ul class="file-list">${plan.excluded.map((file) => `<li>${esc(file.rel)} <span class="muted">· ${esc(file.reason)}</span></li>`).join('') || '<li>No excluded entries.</li>'}</ul><p class="help">Excluded directories represent their entire contents.${plan.excludedCount > plan.excluded.length ? ' Showing the first 200 entries.' : ''}</p></details><p class="help">Each operation checks current files and settings again. A preview never uploads or deletes files.</p>`
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>shared-hosting-sync · Projects</title>
|
|
7
|
+
<link rel="stylesheet" href="/style.css">
|
|
8
|
+
<script type="module" src="/ui.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<header class="topbar"><a class="brand" href="/">shared-hosting-sync<span class="brand-dot"></span></a><span class="topbar-note">Your projects. Your hosting.</span><span class="connection-pill" id="serverStatus">Connecting…</span></header>
|
|
12
|
+
<div class="layout">
|
|
13
|
+
<aside class="sidebar"><div class="sidebar-heading">PROJECTS <span id="projectCount">0</span></div><div id="projectList"></div><button class="add-project" id="addProject">+ Add project</button><div class="sidebar-note">Runs on this computer.<br>Hosting credentials stay local.</div></aside>
|
|
14
|
+
<main id="pane" class="pane" aria-live="polite"><div class="empty">Loading your projects…</div></main>
|
|
15
|
+
</div>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
package/src/ui/style.css
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
:root{color-scheme:dark;--bg:#0e1117;--panel:#151a23;--line:#283141;--text:#e7edf6;--muted:#9aa9bd;--accent:#77d6c1;--blue:#a4c7ff;--danger:#ffb8b8}
|
|
2
|
+
|
|
3
|
+
*{box-sizing:border-box}
|
|
4
|
+
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.55 ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}
|
|
5
|
+
button,input,select{font:inherit}
|
|
6
|
+
button{cursor:pointer}
|
|
7
|
+
button:disabled{opacity:.5;cursor:default}
|
|
8
|
+
button:focus-visible,a:focus-visible,summary:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
|
|
9
|
+
a{color:var(--blue)}
|
|
10
|
+
.topbar{height:70px;display:flex;align-items:center;gap:28px;padding:0 28px;border-bottom:1px solid var(--line)}
|
|
11
|
+
.brand{font-size:24px;font-weight:750;letter-spacing:-1px;text-decoration:none;color:var(--text);display:flex;align-items:center;gap:7px}
|
|
12
|
+
.brand-dot{width:7px;height:7px;border-radius:50%;background:var(--accent)}
|
|
13
|
+
.topbar-note{color:var(--muted);font-size:13px}
|
|
14
|
+
.connection-pill{margin-left:auto;border:1px solid #33554e;border-radius:30px;padding:4px 12px;color:var(--accent);font-size:12px}
|
|
15
|
+
.layout{display:grid;grid-template-columns:240px minmax(0,1fr);min-height:calc(100vh - 70px)}
|
|
16
|
+
.sidebar{padding:28px 16px;border-right:1px solid var(--line)}
|
|
17
|
+
.sidebar-heading{font-size:11px;letter-spacing:1.5px;color:var(--muted);display:flex;justify-content:space-between;padding:0 10px 16px}
|
|
18
|
+
.project{display:block;width:100%;border:0;background:transparent;text-align:left;color:var(--text);padding:12px;border-radius:8px;margin-bottom:5px}
|
|
19
|
+
.project:hover,.project.active{background:#202a38}
|
|
20
|
+
.project strong{display:block}
|
|
21
|
+
.project small{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--muted);margin-top:3px}
|
|
22
|
+
.add-project{width:100%;padding:11px;background:transparent;border:1px dashed #526274;border-radius:8px;color:var(--accent);margin-top:14px}
|
|
23
|
+
.sidebar-note{font-size:12px;color:var(--muted);padding:28px 10px}
|
|
24
|
+
.pane{padding:38px clamp(22px,4vw,64px);max-width:1250px;width:100%}
|
|
25
|
+
.eyebrow{font-size:11px;color:var(--accent);letter-spacing:1.7px;font-weight:650;margin:0 0 8px}
|
|
26
|
+
h1{font-size:30px;line-height:1.2;letter-spacing:-.7px;margin:0 0 12px}
|
|
27
|
+
h2{font-size:20px;margin:0 0 10px}
|
|
28
|
+
h3{font-size:14px;margin:0 0 12px}
|
|
29
|
+
p{margin:0 0 16px}
|
|
30
|
+
.muted,.sub{color:var(--muted)}
|
|
31
|
+
.sub{max-width:620px}
|
|
32
|
+
.welcome{padding-top:45px}
|
|
33
|
+
.welcome .primary{margin:18px 0 30px}
|
|
34
|
+
.cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}
|
|
35
|
+
.card,.setup-card,.summary-card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:25px}
|
|
36
|
+
.card .number{color:var(--accent);font-size:12px;margin-bottom:14px}
|
|
37
|
+
.card p{color:var(--muted);font-size:13px;margin:0}
|
|
38
|
+
.steps{display:flex;list-style:none;padding:0;margin:28px 0;gap:12px}
|
|
39
|
+
.steps li{flex:1;border-top:2px solid var(--line);padding-top:12px;color:var(--muted);font-size:12px}
|
|
40
|
+
.steps li.active{border-color:var(--accent);color:var(--accent)}
|
|
41
|
+
.steps li.done{border-color:#397367}
|
|
42
|
+
.step-number{margin-right:7px}
|
|
43
|
+
.setup-card{max-width:850px}
|
|
44
|
+
.setup-card>p{color:var(--muted)}
|
|
45
|
+
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px;margin:22px 0}
|
|
46
|
+
.field{display:flex;flex-direction:column;gap:7px;min-width:0}
|
|
47
|
+
.field.wide{grid-column:1/-1}
|
|
48
|
+
.field label{font-size:13px;font-weight:600}
|
|
49
|
+
.field input,.field select,.path-row input{background:#0e131c;border:1px solid #3a4658;border-radius:7px;color:var(--text);padding:10px 12px;min-width:0;width:100%}
|
|
50
|
+
.field input:focus,.field select:focus,.path-row input:focus{outline:2px solid #517f75;border-color:var(--accent)}
|
|
51
|
+
.field input:read-only{color:var(--muted)}
|
|
52
|
+
.help{color:var(--muted);font-size:12px}
|
|
53
|
+
.source{display:inline-block;font-size:10px;font-weight:500;margin-left:7px;color:var(--accent);background:#203e38;padding:1px 7px;border-radius:4px}
|
|
54
|
+
.path-row{display:flex;gap:10px;align-items:center}
|
|
55
|
+
.path-row input{flex:1}
|
|
56
|
+
.actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:24px;padding-top:20px;border-top:1px solid var(--line)}
|
|
57
|
+
.spacer{flex:1}
|
|
58
|
+
.primary,.secondary,.danger{padding:10px 17px;border-radius:7px;font-weight:600;white-space:nowrap}
|
|
59
|
+
.primary{background:var(--accent);color:#0b2922;border:1px solid var(--accent)}
|
|
60
|
+
.primary:hover:not(:disabled){background:#9ee7d7}
|
|
61
|
+
.secondary{background:transparent;color:var(--text);border:1px solid #445166}
|
|
62
|
+
.secondary:hover:not(:disabled){background:#222e3e}
|
|
63
|
+
.danger{background:transparent;color:var(--danger);border:1px solid #754848}
|
|
64
|
+
.notice{border:1px solid #3d5e79;background:#172a3d;border-radius:8px;padding:12px 15px;margin:18px 0;color:#cee4ff}
|
|
65
|
+
.notice:empty{display:none}
|
|
66
|
+
.notice.error{background:#361f29;border-color:#80515f;color:#ffd3dc}
|
|
67
|
+
.notice.success{background:#183b33;border-color:#3a7866;color:#b4f0d8}
|
|
68
|
+
.notice.warning{background:#3b3020;border-color:#8a7047;color:#ffe1a6}
|
|
69
|
+
.picker{margin-top:18px;border:1px solid #3a4658;border-radius:9px;padding:16px;background:#10161f}
|
|
70
|
+
.picker-toolbar{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0}
|
|
71
|
+
.picker-toolbar .secondary{padding:6px 12px;font-size:12px}
|
|
72
|
+
.folder-list{max-height:290px;overflow:auto;display:grid;gap:4px;margin:14px 0}
|
|
73
|
+
.folder{display:block;text-align:left;color:var(--text);padding:10px 12px;border:0;border-radius:5px;background:transparent;word-break:break-word}
|
|
74
|
+
.folder:hover{background:#263448}
|
|
75
|
+
.folder::before{content:'▱';color:var(--accent);margin-right:12px}
|
|
76
|
+
.empty{padding:36px 12px;text-align:center;color:var(--muted)}
|
|
77
|
+
.path-display{font:12px/1.6 ui-monospace,monospace;color:var(--blue);word-break:break-all;margin-top:10px}
|
|
78
|
+
.selection{border-left:3px solid var(--accent);padding:12px 16px;background:#192b2a;margin:18px 0}
|
|
79
|
+
.selection small{display:block;color:var(--muted)}
|
|
80
|
+
.review{display:grid;grid-template-columns:150px minmax(0,1fr);gap:14px;margin:24px 0}
|
|
81
|
+
.review dt{color:var(--muted)}
|
|
82
|
+
.review dd{margin:0;word-break:break-word}
|
|
83
|
+
details{border-top:1px solid var(--line);padding-top:15px;margin:18px 0}
|
|
84
|
+
summary{cursor:pointer;color:var(--blue)}
|
|
85
|
+
.check{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--muted);margin-top:4px}
|
|
86
|
+
.check input{width:auto}
|
|
87
|
+
.snapshot-note{font-size:12px;color:var(--muted);margin-top:20px}
|
|
88
|
+
.summary-head{display:flex;gap:20px;align-items:flex-start;justify-content:space-between}
|
|
89
|
+
.summary-card{margin-top:25px}
|
|
90
|
+
.small{font-size:12px}
|
|
91
|
+
.ready{color:var(--accent);font-size:13px}
|
|
92
|
+
.errors{margin:0;padding-left:20px}
|
|
93
|
+
.visually-hidden{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}
|
|
94
|
+
|
|
95
|
+
@media(max-width:850px){.layout{grid-template-columns:190px minmax(0,1fr)}
|
|
96
|
+
.cards{grid-template-columns:1fr}
|
|
97
|
+
.topbar-note{display:none}
|
|
98
|
+
.form-grid{grid-template-columns:1fr}
|
|
99
|
+
.field.wide{grid-column:auto}
|
|
100
|
+
.pane{padding:28px 22px}
|
|
101
|
+
.steps{gap:7px}
|
|
102
|
+
.steps li{font-size:11px}
|
|
103
|
+
.review{grid-template-columns:110px 1fr}
|
|
104
|
+
.setup-card{padding:20px}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@media(max-width:580px){.layout{display:block}
|
|
108
|
+
.sidebar{border-right:0;border-bottom:1px solid var(--line);padding:12px 16px}
|
|
109
|
+
.sidebar-heading,.sidebar-note{display:none}
|
|
110
|
+
#projectList{display:flex;overflow:auto}
|
|
111
|
+
.project{min-width:150px;margin-right:8px}
|
|
112
|
+
.add-project{margin-top:6px}
|
|
113
|
+
.topbar{padding:0 18px;height:62px}
|
|
114
|
+
.pane{padding:24px 16px}
|
|
115
|
+
.path-row{flex-wrap:wrap}
|
|
116
|
+
.path-row input{flex-basis:100%}
|
|
117
|
+
h1{font-size:25px}
|
|
118
|
+
.summary-head{display:block}
|
|
119
|
+
.steps .step-number{display:block}
|
|
120
|
+
.review{grid-template-columns:1fr;gap:5px}
|
|
121
|
+
.review dd{margin-bottom:10px}
|
|
122
|
+
}
|
|
123
|
+
.operation-options{display:flex;align-items:center;gap:22px;flex-wrap:wrap;margin:20px 0}
|
|
124
|
+
.operation-options select{min-width:220px}.operation-actions{display:flex;gap:9px;flex-wrap:wrap;margin:15px 0}
|
|
125
|
+
.operation-progress{display:flex;flex-direction:column;gap:7px;margin:16px 0}.operation-progress progress{width:100%;height:10px;accent-color:var(--accent)}
|
|
126
|
+
.operation-metrics{display:grid;grid-template-columns:repeat(auto-fit,minmax(100px,1fr));gap:12px;margin:20px 0}
|
|
127
|
+
.operation-metrics>div{padding:14px;background:#10161f;border:1px solid var(--line);border-radius:8px}.operation-metrics strong{display:block;font-size:21px}.operation-metrics span{font-size:12px;color:var(--muted)}
|
|
128
|
+
.plan-table-wrap{max-height:300px;overflow:auto;margin:14px 0}.plan-table{width:100%;border-collapse:collapse;font-size:12px;text-align:left}.plan-table th,.plan-table td{padding:10px;border-bottom:1px solid var(--line);word-break:break-word}.plan-table th{color:var(--muted);position:sticky;top:0;background:var(--panel)}.plan-table td:last-child{white-space:nowrap}
|
|
129
|
+
.file-list{font:12px/1.7 ui-monospace,monospace;max-height:220px;overflow:auto;padding:0 0 0 20px;word-break:break-word}.operation-log{font:12px/1.8 ui-monospace,monospace;max-height:260px;overflow:auto;list-style:none;padding:12px;background:#0e131c;border-radius:6px}.operation-log time{color:var(--muted)}.log-error{color:var(--danger)}.log-success{color:var(--accent)}
|
package/src/ui/ui.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { DeploymentPanel } from './deployments.js'
|
|
2
|
+
|
|
3
|
+
const $ = (selector) => document.querySelector(selector)
|
|
4
|
+
const $$ = (selector) => [...document.querySelectorAll(selector)]
|
|
5
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
|
6
|
+
const state = { projects: [], current: null, draft: null, step: 0, busy: false, local: null, remote: null, verifiedPath: null, fileOverrides: false }
|
|
7
|
+
let session
|
|
8
|
+
let renderedStep = 0
|
|
9
|
+
const deploymentPanel = new DeploymentPanel({ api, run: act, isBusy: () => state.busy, message })
|
|
10
|
+
|
|
11
|
+
async function api(method, url, body) {
|
|
12
|
+
if (!session) {
|
|
13
|
+
const response = await fetch('/api/session')
|
|
14
|
+
const data = await response.json()
|
|
15
|
+
if (!response.ok || !data.token) throw new Error(data.error || 'Could not start a local session')
|
|
16
|
+
session = data.token
|
|
17
|
+
}
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
method, headers: { 'content-type': 'application/json', 'x-devsync-session': session },
|
|
20
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
21
|
+
})
|
|
22
|
+
const data = await response.json()
|
|
23
|
+
if (!response.ok) throw new Error(data.error || 'Could not complete that operation')
|
|
24
|
+
return data
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function message(text, kind = 'info') {
|
|
28
|
+
const box = $('#message')
|
|
29
|
+
if (!box) return
|
|
30
|
+
box.textContent = text
|
|
31
|
+
box.className = `notice ${kind}`
|
|
32
|
+
box.setAttribute('role', kind === 'error' ? 'alert' : 'status')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function setBusy(busy) {
|
|
36
|
+
$('#pane').setAttribute('aria-busy', String(busy))
|
|
37
|
+
$$('button,input,select').forEach((element) => {
|
|
38
|
+
if (busy) {
|
|
39
|
+
if (element.dataset.beforeBusy === undefined) element.dataset.beforeBusy = String(element.disabled)
|
|
40
|
+
element.disabled = true
|
|
41
|
+
} else if (element.dataset.beforeBusy !== undefined) {
|
|
42
|
+
element.disabled = element.dataset.beforeBusy === 'true'
|
|
43
|
+
delete element.dataset.beforeBusy
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function act(action, text = '') {
|
|
49
|
+
if (state.busy) return
|
|
50
|
+
state.busy = true
|
|
51
|
+
setBusy(true)
|
|
52
|
+
if (text) message(text)
|
|
53
|
+
try { await action() }
|
|
54
|
+
catch (error) { message(error.message, 'error') }
|
|
55
|
+
finally { state.busy = false; setBusy(false) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function refreshProjects() {
|
|
59
|
+
state.projects = (await api('GET', '/api/projects')).projects
|
|
60
|
+
$('#projectCount').textContent = state.projects.length
|
|
61
|
+
$('#projectList').innerHTML = state.projects.map((project) => `<button class="project ${state.current?.id === project.id ? 'active' : ''}" data-project="${project.id}"><strong>${esc(project.label)}</strong><small title="${esc(project.localPath)}">${esc(project.localPath)}</small></button>`).join('')
|
|
62
|
+
$$('[data-project]').forEach((button) => { button.onclick = () => act(async () => { await discardDraft(); await openProject(Number(button.dataset.project)) }) })
|
|
63
|
+
setBusy(state.busy)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function discardDraft() {
|
|
67
|
+
deploymentPanel.close()
|
|
68
|
+
if (state.draft) {
|
|
69
|
+
try { await api('DELETE', `/api/onboarding/${state.draft.id}`) } catch {}
|
|
70
|
+
}
|
|
71
|
+
state.draft = null
|
|
72
|
+
state.step = 0
|
|
73
|
+
state.local = null
|
|
74
|
+
state.remote = null
|
|
75
|
+
state.verifiedPath = null
|
|
76
|
+
state.fileOverrides = false
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function welcome() {
|
|
80
|
+
deploymentPanel.close()
|
|
81
|
+
$('#pane').innerHTML = `<div id="message" class="notice"></div><div class="welcome"><p class="eyebrow">FROM YOUR FOLDER TO YOUR HOSTING</p><h1>A simpler way to get your project online.</h1><p class="sub">Choose a local folder, connect your hosting account, and pick where your files belong.</p><button class="primary" id="welcomeAdd">${state.projects.length ? 'Add another project' : 'Add your first project'}</button><div class="cards"><article class="card"><div class="number">01 / LOCAL</div><h3>Start with your files</h3><p>Choose your project or build folder. We’ll pick up hosting settings from its .env.</p></article><article class="card"><div class="number">02 / CONNECT</div><h3>Bring your hosting</h3><p>Use FTP, FTPS, or SFTP details from your hosting provider.</p></article><article class="card"><div class="number">03 / DESTINATION</div><h3>Choose the right folder</h3><p>Browse your server folders and save the destination for this project.</p></article></div></div>`
|
|
82
|
+
$('#welcomeAdd').onclick = () => act(startNew)
|
|
83
|
+
setBusy(state.busy)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function startNew() {
|
|
87
|
+
await discardDraft()
|
|
88
|
+
state.current = null
|
|
89
|
+
state.step = 1
|
|
90
|
+
await refreshProjects()
|
|
91
|
+
renderWizard()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function source(key) {
|
|
95
|
+
const value = state.draft?.sources[key]
|
|
96
|
+
const supplied = state.draft?.secrets[key] || state.draft?.values[key] !== '' && state.draft?.values[key] !== undefined
|
|
97
|
+
if (value === 'default' && !supplied && key !== 'DEVSYNC_PORT') {
|
|
98
|
+
return ['DEVSYNC_HOST', 'DEVSYNC_USERNAME', 'DEVSYNC_TRANSPORT'].includes(key) ? '<span class="source">Needed</span>' : ''
|
|
99
|
+
}
|
|
100
|
+
const names = { default: 'Automatic', ui: 'Entered here', override: 'Saved', secret: 'Saved' }
|
|
101
|
+
return value ? `<span class="source">${esc(names[value] || value)}</span>` : ''
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function input(key, label, { secret = false, type = 'text', optional = false } = {}) {
|
|
105
|
+
const draft = state.draft
|
|
106
|
+
const automaticPort = key === 'DEVSYNC_PORT' && draft.sources[key] === 'default'
|
|
107
|
+
const value = secret || automaticPort ? '' : draft.values[key]
|
|
108
|
+
const present = draft.secrets[key]
|
|
109
|
+
const placeholder = present ? 'Already supplied — leave blank to keep' : automaticPort ? `Automatic (${draft.values.DEVSYNC_TRANSPORT === 'sftp' ? 22 : 21})` : ''
|
|
110
|
+
return `<div class="field"><label for="${key}">${esc(label)}${optional ? ' <span class="muted">(optional)</span>' : ''}${source(key)}</label><input id="${key}" name="${key}" type="${secret ? 'password' : type}" value="${esc(value)}" placeholder="${esc(placeholder)}" autocomplete="off">${present ? `<label class="check"><input type="checkbox" data-clear="${key}">Remove supplied ${key === 'DEVSYNC_PASSWORD' ? 'password' : 'key'}</label>` : ''}</div>`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function renderWizard() {
|
|
114
|
+
const draft = state.draft
|
|
115
|
+
const steps = ['Local folder', 'Hosting', 'Destination', 'Review']
|
|
116
|
+
const step = state.step
|
|
117
|
+
const changedStep = renderedStep !== step
|
|
118
|
+
renderedStep = step
|
|
119
|
+
let content = ''
|
|
120
|
+
if (step === 1) {
|
|
121
|
+
content = `<h2>Where are your project files?</h2><p>Choose the folder you want to deploy. For a built frontend, choose its dist or build folder.</p><form id="localForm"><div class="field"><label for="localPath">Local project folder</label><div class="path-row"><input id="localPath" value="${esc(draft?.localPath || '')}" placeholder="Absolute path to a project folder"><button class="secondary" type="button" id="openLocal">Browse folders</button></div><span class="help">Only hosting settings named DEVSYNC_* are read from this folder’s .env.</span></div><div id="localPicker"></div><div class="actions"><button class="secondary" type="button" id="cancelSetup">Cancel</button><span class="spacer"></span><button class="primary" type="submit">Continue to hosting</button></div></form>`
|
|
122
|
+
} else if (step === 2) {
|
|
123
|
+
const transport = draft.values.DEVSYNC_TRANSPORT
|
|
124
|
+
const loaded = Object.entries(draft.sources).filter(([, value]) => value === '.env' || value === '.devsync.env').length
|
|
125
|
+
content = `<h2>Connect your hosting account</h2><p>${loaded ? `Loaded ${loaded} hosting settings from this folder’s environment files. Fill in anything missing.` : 'Enter the connection details from your hosting provider.'} Imported passwords stay on this computer and are not sent to the browser.</p><form id="hostingForm" autocomplete="off"><div class="form-grid"><div class="field"><label for="DEVSYNC_TRANSPORT">Protocol${source('DEVSYNC_TRANSPORT')}</label><select id="DEVSYNC_TRANSPORT" name="DEVSYNC_TRANSPORT"><option value="">Choose a protocol</option>${['ftps', 'sftp', 'ftp'].map((value) => `<option value="${value}" ${transport === value ? 'selected' : ''}>${value === 'ftps' ? 'FTPS — encrypted FTP' : value === 'sftp' ? 'SFTP — SSH file transfer' : 'FTP — unencrypted'}</option>`).join('')}</select></div>${input('DEVSYNC_HOST', 'Host')}${input('DEVSYNC_PORT', 'Port', { type: 'number', optional: true })}${input('DEVSYNC_USERNAME', 'Username')}${input('DEVSYNC_PASSWORD', 'Password / key passphrase', { secret: true })}</div><details><summary>SSH key and advanced settings</summary><div class="form-grid">${input('DEVSYNC_PRIVATE_KEY', 'SSH private key path', { secret: true, optional: true })}<div class="field"><label for="DEVSYNC_DRY_RUN">Default operation</label><select id="DEVSYNC_DRY_RUN" name="DEVSYNC_DRY_RUN"><option value="false" ${String(draft.values.DEVSYNC_DRY_RUN) === 'false' ? 'selected' : ''}>Allow uploads when requested</option><option value="true" ${String(draft.values.DEVSYNC_DRY_RUN) === 'true' ? 'selected' : ''}>Preview only</option></select></div>${input('DEVSYNC_DEBOUNCE_MS', 'Watch delay (milliseconds)', { type: 'number', optional: true })}</div><p class="help">An SSH key is optional and applies to SFTP only. With a key, the password field is an optional passphrase. Local deletions are never mirrored.</p></details><div class="actions"><button class="secondary" type="button" id="backSetup">Back</button><button class="secondary" type="button" id="cancelSetup">Cancel</button><span class="spacer"></span><button class="primary" type="submit">Test connection & continue</button></div></form>`
|
|
126
|
+
} else if (step === 3) {
|
|
127
|
+
const selected = draft.values.DEVSYNC_REMOTE_PATH
|
|
128
|
+
content = `<h2>Choose the folder on your server</h2><p>Open a folder, then select “Use server folder”. Your local files will be placed inside this destination.</p><div class="notice success">Connection verified with ${esc(draft.values.DEVSYNC_HOST)}.</div><div class="selection"><small>Selected destination ${source('DEVSYNC_REMOTE_PATH')}</small><strong id="selectedRemote">${esc(selected || 'Choose a server folder below')}</strong></div><div id="remotePicker"></div><div class="actions"><button class="secondary" type="button" id="backSetup">Back</button><button class="secondary" type="button" id="cancelSetup">Cancel</button><span class="spacer"></span><button class="primary" id="reviewSetup" ${selected && state.verifiedPath === selected ? '' : 'disabled'}>Continue to review</button></div>`
|
|
129
|
+
} else {
|
|
130
|
+
const values = draft.values
|
|
131
|
+
content = `<h2>Ready to save your project</h2><p>Check the source and destination. Saving will not upload or delete server files.</p><div class="field"><label for="projectName">Project name</label><input id="projectName" value="${esc(draft.label)}" maxlength="80"></div><dl class="review"><dt>Local folder</dt><dd>${esc(draft.localPath)}</dd><dt>Hosting</dt><dd>${esc(values.DEVSYNC_HOST)}:${esc(values.DEVSYNC_PORT)} · ${esc(values.DEVSYNC_TRANSPORT?.toUpperCase())}</dd><dt>Username</dt><dd>${esc(values.DEVSYNC_USERNAME)}</dd><dt>Credentials</dt><dd>${draft.secrets.DEVSYNC_PASSWORD ? 'Password supplied' : 'SSH key supplied'} · stored encrypted</dd><dt>Server folder</dt><dd>${esc(values.DEVSYNC_REMOTE_PATH)}</dd></dl>${state.fileOverrides ? '<div class="notice warning">You changed settings loaded from an environment file. The file stays unchanged and will take priority on future runs. Update that file to keep those changes.</div>' : ''}<p class="snapshot-note">The CLI and dashboard will share this saved project. Your application’s .env is never rewritten or uploaded.</p><div class="actions"><button class="secondary" id="backSetup">Back</button><button class="secondary" id="cancelSetup">Cancel</button><span class="spacer"></span><button class="primary" id="saveSetup">Save project</button></div>`
|
|
132
|
+
}
|
|
133
|
+
$('#pane').innerHTML = `<p class="eyebrow">${draft?.projectId ? 'PROJECT SETTINGS' : 'ADD A PROJECT'}</p><h1>A home for your next deployment.</h1><ol class="steps">${steps.map((name, i) => `<li class="${step === i + 1 ? 'active' : step > i + 1 ? 'done' : ''}" ${step === i + 1 ? 'aria-current="step"' : ''}><span class="step-number">0${i + 1}</span>${name}</li>`).join('')}</ol><div id="message" class="notice"></div><section class="setup-card">${content}</section>`
|
|
134
|
+
$('#cancelSetup').onclick = () => act(async () => { const current = state.current; await discardDraft(); if (current) await openProject(current.id); else welcome() })
|
|
135
|
+
if ($('#backSetup')) $('#backSetup').onclick = () => act(async () => { if (step === 2) await pushHosting(); state.step--; renderWizard() })
|
|
136
|
+
if (step === 1) {
|
|
137
|
+
$('#openLocal').onclick = () => act(() => loadLocal($('#localPath').value || undefined))
|
|
138
|
+
$('#localForm').onsubmit = (event) => { event.preventDefault(); act(async () => {
|
|
139
|
+
const localPath = $('#localPath').value.trim()
|
|
140
|
+
if (!localPath) throw new Error('Choose a local project folder first')
|
|
141
|
+
if (!draft || localPath !== draft.localPath) {
|
|
142
|
+
const loaded = await api('POST', '/api/onboarding', { localPath, ...(draft?.projectId ? { projectId: draft.projectId } : {}) })
|
|
143
|
+
if (draft) try { await api('DELETE', `/api/onboarding/${draft.id}`) } catch {}
|
|
144
|
+
state.draft = loaded
|
|
145
|
+
state.fileOverrides = false
|
|
146
|
+
state.remote = null
|
|
147
|
+
state.verifiedPath = null
|
|
148
|
+
}
|
|
149
|
+
state.step = 2
|
|
150
|
+
renderWizard()
|
|
151
|
+
}, 'Reading hosting settings from the selected folder…') }
|
|
152
|
+
if (state.local) renderLocal()
|
|
153
|
+
}
|
|
154
|
+
if (step === 2) {
|
|
155
|
+
$$('[name],[data-clear]').forEach((element) => element.addEventListener('input', () => { element.dataset.dirty = 'true' }))
|
|
156
|
+
$('#DEVSYNC_TRANSPORT').addEventListener('change', () => {
|
|
157
|
+
if (!$('#DEVSYNC_PORT').value) $('#DEVSYNC_PORT').placeholder = `Automatic (${$('#DEVSYNC_TRANSPORT').value === 'sftp' ? 22 : 21})`
|
|
158
|
+
})
|
|
159
|
+
$('#hostingForm').onsubmit = (event) => { event.preventDefault(); act(async () => {
|
|
160
|
+
await pushHosting()
|
|
161
|
+
state.draft = await api('POST', `/api/onboarding/${state.draft.id}/test`, {})
|
|
162
|
+
state.step = 3
|
|
163
|
+
state.remote = null
|
|
164
|
+
state.verifiedPath = null
|
|
165
|
+
renderWizard()
|
|
166
|
+
await loadRemote(state.draft.values.DEVSYNC_REMOTE_PATH || '/')
|
|
167
|
+
}, 'Testing your hosting connection…') }
|
|
168
|
+
}
|
|
169
|
+
if (step === 3) {
|
|
170
|
+
if (state.remote) renderRemote()
|
|
171
|
+
else renderRemoteAddress()
|
|
172
|
+
$('#reviewSetup').onclick = () => { state.step = 4; renderWizard() }
|
|
173
|
+
}
|
|
174
|
+
if (step === 4) $('#saveSetup').onclick = () => act(async () => {
|
|
175
|
+
const label = $('#projectName').value.trim()
|
|
176
|
+
const saved = await api('POST', `/api/onboarding/${state.draft.id}/save`, { label })
|
|
177
|
+
const overridden = state.fileOverrides
|
|
178
|
+
await discardDraft()
|
|
179
|
+
await refreshProjects()
|
|
180
|
+
await openProject(saved.id)
|
|
181
|
+
message(overridden ? 'Project saved. Its environment file still takes priority over the settings snapshot.' : 'Project saved. Your source and server destination are ready.', overridden ? 'warning' : 'success')
|
|
182
|
+
}, 'Checking the destination and saving your project…')
|
|
183
|
+
setBusy(state.busy)
|
|
184
|
+
if (changedStep) {
|
|
185
|
+
const heading = $('#pane h1')
|
|
186
|
+
heading.tabIndex = -1
|
|
187
|
+
heading.focus({ preventScroll: true })
|
|
188
|
+
window.scrollTo(0, 0)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function pushHosting() {
|
|
193
|
+
const entries = []
|
|
194
|
+
$$('[name][data-dirty="true"]').forEach((element) => {
|
|
195
|
+
if (element.type === 'password' && !element.value) return
|
|
196
|
+
entries.push({ key: element.name, value: element.value })
|
|
197
|
+
})
|
|
198
|
+
$$('[data-clear]:checked').forEach((element) => entries.push({ key: element.dataset.clear, value: null }))
|
|
199
|
+
if (!entries.length) return
|
|
200
|
+
noteFileOverrides(entries)
|
|
201
|
+
state.draft = await api('PUT', `/api/onboarding/${state.draft.id}`, { entries })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function noteFileOverrides(entries) {
|
|
205
|
+
if (entries.some((entry) => ['.env', '.devsync.env'].includes(state.draft.sources[entry.key]))) state.fileOverrides = true
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function loadLocal(path) {
|
|
209
|
+
state.local = await api('GET', '/api/local' + (path ? `?path=${encodeURIComponent(path)}` : ''))
|
|
210
|
+
renderLocal()
|
|
211
|
+
}
|
|
212
|
+
function renderLocal() {
|
|
213
|
+
const current = state.local
|
|
214
|
+
$('#localPicker').innerHTML = `<div class="picker"><label class="help" for="localAddress">Browse local folders</label><div class="path-row"><input id="localAddress" value="${esc(current.path)}" aria-label="Local browser path"><button class="secondary" type="button" id="goLocal">Open local path</button></div><div class="picker-toolbar"><button class="secondary" type="button" data-local="${esc(current.home)}">Home</button>${current.parent ? `<button class="secondary" type="button" data-local="${esc(current.parent)}">Up one local folder</button>` : ''}${current.roots.map((root) => `<button class="secondary" type="button" data-local="${esc(root)}">${esc(root)}</button>`).join('')}</div><div class="folder-list">${current.entries.map((entry) => `<button class="folder" type="button" data-local="${esc(entry.path)}">${esc(entry.name)}</button>`).join('') || '<div class="empty">No subfolders here.</div>'}</div><button class="primary" type="button" id="useLocal">Use local folder</button></div>`
|
|
215
|
+
$$('[data-local]').forEach((button) => { button.onclick = () => act(() => loadLocal(button.dataset.local)) })
|
|
216
|
+
$('#goLocal').onclick = () => act(() => loadLocal($('#localAddress').value.trim()))
|
|
217
|
+
$('#localAddress').onkeydown = (event) => { if (event.key === 'Enter') { event.preventDefault(); $('#goLocal').click() } }
|
|
218
|
+
$('#useLocal').onclick = () => { $('#localPath').value = current.path; $('#localPicker').innerHTML = '' }
|
|
219
|
+
setBusy(state.busy)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function renderRemoteAddress() {
|
|
223
|
+
$('#remotePicker').innerHTML = '<div class="picker"><label class="help" for="remoteAddress">Open an existing server folder</label><div class="path-row"><input id="remoteAddress" value="/" aria-label="Server browser path"><button class="secondary" id="goRemote">Open server path</button></div><div id="remoteContents"></div></div>'
|
|
224
|
+
$('#goRemote').onclick = () => act(() => loadRemote($('#remoteAddress').value.trim()))
|
|
225
|
+
$('#remoteAddress').onkeydown = (event) => { if (event.key === 'Enter') { event.preventDefault(); $('#goRemote').click() } }
|
|
226
|
+
}
|
|
227
|
+
async function loadRemote(path) {
|
|
228
|
+
state.remote = await api('POST', `/api/onboarding/${state.draft.id}/browse`, { path })
|
|
229
|
+
if (state.remote.path === state.draft.values.DEVSYNC_REMOTE_PATH) state.verifiedPath = state.remote.path
|
|
230
|
+
renderWizard()
|
|
231
|
+
}
|
|
232
|
+
function renderRemote() {
|
|
233
|
+
const current = state.remote
|
|
234
|
+
renderRemoteAddress()
|
|
235
|
+
$('#remoteAddress').value = current.path
|
|
236
|
+
$('#remoteContents').innerHTML = `<div class="picker-toolbar"><button class="secondary" data-remote="/">Account root</button>${current.parent ? `<button class="secondary" data-remote="${esc(current.parent)}">Up one server folder</button>` : ''}</div><div class="folder-list">${current.entries.map((entry) => `<button class="folder" data-remote="${esc(entry.path)}">${esc(entry.name)}</button>`).join('') || '<div class="empty">No subfolders here. You can still use this folder.</div>'}</div><button class="primary" id="useRemote">Use server folder</button>`
|
|
237
|
+
$$('[data-remote]').forEach((button) => { button.onclick = () => act(() => loadRemote(button.dataset.remote)) })
|
|
238
|
+
$('#useRemote').onclick = () => act(async () => {
|
|
239
|
+
const entries = [{ key: 'DEVSYNC_REMOTE_PATH', value: current.path }]
|
|
240
|
+
noteFileOverrides(entries)
|
|
241
|
+
state.draft = await api('PUT', `/api/onboarding/${state.draft.id}`, { entries })
|
|
242
|
+
state.verifiedPath = current.path
|
|
243
|
+
renderWizard()
|
|
244
|
+
message(`Destination selected: ${current.path}`, 'success')
|
|
245
|
+
})
|
|
246
|
+
setBusy(state.busy)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async function openProject(id) {
|
|
250
|
+
deploymentPanel.close()
|
|
251
|
+
const data = await api('GET', `/api/projects/${id}/env`)
|
|
252
|
+
state.current = { id, ...data }
|
|
253
|
+
state.step = 0
|
|
254
|
+
const config = data.configuration
|
|
255
|
+
const values = config.values
|
|
256
|
+
$('#pane').innerHTML = `<p class="eyebrow">SAVED PROJECT</p><div class="summary-head"><div><h1>${esc(data.label)}</h1><p class="sub">${esc(data.localPath)}</p></div><span class="ready">● ${Object.keys(config.errors).length ? 'Setup needed' : 'Project configured'}</span></div><div id="message" class="notice"></div><section class="summary-card"><h2>Source → destination</h2><dl class="review"><dt>Local source</dt><dd>${esc(data.localPath)}</dd><dt>Server folder</dt><dd>${esc(values.DEVSYNC_REMOTE_PATH || 'Not configured')}</dd><dt>Connection</dt><dd>${esc(values.DEVSYNC_TRANSPORT?.toUpperCase())} · ${esc(values.DEVSYNC_HOST || 'Not configured')}:${esc(values.DEVSYNC_PORT)}</dd><dt>Username</dt><dd>${esc(values.DEVSYNC_USERNAME || 'Not configured')}</dd><dt>Credentials</dt><dd>${config.secrets.DEVSYNC_PASSWORD || config.secrets.DEVSYNC_PRIVATE_KEY ? 'Supplied · never shown in this browser' : 'Not configured'}</dd></dl><div class="actions"><button class="primary" id="editProject">Edit setup</button><button class="secondary" id="testProject">Test connection</button><span class="spacer"></span><button class="danger" id="deleteProject">Remove project</button></div></section>`
|
|
257
|
+
if (Object.keys(config.errors).length) message(Object.values(config.errors).join('; '), 'warning')
|
|
258
|
+
$('#editProject').onclick = () => act(async () => { state.draft = await api('POST', '/api/onboarding', { projectId: id }); deploymentPanel.close(); state.fileOverrides = false; state.local = null; state.remote = null; state.verifiedPath = null; state.step = 1; renderWizard() })
|
|
259
|
+
$('#testProject').onclick = () => act(async () => { await api('POST', '/api/test', { projectId: id }); message('Connection test passed.', 'success') }, 'Testing your hosting connection…')
|
|
260
|
+
$('#deleteProject').onclick = () => act(async () => {
|
|
261
|
+
if (!confirm(`Remove "${data.label}" from devsync? Local and server files stay in place.`)) return
|
|
262
|
+
await api('DELETE', `/api/projects/${id}`)
|
|
263
|
+
state.current = null
|
|
264
|
+
await refreshProjects()
|
|
265
|
+
welcome()
|
|
266
|
+
})
|
|
267
|
+
await refreshProjects()
|
|
268
|
+
const deploymentElement = document.createElement('section')
|
|
269
|
+
deploymentElement.id = 'deploymentPanel'
|
|
270
|
+
deploymentElement.className = 'summary-card operation-card'
|
|
271
|
+
$('#pane').appendChild(deploymentElement)
|
|
272
|
+
await deploymentPanel.open(id, config)
|
|
273
|
+
window.scrollTo(0, 0)
|
|
274
|
+
setBusy(state.busy)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
$('#addProject').onclick = () => act(startNew)
|
|
278
|
+
;(async () => {
|
|
279
|
+
try {
|
|
280
|
+
await refreshProjects()
|
|
281
|
+
$('#serverStatus').textContent = '● Running locally'
|
|
282
|
+
if (state.projects.length === 1) await openProject(state.projects[0].id)
|
|
283
|
+
else welcome()
|
|
284
|
+
} catch (error) {
|
|
285
|
+
$('#pane').innerHTML = '<h1>Could not load your projects</h1><div id="message" class="notice"></div>'
|
|
286
|
+
message(error.message, 'error')
|
|
287
|
+
$('#serverStatus').textContent = 'Connection unavailable'
|
|
288
|
+
}
|
|
289
|
+
})()
|