Skip to content

Commit

Permalink
Allowed setting path aliases to reduce relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Sep 1, 2018
1 parent ed1e0ca commit 619614f
Show file tree
Hide file tree
Showing 40 changed files with 391 additions and 78 deletions.
31 changes: 31 additions & 0 deletions lib/postbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from 'path';
import replace from 'replace-in-file';

import tsconfig from '../../tsconfig.json';

const pathAliases = tsconfig.compilerOptions.paths;

const from = Object.keys(pathAliases).map(key =>
new RegExp(`${key.split('/*')[0]}/[^"]*`, 'g')
);

const to: { [index: string]: string } = {};
for (const [key, value] of Object.entries(pathAliases)) {
const match = key.split('/*')[0];
const replacement = value[0].split('/*')[0];
to[match] = replacement;
}

const options = {
files: ['dist/**/*.js'],
from: from,
to: (...args: Array<string>) => {
const [match, _, __, filename] = args;
const [replacePattern, ...file] = match.split('/');

return path.relative(path.join(process.cwd(), path.dirname(filename)),
path.join(process.cwd(), 'dist', to[replacePattern], ...file));
}
};

replace.sync(options);
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"discord.js": "^11.4.2",
"i18n": "^0.8.3",
"lowdb": "^1.0.0",
"node-opus": "^0.3.0"
"node-opus": "^0.3.0",
"replace-in-file": "^3.4.2"
},
"optionalDependencies": {
"erlpack": "discordapp/erlpack",
Expand All @@ -46,11 +47,13 @@
},
"scripts": {
"clean": "rm -rf dist",
"build": "tsc -p tsconfig.json",
"compile": "tsc -p tsconfig.json",
"build": "npm run compile",
"lint": "tslint -p tsconfig.json",
"serve": "node dist/main.js",
"postcompile": "node dist/lib/postbuild.js",
"serve": "node dist/src/main.js",
"start": "npm run build && npm run serve",
"rebuild": "npm run clean && npm run start",
"rebuild": "npm run clean && npm run build",
"release": "npm run build && npm run lint"
}
}
4 changes: 2 additions & 2 deletions src/bot/MessageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Message } from 'discord.js';
import '../discord/Message';

import config from '../../config/config.json';
import config from '@config/config.json';

import DatabaseAdapter from '../util/db/DatabaseAdapter';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import CommandCollection from './CommandCollection';

export default class MessageHandler {
Expand Down
4 changes: 2 additions & 2 deletions src/bot/SoundBot.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Discord from 'discord.js';

import config from '../../config/config.json';
import config from '@config/config.json';

import LocaleService from '../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import CommandCollection from './CommandCollection';
import MessageHandler from './MessageHandler';

Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/AvatarCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ClientUser, Message, Permissions } from 'discord.js';

import config from '../../../config/config.json';
import config from '@config/config.json';

import IUserCommand from './base/IUserCommand';

import LocaleService from '../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class AvatarCommand implements IUserCommand {
public readonly TRIGGERS = ['avatar'];
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/DownloadCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Attachment, Message } from 'discord.js';

import ICommand from './base/ICommand';

import SoundUtil from '../../util/SoundUtil';
import SoundUtil from '@util/SoundUtil';

export default class DownloadCommand implements ICommand {
public readonly TRIGGERS = ['download'];
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/HelpCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Message } from 'discord.js';

import config from '../../../config/config.json';
import config from '@config/config.json';

import ICommand from './base/ICommand';

import LocaleService from '../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class HelpCommand implements ICommand {
public readonly TRIGGERS = ['commands', 'help'];
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/IgnoreCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Message, Permissions } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import UserFinder from './helpers/UserFinder';

export default class IgnoreCommand implements ICommand {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/LastAddedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import SoundUtil from '../../util/SoundUtil';
import SoundUtil from '@util/SoundUtil';

export default class LastAddedCommand implements ICommand {
public readonly TRIGGERS = ['lastadded'];
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/MostPlayedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import Sound from '../../util/db/models/Sound';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import Sound from '@util/db/models/Sound';

export default class MostPlayedCommand implements ICommand {
public readonly TRIGGERS = ['mostplayed'];
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/RandomCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import QueueItem from '../../util/queue/QueueItem';
import SoundQueue from '../../util/queue/SoundQueue';
import SoundUtil from '../../util/SoundUtil';
import QueueItem from '@util/queue/QueueItem';
import SoundQueue from '@util/queue/SoundQueue';
import SoundUtil from '@util/SoundUtil';
import VoiceChannelFinder from './helpers/VoiceChannelFinder';

export default class RandomCommand implements ICommand {
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/RemoveCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Message, Permissions } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import SoundUtil from '../../util/SoundUtil';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';

export default class RemoveCommand implements ICommand {
public readonly TRIGGERS = ['remove'];
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/RenameCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Message, Permissions } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import SoundUtil from '../../util/SoundUtil';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';

export default class RenameCommand implements ICommand {
public readonly TRIGGERS = ['rename'];
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/SearchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import SoundUtil from '../../util/SoundUtil';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';

export default class SearchCommand implements ICommand {
public readonly TRIGGERS = ['search'];
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/SoundCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import QueueItem from '../../util/queue/QueueItem';
import SoundQueue from '../../util/queue/SoundQueue';
import SoundUtil from '../../util/SoundUtil';
import QueueItem from '@util/queue/QueueItem';
import SoundQueue from '@util/queue/SoundQueue';
import SoundUtil from '@util/SoundUtil';
import VoiceChannelFinder from './helpers/VoiceChannelFinder';

export default class SoundCommand implements ICommand {
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/SoundsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Message } from 'discord.js';

import config from '../../../config/config.json';
import config from '@config/config.json';

import ICommand from './base/ICommand';

import LocaleService from '../../util/i18n/LocaleService';
import SoundUtil from '../../util/SoundUtil';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';
import MessageChunker from './helpers/MessageChunker';

export default class SoundsCommand implements ICommand {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/StopCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import SoundQueue from '../../util/queue/SoundQueue';
import SoundQueue from '@util/queue/SoundQueue';

export default class StopCommand implements ICommand {
public readonly TRIGGERS = ['leave', 'stop'];
Expand Down
6 changes: 3 additions & 3 deletions src/bot/commands/TagCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Message, Permissions } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import SoundUtil from '../../util/SoundUtil';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';

export default class TagCommand implements ICommand {
public readonly TRIGGERS = ['tag'];
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/TagsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Message } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import SoundUtil from '../../util/SoundUtil';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import SoundUtil from '@util/SoundUtil';
import MessageChunker from './helpers/MessageChunker';

export default class TagsCommand implements ICommand {
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/UnignoreCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Message, Permissions } from 'discord.js';

import ICommand from './base/ICommand';

import DatabaseAdapter from '../../util/db/DatabaseAdapter';
import LocaleService from '../../util/i18n/LocaleService';
import DatabaseAdapter from '@util/db/DatabaseAdapter';
import LocaleService from '@util/i18n/LocaleService';
import UserFinder from './helpers/UserFinder';

export default class UnignoreCommand implements ICommand {
Expand Down
4 changes: 2 additions & 2 deletions src/bot/commands/WelcomeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Message } from 'discord.js';

import config from '../../../config/config.json';
import config from '@config/config.json';

import ICommand from './base/ICommand';

import LocaleService from '../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class WelcomeCommand implements ICommand {
public readonly TRIGGERS = ['welcome'];
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/helpers/MessageChunker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LocaleService from '../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class MessageChunker {
private readonly MAX_MESSAGE_LENGTH = 2000;
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/helpers/UserFinder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from 'discord.js';

import LocaleService from '../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class UserFinder {
private readonly localeService: LocaleService;
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/helpers/VoiceChannelFinder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from 'discord.js';

import LocaleService from '../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';

export default class VoiceChannelFinder {
private readonly localeService: LocaleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import { IncomingMessage } from 'http';
import https from 'https';

import LocaleService from '../../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import BaseDownloader from './BaseDownloader';
import AttachmentValidator from './validator/AttachmentValidator';

Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/helpers/downloader/BaseDownloader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from 'discord.js';

import LocaleService from '../../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import BaseValidator from './validator/BaseValidator';

export default abstract class BaseDownloader {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/helpers/downloader/YoutubeDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ffmpeg from 'fluent-ffmpeg';
import fs from 'fs';
import ytdl from 'ytdl-core';

import LocaleService from '../../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import BaseDownloader from './BaseDownloader';
import YoutubeValidator from './validator/YoutubeValidator';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MessageAttachment } from 'discord.js';

import config from '../../../../../../config/config.json';
import config from '@config/config.json';

import LocaleService from '../../../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import BaseValidator from './BaseValidator';

export default class AttachmentValidator extends BaseValidator {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LocaleService from '../../../../../util/i18n/LocaleService';
import SoundUtil from '../../../../../util/SoundUtil';
import LocaleService from '@util/i18n/LocaleService';
import SoundUtil from '@util/SoundUtil';

export default abstract class BaseValidator {
protected readonly localeService: LocaleService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import URL from 'url';

import LocaleService from '../../../../../util/i18n/LocaleService';
import LocaleService from '@util/i18n/LocaleService';
import BaseValidator from './BaseValidator';

export default class YoutubeValidator extends BaseValidator {
Expand Down
13 changes: 5 additions & 8 deletions src/di/DependencyGraph.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* tslint:disable no-consecutive-blank-lines */

import * as awilix from 'awilix';

import DatabaseAdapter from '@util/db/DatabaseAdapter';
import i18n from '@util/i18n/i18n';
import LocaleService from '@util/i18n/LocaleService';
import SoundQueue from '@util/queue/SoundQueue';
import CommandCollection from '../bot/CommandCollection';
import DatabaseAdapter from '../util/db/DatabaseAdapter';
import i18n from '../util/i18n/i18n';
import LocaleService from '../util/i18n/LocaleService';
import SoundQueue from '../util/queue/SoundQueue';


const container = awilix.createContainer({
injectionMode: awilix.InjectionMode.CLASSIC
Expand All @@ -24,7 +21,7 @@ container.register({
container.loadModules([
'bot/**/*.js'
], {
cwd: 'dist/',
cwd: 'dist/src/',
formatName: 'camelCase',
resolverOptions: {
lifetime: awilix.Lifetime.SINGLETON,
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import config from '../config/config.json';
import config from '@config/config.json';

import container from './di/DependencyGraph';

import LocaleService from '@util/i18n/LocaleService';
import SoundBot from './bot/SoundBot';
import LocaleService from './util/i18n/LocaleService';

const localeService = container.cradle.localeService as LocaleService;
localeService.setLocale(config.language);
Expand Down
Loading

0 comments on commit 619614f

Please sign in to comment.