1 | ## Tarima CLI
|
2 |
|
3 | Built on top of [tarima](https://github.com/gextech/tarima) to provide a simple build pipeline with watching support.
|
4 |
|
5 | 1. It can take any amount of files and produce different outputs based on supplied configuration, you can filter out some files, rename different subests, bundle them, etc.
|
6 |
|
7 | 2. Provides a simple hook system to catch-all non supported files, then are piped out to different handlers if they exists.
|
8 |
|
9 | 3. Otherwise, all non supported files are simply copied.
|
10 |
|
11 | It comes with basic dependency tracking, so any change will affect only its dependent sources.
|
12 |
|
13 | ## How it works?
|
14 |
|
15 | The best way is adding tarima as dependency, global or locally, and then setup your `package.json` for using it:
|
16 |
|
17 | ```javascript
|
18 | { // package.json
|
19 | "scripts": {
|
20 | "dev": "tarima -w",
|
21 | "build": "tarima -f"
|
22 | }
|
23 | }
|
24 | ```
|
25 |
|
26 | Now calling `npm run dev` will start in watch-mode and `npm run build` will force a complete rebuild of all sources.
|
27 |
|
28 | The default source directory is `./src` if you need anything else you can provide arguments, e.g. `tarima foo bar` which will produce `{foo,bar}/**/*` as input.
|
29 |
|
30 | Also you can specify this option in your `package.json` file:
|
31 |
|
32 | ```javascript
|
33 | { // package.json
|
34 | "tarima": {
|
35 | "src": "{controllers,models,views}/**/*"
|
36 | }
|
37 | }
|
38 | ```
|
39 |
|
40 | ### Handling sources
|
41 |
|
42 | All files then are read or watch from given directories, any change will trigger a compilation process.
|
43 |
|
44 | This process will transpile the given source file if tarima supports it, if not it will be piped or copied as stated above.
|
45 |
|
46 | Basically you can write `./src/index.md` and obtain `./build/dist/src/index.html` as result.
|
47 |
|
48 | > You'll notice that the source's filepath will be maintained as is, because you can specify multiple source directories and it will be difficult to resolve everything.
|
49 |
|
50 | You can use the `rename` option for cut-off directories from the destination filepath:
|
51 |
|
52 | ```javascript
|
53 | { // package.json
|
54 | "tarima": {
|
55 | "rename": "**:{filepath/1}/{filename}.{extname}"
|
56 | }
|
57 | }
|
58 | ```
|
59 |
|
60 | This will match `./src/index.md` to `./build/dist/index.html` directly.
|
61 |
|
62 | > The `{filepath/1}` expression will split the source's _dirname_ and remove the first directory from its left, e.g. `./dest/src/file.ext` becomes `./dest/file.ext` and such.
|
63 |
|
64 | If you change the `dest` or `public` option you would obtain `./some-directory/index.html`, etc.
|
65 |
|
66 | Tarima will let you organize your source files as your pleasure, and them process them as you expect, to write them finally wherever you want.
|
67 |
|
68 | Not a complete building tool but damn useful for daily work.
|
69 |
|
70 | ### Notifications
|
71 |
|
72 | Tarima will use `node-notifier` to display some feedback about the process.
|
73 |
|
74 | You can customize some values of the notification popup:
|
75 |
|
76 | ```javascript
|
77 | { // package.json
|
78 | "tarima": {
|
79 | "notifications": {
|
80 | "title": "My app",
|
81 | "okIcon": "./success.png",
|
82 | "errIcon": "./failure.png"
|
83 | }
|
84 | }
|
85 | }
|
86 | ```
|
87 |
|
88 | ### Caching support
|
89 |
|
90 | Tarima is efficient by tracking dependencies using a json-file for caching, this way on each startup nothing will be compiled unless they are changes or dirty files.
|
91 |
|
92 | By default the cache is taken from the `dest` directory, but you use a different file specifying the `cacheFile` option:
|
93 |
|
94 | ```javascript
|
95 | { // package.json
|
96 | "tarima": {
|
97 | "cacheFile": "./tarima.cache.json"
|
98 | }
|
99 | }
|
100 | ```
|
101 |
|
102 | ### Bundle support
|
103 |
|
104 | By default all scripts are transpiled only, you must enable the `bundle` option for globally treat each entry-point as bundle.
|
105 |
|
106 | This option can be `true` to enable bundling on all files (filtered), a glob string, or an array of globs.
|
107 |
|
108 | > Files matching the globs will be treated as entry-points, see below.
|
109 |
|
110 | Or locally set the `_bundle` option as front-matter:
|
111 |
|
112 | ```javascript
|
113 | /**
|
114 | ---
|
115 | _bundle: true
|
116 | ---
|
117 | */
|
118 |
|
119 | import { getValue } from './other/script';
|
120 |
|
121 | export default function () {
|
122 | return getValue(...arguments);
|
123 | };
|
124 | ```
|
125 |
|
126 | > When using `_bundle` you don't need to declare it on each imported file, only within the entry-points you want to bundle.
|
127 |
|
128 | Even stylesheets are entry-points by nature:
|
129 |
|
130 | ```less
|
131 | @import 'colors.less';
|
132 |
|
133 | a { color: @link-text-color; }
|
134 | ```
|
135 |
|
136 | So you don't need anything else to bundle stylesheets. ;)
|
137 |
|
138 | ## Ignore sources
|
139 |
|
140 | Ignoring sources will skip all matched files from watching, Tarima will never track them for any purpose.
|
141 |
|
142 | You can use the `ignoreFiles` to provide a glob-based file with patterns to be ignored.
|
143 |
|
144 | Example:
|
145 |
|
146 | ```javascript
|
147 | { // package.json
|
148 | "tarima": {
|
149 | "ignoreFiles": [".gitignore"]
|
150 | }
|
151 | }
|
152 | ```
|
153 |
|
154 | Any `.gitignore` compatible format is supported.
|
155 |
|
156 | ## Filtering sources
|
157 |
|
158 | Filtered sources are watched but not used for any transpilation process, they are ignored because they should be imported from any other entry-point file.
|
159 |
|
160 | A common pattern is ignoring everything which starts with underscore:
|
161 |
|
162 | ```javascript
|
163 | { // package.json
|
164 | "tarima": {
|
165 | "filter": [
|
166 | "!_*",
|
167 | "!_*/**",
|
168 | "!**/_*",
|
169 | "!**/_*/**"
|
170 | ]
|
171 | }
|
172 | }
|
173 | ```
|
174 |
|
175 | ## Rollup.js support
|
176 |
|
177 | You can provide a configuration file for [rollup](https://github.com/rollup/rollup) using the `rollupFile` option:
|
178 |
|
179 | ```javascript
|
180 | { // package.json
|
181 | "tarima": {
|
182 | "rollupFile": "./rollup.config.js"
|
183 | }
|
184 | }
|
185 | ```
|
186 |
|
187 | The `src` and `dest` options are ignored since tarima will override them internally.
|
188 |
|
189 | You can setup the specific behavior of bundling using `bundleOptions`:
|
190 |
|
191 | ```javascript
|
192 | { // package.json
|
193 | "tarima": {
|
194 | "bundleOptions": {
|
195 | "babel": {},
|
196 | "less": { "plugins": [] }
|
197 | }
|
198 | }
|
199 | }
|
200 | ```
|
201 |
|
202 | All given options are passed directly when calling the `bundle()` method on Tarima.
|
203 |
|
204 | ## Locals support
|
205 |
|
206 | You can pass a global `locals` object accesible for all parsed templates, this way you can reuse anything do you need:
|
207 |
|
208 | ```javascript
|
209 | { // package.json
|
210 | "tarima": {
|
211 | "locals": {
|
212 | "title": "My project"
|
213 | }
|
214 | }
|
215 | }
|
216 | ```
|
217 |
|
218 | Given locals are passed directly when calling any `render()` method on Tarima.
|
219 |
|
220 | ## Plugins
|
221 |
|
222 | Using the `plugins` option you can declare scripts or modules to be loaded and perform specific tasks, common plugins are:
|
223 |
|
224 | - `tarima-bower` — quick support for bower files
|
225 | - `tarima-images` — support for sprites and lazy loading
|
226 | - `tarima-lr` — LiveReload integration
|
227 | - `tarima-browser-sync` — BrowserSync integration
|
228 |
|
229 | Some plugins can take its configuration from `pluginOptions` or directly from the main configuration:
|
230 |
|
231 | ```javascript
|
232 | { // package.json
|
233 | "tarima": {
|
234 | "pluginOptions": {
|
235 | "bower": { "bundle": true }
|
236 | }
|
237 | }
|
238 | }
|
239 | ```
|
240 | All plugins are loaded automatically by Tarima on the startup.
|