Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
/ plug-modules Public archive

Retroactively add reasonable module definition paths to plug.dj.

License

Notifications You must be signed in to change notification settings

extplug/plug-modules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plug-modules

Maps plug.dj defined modules to reasonable names, so you can more easily access internal plug.dj javascript.

Warning - Usage - API - How It Works - License

NPM

Warning!

plug-modules makes it easy to use plug.dj's client-side internals. Remember that plug.dj's internal JavaScript is not meant to be a public API. It changes a lot! Modules that you used yesterday, may not exist tomorrow, so make sure to code very defensively and to fall back gracefully.

Usage

If you're writing an extension for use on plug.dj, the easiest way to use plug-modules is using the require.js loader plugin. First, configure require.js to load plug-modules correctly, and then simply require() the stuff you need:

requirejs.config({
  paths: {
    'plug-modules': 'https://unpkg.com/plug-modules@6'
  }
});

require(['plug-modules!plug/core/Events'], function (Events) {
  Events.trigger('notify', 'icon-plug-dj', 'plug-modules works!');
});

If you don't like require.js, plug-modules is available on npm so you can bundle something yourself:

$ npm install plug-modules

You can then use it as a CommonJS module, or an AMD module, or just as window.plugModules when loaded in a <script> tag.

After loading plug-modules, you can access plug.dj modules like:

var SubClass = plugModules.require('plug/core/Class').extend({
  /* class definition */
});

plugModules.require('plug/core/Events')
  .trigger('notify', 'icon-plug-dj', 'Notification text');

Or make yourself an admin locally: (Fun fact! This will make plug.dj log some more debug info to the console 😄 )

var currentUser = plugModules.require('plug/models/currentUser');
currentUser.set('gRole', 5);

See the Wiki for more examples!

plugModules.require() modules in your browser's developer console or use replug to figure out what the different modules are for, and what you can do with/to them.

API

require.js plugin

plug-modules can be used as a require.js plugin:

require([ 'plug-modules!plug/core/Events' ], function (Events) {
  Events.trigger('notify', 'icon-plug-dj', 'Hello from plug-modules!');
});

plugModules.run()

Initialises plug-modules and computes all the module name mappings. You need to run this before using plugModules.register. It's done for you if you're using the require.js plugin.

plugModules.require(modulename)

Returns a plug.dj module. You can use any of the remapped module names, as well as original (obfuscated) names.

plugModules.register()

Defines all the remapped names on the global require() object, so you can use require() to access modules via the remapped names, too. In general, it's better to use plugModules.require instead.

plugModules.isDefined(modulename)

Checks if a module with the given name has been defined. Accepts both remapped and original module names. Note that a module that actually equals undefined also returns false:

define('module', function () { return undefined })
plugModules.isDefined('module') === false

plugModules.getUnknownModules()

Returns an array of original module names that were not remapped. This is mostly useful for finding more modules to reverse-engineer. Note that this is only useful if you've run all resolvers, otherwise modules that haven't yet been used won't be remapped.

How It Works

plug-modules contains several hundred resolver functions that find different modules by duck-typing. They then associate those modules with a descriptive and readable name each. You can call plugModules.register() to inject all those names back into require.js, so you can use the global require() function on plug.dj. Or better, you can use plugModules.require() if you don't want to contaminate the global module-space.

License

MIT

About

Retroactively add reasonable module definition paths to plug.dj.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published