fast-ejs-builder 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +82 -20
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -227,18 +227,18 @@ Remember that only components can access args data `$x`.
227
227
 
228
228
  ### Passing data to pages
229
229
 
230
- #### 1. With base data
230
+ #### 1. Using base data
231
231
 
232
232
  Fast EJS comes with default data that can't be overrided.
233
233
 
234
- - `$` : _function_
234
+ - `$` : _function_\
235
235
  Imports a component by its name. Like a 'super include'.
236
236
 
237
237
  ```ejs
238
238
  <%- $("users/avatar","https://placehold.co/400") %>
239
239
  ```
240
240
 
241
- - `$0`,`$1`,... :
241
+ - `$0`,`$1`,... :\
242
242
  Return the args passed to a component. **Can be accessed only inside a component, not a page**.\
243
243
  In the previous example, we can access `"https://placehold.co/400"` by using `$0` (`0` for the first arg).
244
244
 
@@ -247,14 +247,14 @@ Fast EJS comes with default data that can't be overrided.
247
247
  <img src="<%= $0 %>" class="w-10 aspect-square rounded-full"/>
248
248
  ```
249
249
 
250
- - `$async` : _Promise function_
250
+ - `$async` : _Promise function_\
251
251
  Asynchronously imports a component.
252
252
 
253
253
  ```ejs
254
254
  <%- await $async("dashboard") %>
255
255
  ```
256
256
 
257
- - `$route` :
257
+ - `$route` :\
258
258
  Returns the current route relative to the `pages.dir`. In this example, it will return `/home`
259
259
 
260
260
  ```ejs
@@ -262,7 +262,7 @@ Fast EJS comes with default data that can't be overrided.
262
262
  <%= $route %>
263
263
  ```
264
264
 
265
- - `$css` :
265
+ - `$css` :\
266
266
  Automatically imports the relative path of generated tailwind css from `tailwind.output` inside a page. No need to manually write the css path and change everytime.\
267
267
  \
268
268
  For example, inside `app/pages/users/profile.ejs`, it can return something like `../../public/app.css`\
@@ -272,7 +272,7 @@ Fast EJS comes with default data that can't be overrided.
272
272
  <%- $css %>
273
273
  ```
274
274
 
275
- - `$date` :
275
+ - `$date` :\
276
276
  Returns a new Date object.\
277
277
  Stop writing year manually.
278
278
 
@@ -280,21 +280,21 @@ Fast EJS comes with default data that can't be overrided.
280
280
  <%= $date.getFullYear() %>
281
281
  ```
282
282
 
283
- - `$env` : _function_
283
+ - `$env` : _function_\
284
284
  Get a env variable from `process.env`. Useful to build env based pages.
285
285
 
286
286
  ```ejs
287
287
  <%= $env("NODE_ENV") %>
288
288
  ```
289
289
 
290
- - `$cls` : _function_
290
+ - `$cls` : _function_\
291
291
  Same behavior as `tailwind clsx`. Useful to write conditions based classes.
292
292
 
293
293
  ```ejs
294
294
  <%= $cls(isActive && "text-primary", "bg-gray-100") %>
295
295
  ```
296
296
 
297
- - `$if` : _function_
297
+ - `$if` : _function_\
298
298
  Returns a value based on a condition or a default value if set. Can also works with components :=)
299
299
 
300
300
  ```ejs
@@ -302,7 +302,7 @@ Fast EJS comes with default data that can't be overrided.
302
302
  <%= $if($env("NODE_ENV")=="prod", "Hello","World") %>
303
303
  ```
304
304
 
305
- - `$debug` : _function_
305
+ - `$debug` : _function_\
306
306
  Prints anything in the console during build. Use it to debug your pages or components
307
307
 
308
308
  ```ejs
@@ -317,11 +317,13 @@ Fast EJS comes with default data that can't be overrided.
317
317
  <%- $trim($upper(user.name)) %>
318
318
  ```
319
319
 
320
- Create data files in `data.dir`:
320
+ #### 2. Using your own data
321
+
322
+ Fill data files in `data.dir` (generated automatically if missing).
321
323
 
322
324
  - **Global data** : Can be accessed inside every pages and components
323
325
 
324
- If `data.allow` is `all` or `js`
326
+ If `data.allow` is `all` or `js` (recommended)
325
327
 
326
328
  ```javascript
327
329
  // app/data/global.data.js
@@ -339,7 +341,7 @@ module.exports = {
339
341
 
340
342
  If `data.allow` is `all` or `json`
341
343
 
342
- ```json
344
+ ```js
343
345
  // app/data/global.data.json
344
346
  {
345
347
  "siteName": "My Awesome Site",
@@ -348,26 +350,72 @@ If `data.allow` is `all` or `json`
348
350
  { "label": "About", "url": "/about" },
349
351
  { "label": "Contact", "url": "/contact" },
350
352
  ],
351
- };
353
+ }
352
354
  ```
353
355
 
354
- - **Local data**
356
+ - **Local data** : Can be accessed only in the target page
355
357
 
356
358
  ```javascript
357
- // app/pages/index.data.js
359
+ // app/data/local.data.js
358
360
  module.exports = {
359
- title: "Welcome to My Site",
360
- description: "This is a fast-ejs powered website with Tailwind CSS.",
361
+ // for page "app/pages/users/profile.ejs"
362
+ "users/profile": {
363
+ title: "Welcome to My Site",
364
+ description: "This is a fast-ejs powered website with Tailwind CSS.",
365
+ },
361
366
  };
362
367
  ```
363
368
 
369
+ **Note that all JS data can be asynchronous, and each asynchronous data will affect the build time.**
370
+
364
371
  ## Commands
365
372
 
366
373
  - **`fast-ejs dev`**: Start development server with live reloading
367
374
  - **`fast-ejs build`**: Build static files for production
368
375
 
376
+ ## How it works
377
+
378
+ Here is the real building flow :
379
+
380
+ - Get the data inside `data.dir` that match the `data.allow`.
381
+ - Scan the specified `pages.dir`.
382
+ - All empty folder will be ignored
383
+ - If any `.ejs` file is found, render the html with the corresponding data and generate the right file inside `build.output` depending on `build.useIndexRouting`.
384
+ - For any other file, just copy it inside the `build.output`.
385
+ - Generate the css with tailwind at `tailwind.output` along with `tailwind.imports` if specified.
386
+ - Scan the `build.output` and clean all junk files and folders (files from previous build and empty folders).
387
+
388
+ Notice that all empty folders inside `pages.dir` will be ignored in the build.
389
+
369
390
  ## Usage tips
370
391
 
392
+ - **Prefer using JS data**
393
+
394
+ By setting `data.allow` to `json`, you allow only json data. But in real case you'll mostly need js data because you can write logic inside.\
395
+ By example, using this:
396
+
397
+ ```json
398
+ {
399
+ "year": 2026
400
+ }
401
+ ```
402
+
403
+ is less effective that using:
404
+
405
+ ```js
406
+ module.exports = {
407
+ year: new Date().getFullYear(),
408
+ };
409
+ ```
410
+
411
+ because in the second case, `year` can change at build time.\
412
+ Also js data can be async which is useful to get data from a database. So prefer setting `data.allow` to `all` or `js` when you need dynamic data.
413
+
414
+ - **Duplicate data**
415
+ - If `data.allow` is `all`, js data are prioritized over json data.
416
+ In the [previous example](#usage-tips), if `year` is in both js and json file, the js one will be used.
417
+ - You can't override base data. For example, declaring `$route` will have no effect.
418
+
371
419
  - **Don't misuse EJS tags**
372
420
 
373
421
  ```ejs
@@ -381,9 +429,23 @@ Using `<%` means you're not expecting an output but `$("header")` should return
381
429
  Using `<%=` means you're expecting an escaped value but `$css` requires to be unescaped.
382
430
  Using `<%-` means you're expecting an unescaped but `user.name` may return a string.
383
431
 
432
+ - **Don't put components or data directory inside the pages directory**
433
+
434
+ Any file inside the pages dir is considered a static file cause this directory is scanned to find ejs files and other files to generate an output.
435
+
436
+ `pages.dir` contains files that will be built (ejs, images, css, etc..)
437
+ `components.dir` contains parts of pages. Not pages.
438
+ `data.dir` contains data that will be used by the pages.
439
+
440
+ Therefore, adding components dir inside the pages dir, means components will be generated as pages and data dir files will be generated as static files.
441
+
384
442
  - **Fast EJS is a builder / generator. Not a framework**
385
443
 
386
- You're basiclally coding ejs templates with 'super powers', and something is generating the html and css files for you. You're not using a big framework that will run your SaaS.\
444
+ Because of some features like access of the current route (`$route`) or usage of async data, you might think you're using a kind of framework. But no. You're basically coding ejs templates with 'super powers', and something is generating the html and css files for you.
445
+
446
+ When someone visit your site, he will just see the static files early built. Even if some of your data are retrieved at build time, they can't change once the build is done.
447
+
448
+ So, you're not using a big framework that will run your SaaS.\
387
449
  Please consider using this for small projects like static portfolios or landing pages.
388
450
 
389
451
  ## Contributing
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "fast-ejs-builder",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Fast-EJS is a simple and fast tool to pre-render EJS templates into static HTML files with clean conventions and flexible data handling.",
5
5
  "keywords": [
6
6
  "tailwind",
7
7
  "html",
8
8
  "build"
9
9
  ],
10
- "homepage": "https://github.com/D3R50N/tailwind-html#readme",
10
+ "homepage": "https://github.com/D3R50N/fast-ejs#readme",
11
11
  "bugs": {
12
- "url": "https://github.com/D3R50N/tailwind-html/issues"
12
+ "url": "https://github.com/D3R50N/fast-ejs/issues"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "git+https://github.com/D3R50N/tailwind-html.git"
16
+ "url": "git+https://github.com/D3R50N/fast-ejs.git"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "D3R50N",