|
1 | 1 | # @liferay/cli |
2 | 2 |
|
3 | | -This project hosts the Liferay JS Toolkit CLI Tool |
| 3 | +This project hosts the Liferay JS Toolkit CLI Tool. |
| 4 | + |
| 5 | +Inspired by other frameworks, like React, Angular, or Vue.js, the Liferay JS |
| 6 | +Toolkit is providing a unifying CLI tool to invoke all implemented features, |
| 7 | +like project generation, build, deployment, etc. |
| 8 | + |
| 9 | +> 👀 Note that this tool still uses the JS Toolkit under the hood, so please |
| 10 | +> refer to |
| 11 | +> [its documentation](https://github.com/liferay/liferay-frontend-projects/blob/master/maintenance/projects/js-toolkit/docs/README.md) |
| 12 | +> for more details on configuration and behavior. |
| 13 | +
|
| 14 | +## Installation |
| 15 | + |
| 16 | +The `@liferay/cli` tool may be installed globally using `npm install -g` or |
| 17 | +`yarn global add`, to make it available from the command line. |
| 18 | + |
| 19 | +However, if you don't want to mess with global installations, you can also run |
| 20 | +it using `npx`. This ensures that you always use the latest version, and won't |
| 21 | +install it locally. |
| 22 | + |
| 23 | +So, to run it, just type `npx @liferay/cli ...` in your command line and you are |
| 24 | +good to go. |
| 25 | + |
| 26 | +Alternatively, if you decide to install it globally, simple invoke `liferay` |
| 27 | +from the command line, which is the name of the |
| 28 | +[binary provided by `@liferay/cli`](https://github.com/liferay/liferay-frontend-projects/blob/master/projects/js-toolkit/packages/liferay-cli/bin/liferay.js). |
| 29 | + |
| 30 | +## Available actions |
| 31 | + |
| 32 | +Currently, the `@liferay/cli` tool supports the following features: |
| 33 | + |
| 34 | +- [Project generation](#project-generation) |
| 35 | +- [Project adaptation](#project-adaptation) |
| 36 | +- [Project build](#project-build) |
| 37 | +- [Project deployment](#project-deployment) |
| 38 | +- [Project clean](#project-clean) |
| 39 | + |
| 40 | +## Project generation |
| 41 | + |
| 42 | +Project generation lets you create new projects for the main existing |
| 43 | +frameworks: |
| 44 | + |
| 45 | +- [React](https://reactjs.org/) |
| 46 | +- [Angular](https://angular.io/) |
| 47 | +- [Vue.js](https://vuejs.org/) |
| 48 | + |
| 49 | +We try to always support the latest version of these frameworks but, given the |
| 50 | +fast pace at which they evolve, there may be some lag between the time when a |
| 51 | +framework's version is published and the time `@liferay/cli` supports it. |
| 52 | + |
| 53 | +> 👀 This feature is a replacement of the |
| 54 | +> [older Yeoman Liferay JavaScript generator](https://github.com/liferay/liferay-frontend-projects/tree/master/maintenance/projects/js-toolkit/packages/generator-liferay-js) |
| 55 | +> but it doesn't rely on Yeoman any more. |
| 56 | +
|
| 57 | +### Usage |
| 58 | + |
| 59 | +```sh |
| 60 | +$ liferay new my-project ↩ |
| 61 | +``` |
| 62 | + |
| 63 | +The above command will start a wizard that will generate a project called |
| 64 | +`my-project` in the current folder. Simply answer the questions you are asked, |
| 65 | +and let the generator do its duties. |
| 66 | + |
| 67 | +Once the project is created, you may change to its folder and run |
| 68 | +`npm|yarn install` to install the dependencies, then invoke the supported |
| 69 | +actions (like `build`, `deploy`, etc.) with `npm|yarn run <command>`. |
| 70 | + |
| 71 | +#### Target platform |
| 72 | + |
| 73 | +One of the key questions in the wizard is related to the platform you wish to |
| 74 | +target. A target platform defines: |
| 75 | + |
| 76 | +- The set of rules to build the project |
| 77 | +- The default dependencies of the project |
| 78 | + |
| 79 | +So, for example, when using |
| 80 | +[`portal-7.4-ga1`](https://github.com/liferay/liferay-frontend-projects/tree/master/target-platforms/packages/portal-7.4-ga1) |
| 81 | +you are saying that your project will be deployed to Liferay Portal CE 7.4 GA1 |
| 82 | +and thus your project will have access to |
| 83 | +[any JavaScript API available in that version](https://github.com/liferay/liferay-frontend-projects/blob/master/target-platforms/packages/portal-7.4-ga1/config.json#L21-L171) |
| 84 | +(for instance, if you use React, the copy of `react` that comes bundled with |
| 85 | +Liferay Portal will be used in your project, instead of referring to a new one, |
| 86 | +local to the project). |
| 87 | + |
| 88 | +Note that, if you don't want to couple your project to any version of |
| 89 | +Liferay Portal, you may choose to use the |
| 90 | +[`portal-agnostic`](https://github.com/liferay/liferay-frontend-projects/tree/master/target-platforms/packages/portal-agnostic) |
| 91 | +target platform. Choosing that platform your project will not be injected any of |
| 92 | +the packages that come bundled with Liferay Portal. |
| 93 | + |
| 94 | +## Project adaptation |
| 95 | + |
| 96 | +Project adaptation lets you transform you native React, Angular and Vue.js |
| 97 | +projects into Liferay widgets that you can deploy to your Liferay Portal |
| 98 | +instance. |
| 99 | + |
| 100 | +We try to always support the latest version of the three frameworks mentioned |
| 101 | +above but, given the fast pace at which they evolve, there may be some lag |
| 102 | +between the time when a framework's version is published and the time |
| 103 | +`@liferay/cli` supports it. |
| 104 | + |
| 105 | +> 👀 This feature is a replacement of the |
| 106 | +> [older Yeoman Liferay JavaScript generator](https://github.com/liferay/liferay-frontend-projects/tree/master/maintenance/projects/js-toolkit/packages/generator-liferay-js) |
| 107 | +> but it doesn't rely on Yeoman any more. |
| 108 | +> |
| 109 | +> Also note that adaptation is a best effort heuristic process so don't expect |
| 110 | +> every native framework functionality to work when a project is adapted. |
| 111 | +> |
| 112 | +> This is mainly due to the fact that there's some mismatch between these |
| 113 | +> frameworks' application model (they assume a SPA deployed as a single webapp) |
| 114 | +> and the one of Liferay, that assumes that many unrelated portlets cooperate |
| 115 | +> together to produce a single HTML page. |
| 116 | +
|
| 117 | +### Usage |
| 118 | + |
| 119 | +In your native project's directory run: |
| 120 | + |
| 121 | +```sh |
| 122 | +$ liferay adapt ↩ |
| 123 | +``` |
| 124 | + |
| 125 | +The above command will start a wizard that will adapt your project to be |
| 126 | +deployable to Liferay portal. |
| 127 | + |
| 128 | +Once the project is adapted you may use the `build:liferay`, `deploy:liferay`, |
| 129 | +`clean:liferay`, etc. tasks to perform the same tasks you would do for a true |
| 130 | +Liferay project (ie: one that had been generated with `liferay new`). |
| 131 | + |
| 132 | +Learn more about project adaptation in |
| 133 | +[JS Toolkit's documentation on adaptation](https://github.com/liferay/liferay-frontend-projects/blob/master/maintenance/projects/js-toolkit/docs/How-to-adapt-most-popular-frameworks-projects.md#supported-projects). |
| 134 | + |
| 135 | +## Project build |
| 136 | + |
| 137 | +The `build` command will build your project and leave the resulting JAR file in |
| 138 | +the `dist` directory. You may then deploy it to a Liferay Portal instance |
| 139 | +copying the file by hand, or using the [Liferay deployment](#project-deployment) |
| 140 | +feature. |
| 141 | + |
| 142 | +### Usage |
| 143 | + |
| 144 | +```sh |
| 145 | +$ liferay build ↩ |
| 146 | + |
| 147 | +# or |
| 148 | + |
| 149 | +$ npm run build ↩ |
| 150 | + |
| 151 | +# or |
| 152 | + |
| 153 | +$ yarn build ↩ |
| 154 | +``` |
| 155 | + |
| 156 | +Note that `npm|yarn run build` is an alias to `liferay build` (you can see that |
| 157 | +by inspecting your project's `package.json` file). |
| 158 | + |
| 159 | +## Project deployment |
| 160 | + |
| 161 | +The `deploy` command will copy the JAR file created by the |
| 162 | +[project build](#project-build), in the `dist` directory, to your local Liferay |
| 163 | +Portal instance. |
| 164 | + |
| 165 | +The first time you run this task it will ask you for your Liferay Portal |
| 166 | +directory and store your answer in a `.liferay.json` file in your project for |
| 167 | +subsequent runs. |
| 168 | + |
| 169 | +### Usage |
| 170 | + |
| 171 | +```sh |
| 172 | +$ liferay deploy ↩ |
| 173 | + |
| 174 | +# or |
| 175 | + |
| 176 | +$ npm run deploy ↩ |
| 177 | + |
| 178 | +# or |
| 179 | + |
| 180 | +$ yarn deploy ↩ |
| 181 | +``` |
| 182 | + |
| 183 | +Note that `npm|yarn run deploy` is an alias to `liferay deploy` (you can see |
| 184 | +that by inspecting your project's `package.json` file). |
| 185 | + |
| 186 | +## Project clean |
| 187 | + |
| 188 | +The `clean` command will delete the `build` and `dist` directories created by |
| 189 | +[project build](#project-build) and [project deployment](#project-deployment) |
| 190 | +tasks. |
| 191 | + |
| 192 | +### Usage |
| 193 | + |
| 194 | +```sh |
| 195 | +$ liferay clean ↩ |
| 196 | + |
| 197 | +# or |
| 198 | + |
| 199 | +$ npm run clean ↩ |
| 200 | + |
| 201 | +# or |
| 202 | + |
| 203 | +$ yarn clean ↩ |
| 204 | +``` |
| 205 | + |
| 206 | +Note that `npm|yarn run clean` is an alias to `liferay clean` (you can see |
| 207 | +that by inspecting your project's `package.json` file). |
| 208 | + |
| 209 | +## Internal architecture |
| 210 | + |
| 211 | +The big majority of `@liferay/cli`'s source code is devoted to project |
| 212 | +generation and adaptation, that is what previously was the Yeoman generator of |
| 213 | +JS Toolkit. |
| 214 | + |
| 215 | +The rest of the commands (those used on generated/adapted projects) are simply |
| 216 | +delegated to the selected target platform (see |
| 217 | +[Target platform](#target-platform) above). |
| 218 | + |
| 219 | +That means that, in those cases the `liferay` command is simply a bridge that |
| 220 | +looks inside your project's `node_modules` folder to locate the selected target |
| 221 | +platform and invoke it to do its duties. |
| 222 | + |
| 223 | +This eases maintenance and evolution of `@liferay/cli` because we don't need to |
| 224 | +maintain a huge monolyth of code targeting disparate targets. |
| 225 | + |
| 226 | +To gain more insights on target platforms and what they are intended for, you |
| 227 | +may have a look at |
| 228 | +[their project directory](https://github.com/liferay/liferay-frontend-projects/tree/master/target-platforms). |
0 commit comments