-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-and-build.ts
46 lines (43 loc) · 1.49 KB
/
sync-and-build.ts
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
import 'dotenv/config';
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';
import { $, within, chalk } from 'zx';
const ROOT_DIR = process.env.ROOT_DIR;
const SyncAndBuild = async () => {
let logs = '';
await within(async () => {
$.verbose = false;
$.cwd = `${ROOT_DIR}/quartz`;
logs += await $`rclone sync -v --exclude "**/.*" "gdrive:Nonsense/Master Tracker" ${ROOT_DIR}/quartz/content`;
logs += await $`npx quartz build`;
});
return logs;
};
const name = 'sync-and-build';
export default {
name,
data: new SlashCommandBuilder()
.setName(name)
.setDescription('Sync and build the Master Tracker website'),
async execute(interaction: CommandInteraction) {
console.log(
chalk.grey(new Date().toLocaleString()),
chalk.yellow(`Sync triggered by ${interaction.user.tag}...`)
);
await interaction.reply('Syncing and building the website...');
try {
const logs = await SyncAndBuild();
console.log(
chalk.gray(new Date().toLocaleString()),
chalk.green('Sync and build complete!')
);
await interaction.editReply(`Sync and build complete! Logs:\n\`\`\`${logs}\n\`\`\`\nGo to https://master-tracker.retrocraft.ca/ to see the changes.`);
} catch (p) {
const logs = `Failure: \n\`\`\`${p}\`\`\` `;
console.log(
chalk.gray(new Date().toLocaleString()),
chalk.red('Sync and build failed!')
);
await interaction.editReply(`Sync and build failed. ${logs}`);
}
},
};