npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cep-extendscript-eval-promise

v1.1.0

Published

An interface for CEP panels to run Adobe ExtendScript evals and files with agruments as promises with UMD wrapper for cross-compatability with AMD and node.js require.

Downloads

7

Readme

Summary

An interface for CEP panels to run Adobe ExtendScript evals and files (with arguments!) as promises with cross-compatibility for AMD and node.js require.

Trying to split the difference between too-basic and OMG-features-and-dependencies.

Features

  • Run (eval) ExtendScript files with arguments as promises
  • Mix and match command strings with files into a single call via "evalConcat()"
  • Set ExtendScript's current working directory with "cwd()" (make script includes work again!)
  • Works with node.js require and AMD(probably)
  • Optional logger replacement (defaults to console.log)

Recommended additional modules

Import

NPM

If running Node NPM, you can npm install cep-extendscript-eval-promise to add to your node_modules folder Bonus points for adding to your package.json with npm install cep-extendscript-eval-promise --save

github

Clone or download the repo and copy to your project?

Include

var esp = require("cep-extendscript-eval-promise");

Use:

init()

    /**
     * Initialize with parameters
     * @method
     * @param  {String} [scriptsPath]        root path for scripts, defaults to extension dir
     * @param  {Boolean} [encapsulate=false] Flag to wrap script in its own IIFE scope, defaults true
     * @param  {String} [paramsVarName="params"]      variable name to save parameter obj in
     * @param  {Boolean} [enableLog=false]   Toggle to print logs
     * @param  {Object} [logger]             Replacement logger. Defaults to "console"
     * @param  {CSInterface} [csInterface]   An existing CSInterface object. A new one is made by default.
     * @return {ExtendscriptEvalPromise}      Self for chaining
     */
    esp.init(scriptsPath, encapsulate, paramsVarName, enableLog, logger, csInterface);

enableEncapsulate()

    /**
     * Toggle for enabling script scope encapsulation withing an IIFE
     * @method
     * @param  {Boolean} doEncapsulate Flag to wrap script in its own IIFE scope. Default is true
     * @return {ExtendScriptEvalPromise} Returns self for chaining
     */
    esp.enableEncapsulate(doEncapsulate);

enableLog()

    /**
     * Toggle for enabling log printing
     * @method
     * @param  {Boolean} doEnable Flag to enable. Default is true
     * @return {ExtendScriptEvalPromise} Returns self for chaining
     */
    esp.enableLog(doEnable);

evalScript()

    /**
    * Wrapper for evalScript to jsx context as promise
    * @param {String} command String to send to JSX context for evalScript = function(script, callback)
    * @return {promise} a promise that will resolve later with the result of the eval
    */
    evalScript(command, encapsulate);

evalFile()

    /**
     * Evaluate a file in Extendscript as a promise
     * @method
     * @param  {String} scriptPath  path of script file
     * @param  {Boolean} encapsulate Adds encapsulation IIFE around eval
     * @return {Promise}             Promise for async script resolution
     */
    evalFile(scriptPath, encapsulate);

evalFileWithParams()

    /**
     * Evaluate a file with argument parameters passed as an object in Extendscript as a promise
     * @method
     * @param  {String} scriptPath  path of script file
     * @param  {Object} params  parameters object to pass to script
     *                          var params = {
     *                             "title":"Prompt",
     *                             "text":"Message"
     *                          }
     * @param  {String} paramsVarName optional name for parameter variable definition
     * @param  {Boolean} encapsulate Adds encapsulation IIFE around eval
     * @return {Promise}             Promise for async script resolution
     */
    evalFileWithParams(scriptPath, params, paramsVarName, encapsulate)

evalConcat()

    /**
     * Concatenate files and javascript strings into a single eval in Extendscript as a promise
     * @method
     * @param  {String Array} jsxlist  any combo of files or javascript strings
     * @param  {Boolean} encapsulate Adds encapsulation IIFE around eval
     * @return {Promise}             Promise for async script resolution
     */
    evalConcat( jsxList, encapsulate );

cwd()


    /**
    * Change the global current working directory for scripts (for relative paths and includes)
    * @param {String} inDir String folder path set as the current working directory for scripts
    * @return {promise} a promise that will resolve later with the result of the eval
    */
    cwd(pathToScriptFolder);

#Example

    /** contents of photoshop.jsx
    *
    * if(typeof params == 'object') {
    *     $.writeln(params.log);  
    *     alert(params.message);
    * }
    */

    var myFilePath = csInterface.getSystemPath(SystemPath.EXTENSION)+'/host/photoshop.jsx';
    var params = { log:"Sent alarms...", message:"Alarming!" };

    var esp = require("cep-extendscript-eval-promise");

    esp.enableLog(true);

    esp.evalFileWithParams(myFilePath, params).then(
        function jsxResolve(data){
            console.info('The thing got did.');
            esp.evalScript('alert("This is informative.");');
        },
        function jsxReject(data){
            console.log(data);
            console.error('Failed to do that extendscript thing.');
        }
    );

    esp.evalConcat(['var params = { log:"Sent alarms...", message:"Alarming!" }; ', myFilePath, ' "this string will be passed back cause it is the last thing in the pipe";']).then(
        function jsxResolve(data){
            console.info(data);
            esp.evalScript('alert("This is informative.");');
        },
        function jsxReject(data){
            console.log(data);
            console.error('Failed to do that extendscript thing.');
        }
    );