Comparing version 0.0.3 to 0.0.7
{ | ||
"name": "symply", | ||
"version": "0.0.3", | ||
"version": "0.0.7", | ||
"description": "A dead-simple Bootstrap static site generator.", | ||
@@ -31,2 +31,5 @@ "author": "Oleg Legun <oleg.legun@gmail.com>", | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"tap-spec": "^5.0.0", | ||
@@ -33,0 +36,0 @@ "tape": "^4.13.0" |
@@ -8,3 +8,2 @@ const fs = require('fs') | ||
EmptyConfigurationFileError, | ||
InvalidConfigurationError, | ||
MissingRequiredConfigurationOptionError, | ||
@@ -19,2 +18,4 @@ } = require('./errors') | ||
VIEWS_DIR_NAME: 'views', | ||
TEMPLATES_DIR_NAME: 'templates', | ||
IGNORE_MISSING_PROPERTIES: false | ||
} | ||
@@ -24,2 +25,3 @@ | ||
const GLOBALS_FILE_NAME = 'symply-globals.js' | ||
const CONFIGURATION_FILE_NAME = 'symply-config.yaml' | ||
@@ -37,12 +39,13 @@ const systemFilesToBeCreated = [ | ||
}, | ||
{ name: CONFIGURATION_FILE_NAME, dir: '.', contents: yaml.dump(DEFAULT_CONFIGURATION) }, | ||
] | ||
function getConfiguration(configurationFilename) { | ||
function getConfiguration() { | ||
try { | ||
const configuration = yaml.safeLoad( | ||
fs.readFileSync(path.join(process.cwd(), configurationFilename), { encoding: 'utf8' }) | ||
fs.readFileSync(path.join(process.cwd(), CONFIGURATION_FILE_NAME), { encoding: 'utf8' }) | ||
) | ||
if (!configuration) { | ||
throw new EmptyConfigurationFileError(configurationFilename) | ||
throw new EmptyConfigurationFileError(CONFIGURATION_FILE_NAME) | ||
} | ||
@@ -55,7 +58,3 @@ | ||
if (err.code === 'ENOENT') { | ||
logger.info( | ||
`Configuration file (${configurationFilename}) is not found. Using default configuration:\n${getPrintableConfigurationRepresentation( | ||
DEFAULT_CONFIGURATION | ||
)}` | ||
) | ||
logger.info(`Configuration file (${CONFIGURATION_FILE_NAME}) is not found. Using default configuration.`) | ||
return DEFAULT_CONFIGURATION | ||
@@ -100,4 +99,4 @@ } else if (err instanceof UnsupportedConfigurationOptionError) { | ||
/** | ||
* @param {Object<string, any>} configObject | ||
* @returns {string} | ||
* @param {Object<string, any>} configObject | ||
* @return {string} | ||
*/ | ||
@@ -109,3 +108,3 @@ function getPrintableConfigurationRepresentation(configObject) { | ||
Object.keys(configObject).forEach(key => { | ||
const value = typeof configObject[key] === 'string' ? `'${configObject[key]}'` : configObject[key] | ||
const value = typeof configObject[key] === 'string' ? `'${configObject[key]}'` : configObject[key] | ||
@@ -123,2 +122,3 @@ result += `${paddingChars}${key}: ${value}\n` | ||
HELPERS_FILE_NAME, | ||
CONFIGURATION_FILE_NAME, | ||
} |
@@ -18,3 +18,3 @@ const fs = require('fs-extra') | ||
* @param {boolean} scanNestedDirectories | ||
* @returns {FileEntry[]} | ||
* @return {FileEntry[]} | ||
*/ | ||
@@ -83,2 +83,9 @@ function scanFiles(scanPath, readFileContents, removeScanPath, scanNestedDirectories) { | ||
} | ||
/** | ||
* | ||
* @param {*} dirPath | ||
*/ | ||
async function createDirectoryAsync(dirPath) { | ||
return fs.ensureDir(dirPath) | ||
} | ||
@@ -150,2 +157,3 @@ async function copyFileAsync(filePath, destinationPath) { | ||
copyFileAsync, | ||
createDirectoryAsync, | ||
clearDirectoryContents, | ||
@@ -152,0 +160,0 @@ createDirectoryIfNotExists, |
@@ -9,2 +9,3 @@ const fs = require('fs') | ||
const { loadPartials } = require('./partials') | ||
const { loadTemplates } = require('./templates') | ||
const { loadViews } = require('./views') | ||
@@ -19,7 +20,6 @@ const { | ||
copyFileAsync, | ||
createDirectoryAsync, | ||
joinAndResolvePath, | ||
} = require('./fs-helpers') | ||
const CONFIGURATION_FILE_NAME = 'configuration.yaml' | ||
async function main(commands) { | ||
@@ -30,2 +30,3 @@ switch (commands[0]) { | ||
initialize() | ||
logger.info('Initialization successfully done.') | ||
break | ||
@@ -41,2 +42,5 @@ case 'generate': | ||
/** | ||
* | ||
*/ | ||
async function generate() { | ||
@@ -47,3 +51,3 @@ /*----------------------------------------------------------------------------- | ||
const configuration = config.getConfiguration(CONFIGURATION_FILE_NAME) | ||
const configuration = config.getConfiguration() | ||
@@ -61,3 +65,3 @@ /*----------------------------------------------------------------------------- | ||
/*----------------------------------------------------------------------------- | ||
* Load views and globals | ||
* Load views, templates and globals | ||
*----------------------------------------------------------------------------*/ | ||
@@ -67,2 +71,3 @@ | ||
const globals = require(joinAndResolvePath(config.GLOBALS_FILE_NAME)) | ||
const templates = loadTemplates(configuration.TEMPLATES_DIR_NAME) | ||
@@ -82,2 +87,12 @@ /*----------------------------------------------------------------------------- | ||
Handlebars.registerHelper('template', injectHelperContextDecorator(templateHelper, views, globals)) | ||
function templateHelper(templateName, data) { | ||
return templates[templateName].replace('{{}}', data.fn(this)) | ||
} | ||
if (!configuration.IGNORE_MISSING_PROPERTIES) { | ||
Handlebars.registerHelper('helperMissing', missingHelperOrPropertyHandler) | ||
} | ||
/*----------------------------------------------------------------------------- | ||
@@ -141,4 +156,5 @@ * Scan source files, detect template files for processing | ||
const srcFilePath = joinAndResolvePath(configuration.SOURCE_DIR_NAME, file.dirname, file.name) | ||
const fileDir = joinAndResolvePath(configuration.DISTRIBUTION_DIR_NAME, file.dirname) | ||
const distFilePath = joinAndResolvePath(configuration.DISTRIBUTION_DIR_NAME, file.dirname, file.name) | ||
copyPromises.push(copyFileAsync(srcFilePath, distFilePath)) | ||
copyPromises.push(createDirectoryAsync(fileDir).then(() => copyFileAsync(srcFilePath, distFilePath))) | ||
}) | ||
@@ -156,3 +172,3 @@ | ||
const configuration = config.getConfiguration(CONFIGURATION_FILE_NAME) | ||
const configuration = config.getConfiguration() | ||
@@ -183,14 +199,36 @@ /*----------------------------------------------------------------------------- | ||
/** | ||
* | ||
* @param {(...args:Object[])=> {}} helperFunction | ||
* @param {Object<string, string>} views | ||
* @param {Object} globals | ||
*/ | ||
function injectHelperContextDecorator(helperFunction, views, globals) { | ||
return function(params) { | ||
const viewName = params && params.hash && params.hash.view | ||
return function(...args) { | ||
console.log(args) | ||
if (viewName) { | ||
return new Handlebars.SafeString(helperFunction({ globals, view: views[viewName], params: params.hash })) | ||
} else { | ||
return new Handlebars.SafeString(helperFunction({ globals, params: params.hash })) | ||
} | ||
const passedArgs = args.slice(0, args.length - 1) | ||
const data = args[args.length - 1] | ||
const fn = data.fn // if block helper | ||
const viewName = data.hash && data.hash.view | ||
return new Handlebars.SafeString( | ||
viewName | ||
? helperFunction(...passedArgs, { globals, params: data.hash, view: views[viewName], fn }) | ||
: helperFunction(...passedArgs, { globals, params: data.hash, fn }) | ||
) | ||
} | ||
} | ||
function detectBlockHelper() {} | ||
function missingHelperOrPropertyHandler(data) { | ||
Object.keys(data).forEach(item => { | ||
const message = 'Missing helper or property: ' + data.name | ||
logger.error(message) | ||
throw new Error(message) | ||
}) | ||
} | ||
module.exports = main |
const path = require('path') | ||
const { scanFiles } = require('./fs-helpers') | ||
// TODO: add support for md and txt formats | ||
const PARTIAL_EXTENTION = '.html' | ||
@@ -27,3 +28,3 @@ | ||
* @param {string} fileName | ||
* @returns {string} | ||
* @return {string} | ||
*/ | ||
@@ -30,0 +31,0 @@ function getPartialName(fileName) { |
module.exports = { | ||
logo: ` | ||
███████╗ ████████╗ ███╗ ███╗ ████████╗ ██╗ ████████╗ | ||
████/══╝ ╚██████╔╝ ████╗ ████║ ███╔═══██╗ ██║ ╚██████╔╝ | ||
███████╗ ╚████╔╝ █████╗ █████║ ████████╔╝ ██║ ╚████╔╝ | ||
╚═/████║ ╚██╔╝ ████████████║ ███╔════╝ ██║ ╚██╔╝ | ||
███████║ ██║ ████████████║ ███║ ███████╗██║ | ||
╚══════╝ ╚═╝ ╚═══════════╝ ╚══╝ ╚══════╝╚═╝ | ||
███████╗ ████████╗ ███╗ ███╗ ████████╗ ██╗ ████████╗ | ||
████▌/═╝ ╚██████╔╝ ████╗ ████║ ███╔═══██╗ ██║ ╚██████╔╝ | ||
███████╗ ╚████╔╝ █████╗ █████║ ████████╔╝ ██║ ╚████╔╝ | ||
╚/▐████║ ╚██╔╝ ████████████║ ███╔════╝ ██║ ╚██╔╝ | ||
███████║ ██║ ████████████║ ███║ ███████╗ ██║ | ||
╚══════╝ ╚═╝ ╚═══════════╝ ╚══╝ ╚══════╝ ╚═╝ | ||
======= Bootstrap Static Site Generator ======= | ||
@@ -11,0 +11,0 @@ `, |
const path = require('path') | ||
const { scanFiles } = require('./fs-helpers') | ||
// TODO add support for yaml and js formats | ||
// TODO add support for nested dir structure | ||
const VIEW_EXTENSION = '.json' | ||
@@ -5,0 +7,0 @@ |
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
145095
26
683
5