-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-dockerizer.js
More file actions
executable file
·111 lines (98 loc) · 3.14 KB
/
Copy pathtest-dockerizer.js
File metadata and controls
executable file
·111 lines (98 loc) · 3.14 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
#!/usr/bin/env node
/**
* Test script for Dockerizer
*
* This script will run the Dockerizer tool on the example monorepo
* and show the output.
*/
const path = require("path");
const chalk = require("chalk");
const { dockerize } = require("./src/index");
// Parse command-line arguments
const args = process.argv.slice(2);
const overwrite = args.includes("--overwrite");
const runTwice = args.includes("--run-twice");
async function runTest() {
console.log(chalk.blue("🧪 Testing Dockerizer on example monorepo\n"));
const targetDir = path.join(__dirname, "example");
console.log(chalk.gray(`Target directory: ${targetDir}\n`));
console.log(
chalk.gray(
`Options: ${
overwrite ? "Overwrite existing files" : "Preserve existing files"
}\n`
)
);
try {
console.log(chalk.yellow("Starting dockerization process..."));
const result = await dockerize({
targetDir,
verbose: true,
maxRetries: 3,
overwrite,
});
// If we need to run twice to test the idempotent behavior
if (runTwice && result.success) {
console.log(
chalk.yellow(
"\n\n🔄 Running dockerization a second time to test idempotent behavior...\n"
)
);
const secondResult = await dockerize({
targetDir,
verbose: true,
maxRetries: 3,
overwrite,
});
if (secondResult.success) {
console.log(chalk.green("\n✅ Second run completed successfully!"));
if (!overwrite && secondResult.newFilesCount === 0) {
console.log(
chalk.green(
"✓ Idempotent behavior confirmed: No files were overwritten."
)
);
} else if (overwrite) {
console.log(
chalk.green(
`✓ Files were successfully updated with --overwrite flag.`
)
);
}
} else {
console.log(chalk.red("\n❌ Second dockerization run failed:"));
console.log(chalk.red(secondResult.message));
process.exit(1);
}
}
// Show results of the first run (or only run)
if (result.success) {
console.log(chalk.green("\n✅ Dockerization completed successfully!"));
console.log(
chalk.gray(
`Generated ${result.filesCount} files, ${result.newFilesCount} new.`
)
);
console.log(
chalk.gray("You can now navigate to the example directory and run:")
);
console.log(chalk.cyan("docker compose -f docker-compose.dev.yml up"));
console.log(chalk.gray("or for production:"));
console.log(chalk.cyan("docker compose -f docker-compose.yml up"));
} else {
console.log(chalk.red("\n❌ Dockerization failed:"));
console.log(chalk.red(result.message));
if (result.errors && result.errors.length > 0) {
console.log(chalk.red("\nErrors:"));
result.errors.forEach((err, index) => {
console.log(chalk.red(`${index + 1}. ${err.message || err}`));
});
}
process.exit(1);
}
} catch (error) {
console.error(chalk.red("\n❌ Test failed with error:"), error);
process.exit(1);
}
}
runTest();