-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathnode_script.ts
More file actions
84 lines (70 loc) · 2.31 KB
/
node_script.ts
File metadata and controls
84 lines (70 loc) · 2.31 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
const { exec } = require('child_process');
let devProcess: any;
async function runDevScript(param: string): Promise<void> {
return new Promise((resolve, reject) => {
devProcess = exec(`cd ../.. && pnpm dev -i ${param}`, (error: any, stdout: any, stderr: any) => {
if (error) {
console.error(`Error running dev script: ${error}`);
reject(error);
} else {
console.log(`Dev script output: ${stdout}`);
resolve();
}
});
devProcess.stdout.on('data', (data: any) => {
console.log(`stdout: ${data}`);
});
devProcess.stderr.on('data', (data: any) => {
console.error(`stderr: ${data}`);
});
});
}
async function runPlaywrightScript(scriptName: string) {
return new Promise((resolve, reject) => {
const command = `npx ts-node ${scriptName}`;
const playwrightProcess = exec(command, (error: any, stdout: any, stderr: any) => {
if (error) {
console.error(`Error running script: ${error.message}`);
reject(error);
}
if (stderr) {
console.error(`Error output: ${stderr}`);
reject(stderr);
}
console.log(`Script output: ${stdout}`);
resolve(stdout);
});
playwrightProcess.stdout.on('data', (data: any) => {
console.log(`stdout: ${data}`);
});
playwrightProcess.stderr.on('data', (data: any) => {
console.error(`stderr: ${data}`);
});
});
}
async function runPlaywrightTasks() {
try {
await runPlaywrightScript('playwright_save_all.ts');
await runPlaywrightScript('playwright_save_combo.ts');
await runPlaywrightScript('playwright_load.ts');
process.exit(0);
} catch (error) {
console.error('Error during Playwright tasks:', error);
}
}
async function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('Please provide a parameter.');
return;
}
const param = args[0];
try {
runDevScript(param);
console.log('Dev script started successfully');
runPlaywrightTasks();
} catch (error) {
console.error('Error running script:', error);
}
}
main();