-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsync-examples.js
More file actions
108 lines (91 loc) · 2.76 KB
/
Copy pathsync-examples.js
File metadata and controls
108 lines (91 loc) · 2.76 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
#!/usr/bin/env node
/**
* Sync examples from playgrounds.
*
* Playgrounds are the source of truth for examples. This script copies playground
* files to the examples directory and transforms:
* - `workspace:*` dependencies → `^<published-version>`
* - `catalog:` dependencies → `^<catalog-version>`
*
* Usage:
* node scripts/sync-examples.js # Sync all examples
* node scripts/sync-examples.js --check # Check if examples are in sync (for CI)
*/
import { existsSync, readdirSync, readFileSync } from "node:fs";
import { basename, join } from "node:path";
import { argv } from "node:process";
import { PLAYGROUNDS_DIR } from "./sync-lib/constants.js";
import { syncRenovateConfig } from "./sync-lib/renovate.js";
import { syncPlayground } from "./sync-lib/sync.js";
import { parseCatalog } from "./sync-lib/workspace.js";
/**
* Main function
*/
function main() {
const checkOnly = argv.includes("--check");
const catalog = parseCatalog();
console.log(
checkOnly
? "Checking examples sync status..."
: "Syncing examples from playgrounds...",
);
// Find all playgrounds with arkenvExamples metadata
const playgroundDirs = readdirSync(PLAYGROUNDS_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => join(PLAYGROUNDS_DIR, d.name));
let hasChanges = false;
const generatedExampleNames = [];
for (const playgroundPath of playgroundDirs) {
const pkgPath = join(playgroundPath, "package.json");
if (!existsSync(pkgPath)) {
continue;
}
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
if (!pkg.arkenvExamples || !Array.isArray(pkg.arkenvExamples)) {
continue;
}
for (const exampleConfig of pkg.arkenvExamples) {
if (!exampleConfig.name) {
console.warn(
`Warning: Example config missing 'name' in ${basename(playgroundPath)}`,
);
continue;
}
if (exampleConfig.skipSync) {
continue;
}
generatedExampleNames.push(exampleConfig.name);
const changes = syncPlayground(
playgroundPath,
exampleConfig,
catalog,
checkOnly,
);
if (checkOnly && changes.length > 0) {
hasChanges = true;
console.log(`\n ✗ ${exampleConfig.name} is out of sync:`);
for (const change of changes) {
console.log(` - ${change}`);
}
}
}
}
if (syncRenovateConfig(generatedExampleNames, checkOnly)) {
hasChanges = true;
console.log(
"\n ✗ Renovate config is out of sync with playground metadata.",
);
}
if (checkOnly) {
if (hasChanges) {
console.log("\n❌ Examples are out of sync with playgrounds.");
console.log("Run 'pnpm sync:examples' to update them.");
process.exit(1);
} else {
console.log("\n✓ All examples are in sync with playgrounds.");
}
} else {
console.log("\n✓ Examples synced successfully.");
}
}
main();