Skip to content

Commit 9a75d60

Browse files
committed
added writeFileSyncIfChanged to all the codegen
1 parent 229209f commit 9a75d60

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

apps/backend/scripts/generate-docs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { parseOpenAPI, parseWebhookOpenAPI } from '@/lib/openapi';
22
import { isSmartRouteHandler } from '@/route-handlers/smart-route-handler';
33
import { webhookEvents } from '@stackframe/stack-shared/dist/interface/webhooks';
4+
import { writeFileSyncIfChanged } from '@stackframe/stack-shared/dist/utils/fs';
45
import { HTTP_METHODS } from '@stackframe/stack-shared/dist/utils/http';
56
import { typedKeys } from '@stackframe/stack-shared/dist/utils/objects';
6-
import fs from 'fs';
77
import { glob } from 'glob';
88
import path from 'path';
99
import yaml from 'yaml';
@@ -33,12 +33,12 @@ async function main() {
3333
}))),
3434
audience,
3535
}));
36-
fs.writeFileSync(`../../docs/fern/openapi/${audience}.yaml`, openAPISchema);
36+
writeFileSyncIfChanged(`../../docs/fern/openapi/${audience}.yaml`, openAPISchema);
3737

3838
const webhookOpenAPISchema = yaml.stringify(parseWebhookOpenAPI({
3939
webhooks: webhookEvents,
4040
}));
41-
fs.writeFileSync(`../../docs/fern/openapi/webhooks.yaml`, webhookOpenAPISchema);
41+
writeFileSyncIfChanged(`../../docs/fern/openapi/webhooks.yaml`, webhookOpenAPISchema);
4242
}
4343
console.log("Successfully updated docs schemas");
4444
}

packages/stack-shared/src/utils/fs.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ export async function listRecursively(p: string, options: { excludeDirectories?:
2121
}))).flat(),
2222
];
2323
}
24+
25+
export function writeFileSyncIfChanged(path: string, content: string): void {
26+
if (stackFs.existsSync(path)) {
27+
const existingContent = stackFs.readFileSync(path, "utf-8");
28+
if (existingContent === content) {
29+
return;
30+
}
31+
}
32+
stackFs.writeFileSync(path, content);
33+
}

packages/template/scripts/merge-quetzal-translations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { writeFileSyncIfChanged } from "@stackframe/stack-shared/dist/utils/fs";
12
import { deindent, stringCompare } from "@stackframe/stack-shared/dist/utils/strings";
23
import * as fs from "fs";
34
import * as path from "path";
@@ -34,7 +35,7 @@ async function main() {
3435
}
3536
}
3637

37-
fs.writeFileSync("src/generated/quetzal-translations.ts", deindent`
38+
writeFileSyncIfChanged("src/generated/quetzal-translations.ts", deindent`
3839
// THIS FILE IS AUTO-GENERATED BY THE \`merge-quetzal-translations.ts\` SCRIPT.
3940
// DO NOT EDIT IT BY HAND.
4041

packages/template/scripts/process-css.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { writeFileSyncIfChanged } from '@stackframe/stack-shared/dist/utils/fs';
12
import { replaceAll } from '@stackframe/stack-shared/dist/utils/strings';
23
import autoprefixer from 'autoprefixer';
34
import * as fs from 'fs';
@@ -45,12 +46,12 @@ async function main() {
4546
}
4647

4748
// output css file for debugging
48-
fs.writeFileSync(outputPath.replace(/\.ts$/, '.css'), content);
49+
writeFileSyncIfChanged(outputPath.replace(/\.ts$/, '.css'), content);
4950

5051
content = JSON.stringify(content);
5152
content = `export const globalCSS = ${content};\n`;
5253

53-
fs.writeFileSync(outputPath, content);
54+
writeFileSyncIfChanged(outputPath, content);
5455

5556
}
5657

scripts/generate-from-template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file needs to run without any dependencies.
2+
13
import fs from "fs";
24
import path from "path";
35

@@ -448,8 +450,6 @@ function writeFileSyncIfChanged(path: string, content: string): void {
448450
fs.writeFileSync(path, content);
449451
}
450452

451-
452-
453453
// Copy package-template.json to package.json and apply macros
454454
const packageTemplateContent = fs.readFileSync(path.join(srcDir, 'package-template.json'), 'utf-8');
455455
const processedPackageJson = processMacros(packageTemplateContent, allEnvs);

0 commit comments

Comments
 (0)