8 Commits

Author SHA1 Message Date
3ef9388979 2.0.4 2019-09-10 17:58:32 +02:00
1d35da50cd update 2019-09-10 17:58:14 +02:00
f5b86154db 2.0.3 2019-02-17 17:02:35 +01:00
7474d208e4 fix(documentation): update 2019-02-17 17:02:35 +01:00
74f4026c74 2.0.2 2019-02-17 17:00:29 +01:00
3808e4168f fix(security): add snyk 2019-02-17 17:00:28 +01:00
084bee68af 2.0.1 2019-02-17 16:59:56 +01:00
9f6b67fa4e fix(core): update 2019-02-17 16:59:56 +01:00
26 changed files with 1387 additions and 520 deletions

View File

@ -1,4 +1,4 @@
# gitzone standard
# gitzone ci_default
image: hosttoday/ht-docker-node:npmci
cache:
@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -33,24 +34,39 @@ snyk:
- docker
- notpriv
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- npmci npm prepare
- npmci npm install
- npmci command npm run build
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags:
- docker
- priv
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -62,6 +78,7 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
@ -118,6 +135,7 @@ pages:
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
@ -130,13 +148,3 @@ pages:
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

4
.snyk Normal file
View File

@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.3
ignore: {}
patch: {}

View File

@ -1,32 +1,23 @@
# smarthbs
# @pushrocks/smarthbs
handlebars with better fs support
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smarthbs)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smarthbs)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smarthbs)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smarthbs/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smarthbs)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smarthbs)
* [github.com (source mirror)](https://github.com/pushrocks/smarthbs)
* [docs (typedoc)](https://pushrocks.gitlab.io/smarthbs/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smarthbs/badges/master/build.svg)](https://GitLab.com/pushrocks/smarthbs/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smarthbs/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smarthbs/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smarthbs.svg)](https://www.npmjs.com/package/smarthbs)
[![Dependency Status](https://david-dm.org/pushrocks/smarthbs.svg)](https://david-dm.org/pushrocks/smarthbs)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smarthbs/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smarthbs/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smarthbs/badges/code.svg)](https://www.bithound.io/github/pushrocks/smarthbs)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![build status](https://gitlab.com/pushrocks/smarthbs/badges/master/build.svg)](https://gitlab.com/pushrocks/smarthbs/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smarthbs/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smarthbs/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smarthbs.svg)](https://www.npmjs.com/package/@pushrocks/smarthbs)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smarthbs/badge.svg)](https://snyk.io/test/npm/@pushrocks/smarthbs)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> Note: Why did we decide against a class based architecture?
> Easy: handlebars.js is already pretty determined how things are handled internally, namely a global partial template registry
> It doesn't make sense to then introduce a scoped partial template approach.
@ -41,7 +32,9 @@ smarthbs.registerPartialDir(testPartialDir);
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
```
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
For further information read the linked docs at the top of this readme.
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuY29tcGlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmNvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsNERBQThDO0FBRTlDOztHQUVHO0FBQ1EsUUFBQSxnQkFBZ0IsR0FBRyxLQUFLLEVBQ2pDLGdCQUF3QixFQUN4QixxQkFBNkIsRUFDN0IsZUFBdUIsRUFDd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BQUUsVUFBVSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsQ0FDcEUsQ0FBQztLQUNIO0FBQ0gsQ0FBQyxDQUFDIn0=

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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudmFyaWFibGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRoYnMudmFyaWFibGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwRkFBMEY7QUFDMUYsOENBQThDOzs7Ozs7Ozs7QUFFOUMsNERBQThDO0FBRTlDLDBCQUEwQjtBQUMxQixJQUFJLGdCQUFnQixHQUFHLHNCQUFzQixDQUFDO0FBQzlDLElBQUksZ0JBQWdCLEdBQUcsb0JBQW9CLENBQUM7QUFDNUMsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUM7QUFFakM7OztHQUdHO0FBQ1EsUUFBQSxtQkFBbUIsR0FBRyxLQUFLLEVBQUUsWUFBb0IsRUFBRSxFQUFFO0lBQzlELElBQUksU0FBUyxHQUFHLFlBQVksQ0FBQyxDQUFDLDREQUE0RDtJQUMxRixJQUFJLFlBQVksR0FBYSxFQUFFLENBQUM7SUFDaEMsSUFBSSxrQkFBa0IsR0FBRyxTQUFTLENBQUMsS0FBSyxDQUFDLGdCQUFnQixDQUFDLENBQUM7SUFDM0QsSUFBSSxrQkFBa0IsR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sRUFBRTtRQUN4QyxJQUFJLFlBQVksR0FBRyxTQUFTLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ3hDLElBQUksZUFBZSxHQUFHLGtCQUFrQixDQUFDO1FBQ3pDLEtBQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxZQUFZLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFO1lBQzVDLElBQUksUUFBUSxHQUFHLFlBQVksQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUMvQixJQUFJLFlBQVksR0FBRyxlQUFlLENBQUMsUUFBUSxDQUFDLEtBQUssU0FBUyxDQUFDO1lBQzNELElBQUksWUFBWSxJQUFJLFlBQVksQ0FBQyxNQUFNLEtBQUssQ0FBQyxHQUFHLENBQUMsRUFBRTtnQkFDakQsS0FBSzthQUNOO2lCQUFNLElBQUksWUFBWSxFQUFFO2dCQUN2QixlQUFlLEdBQUcsZUFBZSxDQUFDLFFBQVEsQ0FBQyxDQUFDO2FBQzdDO2lCQUFNO2dCQUNMLGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztnQkFDbEMsQ0FBQyxHQUFHLFlBQVksQ0FBQyxNQUFNLENBQUM7YUFDekI7U0FDRjtLQUNGO0lBQ0QsT0FBTyxpQkFBaUIsQ0FBQztBQUMzQixDQUFDLENBQUMifQ==

View File

@ -1,47 +0,0 @@
# smarthbs
handlebars with better fs support
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smarthbs)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smarthbs)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smarthbs)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smarthbs/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smarthbs/badges/master/build.svg)](https://GitLab.com/pushrocks/smarthbs/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smarthbs/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smarthbs/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smarthbs.svg)](https://www.npmjs.com/package/smarthbs)
[![Dependency Status](https://david-dm.org/pushrocks/smarthbs.svg)](https://david-dm.org/pushrocks/smarthbs)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smarthbs/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smarthbs/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smarthbs/badges/code.svg)](https://www.bithound.io/github/pushrocks/smarthbs)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> Note: Why did we decide against a class based architecture?
> Easy: handlebars.js is already pretty determined how things are handled internally, namely a global partial template registry
> It doesn't make sense to then introduce a scoped partial template approach.
```javascript
import * as smarthbs from 'smarthbs';
// read all .hbs files in a directory and any child directories and use relative path as partial string identifier
smarthbs.registerPartialDir(testPartialDir);
// read all .hbs files in a particular directory and level, output them to a destination and specify a .json file to read any referenced data
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
```
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -2,5 +2,15 @@
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smarthbs",
"shortDescription": "handlebars with better fs support",
"npmPackagename": "@pushrocks/smarthbs",
"license": "MIT"
}
}
}
}

1396
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smarthbs",
"version": "2.0.0",
"version": "2.0.4",
"private": false,
"description": "handlebars with better fs support",
"main": "dist/index.js",
@ -23,18 +23,17 @@
},
"homepage": "https://gitlab.com/pkunz/smarthbs#README",
"dependencies": {
"@pushrocks/smartfile": "^6.0.8",
"@pushrocks/smartpromise": "^2.0.5",
"@types/handlebars": "^4.0.39",
"@types/lodash": "^4.14.116",
"handlebars": "^4.0.11",
"lodash": "^4.17.10"
"@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.0.22",
"@gitzone/tsrun": "^1.1.12",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.5",
"@types/node": "^10.9.2"
"@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;
};

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}