-
Notifications
You must be signed in to change notification settings - Fork 0
/
newlab.js
58 lines (48 loc) · 1.61 KB
/
newlab.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
const readline = require('readline');
const fs = require('fs');
const path = require('path');
const pkg = require('./package.json');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const codelabsDir = './labs';
function createStubFolder(title) {
// Create a web-friendly stub by replacing spaces with hyphens and making it lowercase
return title.toLowerCase().replace(/\s+/g, '-');
}
function createCodelabMd(stubFolder, title, duration, summary) {
const codelabData = `
author: ${pkg.codelab.author}
summary: ${summary}
id: ${stubFolder}
categories: codelab,markdown
environments: Web
status: Published
feedback link: ${pkg.codelab['feedback-url']}
analytics account: ${pkg.codelab['ga-analytics']}
# ${title}
`;
const codelabMdPath = path.join(codelabsDir, stubFolder, 'codelab.md');
fs.writeFile(codelabMdPath, codelabData, (err) => {
if (err) {
console.error('Error writing to codelab.md:', err);
} else {
console.log(`codelab.md created and placed in '${stubFolder}' folder.`);
}
rl.close();
});
}
rl.question('Enter the title of the codelab: ', (title) => {
rl.question('Enter the duration (in minutes): ', (duration) => {
rl.question('Enter a brief summary: ', (summary) => {
const stubFolder = createStubFolder(title);
const codelabFolderPath = path.join(codelabsDir, stubFolder);
// Create the stub folder if it doesn't exist
if (!fs.existsSync(codelabFolderPath)) {
fs.mkdirSync(codelabFolderPath, { recursive: true });
}
createCodelabMd(stubFolder, title, duration, summary);
});
});
});