-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (49 loc) · 2.06 KB
/
index.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
#!/usr/bin/env node
import chalk from "chalk";
import path from "node:path";
import { cwd } from "node:process";
import { mkdirSync } from "node:fs";
import gradient from "gradient-string";
import figlet from "figlet";
import getQuote from "./quotes.js";
import getDayText from "./dayText.js";
import * as fs from "node:fs";
// getting dayNumber from cli arguments.
const cliArguments = process.argv;
const dayNumber = cliArguments[2];
// exiting if the number is not specified correctly in the cli.
if (!isNumber(dayNumber)) {
console.log(chalk.red("Please enter a number."));
console.log(chalk.blueBright("eg., typecreate 1"));
process.exit(1);
}
// creating directories for all the directory names specified in the cli.
const currentTerminalDirectory = cwd();
const directoriesToCreate = ["dayNUMBER/videos", "dayNUMBER/videos/edited", "dayNUMBER/videos/recorded", "dayNUMBER/videos/recorded/Bubble Text", "dayNUMBER/videos/recorded/Result Screenshot", "dayNUMBER/videos/recorded/Typing"];
const directoryNames = directoriesToCreate.map((directoryName) => directoryName.replace("NUMBER", dayNumber));
directoryNames.forEach(directoryName => {
try {
const directory = path.resolve(currentTerminalDirectory, directoryName);
mkdirSync(directory, { recursive: true });
} catch (error) {
console.log(chalk.red(error.message));
process.exit(1);
}
});
const quoteOfTheDay = getQuote(dayNumber);
const dayText = getDayText(dayNumber);
const subscriptionMessage = "If you enjoy watching these videos, I invite you to subscribe to my channel. It help support my channel's growth. Thank you for your support!";
const completeText = dayText + "\n\n" + quoteOfTheDay + "\n\n" + subscriptionMessage;
try {
fs.writeFileSync(path.resolve("day" + dayNumber, "day" + dayNumber + ".txt"), completeText, 'utf-8');
} catch (error) {
console.log(chalk.red(error.message));
process.exit(1);
}
//displaying a cool done message.
figlet("Done :)", (error, data) => {
console.log(gradient.mind(data));
});
function isNumber(str) {
return !isNaN(parseFloat(str)) && isFinite(str);
}