-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-new-text.js
executable file
·75 lines (66 loc) · 2.14 KB
/
add-new-text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
/**
* Convenience script for adding a new text.
*
* This creates a directory in the root of the repository
* matching the title of the text, and a minimal config.json
* file in that directory based on the optional prompts.
*
* Requires Node.js to be installed.
*/
import { mkdir, writeFile } from 'node:fs'
import path from 'node:path';
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
const rl = readline.createInterface({ input, output });
let title = '';
while (!title) {
title = await rl.question('Title (required): ');
}
const source = await rl.question('Τράπεζα κειμένων URL (optional): ')
const imgExtension = await rl.question('Image Extension (optional): ')
const imgAttribution = await rl.question('Image URL (optional): ')
const level = await rl.question('Level (optional): ');
const speaker = await rl.question('Speaker (optional): ');
const numberOfVocabularyWordsAnswer = await rl.question('Number of vocabulary words (optional): ');
let numberOfVocabularyWords = parseInt(numberOfVocabularyWordsAnswer);
if (!numberOfVocabularyWords) {
numberOfVocabularyWords = 1;
}
const handleError = err => { if (err) throw err };
mkdir(title, { recursive: true }, handleError);
const config = JSON.stringify({
"title": title,
"titleCueId": null,
"speaker": speaker,
"level": level,
"source": source,
"img": {
"ext": imgExtension,
"alt": title,
"attribution": imgAttribution
},
"vocabulary": [...Array(numberOfVocabularyWords)].map(() => (
{
"source": "",
"translation": ""
}
)),
"markup": [
{
"type": "p",
"children": [
{
"type": "cueRange",
"start": "",
"end": ""
}
]
}
]
}, null, 2);
writeFile(path.join(title, 'config.json'), config, 'utf8', handleError);
console.log(`\nCreated ${title}/ directory with config.json\n`);
console.log('Next steps are to add an image, the audio.mp3, and transcript.vtt files to this directory.\n')
console.log('Lastly, add the text to the select element in index.html.\n')
rl.close();