CommonJS implementation for Photoshop

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

theiviaxx

CommonJS implementation for Photoshop

Post by theiviaxx »

I used some boilerplate code for a CommonJS implementation and fitted it for extendscript. It conforms to CommonJS/Modules 1.0 & 1.1.

https://github.com/theiviaxx/PSLib

To use, include or eval/evalFile require.jsx. This will add a require function to the global namespace. After this, you can simply:

Code: Select allvar api = require('path/to/api');
api.foo();


When writing modules, each module will have access to a few variables:

exports - Object to add your api to
module - Object representing the current module on the require object.
module.exports is the same as exports (CommonJS/Modules 1.0 and 1.1)
require - The global require object
So just add your api to the exports var or module.exports and that's it. You can call require inside your modules. See the tests for some examples.

You can also add paths to search to require.path or set an environment var, PHOTOSHOP_PATH, to search for modules.

Tests are included and the current version passes all but 1: implicitly bound members

I've also included a JSON(crockfords) module and underscore.

Please let me know if you find any bugs or issues while using it.