|
| 1 | +# style-parser |
| 2 | + |
| 3 | +> This project was create with [create-expression-lib](https://github.com/motiondeveloper/create-expression-lib) |
| 4 | +
|
| 5 | +## Use the library |
| 6 | + |
| 7 | +1. Download the latest version from the releases page. |
| 8 | +2. Import into After Effects and reference in your expressions |
| 9 | + |
| 10 | +Learn more about writing `.jsx` files for After Effects here: https://motiondeveloper.com/blog/write-expressions-external-files/ |
| 11 | + |
| 12 | +## Development |
| 13 | + |
| 14 | +1. **Clone project locally** |
| 15 | + |
| 16 | + ```sh |
| 17 | + git clone repoUrl.git |
| 18 | + cd style-parser |
| 19 | + ``` |
| 20 | + |
| 21 | +2. **Start Rollup** |
| 22 | + |
| 23 | + Start Rollup in watch mode to automatically refresh your code as you make changes, by running: |
| 24 | + |
| 25 | + ```sh |
| 26 | + npm run watch |
| 27 | + ``` |
| 28 | + |
| 29 | + _You can run also run a once off build:_ `npm run build` |
| 30 | + |
| 31 | +3. **Edit the `src` files** |
| 32 | + |
| 33 | + _The `index.ts` contains an example expression setup._ |
| 34 | + |
| 35 | + Any values exported from this file will be included in your library, for example: |
| 36 | + |
| 37 | + ```js |
| 38 | + export { someValue }; |
| 39 | + ``` |
| 40 | + |
| 41 | +4. **Import the `dist` file into After Effects** |
| 42 | + |
| 43 | + Use the compiled output file as you would any other `.jsx` library. Any changes to the `src` files will be live updated, and After Effects will update the result of your expression. |
| 44 | + |
| 45 | +5. **Distribute releases** |
| 46 | + |
| 47 | + To distribute your output file using Github releases (via [Hub](https://github.com/github/hub)), use the command: |
| 48 | + |
| 49 | + ```sh |
| 50 | + npm run release |
| 51 | + ``` |
| 52 | + |
| 53 | + This will use the GitHub CLI to create a new tag and release |
| 54 | + |
| 55 | + The release version number is the `"version"` in `package.json`, and it will attach the `"main"` file to the release. |
| 56 | + |
| 57 | + > You can add this version to the output file by placing the string `_npmVersion` in your code, which will be replaced with the version number in `package.json` at build time. |
| 58 | +
|
| 59 | +## After Effects API |
| 60 | + |
| 61 | +> This template uses the [`expression-globals-typescript`](https://github.com/motiondeveloper/expression-globals-typescript) package to provide types for the expressions API. |
| 62 | +
|
| 63 | +### Classes |
| 64 | + |
| 65 | +To create layers, compositions and properties, you can use the classes exported from the library. For example: |
| 66 | + |
| 67 | +```ts |
| 68 | +import { Comp, Layer } from 'expression-globals-typescript'; |
| 69 | +const thisComp = new Comp(); |
| 70 | +const thisLayer = new Layer(); |
| 71 | +``` |
| 72 | + |
| 73 | +To create properties (such as position or scale), you can use the `Property` class. |
| 74 | + |
| 75 | +```ts |
| 76 | +import { Property, Vector } from 'expression-globals-typescript'; |
| 77 | +const thisProperty = new Property<Vector>([0, 100]); |
| 78 | +``` |
| 79 | + |
| 80 | +> The `Property` constructor takes a value to set as the property value, and a type (`<>`) to set as the type for the property. |
| 81 | +
|
| 82 | +### After Effects Types |
| 83 | + |
| 84 | +You can import After Effect's specific types such as `Color` and `Vector` from the package to properly type your expressions. |
| 85 | + |
| 86 | +#### _To see all the Types and Base Objects available, see the [`expression-globals-typescript`](https://github.com/motiondeveloper/expression-globals-typescript) source code._ |
| 87 | + |
| 88 | +## Testing |
| 89 | + |
| 90 | +You can test your expression library code using [Jest](https://jestjs.io/), which comes pre-configured in this template repo. |
| 91 | + |
| 92 | +You write tests in the `index.test.ts` file, importing the code you want to test from `index.ts`, for example: |
| 93 | + |
| 94 | +```ts |
| 95 | +import { welcome } from './index'; |
| 96 | + |
| 97 | +test('returns correct welcome string', () => { |
| 98 | + expect(welcome('test')).toEqual('Welcome test!'); |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | +And then run the test suite: |
| 103 | + |
| 104 | +```sh |
| 105 | +npm run test |
| 106 | +``` |
| 107 | + |
| 108 | +Which will run Jest in watch mode. |
| 109 | + |
| 110 | +> You can learn more about testing using Jest from the [Jest docs](https://jestjs.io/docs/en/getting-started). |
| 111 | +
|
| 112 | +## Configuration |
| 113 | + |
| 114 | +There a couple of files you may wish to change to reflect the content of your project: |
| 115 | + |
| 116 | +- `package.json`: |
| 117 | + - `version`: The current version of the library, which is used for releases and added to `dist` files. |
| 118 | + - `main`: The build output file which will be attached to releases |
| 119 | +- `rollup.config.js`: |
| 120 | + - `input`: The source file to be built |
| 121 | + - `typescript()`: Custom typescript compiler options |
| 122 | + |
| 123 | +## How |
| 124 | + |
| 125 | +- [expression-globals-typescript](https://github.com/motiondeveloper/expression-globals-typescript) mocks the After Effects expressions API in typescript, so you can use global functions and objects such as `linear()` and `time`, while also providing expression specific types such as `Layer`. |
| 126 | + |
| 127 | +- [Rollup](https://rollupjs.org/) is a lightweight module bundler that handles outputting the `.jsx` file via the plugins below. |
| 128 | + |
| 129 | +- The Rollup [Typescript plugin](https://www.npmjs.com/package/@rollup/plugin-typescript) runs the TypeScript compiler |
| 130 | + |
| 131 | +- The Rollup plugin [rollup-plugin-ae-jsx](https://www.npmjs.com/package/rollup-plugin-ae-jsx) transforms the JavaScript output into After Effects JSON (`.jsx`) compliant syntax |
| 132 | + |
| 133 | +- Testing via [Jest](https://jestjs.io/), and [ts-jest](https://github.com/kulshekhar/ts-jest) |
0 commit comments