Neatly Packaged Magic

    @discordx/importer
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.10 • Public • Published

    Discord server NPM version NPM downloads Build status paypal

    Create a discord bot with TypeScript and Decorators!

    📖 Introduction

    You can use this library without discordx

    Support esm and cjs at the same time

    💻 Installation

    Version 16.6.0 or newer of Node.js is required

    npm install @discordx/importer
    yarn add @discordx/importer
    

    Usage

    If you use this code with esm or ejs, it will tell you about your environment.

    import { isESM } from "@discordx/importer";
    
    console.log(`isESM: ${isESM}`);

    Resolve glob paths

    console.log(resolve(`${__dirname}/commands/**.js`));

    Import glob paths

    Here is an example that could be used with the commonjs or esm modules

    Module - CommonJS

    importx(`${__dirname}/commands/**.js`).then(() =>
      console.log("All files imported")
    );

    Module - ESNext

    Remember: In esm, __dirname is not defined, so here is a workaround

    import { dirname, importx } from "@discordx/importer";
    const __dirname = dirname(import.meta.url);
    
    importx(`${__dirname}/commands/**.js`).then(() =>
      console.log("All files imported")
    );

    Combine - CommonJS and ESNext

    If you are creating a module or extension of your own library, you can set it to auto-import paths based on the user module

    import { dirname, importx, isESM } from "@discordx/importer";
    const folder = isESM ? dirname(import.meta.url) : __dirname;
    
    importx(`${folder}/commands/**.js`).then(() =>
      console.log("All files imported")
    );

    Use relative path

    You can use relative path, which will be more convenient to write code by eliminating DIRNAME

    import { importx } from "@discordx/importer";
    
    // relative path start from root folder
    importx("./tests/commands/**.js").then(() => console.log("All files imported"));

    ☎️ Need help?

    Ask in discord server or open a issue

    Thank you

    Show your support for discordx by giving us a star on github.

    Install

    npm i @discordx/importer

    DownloadsWeekly Downloads

    1,820

    Version

    1.1.10

    License

    Apache-2.0

    Unpacked Size

    21.8 kB

    Total Files

    13

    Last publish

    Collaborators

    • iorp