Skip to content

Commit ea30713

Browse files
committed
Log output when generating
1 parent fec2278 commit ea30713

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (!flags.snippets && !flags.docs) {
1616
console.log("Please specify at least one flag: --snippets or --docs");
1717
} else {
1818
if (flags.snippets) {
19+
console.log("\nGenerating snippets...");
1920
languages.forEach((language) => {
2021
const categorizedVscSnippets = language
2122
.snippetDefinitions.map(
@@ -35,6 +36,7 @@ if (!flags.snippets && !flags.docs) {
3536
// TODO: probably better to make it generate from vsc json
3637
// pass in meta, and snippets converted to vsc format
3738
if (flags.docs) {
39+
console.log("\nGenerating docs...");
3840
const docs = generateDocs(languages);
3941
populateDocsBlock(docs);
4042
}

src/docs-gen/snippets.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,23 @@ export const populateDocsBlock = async (input: string) => {
7878
"g",
7979
);
8080

81+
const file = "./README.md";
8182
const options = {
82-
files: "./README.md",
83+
files: file,
8384
from: regex,
8485
to: docsBlock(input),
8586
};
8687

8788
try {
8889
const results = await replaceInFile(options);
89-
console.log("Replacement results:", results);
90+
const readmeResult = results.find((r) => r.file === file);
91+
92+
if (readmeResult?.hasChanged) {
93+
console.log("✅ README updated");
94+
} else {
95+
console.log("👍 README already up to date");
96+
}
9097
} catch (error) {
91-
console.error("Error occurred:", error);
98+
console.error("Error while updating README:", error);
9299
}
93100
};

src/utils/snippets.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ export const groupSnippets = (dicts: VscSnippetDict[]) => {
1919

2020
export const generateSnippets = (name: string, data: VscSnippetDict) => {
2121
const path = "./dist";
22-
ensureDirSync(path);
23-
const file = `${path}/${name}.code-snippets`;
22+
const fileName = `${name}.code-snippets`;
23+
try {
24+
ensureDirSync(path);
25+
const file = `${path}/${fileName}`;
2426

25-
Deno.writeTextFileSync(
26-
file,
27-
JSON.stringify(data, null, 2),
28-
);
27+
Deno.writeTextFileSync(
28+
file,
29+
JSON.stringify(data, null, 2),
30+
);
31+
32+
console.log(`✅ ${fileName}`);
33+
} catch (error) {
34+
console.log(`❌ ${fileName}`);
35+
console.error(error);
36+
}
2937
};

0 commit comments

Comments
 (0)