@@ -8,7 +8,7 @@ import { SONGS_FOLDER_PATH } from '../definitions/paths';
8
8
import pushIds from '../util/pushIds' ;
9
9
import { getAllSongPaths } from '../util/songs' ;
10
10
11
- export default function create ( title : string , ...args : string [ ] ) : void {
11
+ export default async function create ( title : string , ...args : string [ ] ) : Promise < void > {
12
12
if ( ! title ) return console . error ( 'A title for the new song must be provided!' ) ;
13
13
const { id, ...parsedArgs } = parseArgs ( args ) ;
14
14
@@ -18,23 +18,23 @@ export default function create(title: string, ...args: string[]): void {
18
18
19
19
if ( id !== undefined ) pushIds ( id ) ;
20
20
21
- writeFileSync ( join ( SONGS_FOLDER_PATH , newTitle ) , newContent ) ;
21
+ writeFileSync ( join ( SONGS_FOLDER_PATH , newTitle ) , await newContent ) ;
22
22
}
23
23
24
24
function nextId ( ) : number {
25
25
return getAllSongPaths ( ) . length ;
26
26
}
27
27
28
- function generateDefaultSongFileContent (
28
+ async function generateDefaultSongFileContent (
29
29
title : string ,
30
30
{
31
31
author,
32
32
melody,
33
33
composer,
34
34
tags = [ ] ,
35
35
content,
36
- } : Omit < Song , 'id' | 'title' | 'deleted' | 'content' > & { content ?: string }
37
- ) : string {
36
+ } : Omit < Song , 'id' | 'title' | 'deleted' | 'content' > & { content ?: string } ,
37
+ ) : Promise < string > {
38
38
let contentBuilder = `---\ntitle: ${ title } \n` ;
39
39
contentBuilder += `author: ${ author || '' } \n` ;
40
40
contentBuilder += `melody: ${ melody || '' } \n` ;
@@ -43,11 +43,11 @@ function generateDefaultSongFileContent(
43
43
contentBuilder += '---\n' ;
44
44
if ( content ) contentBuilder += content ;
45
45
46
- return format ( contentBuilder , { parser : 'markdown' } ) ;
46
+ return await format ( contentBuilder , { parser : 'markdown' } ) ;
47
47
}
48
48
49
49
function parseArgs (
50
- args : string [ ]
50
+ args : string [ ] ,
51
51
) : Partial < Omit < Song , 'title' | 'deleted' | 'tags' > > & { tags : Tag [ ] } {
52
52
const [ idString ] = getArgValues ( args , 'id' ) ;
53
53
const [ author ] = getArgValues ( args , 'author' ) ;
0 commit comments