This commit is contained in:
Philipp Kunz 2019-09-10 17:58:14 +02:00
parent f5b86154db
commit 1d35da50cd
21 changed files with 804 additions and 332 deletions

View File

@ -1,4 +1,4 @@
# gitzone standard
# gitzone ci_default
image: hosttoday/ht-docker-node:npmci
cache:

9
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import * as plugins from './smarthbs.plugins';
export declare type TTemplateStringType = 'filePath' | 'code';
export declare let handlebars: typeof plugins.handlebars;
export * from './smarthbs.compile';
import './smarthbs.helpers';
export * from './smarthbs.partials';
export * from './smarthbs.template';
export * from './smarthbs.variables';
export * from './smarthbs.postprocess';

21
dist/index.js vendored Normal file
View File

@ -0,0 +1,21 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
exports.handlebars = plugins.handlebars;
__export(require("./smarthbs.compile"));
require("./smarthbs.helpers");
__export(require("./smarthbs.partials"));
__export(require("./smarthbs.template"));
__export(require("./smarthbs.variables"));
__export(require("./smarthbs.postprocess"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSw0REFBOEM7QUFHbkMsUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQztBQUMzQyx3Q0FBbUM7QUFDbkMsOEJBQTRCO0FBQzVCLHlDQUFvQztBQUNwQyx5Q0FBb0M7QUFDcEMsMENBQXFDO0FBQ3JDLDRDQUF1QyJ9

4
dist/smarthbs.compile.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/**
* compiles a directory and outputs it
*/
export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise<void>;

27
dist/smarthbs.compile.js vendored Normal file
View File

@ -0,0 +1,27 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
/**
* compiles a directory and outputs it
*/
exports.compileDirectory = async (originDirPathArg, destinationDirPathArg, dataFileNameArg) => {
let hbsFilePathArray = plugins.smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
let data = plugins.smartfile.fs.toObjectSync(plugins.path.join(originDirPathArg, dataFileNameArg));
for (let hbsFilePath of hbsFilePathArray) {
let parsedPath = plugins.path.parse(hbsFilePath);
let hbsFileString = plugins.smartfile.fs.toStringSync(plugins.path.join(originDirPathArg, hbsFilePath));
let template = plugins.handlebars.compile(hbsFileString);
let output = template(data);
console.log('hi ' + output + ' hi');
await plugins.smartfile.fs.ensureDir(destinationDirPathArg);
plugins.smartfile.memory.toFsSync(output, plugins.path.join(destinationDirPathArg, parsedPath.name + '.html'));
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuY29tcGlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmNvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsNERBQThDO0FBRTlDOztHQUVHO0FBQ1EsUUFBQSxnQkFBZ0IsR0FBRyxLQUFLLEVBQ2pDLGdCQUF3QixFQUN4QixxQkFBNkIsRUFDN0IsZUFBdUIsR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CLEVBQUUsVUFBVSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsQ0FDcEUsQ0FBQztLQUNIO0FBQ0gsQ0FBQyxDQUFDIn0=

1
dist/smarthbs.helpers.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

39
dist/smarthbs.helpers.js vendored Normal file
View File

@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
/**
* Helper:
* Allows you to analyze a context
*/
plugins.handlebars.registerHelper('__analyze', analyzeContext => {
if (typeof analyzeContext === 'string') {
if (plugins.handlebars.partials[analyzeContext]) {
console.log(`The analyzed partial ${analyzeContext} looks like this`);
console.log(plugins.handlebars.partials[analyzeContext]);
}
else {
console.error(`The Partial ${analyzeContext} cannot be found`);
}
return 'analyzed';
}
});
/**
* Helper:
* logs all registered partials to console
*/
plugins.handlebars.registerHelper('__allPartialsLog', analyzeContext => {
console.log(plugins.handlebars.partials);
return 'analyzed';
});
plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationContext) => {
let template = plugins.handlebars.compile(evaluationString);
return template(evaluationContext);
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsNERBQThDO0FBRTlDOzs7R0FHRztBQUNILE9BQU8sQ0FBQyxVQUFVLENBQUMsY0FBYyxDQUFDLFdBQVcsRUFBRSxjQUFjLENBQUMsRUFBRTtJQUM5RCxJQUFJLE9BQU8sY0FBYyxLQUFLLFFBQVEsRUFBRTtRQUN0QyxJQUFJLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQyxFQUFFO1lBQy9DLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLGNBQWMsa0JBQWtCLENBQUMsQ0FBQztZQUN0RSxPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQyxDQUFDLENBQUM7U0FDMUQ7YUFBTTtZQUNMLE9BQU8sQ0FBQyxLQUFLLENBQUMsZUFBZSxjQUFjLGtCQUFrQixDQUFDLENBQUM7U0FDaEU7UUFDRCxPQUFPLFVBQVUsQ0FBQztLQUNuQjtBQUNILENBQUMsQ0FBQyxDQUFDO0FBRUg7OztHQUdHO0FBQ0gsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsa0JBQWtCLEVBQUUsY0FBYyxDQUFDLEVBQUU7SUFDckUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxDQUFDO0lBQ3pDLE9BQU8sVUFBVSxDQUFDO0FBQ3BCLENBQUMsQ0FBQyxDQUFDO0FBRUgsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUMsV0FBVyxFQUFFLENBQUMsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQUUsRUFBRTtJQUNyRixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO0lBQzVELE9BQU8sUUFBUSxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDckMsQ0FBQyxDQUFDLENBQUMifQ==

4
dist/smarthbs.partials.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/**
* registers a directory of partials to make them available within handlebars compilation
*/
export declare let registerPartialDir: (dirPathArg: string) => Promise<any>;

33
dist/smarthbs.partials.js vendored Normal file
View File

@ -0,0 +1,33 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
/**
* registers a directory of partials to make them available within handlebars compilation
*/
exports.registerPartialDir = (dirPathArg) => {
let done = plugins.smartpromise.defer();
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = plugins.path.parse(hbsFilePath);
let hbsFileString = plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, hbsFilePath));
if (parsedPath.dir === '/') {
parsedPath.dir = '';
}
if (parsedPath.dir !== '') {
parsedPath.dir = parsedPath.dir + '/';
}
let partialName = `partials/${parsedPath.dir}${parsedPath.name}`;
plugins.handlebars.registerPartial(partialName, hbsFileString);
done.resolve();
}
});
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGFydGlhbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wYXJ0aWFscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSw0REFBOEM7QUFFOUM7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQUMsVUFBa0IsRUFBZ0IsRUFBRTtJQUNuRSxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQ3hDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxVQUFVLEVBQUUsVUFBVSxDQUFDLENBQUMsSUFBSSxDQUFDLGVBQWUsQ0FBQyxFQUFFO1FBQy9FLEtBQUssSUFBSSxXQUFXLElBQUksZUFBZSxFQUFFO1lBQ3ZDLElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLFdBQVcsQ0FBQyxDQUFDO1lBQ2pELElBQUksYUFBYSxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FDbkQsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFFLFdBQVcsQ0FBQyxDQUMzQyxDQUFDO1lBQ0YsSUFBSSxVQUFVLENBQUMsR0FBRyxLQUFLLEdBQUcsRUFBRTtnQkFDMUIsVUFBVSxDQUFDLEdBQUcsR0FBRyxFQUFFLENBQUM7YUFDckI7WUFDRCxJQUFJLFVBQVUsQ0FBQyxHQUFHLEtBQUssRUFBRSxFQUFFO2dCQUN6QixVQUFVLENBQUMsR0FBRyxHQUFHLFVBQVUsQ0FBQyxHQUFHLEdBQUcsR0FBRyxDQUFDO2FBQ3ZDO1lBQ0QsSUFBSSxXQUFXLEdBQUcsWUFBWSxVQUFVLENBQUMsR0FBRyxHQUFHLFVBQVUsQ0FBQyxJQUFJLEVBQUUsQ0FBQztZQUNqRSxPQUFPLENBQUMsVUFBVSxDQUFDLGVBQWUsQ0FBQyxXQUFXLEVBQUUsYUFBYSxDQUFDLENBQUM7WUFDL0QsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1NBQ2hCO0lBQ0gsQ0FBQyxDQUFDLENBQUM7SUFDSCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDdEIsQ0FBQyxDQUFDIn0=

6
dist/smarthbs.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
import * as handlebars from 'handlebars';
import lodashUniq from 'lodash.uniq';
import * as path from 'path';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
export { handlebars, lodashUniq, path, smartfile, smartpromise };

23
dist/smarthbs.plugins.js vendored Normal file
View File

@ -0,0 +1,23 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const handlebars = __importStar(require("handlebars"));
exports.handlebars = handlebars;
const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
exports.lodashUniq = lodash_uniq_1.default;
const path = __importStar(require("path"));
exports.path = path;
const smartfile = __importStar(require("@pushrocks/smartfile"));
exports.smartfile = smartfile;
const smartpromise = __importStar(require("@pushrocks/smartpromise"));
exports.smartpromise = smartpromise;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7O0FBQUEsdURBQXlDO0FBTWhDLGdDQUFVO0FBTG5CLDhEQUFxQztBQUtoQixxQkFMZCxxQkFBVSxDQUtjO0FBSi9CLDJDQUE2QjtBQUlJLG9CQUFJO0FBSHJDLGdFQUFrRDtBQUdYLDhCQUFTO0FBRmhELHNFQUF3RDtBQUVOLG9DQUFZIn0=

5
dist/smarthbs.postprocess.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/**
* allows you to keep handlebars in place across multiple iterations
* helpful when handlebars syntax is used by more than one tool in a build chain
*/
export declare let postprocess: (stringArg: string) => Promise<string>;

15
dist/smarthbs.postprocess.js vendored Normal file
View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let safeSyntaxBeginRegex = /{-{/g;
let safeSyntaxEndRegex = /}-}/g;
/**
* allows you to keep handlebars in place across multiple iterations
* helpful when handlebars syntax is used by more than one tool in a build chain
*/
exports.postprocess = async (stringArg) => {
let processedString = stringArg;
processedString = processedString.replace(safeSyntaxBeginRegex, '{{');
processedString = processedString.replace(safeSyntaxEndRegex, '}}');
return processedString;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucG9zdHByb2Nlc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wb3N0cHJvY2Vzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLElBQUksb0JBQW9CLEdBQUcsTUFBTSxDQUFDO0FBQ2xDLElBQUksa0JBQWtCLEdBQUcsTUFBTSxDQUFDO0FBRWhDOzs7R0FHRztBQUNRLFFBQUEsV0FBVyxHQUFHLEtBQUssRUFBRSxTQUFpQixFQUFtQixFQUFFO0lBQ3BFLElBQUksZUFBZSxHQUFHLFNBQVMsQ0FBQztJQUNoQyxlQUFlLEdBQUcsZUFBZSxDQUFDLE9BQU8sQ0FBQyxvQkFBb0IsRUFBRSxJQUFJLENBQUMsQ0FBQztJQUN0RSxlQUFlLEdBQUcsZUFBZSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsRUFBRSxJQUFJLENBQUMsQ0FBQztJQUNwRSxPQUFPLGVBQWUsQ0FBQztBQUN6QixDQUFDLENBQUMifQ==

9
dist/smarthbs.template.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import * as plugins from './smarthbs.plugins';
/**
* get a template for a file on disk
*/
export declare let getTemplateForFile: (filePathArg: string) => Promise<plugins.handlebars.TemplateDelegate<any>>;
/**
* get a template for string
*/
export declare let getTemplateForString: (fileStringArg: string) => Promise<plugins.handlebars.TemplateDelegate<any>>;

24
dist/smarthbs.template.js vendored Normal file
View File

@ -0,0 +1,24 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
/**
* get a template for a file on disk
*/
exports.getTemplateForFile = async (filePathArg) => {
let filePathAbsolute = plugins.path.resolve(filePathArg);
return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute));
};
/**
* get a template for string
*/
exports.getTemplateForString = async (fileStringArg) => {
return plugins.handlebars.compile(fileStringArg);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudGVtcGxhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy50ZW1wbGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSw0REFBOEM7QUFFOUM7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLEtBQUssRUFBRSxXQUFtQixFQUFFLEVBQUU7SUFDNUQsSUFBSSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUN6RCxPQUFPLE9BQU8sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7QUFDekYsQ0FBQyxDQUFDO0FBRUY7O0dBRUc7QUFDUSxRQUFBLG9CQUFvQixHQUFHLEtBQUssRUFBRSxhQUFxQixFQUFFLEVBQUU7SUFDaEUsT0FBTyxPQUFPLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQztBQUNuRCxDQUFDLENBQUMifQ==

12
dist/smarthbs.variables.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
/**
* finds all variables in a handlebars template
* @param hbsStringArg
*/
export declare let findVarsInHbsString: (hbsStringArg: string) => Promise<string[]>;
/**
* checks if supplied variables satisfy an handlebars template
* @param hbsStringArg
* @param varObjectArg
* @return string array with missing variable names
*/
export declare let checkVarsSatisfaction: (hbsStringArg: string, varObjectArg: any) => Promise<string[]>;

74
dist/smarthbs.variables.js vendored Normal file
View File

@ -0,0 +1,74 @@
"use strict";
// This file contains code that makes it easy to search handlebar templates for variables.
// Why? To get a clue if you are missing some.
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smarthbs.plugins"));
// the curly regex objects
let tripleCurlyRegex = /{{{\s*[\w\.]+\s*}}}/g;
let doubleCurlyRegex = /{{\s*[\w\.]+\s*}}/g;
let nameInCurlsRegex = /[\w\.]+/;
/**
* finds all variables in a handlebars template
* @param hbsStringArg
*/
exports.findVarsInHbsString = async (hbsStringArg) => {
let hbsString = hbsStringArg; // make sure we have a new string object that we may destroy
let varNameArray = [];
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex);
if (tripleCurlyMatches) {
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]');
varNameArray = varNameArray.concat(tripleCurlyMatches);
}
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex);
if (doubleCurlyMatches) {
varNameArray = varNameArray.concat(doubleCurlyMatches);
}
// make sure we are clean from curly brackets
varNameArray = varNameArray.map(x => {
return x.match(nameInCurlsRegex)[0];
});
// make sure are uniq
varNameArray = plugins.lodashUniq(varNameArray);
return varNameArray;
};
/**
* checks if supplied variables satisfy an handlebars template
* @param hbsStringArg
* @param varObjectArg
* @return string array with missing variable names
*/
exports.checkVarsSatisfaction = async (hbsStringArg, varObjectArg) => {
// required vars as combined deep string with . notation
let requiredVarStrings = await exports.findVarsInHbsString(hbsStringArg);
// comparison objects
let suppliedVarsObject = varObjectArg;
let missingVarsObject = [];
// building the
for (let stringVar of requiredVarStrings) {
let splittedVars = stringVar.split('.');
let requiredPointer = suppliedVarsObject;
for (let i = 0; i < splittedVars.length; i++) {
let splitVar = splittedVars[i];
let varAvailable = requiredPointer[splitVar] !== undefined;
if (varAvailable && splittedVars.length === i + 1) {
// ok
}
else if (varAvailable) {
requiredPointer = requiredPointer[splitVar];
}
else {
missingVarsObject.push(stringVar);
i = splittedVars.length;
}
}
}
return missingVarsObject;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudmFyaWFibGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRoYnMudmFyaWFibGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwRkFBMEY7QUFDMUYsOENBQThDOzs7Ozs7Ozs7QUFFOUMsNERBQThDO0FBRTlDLDBCQUEwQjtBQUMxQixJQUFJLGdCQUFnQixHQUFHLHNCQUFzQixDQUFDO0FBQzlDLElBQUksZ0JBQWdCLEdBQUcsb0JBQW9CLENBQUM7QUFDNUMsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUM7QUFFakM7OztHQUdHO0FBQ1EsUUFBQSxtQkFBbUIsR0FBRyxLQUFLLEVBQUUsWUFBb0IsRUFBRSxFQUFFO0lBQzlELElBQUksU0FBUyxHQUFHLFlBQVksQ0FBQyxDQUFDLDREQUE0RDtJQUMxRixJQUFJLFlBQVksR0FBYSxFQUFFLENBQUM7SUFDaEMsSUFBSSxrQkFBa0IsR0FBRyxTQUFTLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUM7SUFDM0QsSUFBSSxrQkFBa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Ba0IsRUFBRTtRQUN4QyxJQUFJLFlBQVksR0FBRyxTQUFTLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ3hDLElBQUksZUFBZSxHQUFHLGtCQUFrQixDQUFDO1FBQ3pDLEtBQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxZQUFZLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFO1lBQzVDLElBQUksUUFBUSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUMvQixJQUFJLFlBQVksR0FBRyxlQUFlLENBQUMsUUFBUSxDQUFDLEtBQUssU0FBUyxDQUFDO1lBQzNELElBQUksWUFBWSxJQUFJLFlBQVksQ0FBQyxNQUFNLEtBQUssQ0FBQyxHQUFHLENBQUMsRUFBRTtnQkFDakQsS0FBSzthQUNOO2lCQUFNLElBQUksWUFBWSxFQUFFO2dCQUN2QixlQUFlLEdBQUcsZUFBZSxDQUFDLFFBQVEsQ0FBQyxDQUFDO2FBQzdDO2lCQUFNO2dCQUNMLGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztnQkFDbEMsQ0FBQyxHQUFHLFlBQVksQ0FBQyxNQUFNLENBQUM7YUFDekI7U0FDRjtLQUNGO0lBQ0QsT0FBTyxpQkFBaUIsQ0FBQztBQUMzQixDQUFDLENBQUMifQ==

798
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,17 +23,17 @@
},
"homepage": "https://gitlab.com/pkunz/smarthbs#README",
"dependencies": {
"@pushrocks/smartfile": "^6.0.12",
"@pushrocks/smartpromise": "^2.0.5",
"@types/lodash": "^4.14.121",
"handlebars": "^4.1.0",
"lodash": "^4.17.11"
"@pushrocks/smartfile": "^7.0.4",
"@pushrocks/smartpromise": "^3.0.2",
"handlebars": "^4.2.0",
"lodash": "^4.17.11",
"lodash.uniq": "^4.5.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.8",
"@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^11.9.4"
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.4"
}
}

View File

@ -1,7 +1,7 @@
import * as handlebars from 'handlebars';
import * as lodash from 'lodash';
import lodashUniq from 'lodash.uniq';
import * as path from 'path';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
export { handlebars, lodash, path, smartfile, smartpromise };
export { handlebars, lodashUniq, path, smartfile, smartpromise };

View File

@ -18,11 +18,11 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
let tripleCurlyMatches = hbsString.match(tripleCurlyRegex);
if (tripleCurlyMatches) {
hbsString = hbsString.replace(tripleCurlyRegex, '[[[replaced]]]');
varNameArray = plugins.lodash.concat(varNameArray, tripleCurlyMatches);
varNameArray = varNameArray.concat(tripleCurlyMatches);
}
let doubleCurlyMatches = hbsString.match(doubleCurlyRegex);
if (doubleCurlyMatches) {
varNameArray = plugins.lodash.concat(varNameArray, doubleCurlyMatches);
varNameArray = varNameArray.concat(doubleCurlyMatches);
}
// make sure we are clean from curly brackets
@ -31,7 +31,7 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
});
// make sure are uniq
varNameArray = plugins.lodash.uniq(varNameArray);
varNameArray = plugins.lodashUniq(varNameArray);
return varNameArray;
};