-
Notifications
You must be signed in to change notification settings - Fork 0
/
phd.mjs
executable file
·164 lines (137 loc) · 6.14 KB
/
phd.mjs
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env -S npm exec --yes --package=zx@latest zx --
import deployProcess from './cli/deployProcess.mjs'
import { stringifySnapshot } from './cli/snapshots.mjs'
import generateActivityLogs from './cli/generateActivityLogs.mjs'
$.verbose = false
if (argv.help || argv._[0] === 'help') {
argv._[0] === 'help' && argv._[1] && await help(...argv._.slice(1)) // called with help + something
argv._[0] === 'help' && !argv._[1] && await help() // called with help only
argv._[0] !== 'help' && !argv._[1] && await help(...argv._) // called with --help
} else if (argv._[0] === 'run' || argv._[0] === 'start') {
await dockerRun(...argv._.slice(1));
} else if (argv._[0] === 'stop') {
await dockerStop(...argv._.slice(1));
} else if (argv._[0] === 'test') {
await test(...argv._.slice(1));
} else if (argv._[0] === 'clean') {
await clean(...argv._.slice(1));
} else if (argv._[0] === 'deploy-bpmn') {
await deployProcess();
} else if (argv._[0] === 'stringify-snapshot') {
await stringifySnapshot(argv);
} else if (argv._[0] === 'git-pull-all') {
await gitPullAll(...argv._.slice(1));
} else if (argv._[0] === 'generate-activity-logs') {
await generateActivityLogs(argv);
} else {
await help(...argv._);
}
async function help(args) {
await echo`
Usage:
phd help Show this message
phd start Start the docker stack. You can use 'phd run' too
phd start zeebe Start the docker stack, but only the zeebe stack
phd stop Stop the docker stack
phd clean Wipe all data. All steps have to be confirmed
phd test Launch tests
phd test e2e Launch e2e tests with a headless browser
phd test load-fixtures Load locally task fixtures
phd git-pull-all Git refresh all the known modules / submodules
phd deploy-bpmn Interactively deploy a BPMN
phd stringify-snapshot Use the PERL-tools to export a DB to a *.txt. Use --path=PATH_TO_CURRENT
phd generate-activity-logs Initiate the activityLogs table for the new dashboard milestone (temp)
`
}
async function dockerRun(args) {
cd(path.join(__dirname, `docker`));
console.log('Starting the zeebe stack..')
await $`docker compose up -d zeebe_node_0 zeebe_node_1 zeebe_node_2`;
if (args !== 'zeebe') {
console.log('Starting the pdf, notifier, ged, isa..')
await $`docker compose up -d pdf notifier ged isa`;
console.log('Starting the simple-monitor (localhost:8082)..')
await $`docker compose up -d simple-monitor`;
}
console.log(`Stack started.`);
console.log(`To see the logs, use "cd ${path.join(__dirname, `docker`)}; docker compose logs -f --since 5m"`);
console.log(`To stop, use the './phd.mjs stop' command`);
}
async function dockerStop(args) {
cd(path.join(__dirname, `docker`));
await spinner(`Stopping the containers`, async () => {
await $`docker compose stop`;
});
console.log('Containers stopped.')
}
async function clean(args) {
if (await question(`Clean Zeebe partitions ? [y/N] `) === 'y') {
const pathZeebeVolume = path.join(__dirname, `docker/volumes`);
if (await question(`Backup Zeebe partitions before deleting ? (${ path.join(__dirname, `docker/volumes/`) }*.bak) [y/N] `) === 'y') {
['zeebe_data_node_0', 'zeebe_data_node_1', 'zeebe_data_node_2'].forEach((pathVolume) => {
const partitionInstanceVolumePath = path.join(pathZeebeVolume, pathVolume);
const bakPartitionInstanceVolumePath = path.join(pathZeebeVolume, `${ pathVolume }.bak`);
fs.pathExistsSync(partitionInstanceVolumePath) &&
fs.moveSync(partitionInstanceVolumePath, bakPartitionInstanceVolumePath);
console.log(`Successfully moved ${ partitionInstanceVolumePath } to ${ bakPartitionInstanceVolumePath }`)
});
} else {
['zeebe_data_node_0', 'zeebe_data_node_1', 'zeebe_data_node_2'].forEach((pathVolume) => {
const partitionInstanceVolumePath = path.join(pathZeebeVolume, pathVolume);
fs.pathExistsSync(partitionInstanceVolumePath) &&
fs.removeSync(partitionInstanceVolumePath);
console.log(`Successfully deleted ${ partitionInstanceVolumePath }`)
});
}
}
if (await question('Clean meteor db ? [y/N] ') === 'y') {
const fillFormPath = path.join(__dirname, `apps/fillForm`);
cd(fillFormPath);
await $`meteor reset`;
await $`meteor npm i`;
console.log(`Successfully reset the meteor db`)
}
if (await question('Clean simple monitor data ? [y/N] ') === 'y') {
const simpleMonitorVolumePath = path.join(__dirname, `docker/volumes/simple_monitor_h2_db`);
await fs.remove(path.join(simpleMonitorVolumePath, 'simple-monitor.mv.db'));
console.log(`Successfully removed ${path.join(simpleMonitorVolumePath, 'simple-monitor.mv.db')}`)
}
}
async function test(args) {
$.verbose = true
if (args === 'load-fixtures') {
await cd('./apps/fillForm');
//await $`echo "Meteor.isServer && Meteor.isDevelopment" | meteor shell`
const p = await $`echo "Meteor.call('loadFixtures')" | meteor shell`.pipe(process.stdout)
for await (const chunk of p.stdout) {
echo(chunk)
}
} else if (args === 'e2e') {
await cd(path.join(__dirname, './apps/fillForm/tests/E2E'));
await $`npx playwright test --ui`;
} else {
const testServer = process.env.TEST_SERVER ?? '1'
const testClient = process.env.TEST_CLIENT ?? '1'
await cd(path.join(__dirname, './apps/fillForm'));
await $`TEST_SERVER=${testServer} TEST_CLIENT=${testClient} meteor test --driver-package meteortesting:mocha --port 3100`;
}
}
async function gitPullAll(args) {
const projectsPathes = [
path.join(__dirname, 'apps/fillForm'),
path.join(__dirname, '..', 'PhDAssess-meta'),
path.join(__dirname, '..', 'PhDAssess-PDF'),
path.join(__dirname, '..', 'PhDAssess-Notifier'),
path.join(__dirname, '..', 'PhDAssess-GED'),
];
for (const projectPath of projectsPathes) {
if (fs.pathExistsSync(projectPath)) {
console.log(`Doing ${projectPath}..`)
cd(projectPath)
await $`git pull`
console.log(`${projectPath} done`)
} else {
console.log(`skipping inexisting ${projectPath}`)
}
}
}