-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrebase-ess.mjs
More file actions
130 lines (108 loc) · 3.35 KB
/
Copy pathrebase-ess.mjs
File metadata and controls
130 lines (108 loc) · 3.35 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
#!/usr/bin/env node
import { execSync } from 'node:child_process';
// ESS lab branch chain. Each starter branch is the solution of the
// previous lab and the starting point for the next one. Rebasing the
// chain top-to-bottom propagates changes made to ess-starter (or any
// earlier branch) downstream through every lab up to ess-solution.
const tasks = [
{ branch: 'ess-intro-starter', base: 'ess-starter' },
{ branch: 'ess-signals-starter', base: 'ess-intro-starter' },
{ branch: 'ess-services-starter', base: 'ess-signals-starter' },
{ branch: 'ess-pipes-starter', base: 'ess-services-starter' },
{ branch: 'ess-components-starter', base: 'ess-pipes-starter' },
{ branch: 'ess-testing-starter', base: 'ess-components-starter' },
{ branch: 'ess-routing-starter', base: 'ess-testing-starter' },
{ branch: 'ess-solution', base: 'ess-routing-starter' },
];
const args = process.argv.slice(2);
const check = args.includes('--check');
const doBuild = check || args.includes('--build');
const doLint = check || args.includes('--lint');
function run(cmd) {
console.log(`\n> ${cmd}`);
execSync(cmd, { stdio: 'inherit' });
}
function runSafe(cmd, branch, label) {
try {
run(cmd);
} catch {
console.error(`\n❌ ${label} failed on branch ${branch}. Aborting.`);
process.exit(1);
}
}
function parseSkipArgs(argv) {
const skips = [];
for (let i = 0; i < argv.length; i++) {
const arg = argv[i];
if (arg.startsWith('--skip=')) {
skips.push(arg.slice('--skip='.length));
continue;
}
if (arg !== '--skip') {
continue;
}
const value = argv[++i];
if (value && !value.startsWith('--')) {
skips.push(value);
continue;
}
console.error(
'❌ --skip benötigt einen Wert (z. B. --skip ess-pipes-starter).',
);
process.exit(1);
}
return skips;
}
function main() {
const skips = parseSkipArgs(args);
// Sicherheitscheck: sauberes Working Tree
try {
const status = execSync('git status --porcelain', {
encoding: 'utf8',
}).trim();
if (status.length > 0) {
console.error(
'❌ Working tree ist nicht clean. Bitte commit/stash vorher.',
);
process.exit(1);
}
} catch {
console.error('❌ Kein Git-Repo oder git nicht verfügbar.');
process.exit(1);
}
const startBranch = execSync('git branch --show-current', {
encoding: 'utf8',
}).trim();
const filteredTasks = tasks.filter(({ branch }) => {
const match = skips.find((s) => branch.includes(s));
if (match) {
console.log(`⏭ Skip: ${branch} (matcht --skip ${match})`);
return false;
}
return true;
});
for (const { branch, base } of filteredTasks) {
console.log(`\n==============================`);
console.log(`Rebase: ${branch} <- ${base}`);
console.log(`==============================`);
// branch auschecken
run(`git checkout ${branch}`);
// Rebase
run(`git rebase ${base}`);
console.log(`✅ OK: ${branch} rebased on ${base}`);
if (doBuild) {
runSafe('npx ng build', branch, 'Build');
console.log(`✅ Build OK: ${branch}`);
}
if (doLint) {
runSafe('npx ng lint', branch, 'Lint');
console.log(`✅ Lint OK: ${branch}`);
}
}
// zurück zum Start-Branch
if (startBranch) {
run(`git checkout ${startBranch}`);
}
console.log('\n🎉 Fertig.');
}
main();