@iannisz/node-cms
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -16,3 +16,70 @@ "use strict"; | ||
var chalk = require("chalk"); | ||
exports.compile = function (pagesTable, pageTypesTable, compilePage, root) { | ||
var node_json_database_1 = require("node-json-database"); | ||
// Write the ./root directory if it does not exist | ||
if (!fs.existsSync('root')) { | ||
fs.mkdirSync('root'); | ||
} | ||
var pagesDB = node_json_database_1.db('pages.json'); | ||
// Create database if it does not exist | ||
if (!pagesDB.exists) { | ||
pagesDB.create(); | ||
} | ||
// Create pageTypes table if it does not exist | ||
if (!pagesDB.table('pageTypes').exists) { | ||
var table = pagesDB.table('pageTypes'); | ||
table.create(); | ||
table.columns.add([ | ||
{ | ||
name: 'name', | ||
dataType: 'String', | ||
constraints: [ | ||
'primaryKey' | ||
] | ||
}, | ||
{ | ||
name: 'template', | ||
dataType: 'JSON', | ||
constraints: [ | ||
'notNull' | ||
] | ||
}, | ||
{ | ||
name: 'canAdd', | ||
dataType: 'Boolean' | ||
} | ||
]); | ||
} | ||
// Create pages table if it does not exist | ||
if (!pagesDB.table('pages').exists) { | ||
var table = pagesDB.table('pages'); | ||
table.create(); | ||
table.columns.add([ | ||
{ | ||
name: 'id', | ||
dataType: 'Int', | ||
constraints: [ | ||
'primaryKey', | ||
'autoIncrement' | ||
] | ||
}, | ||
{ | ||
name: 'pageType', | ||
dataType: 'String', | ||
foreignKey: { | ||
table: 'pageTypes', | ||
column: 'name' | ||
} | ||
}, | ||
{ | ||
name: 'pageContent', | ||
dataType: 'JSON', | ||
constraints: [ | ||
'notNull' | ||
] | ||
} | ||
]); | ||
} | ||
var pageTypesTable = pagesDB.table('pageTypes').get(); | ||
var pagesTable = pagesDB.table('pages').get(); | ||
exports.compile = function (compilePage) { | ||
// Store start time | ||
@@ -27,3 +94,3 @@ var e_1, _a; | ||
// Create directory, if needed | ||
var directory = getDirectory(root + page.path); | ||
var directory = getDirectory(page.path); | ||
if (!fs.existsSync(directory)) { | ||
@@ -34,4 +101,4 @@ fs.mkdirSync(directory); | ||
// Write the file | ||
fs.writeFileSync(root + page.path, page.html); | ||
console.log(chalk.green('✔') + " Wrote file: " + chalk.yellow(root + page.path)); | ||
fs.writeFileSync(page.path, page.html); | ||
console.log(chalk.green('✔') + " Wrote file: " + chalk.yellow(page.path)); | ||
} | ||
@@ -38,0 +105,0 @@ }; |
101
compiler.ts
import * as fs from 'fs' | ||
import * as chalk from 'chalk' | ||
import { Table } from 'node-json-database' | ||
import { db } from 'node-json-database' | ||
type PageCompiler = (pageContent: Object, pages: any) => { html: string, path: string } | ||
type PageCompiler = (pageContent: Object, pages: Object) => { | ||
html: string | ||
path: string | ||
} | ||
export const compile = (pagesTable: Table, pageTypesTable: Table, compilePage: any, root: string) => { | ||
interface ObjectOf<T> { | ||
[key: string]: T | ||
} | ||
// Write the ./root directory if it does not exist | ||
if (!fs.existsSync('root')) { | ||
fs.mkdirSync('root') | ||
} | ||
const pagesDB = db('pages.json') | ||
// Create database if it does not exist | ||
if (!pagesDB.exists) { | ||
pagesDB.create() | ||
} | ||
// Create pageTypes table if it does not exist | ||
if (!pagesDB.table('pageTypes').exists) { | ||
const table = pagesDB.table('pageTypes') | ||
table.create() | ||
table.columns.add([ | ||
{ | ||
name: 'name', | ||
dataType: 'String', | ||
constraints: [ | ||
'primaryKey' | ||
] | ||
}, | ||
{ | ||
name: 'template', | ||
dataType: 'JSON', | ||
constraints: [ | ||
'notNull' | ||
] | ||
}, | ||
{ | ||
name: 'canAdd', | ||
dataType: 'Boolean' | ||
} | ||
]) | ||
} | ||
// Create pages table if it does not exist | ||
if (!pagesDB.table('pages').exists) { | ||
const table = pagesDB.table('pages') | ||
table.create() | ||
table.columns.add([ | ||
{ | ||
name: 'id', | ||
dataType: 'Int', | ||
constraints: [ | ||
'primaryKey', | ||
'autoIncrement' | ||
] | ||
}, | ||
{ | ||
name: 'pageType', | ||
dataType: 'String', | ||
foreignKey: { | ||
table: 'pageTypes', | ||
column: 'name' | ||
} | ||
}, | ||
{ | ||
name: 'pageContent', | ||
dataType: 'JSON', | ||
constraints: [ | ||
'notNull' | ||
] | ||
} | ||
]) | ||
} | ||
const pageTypesTable = pagesDB.table('pageTypes').get() | ||
const pagesTable = pagesDB.table('pages').get() | ||
export const compile = (compilePage: ObjectOf<PageCompiler>) => { | ||
// Store start time | ||
@@ -18,3 +105,3 @@ | ||
for (let i = 0; i < pages.length; i++) { | ||
const pageCompiler = compilePage[pageType.name] as PageCompiler | ||
const pageCompiler = compilePage[pageType.name] | ||
const page = pageCompiler(pages[i].pageContent, pagesTable) | ||
@@ -24,3 +111,3 @@ | ||
const directory = getDirectory(root + page.path) | ||
const directory = getDirectory(page.path) | ||
@@ -34,4 +121,4 @@ if (!fs.existsSync(directory)) { | ||
fs.writeFileSync(root + page.path, page.html) | ||
console.log(`${ chalk.green('✔') } Wrote file: ${ chalk.yellow(root + page.path) }`) | ||
fs.writeFileSync(page.path, page.html) | ||
console.log(`${ chalk.green('✔') } Wrote file: ${ chalk.yellow(page.path) }`) | ||
} | ||
@@ -38,0 +125,0 @@ } |
{ | ||
"name": "@iannisz/node-cms", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -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
7086
241