From 87521d440c4e790392d9f53ccf7ee99e1e33e697 Mon Sep 17 00:00:00 2001 From: maelanleborgne Date: Wed, 25 Oct 2023 09:03:37 +0200 Subject: [PATCH] Add documentation (#12) * Add documentation * Add link to doc to README --------- Co-authored-by: Maelan LE BORGNE --- README.md | 3 +- doc/index.rst | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 doc/index.rst diff --git a/README.md b/README.md index 4b81700..ba97f12 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ This bundle allows you to compile TypeScript and use it with Symfony's AssetMapp - Automatically downloads the correct [SWC](https://github.com/swc-project/swc) binary - Adds a ``typescript:build`` command to compile your typescript files +- Automatically compiles your typescript files when you run ``asset-map:compile`` command ## Documentation -Read the documentation at: **#- TODO -#** +Read the documentation at: [doc/index.md](doc/index.rst) ## Credits This bundle was greatly inspired by the [Sass Bundle](https://github.com/SymfonyCasts/sass-bundle) from [SymfonyCasts](https://github.com/SymfonyCasts). diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000..e0cdc81 --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,81 @@ +TypeScript Bundle For Symfony +================= + +This bundle allows you to compile TypeScript and use it with Symfony's AssetMapper Component +(no Node required!). + +- Automatically downloads the correct [SWC](https://github.com/swc-project/swc) binary +- Adds a ``typescript:build`` command to compile your typescript files +- Automatically compiles your typescript files when you run ``asset-map:compile`` command + +Installation +------------ + +Install the bundle: + +.. code-block:: terminal + + $ composer require sensiolabs/typescript-bundle + +Usage +----- + +Start by setting the ``sensiolabs_typescript.source_dir`` option to the list of location where your typescript files are located. + +For instance, if your TypeScript code lives in ``assets/typescript`` directory, with a ``assets/typescript/app.ts`` entrypoint file, you could set the option like this: + +.. code-block:: yaml + # config/packages/asset_mapper.yaml + sensiolabs_typescript: + source_dir: ['%kernel.project_dir%/assets/typescript'] + +Then point your TypeScript files in your templates + +.. code-block:: html+twig + + {# templates/base.html.twig #} + + {% block javascripts %} + + {% endblock %} + + +Then run the command: + +.. code-block:: terminal + + # To compile only the typescript files + $ php bin/console typescript:build + + # To compile ALL your assets + $ php bin/console asset-map:compile + +And that's it! + +How Does it Work? +----------------- + +The first time you run one of the TypeScript commands, the bundle will download the correct SWC binary for your system into the ``var`` directory. + +When you run ``typescript:build``, that binary is used to compile TypeScript files into a ``var/typescript`` directory. Finally, when the contents of ``assets/typescript/app.ts`` is requested, the bundle swaps the contents of that file with the contents of from ``var/typescript/`` directory. + +Configuration +-------------- + +To see the full config from this bundle, run: + +.. code-block:: terminal + + $ php bin/console config:dump sensiolabs_typescript + +The main option is ``source_dir`` option, which defaults to ``[%kernel.project_dir%/assets]``. This is an array of directories that will be compiled. + +Using a different binary +-------------------------- + +This bundle already installed for you the right SWC binary. However, if you already have a SWC binary installed on your machine you can instruct the bundle to use that binary, set the ``binary`` option: + +.. code-block:: yaml + + sensiolabs_typescript: + binary: 'node_modules/.bin/swc'