boxedjs
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
const packagejson = require('./package.json'); | ||
const boxedrc = require('rcfile')('boxed'); | ||
@@ -18,3 +19,2 @@ | ||
if (program.new) { | ||
@@ -28,6 +28,6 @@ boxed.createNewProject(program.new); | ||
console.log('%s changed.', name); | ||
boxed.compile(); | ||
boxed.compile(boxedrc); | ||
}); | ||
} else { | ||
boxed.compile(); | ||
boxed.compile(boxedrc); | ||
} |
const fs = require('fs-extra'); | ||
const _ = require('lodash'); | ||
const defaultConfig = require('./default-config.json'); | ||
module.exports = { | ||
compile: () => { | ||
compile: (boxedrc) => { | ||
const conf = !_.isEmpty(boxedrc) | ||
&& boxedrc.folders ? boxedrc : defaultConfig; | ||
const folders = conf.folders; | ||
let pages = {}; | ||
let templates = {}; | ||
console.log('Welcome to boxedjs.'); | ||
console.log(`Preparing to compile ${conf.name}...`); | ||
console.log('-- Removing old dist/ folder'); | ||
fs.removeSync('dist'); | ||
fs.mkdir('dist'); | ||
fs.removeSync(folders.dist); | ||
fs.mkdir(folders.dist); | ||
console.log('-- Loading pages...'); | ||
fs.readdirSync('./pages') | ||
fs.readdirSync(folders.pages) | ||
.filter((item) => { | ||
@@ -19,7 +27,7 @@ return item.indexOf('.html') > -1; | ||
const itemKey = item.substring(0, item.length - 5); | ||
pages[itemKey] = fs.readFileSync(`./pages/${item}`, 'utf8'); | ||
pages[itemKey] = fs.readFileSync(`${folders.pages}/${item}`, 'utf8'); | ||
}); | ||
console.log('-- Loading templates...'); | ||
fs.readdirSync('./templates') | ||
fs.readdirSync(folders.templates) | ||
.filter((item) => { | ||
@@ -29,3 +37,3 @@ return item.indexOf('.html') > -1; | ||
const itemKey = item.substring(0, item.length - 5); | ||
templates[itemKey] = fs.readFileSync(`./templates/${item}`, 'utf8'); | ||
templates[itemKey] = fs.readFileSync(`${folders.templates}/${item}`, 'utf8'); | ||
}); | ||
@@ -40,3 +48,3 @@ | ||
}); | ||
fs.writeFile(`dist/${pageKey}.html`, templatedPage, (err) => { | ||
fs.writeFile(`${folders.dist}/${pageKey}.html`, templatedPage, (err) => { | ||
if (err) { | ||
@@ -49,5 +57,5 @@ console.log(err); | ||
if (fs.pathExistsSync('assets')) { | ||
if (fs.pathExistsSync(folders.assets)) { | ||
console.log('-- Copying asset folder'); | ||
fs.copySync('assets', 'dist'); | ||
fs.copySync(folders.assets, folders.dist); | ||
} | ||
@@ -54,0 +62,0 @@ |
{ | ||
"name": "boxedjs", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "A simple static HTML templating engine.", | ||
@@ -36,3 +36,5 @@ "main": "index.js", | ||
"fs-extra": "^4.0.1", | ||
"node-watch": "^0.5.5" | ||
"lodash": "^4.17.4", | ||
"node-watch": "^0.5.5", | ||
"rcfile": "^1.0.3" | ||
}, | ||
@@ -39,0 +41,0 @@ "devDependencies": { |
@@ -39,11 +39,30 @@ # boxedjs | ||
/ | ||
├── assets/ | ||
├── pages/ | ||
├── templates/ | ||
├── src/ | ||
├── assets/ | ||
├── pages/ | ||
├── templates/ | ||
├── .boxedrc | ||
``` | ||
where the content of the folders is the following: | ||
- `assets`: contains all the styling files, images and other files but html. | ||
- `pages`: contains the pages of your website | ||
- `templates`: contains the templates used inside the `pages` | ||
- `src/assets`: contains all the styling files, images and other files but html. | ||
- `src/pages`: contains the pages of your website | ||
- `src/templates`: contains the templates used inside the `pages` | ||
### .boxedrc | ||
This file contains the configuration for the project. | ||
By default it has the following content: | ||
```json | ||
{ | ||
"name": "Untitled project", \\ name of the project | ||
"folders": { | ||
"pages": "src/pages", \\ location containing the pages | ||
"templates": "src/templates", \\ location containing the templates | ||
"assets": "src/assets", \\ location containing the assets | ||
"dist": "dist" \\ export directory (where your compiled website will be) | ||
} | ||
} | ||
``` | ||
Feel free to customise it to suit your project structure better. | ||
### How to use the templates in a page | ||
@@ -50,0 +69,0 @@ Whenever you want to use one of the `templates` in one of the `pages` you can require them like the following: |
10531
15
124
98
5
+ Addedlodash@^4.17.4
+ Addedrcfile@^1.0.3
+ Addedargparse@1.0.10(transitive)
+ Addedcaller-path@0.1.0(transitive)
+ Addedcallsites@0.2.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedrcfile@1.0.3(transitive)
+ Addedrequire-uncached@1.0.3(transitive)
+ Addedresolve-from@1.0.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)