11import { markdownTable } from "https://esm.sh/markdown-table@3" ;
22import { VscSnippet , VscSnippetDict , XSnippetDict } from "../models/app.ts" ;
3+ import { ensureDirSync } from "https://deno.land/std@0.141.0/fs/ensure_dir.ts" ;
4+
5+ const SYMBOL = "⚡" ;
6+
7+ const code = ( str : string ) => `\`${ str } \`` ;
8+ const replaceSymbol = ( str : string ) => str . replace ( ` ${ SYMBOL } ` , "" ) ;
39
410// only to move current code-snippets to my format
511export const vscToCustom = ( snippets : VscSnippetDict ) : XSnippetDict => {
612 return Object . entries ( snippets ) . reduce ( ( acc , [ name , { prefix, body } ] ) => {
7- acc [ prefix as string ] = { name : name . replace ( ` ⚡` , "" ) , body } ;
13+ acc [ prefix as string ] = { name : replaceSymbol ( name ) , body } ;
814 return acc ;
915 } , { } as XSnippetDict ) ;
1016} ;
1117
1218export const convertToVscSnippet = ( snippets : XSnippetDict ) : VscSnippetDict => {
1319 return Object . entries ( snippets )
1420 . reduce ( ( acc , [ prefix , { name, body } ] ) => {
15- const styledName = `${ name } ⚡ ` ;
21+ const styledName = `${ name } ${ SYMBOL } ` ;
1622 acc [ styledName ] = { prefix, body } as VscSnippet ;
1723 return acc ;
1824 } , { } as VscSnippetDict ) ;
@@ -26,19 +32,18 @@ export const groupSnippets = (dicts: VscSnippetDict[]) => {
2632} ;
2733
2834export const writeSnippetFile = ( name : string , data : VscSnippetDict ) => {
35+ const file = `./dist/${ name } .code-snippets` ; // `deep` doesn't need to exist
36+ ensureDirSync ( "./dist" ) ; // ensures directory (and all parent directories
37+
2938 Deno . writeTextFileSync (
30- `./ ${ name } .code-snippets` ,
39+ file ,
3140 JSON . stringify ( data , null , 2 ) ,
3241 ) ;
3342} ;
3443
3544export const generateMarkdownTable = ( input : VscSnippetDict ) => {
3645 const header = [ "Prefix" , "Description" , "Body" ] ;
3746
38- const symbol = "⚡" ;
39- const replaceSymbol = ( str : string ) => str . replace ( ` ${ symbol } ` , "" ) ;
40- const code = ( str : string ) => `\`${ str } \`` ;
41-
4247 const rows = Object . entries ( input )
4348 . map ( ( [ name , { prefix, body } ] ) => [
4449 code ( prefix as string ) ,
0 commit comments