Update
All of my work to get a fully functioning InDesign CC 2018/2019 CEP panel working is in https://github.com/theasci/cep-boostrap. I was able to successfully get npm packages working in both the client and host portions of the CEP panel and in the Scripts Panel. However, the node and ExtendScript versions are woefully old. See the repo READMEs for more details
Original Question
I have a large collection of scripts in AppleScript, mostly for InDesign CC 2018, that I'm trying to redo in ExtendScript (for portability). With the recent prerelease of the ExtendScript Debugger for Visual Studio Code, I've gotten the stack to work. I am able to log to the console and display alerts using the builtins $.write()
and alert()
through InDesign.
I'd like to use the goodness that is npm packages for heavy lifting but I'm failing to get them to load properly. For instance, I want to load the fairly simple node-logger (compared to winston), but loading all the shims I can find, doesn't seem to work.
Here is an example of my index.jsx
file
// Any attempt to write to a read-only property causes a runtime error.
$.strict = true
// Run this script within the InDesign application
#target indesign
var rootDir = File($.fileName).path;
// Load ExtendScript monkey patches to allow for Node.js related functionality
$.evalFile(rootDir + '/vendor/node_modules/extendscript-es6-shim/index.js'); //loads fine
$.evalFile(rootDir + '/vendor/node_modules/extendscript.prototypes/lib/extendscript.prototypes.js'); //loads fine
$.evalFile(rootDir + '/vendor/es-require/lib/require.js'); //loads fine
$.evalFile(rootDir + '/vendor/node_modules/node-logger/logger.js'); //Error: require is not a function
alert("If you're here, it's working!");
My .vscode/launch.json
looks like this
{
"version": "0.2.0",
"configurations": [
{
"type": "extendscript-debug",
"request": "launch",
"name": "Project name",
"program": "${workspaceFolder}/source/index.jsx",
"targetSpecifier": "indesign-13.064",
"engineName": "main",
}
]
}
As you can see, I'm a bit over my head, since node and npm are new to me. It seems like ExtendScript doesn't have the require functionality it needs to pull in node modules. It also seems like people go the other direction: start in node and then execute ExtendScript.
Questions
- Do people load recent versions of npm packages into ExtendScript? If so, how?
- Should I do this? If not, what's the best way to use npm modules with ExtendScript to automate stuff within Adobe products?
Environment
- Mac OSX El Capitan 10.11.6 (also tried on High Sierra, with same result)
- Visual Studio Code 1.31.1
- ExtendScript Debugger Plugin for VSCode 0.2.4
npm config list
saysuser-agent = "npm/6.5.0 node/v11.9.0 darwin x64"
Thanks in advance for having pity on this poor soul.