-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-setup.mjs
More file actions
59 lines (53 loc) · 2.43 KB
/
Copy pathnode-setup.mjs
File metadata and controls
59 lines (53 loc) · 2.43 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
#!/usr/bin/env node
/*
* node-setup — one-time setup to run the ports on the Node backend.
*
* Clones abap2UI5 into .abap2UI5 (in-repo, gitignored), installs its deps and
* this repo's deps, then builds the backend. After this, `npm run node:serve`
* starts the server on http://localhost:3000.
*
* Re-runnable: if .abap2UI5 already exists it is updated instead of
* re-cloned. Override the source with A2UI5_REPO / A2UI5_BRANCH env vars.
*
* By default the checkout is fixed at the commit in A2UI5_PIN (repo root), so
* a build today and a build next week run against the same framework. Setting
* A2UI5_BRANCH (or removing the pin file) tracks a branch tip instead.
*/
import { execSync } from 'child_process';
import fs from 'fs';
import { IN_REPO_A2UI5, REPO_ROOT, readA2UI5Pin } from './lib-a2ui5.mjs';
const REPO = process.env.A2UI5_REPO || 'https://github.com/abap2UI5/abap2UI5';
const BRANCH = process.env.A2UI5_BRANCH || '';
const PIN = BRANCH ? null : readA2UI5Pin();
const run = (cmd, cwd = REPO_ROOT) => {
console.log(`\n$ ${cmd} (in ${cwd})`);
execSync(cmd, { cwd, stdio: 'inherit' });
};
// 1. clone (or update) abap2UI5 into .abap2UI5
if (fs.existsSync(`${IN_REPO_A2UI5}/node/srv/express.mjs`)) {
console.log('node-setup: .abap2UI5 already present — updating');
if (PIN) {
try {
run(`git fetch --depth 1 origin ${PIN}`, IN_REPO_A2UI5);
run(`git checkout --detach ${PIN}`, IN_REPO_A2UI5);
} catch { console.log('node-setup: pin checkout failed (offline / local changes) — using existing checkout'); }
} else {
try { run('git pull --ff-only', IN_REPO_A2UI5); } catch { console.log('node-setup: git pull skipped (local changes / detached) — using existing checkout'); }
}
} else {
fs.rmSync(IN_REPO_A2UI5, { recursive: true, force: true });
const branch = BRANCH ? `--branch ${BRANCH} ` : '';
run(`git clone --depth 1 ${branch}${REPO} .abap2UI5`);
if (PIN) {
run(`git fetch --depth 1 origin ${PIN}`, IN_REPO_A2UI5);
run(`git checkout --detach ${PIN}`, IN_REPO_A2UI5);
}
}
// 2. install deps — the framework (transpiler, express, runtime) and this repo
run('npm ci', IN_REPO_A2UI5);
run('npm ci');
// 3. build the backend (downport + transpile framework + all ports)
run('node scripts/e2e-build.mjs');
console.log('\nnode-setup: done ✔');
console.log('Start the server with: npm run node:serve');
console.log('Then open: http://localhost:3000/?app_start=z2ui5_cl_smpc_app_000');