Giter Club home page Giter Club logo

extender's Introduction

extender

A modern starter for writing Adobe Extendscript

(yes, another one)

Why?

Writing Extendscript (Ecmascript 3) is rather annoying once you're used to modern Javascript. You expect to use array methods and common practices such as .env files, no-nonsense bundling, rebuilding on changes, etc.

Other starters don't actually transform modern Javascript, so you have to write helper functions for your beloved array methods which totally defeats the point of writing modern Javascript. You might polyfill them, but that pollutes the global scope (which is bad for everyone if you found a shitty implementation on Stack Overflow).

Features

  • Modern Javascript with ponyfills (see babel-preset-extendscript)
  • Ecmascript modules for importing and exporting
  • Fast bundling with esbuild (TODO: insert obligatory lightning bolt emoji)
  • Rebundles on file changes
  • Minifies the release version
  • Converts to binary with extendscript-debugger
  • Wraps bundle in an IIFE to avoid global variables
  • Exposes environment variables to Javascript files
  • Includes JSON automatically as a ponyfill
  • Copies static files from /static (with esbuild-copy-static-files)
  • Imports ?text suffixed paths as strings
  • Imports icons as binary strings

Try the example

  1. Duplicate .env.example and remove the .example extension
  2. Run npm install && npm start in your terminal
  3. Run /build/extender.jsx in your Adobe app of choice

Development

npm install && npm start

This will start watching your source files and builds into the build folder.

Release

npm run release

This will bundle, minify and jsxbin your source files into the dist folder.

Environment Variables

All variables are replaced by their values upon bundling.

By default the bundler exposes:

  • DEVMODE when NODE_ENV is development or not,
  • PRODUCT_NAME which is name from package.json,
  • PRODUCT_DISPLAY_NAME which is displayName from package.json and
  • PRODUCT_VERSION which is version from package.json

If you have a .env file it will automatically expose the variables by their name to all Javascript files.

Entrypoints

Every .js file in the root of the source/ folder is considered an entrypoint. Multiple entrypoints will result in multiple scripts being bundled separately, keeping the same name as their entrypoint. If there's a single entrypoint it will be renamed to name from package.json.

Debugging

Press F5 in VSCode to launch the debugger and you will be prompted for the host application. To avoid the prompt set the hostAppSpecifier in launch.json

You can't use breakpoints in your source files, because the Extendscript Debugger doesn't support source maps. Instead, use a debugger statement in your source files or set breakpoints in the bundled file (/build/{PRODUCT_NAME}.jsx).

Import JavaScript as String

To import JavaScript files as strings you can suffix the path with ?text and import them with a custom default name. This is useful when you have snippets that you want to import as strings. Having them as separate files allows you to format and lint them separately, use TypeScript definitions on them, etc. Note that they will be imported as-is and don't get transpiled. This works for any other text based files.

See src/main.js

Import Icons as Binary String

Using icons in scriptUI is easiest when you add them to your source code. To do this you can import the icons directly as .png or .jpg. They are then transformed to a binary string that can be read by File.decode().

See src/main.js

Import Node Modules

You can import Node modules by simply using import xyz from 'xyz'. Note that they can't contain browser or Node APIs. Also note that quite some modern Javascript is not yet ponyfilled by babel-preset-extendscript.

Static Files

The contents of /static will be copied to the outdir whenever you run the bundler. This is useful for icons, readme files, etc. Note that any changes in this folder will not be watched, so you need to run the bundler again or save a change in your source files.

Minification

Only whitespaces are removed and variable names are shortened. The syntax remains intact to avoid Extendscript errors.

Types for Adobe

Types for Adobe is part of the package, so you can simply use triple-slash directives to get the type definitions for your target app. Or create a tsconfig.json to define which types to use in the whole project.

See src/main.js

Typescript

You should even be able to make it work with Typescript if that's your thing.

By the way

You can still write regular old Extendscript without the modern syntax.

extender's People

Contributors

klustre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

extender's Issues

Resulting code is not from Babel

The resulting Babel code is somehow transformed after the plugin ran.

I have been trying to figure out the problem but haven't found the solution yet. The relevant test ternary statement is const a = false ? false ? 1 : 2 : 3. After esbuild-plugin-babel's onLoad is called and the content is transformed, I log the results in the onLoad callback and get var a = false ? (false ? 1 : 2) : 3; for that line—which is good. I also double checked with babel.transform to make sure the extendscript preset works well.

But when I check the final esbuild output file, the brackets disappeared. I am somewhat aware that the plugins for esbuild aren't the last line of bundling process, so it probably modified the babel output and removed the brackets. I am not too familiar with what goes on in esbuild between calling the plugins and writing to output, but it would be helpful if you might know the answer.

See fusepilot/babel-preset-extendscript#15

Possible solution: evanw/esbuild#1010 (comment)

Support Windows

Follow these steps to use Extender on Windows:

  1. After running npm install run npm install cross-env -D
  2. In package.json replace line 11 and 12 with:
    "start": "cross-env NODE_ENV=development npm-run-all build",
    "release": "cross-env NODE_ENV=production run-s build jsxbin",
  3. In scripts/build.js comment out line 22 to 24
  4. In src/main.js replace line 10 with:
    const greetings = [expression]
  5. Run npm start

Object.values(obj) not being compiled

hi, I am very new with es6, why this code not work with extender?

let salaries = {
  "John": 100,
  "Pete": 3100,
  "Mary": 2150
};
function topS (obj) {
  return Object.values(obj).sort((a,b) => b-a)[0];
}
alert(topS(salaries));

reduce() not works

reduce() is compiled, but running with an error message

const array1 = [1, 2, 3, 4];

// 0 + 1 + 2 + 3 + 4
const initialValue = 0;
const sumWithInitial = array1.reduce(
  (previousValue, currentValue) => previousValue + currentValue,
  initialValue
);
alert(array1);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.