Skip to content

Commit 6740385

Browse files
committed
Generate snippets from custom format on
demand, add docs
1 parent 8633827 commit 6740385

30 files changed

+1035
-1119
lines changed

README.md

Lines changed: 246 additions & 258 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "modern-js-snippets",
33
"displayName": "Modern JavaScript Snippets ⚡",
4-
"version": "0.1.0",
4+
"version": "0.2.0",
55
"license": "MIT",
66
"description": "Code snippets for modern JavaScript & TypeScript",
77
"icon": "assets/icon.png",
@@ -39,33 +39,34 @@
3939
"scripts": {
4040
"publish": "vsce package && vsce publish",
4141
"generate": "deno run --allow-write --allow-read src/app.ts",
42-
"docs": "deno run --allow-write --allow-read src/docs-gen.ts"
42+
"generate:table": "deno run --allow-write --allow-read src/app.ts --table --snippets=false",
43+
"generate:all": "deno run --allow-write --allow-read src/app.ts --table --snippets"
4344
},
4445
"contributes": {
4546
"snippets": [
4647
{
4748
"language": "javascript",
48-
"path": "./snippets/js.code-snippets"
49+
"path": "./dist/js.code-snippets"
4950
},
5051
{
5152
"language": "typescript",
52-
"path": "./snippets/js.code-snippets"
53+
"path": "./dist/js.code-snippets"
5354
},
5455
{
5556
"language": "typescriptreact",
56-
"path": "./snippets/js.code-snippets"
57+
"path": "./dist/js.code-snippets"
5758
},
5859
{
5960
"language": "typescriptreact",
60-
"path": "./snippets/js.code-snippets"
61+
"path": "./dist/js.code-snippets"
6162
},
6263
{
6364
"language": "typescript",
64-
"path": "./snippets/ts.code-snippets"
65+
"path": "./dist/ts.code-snippets"
6566
},
6667
{
6768
"language": "typescriptreact",
68-
"path": "./snippets/ts.code-snippets"
69+
"path": "./dist/ts.code-snippets"
6970
}
7071
]
7172
}

src/app.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
import { parse } from "https://deno.land/std@0.168.0/flags/mod.ts";
12
import { variants } from "./snippets/app.ts";
23
import {
34
convertToVscSnippet,
5+
generateSnippetsFile,
46
groupSnippets,
5-
writeSnippetFile,
7+
logTables,
68
} from "./utils/app.ts";
79

8-
variants.forEach((variant) => {
9-
const snippetSections = variant.snippets.map(convertToVscSnippet);
10-
const snippetSingle = groupSnippets(snippetSections);
11-
writeSnippetFile(variant.language.toLowerCase(), snippetSingle);
10+
const flags = parse(Deno.args, {
11+
boolean: ["table", "snippets"],
12+
default: { snippets: true },
1213
});
14+
15+
if (!flags.table && !flags.snippets) {
16+
console.log("Please specify at least one flag: --table or --snippets");
17+
} else {
18+
variants.forEach((variant) => {
19+
const categorizedVscSnippets = variant.snippets.map(convertToVscSnippet);
20+
if (flags.table) {
21+
logTables(variant.label, categorizedVscSnippets);
22+
}
23+
if (flags.snippets) {
24+
const variantVscSnippet = groupSnippets(categorizedVscSnippets);
25+
generateSnippetsFile(variant.extension, variantVscSnippet);
26+
}
27+
});
28+
}

src/docs-gen.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/models/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ export type VscSnippet = {
33
body: string | string[];
44
description?: string;
55
};
6-
// name: { prefix: string | [], body: string | string[], description?: string }
6+
77
export type VscSnippetDict = Record<string, VscSnippet>;
88

99
export type XSnippet = Omit<VscSnippet, "prefix"> & { name: string };
1010

11-
// prefix: { name: string, body: string | string[], description?: string }
1211
export type XSnippetDict = Record<string, XSnippet>;

src/snippets/app.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { typescript } from "./ts/app.ts";
33

44
export const variants = [
55
{
6-
language: "JavaScript",
6+
label: "JavaScript",
7+
language: "javascript",
8+
extension: "js",
79
snippets: javascript,
810
},
911
{
10-
language: "TypeScript",
12+
label: "TypeScript",
13+
language: "typescript",
14+
extension: "ts",
1115
snippets: typescript,
1216
},
1317
];

0 commit comments

Comments
 (0)