Skip to content

Commit 683f24d

Browse files
committed
Getting ready to update all templates to the newest SDK after it’s released
1 parent c4249d9 commit 683f24d

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

scripts/updateTemplateDependencies.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { exec } = require("child_process");
22
const fs = require("fs");
33
const path = require("path");
44
const fetch = require("node-fetch");
5+
const readline = require("node:readline");
56

67
const templatesDir = process.argv[2];
78
if (!templatesDir) {
@@ -13,10 +14,37 @@ async function updateTemplate(templateName) {
1314
const templateDir = path.join(templatesDir, templateName);
1415

1516
if (fs.statSync(templateDir).isDirectory()) {
16-
console.log(`Updating dependencies for template '${templateName}'`);
17+
const currentBranch = (
18+
await execAsync(`cd ${templateDir} && git rev-parse --abbrev-ref HEAD`)
19+
).trim();
20+
21+
console.log(
22+
`Updating dependencies for template '${templateName}' in current branch '${currentBranch}'`
23+
);
24+
25+
// Ask the user if they want to update the template (default to yes)
26+
const updateTemplate = await new Promise((resolve) => {
27+
const rl = readline.createInterface({
28+
input: process.stdin,
29+
output: process.stdout,
30+
});
31+
32+
rl.question(
33+
`Update dependencies for template '${templateName}' in branch ${currentBranch}? [Y/n] `,
34+
(answer) => {
35+
rl.close();
36+
resolve(answer.toLowerCase() !== "n");
37+
}
38+
);
39+
});
40+
41+
if (!updateTemplate) {
42+
console.log(`Skipping '${templateName}'`);
43+
return;
44+
}
1745

1846
// Make sure we're on the main branch and there are no uncommitted changes
19-
await execAsync(`cd ${templateDir} && git checkout main`);
47+
await execAsync(`cd ${templateDir} && git checkout ${currentBranch}`);
2048

2149
// Make sure there are no uncommitted changes
2250
const preStatus = await execAsync(`cd ${templateDir} && git status`);
@@ -29,7 +57,7 @@ async function updateTemplate(templateName) {
2957
}
3058

3159
// Make sure we're up to date with the remote
32-
await execAsync(`cd ${templateDir} && git pull origin main`);
60+
await execAsync(`cd ${templateDir} && git pull origin ${currentBranch}`);
3361

3462
// Find all the dependencies that start with @trigger.dev/
3563
const packageJson = JSON.parse(
@@ -75,7 +103,7 @@ async function updateTemplate(templateName) {
75103
);
76104

77105
// Push to remote
78-
await execAsync(`cd ${templateDir} && git push origin main`);
106+
await execAsync(`cd ${templateDir} && git push origin ${currentBranch}`);
79107

80108
console.log(`Updated dependencies for template '${templateName}'`);
81109
} else {
@@ -84,6 +112,8 @@ async function updateTemplate(templateName) {
84112
}
85113

86114
async function execAsync(command) {
115+
console.log(`Executing command: ${command}`);
116+
87117
return new Promise((resolve, reject) => {
88118
exec(command, (error, stdout, stderr) => {
89119
if (error) {

0 commit comments

Comments
 (0)