@nitunity/api-compiler
Advanced tools
Comparing version 0.1.0 to 0.1.1
require('dotenv').config() | ||
module.exports = require('./modules') | ||
module.exports = require('./modules').run() |
@@ -6,25 +6,25 @@ const nunjucks = require('nunjucks') | ||
module.exports.home = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/home/index.njk`, {}) | ||
fs.writeFileSync(`${object.cache}/home/index.html`, template.toString()) | ||
module.exports.home = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/home/index.njk`, {}) | ||
fs.writeFileSync(`${config.cache}/home/index.html`, template.toString()) | ||
} | ||
module.exports.categories = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/categories/index.njk`, {}) | ||
fs.writeFileSync(`${object.cache}/categories/index.html`, template.toString()) | ||
module.exports.categories = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/categories/index.njk`, {}) | ||
fs.writeFileSync(`${config.cache}/categories/index.html`, template.toString()) | ||
} | ||
module.exports.categoryPosts = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/categories/`, {}) | ||
fs.writeFileSync(`${object.cache}/categories/`, template.toString()) | ||
module.exports.categoryPosts = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/categories/`, {}) | ||
fs.writeFileSync(`${config.cache}/categories/`, template.toString()) | ||
} | ||
module.exports.post = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/posts`, {}) | ||
fs.writeFileSync(`${object.cache}/posts/`, template.toString()) | ||
module.exports.post = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/posts`, {}) | ||
fs.writeFileSync(`${config.cache}/posts/`, template.toString()) | ||
} | ||
module.exports.tags = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/tags/index.njk`, {}) | ||
fs.writeFileSync(`${object.cache}/tags/index.html`, template.toString()) | ||
module.exports.tags = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/tags/index.njk`, {}) | ||
fs.writeFileSync(`${config.cache}/tags/index.html`, template.toString()) | ||
} | ||
module.exports.tagPosts = async (object) => { | ||
let template = await nunjucks.render(`${object.views}/tags/`, {}) | ||
fs.writeFileSync(`${object.cache}/tags`, template.toString()) | ||
module.exports.tagPosts = async (config) => { | ||
let template = await nunjucks.render(`${config.views}/tags/`, {}) | ||
fs.writeFileSync(`${config.cache}/tags`, template.toString()) | ||
} |
@@ -5,25 +5,28 @@ const request = require('./request') | ||
module.exports.run = async (object) => { | ||
await destroy(object) | ||
await call(object) | ||
module.exports.run = async (config) => { | ||
//await destroy(config) | ||
await call(config) | ||
} | ||
const call = (object) => { | ||
request.posts() | ||
.then((response) => { | ||
let counter = 0; | ||
const call = (config) => { | ||
request.home() | ||
.then(() => { | ||
let counter = 1; | ||
let interval = setInterval(() => { | ||
if (counter >= response.length) { | ||
clearInterval(interval) | ||
return | ||
} | ||
let slug = response[counter] | ||
request.post(slug) | ||
.then((res) => { | ||
request.posts(counter) | ||
.then((response) => { | ||
if (response.current_page !== response.last_page) { | ||
engine.home(config) | ||
.then(() => { | ||
console.log('Home is ready') | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
} else { | ||
clearInterval(interval) | ||
counter++ | ||
} | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
counter++ | ||
}, 2000) | ||
@@ -37,3 +40,3 @@ }) | ||
.then((response) => { | ||
engine.categories(object) | ||
engine.categories(config) | ||
.then(() => { | ||
@@ -65,2 +68,9 @@ console.log('Categories compiled') | ||
if (res.posts.current_page !== res.posts.last_page) { | ||
engine.categoryPosts(config) | ||
.then(() => { | ||
console.log('CategoryPosts is compiled') | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
cnt++ | ||
@@ -92,3 +102,15 @@ } else { | ||
let slug = response[counter] | ||
let post = await request.post(slug) | ||
request.post(slug) | ||
.then((res) => { | ||
engine.post(config) | ||
.then(() => { | ||
console.log(`Post-${slug} is compiled`) | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
@@ -104,3 +126,3 @@ counter++ | ||
.then((response) => { | ||
engine.tags(object) | ||
engine.tags(config) | ||
.then(() => { | ||
@@ -126,3 +148,15 @@ console.log('Tags compiled') | ||
let slug = response[counter] | ||
let post = await request.post(slug) | ||
request.tagPosts(slug) | ||
.then((res) => { | ||
engine.tagPosts(config) | ||
.then(() => { | ||
console.log('TagPosts is compiled') | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
}) | ||
.catch(e => { | ||
console.log(e.message) | ||
}) | ||
@@ -129,0 +163,0 @@ counter++ |
@@ -5,5 +5,9 @@ const fetch = require('node-fetch') | ||
{ | ||
async posts() | ||
async home() | ||
{ | ||
const response = await fetch(`${process.env.API_URL}/posts?path=${process.env.APP_NAME}`) | ||
} | ||
async posts(counter) | ||
{ | ||
const response = await fetch(`${process.env.API_URL}?path=${process.env.APP_NAME}&page=${counter}`) | ||
return await response.json() | ||
@@ -10,0 +14,0 @@ } |
{ | ||
"name": "@nitunity/api-compiler", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "This package is API for compiling HTML templates using Nunjucks template engine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10321
284