Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
0ab254e4ed | |||
185b7a38d5 | |||
7ab6922eed | |||
31bf5f7486 | |||
78d4df7082 | |||
74d2d980a5 | |||
49aa80aca8 | |||
b382256cc7 | |||
97400fa501 | |||
914a8eafce | |||
7299b3a9c6 | |||
cfd257d359 | |||
203ea05f67 | |||
f00a11bf9b | |||
7b0f2ab8d6 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,6 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
test/testresult/
|
||||
.nogit/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
144
.gitlab-ci.yml
144
.gitlab-ci.yml
@ -1,144 +1,122 @@
|
||||
# gitzone ci_default
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
- docker
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
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
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -146,5 +124,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.3
|
||||
ignore: {}
|
||||
patch: {}
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
40
README.md
40
README.md
@ -1,40 +0,0 @@
|
||||
# @pushrocks/smarthbs
|
||||
handlebars with better fs support
|
||||
|
||||
## 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
|
||||
[](https://gitlab.com/pushrocks/smarthbs/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smarthbs/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smarthbs)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smarthbs)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
> 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');
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
9
dist/index.d.ts
vendored
9
dist/index.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
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
21
dist/index.js
vendored
@ -1,21 +0,0 @@
|
||||
"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
4
dist/smarthbs.compile.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* compiles a directory and outputs it
|
||||
*/
|
||||
export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise<void>;
|
27
dist/smarthbs.compile.js
vendored
27
dist/smarthbs.compile.js
vendored
@ -1,27 +0,0 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuY29tcGlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmNvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsNERBQThDO0FBRTlDOztHQUVHO0F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BQyxNQUFNLENBQUMsUUFBUSxDQUMvQixNQUFNLEVBQ04sT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMscUJBQXFCLEVBQUUsVUFBVSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsQ0FDcEUsQ0FBQztLQUNIO0FBQ0gsQ0FBQyxDQUFDIn0=
|
1
dist/smarthbs.helpers.d.ts
vendored
1
dist/smarthbs.helpers.d.ts
vendored
@ -1 +0,0 @@
|
||||
export {};
|
39
dist/smarthbs.helpers.js
vendored
39
dist/smarthbs.helpers.js
vendored
@ -1,39 +0,0 @@
|
||||
"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);
|
||||
});
|
||||
//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ENBQUMsV0FBVyxFQUFFLENBQUMsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQUUsRUFBRTtJQUNyRixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO0lBQzVELE9BQU8sUUFBUSxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDckMsQ0FBQyxDQUFDLENBQUMifQ==
|
4
dist/smarthbs.partials.d.ts
vendored
4
dist/smarthbs.partials.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 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
33
dist/smarthbs.partials.js
vendored
@ -1,33 +0,0 @@
|
||||
"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
6
dist/smarthbs.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
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
23
dist/smarthbs.plugins.js
vendored
@ -1,23 +0,0 @@
|
||||
"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
5
dist/smarthbs.postprocess.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
/**
|
||||
* 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
15
dist/smarthbs.postprocess.js
vendored
@ -1,15 +0,0 @@
|
||||
"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
9
dist/smarthbs.template.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
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
24
dist/smarthbs.template.js
vendored
@ -1,24 +0,0 @@
|
||||
"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
12
dist/smarthbs.variables.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* 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
74
dist/smarthbs.variables.js
vendored
@ -1,74 +0,0 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudmFyaWFibGVzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRoYnMudmFyaWFibGVzLnRzIl0sIm5hbW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LFFBQVEsQ0FBQyxDQUFDO2FBQzdDO2lCQUFNO2dCQUNMLGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztnQkFDbEMsQ0FBQyxHQUFHLFlBQVksQ0FBQyxNQUFNLENBQUM7YUFDekI7U0FDRjtLQUNGO0lBQ0QsT0FBTyxpQkFBaUIsQ0FBQztBQUMzQixDQUFDLENBQUMifQ==
|
@ -4,11 +4,12 @@
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smarthbs",
|
||||
"shortDescription": "handlebars with better fs support",
|
||||
"description": "handlebars with better fs support",
|
||||
"npmPackagename": "@pushrocks/smarthbs",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
1589
package-lock.json
generated
1589
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "@pushrocks/smarthbs",
|
||||
"version": "2.0.4",
|
||||
"version": "3.0.2",
|
||||
"private": false,
|
||||
"description": "handlebars with better fs support",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --allowimplicitany)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -23,17 +24,31 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pkunz/smarthbs#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": "^7.0.4",
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"handlebars": "^4.2.0",
|
||||
"lodash": "^4.17.11",
|
||||
"lodash.uniq": "^4.5.0"
|
||||
"@pushrocks/smartfile": "^10.0.2",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"handlebars": "^4.7.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsrun": "^1.2.37",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.0.6"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
4393
pnpm-lock.yaml
generated
Normal file
4393
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
52
readme.md
Normal file
52
readme.md
Normal file
@ -0,0 +1,52 @@
|
||||
# @pushrocks/smarthbs
|
||||
handlebars with better fs support
|
||||
|
||||
## 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
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
> 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');
|
||||
```
|
||||
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
30
test/test.ts
30
test/test.ts
@ -1,24 +1,28 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smarthbs from '../ts/index';
|
||||
import * as smarthbs from '../ts/index.js';
|
||||
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as path from 'path';
|
||||
|
||||
let testHbsDir = path.join(__dirname, 'hbs_testfiles');
|
||||
let testPartialDir = path.join(testHbsDir, 'partials');
|
||||
let testResultDir = path.join(__dirname, 'testresult');
|
||||
const dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
||||
|
||||
let hbs_testfilesDir = path.join(dirname, 'hbs_testfiles');
|
||||
let testPartialDir = path.join(hbs_testfilesDir, 'partials');
|
||||
let testResultDir = path.join(dirname, 'testresult');
|
||||
|
||||
tap.test('smarthbs -> should create partials', async () => {
|
||||
await smarthbs.registerPartialDir(testPartialDir);
|
||||
});
|
||||
|
||||
tap.test('smarthbs -> should compile a directory', async () => {
|
||||
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
|
||||
smarthbs.compileDirectory(hbs_testfilesDir, testResultDir, 'data.json');
|
||||
});
|
||||
|
||||
tap.test('', async () => {
|
||||
let templateString = '{{{firstVar}}} {{secondVar}}';
|
||||
let templateVars = await smarthbs.findVarsInHbsString(templateString);
|
||||
expect(templateVars).to.include('firstVar');
|
||||
expect(templateVars).to.include('secondVar');
|
||||
expect(templateVars).toContain('firstVar');
|
||||
expect(templateVars).toContain('secondVar');
|
||||
});
|
||||
|
||||
tap.test('', async () => {
|
||||
@ -29,12 +33,14 @@ tap.test('', async () => {
|
||||
secondVar: 'hello',
|
||||
fourthVar: {
|
||||
otherKey: {
|
||||
nextKey: 'wow'
|
||||
}
|
||||
}
|
||||
nextKey: 'wow',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(missingVars).to.contain('thirdVar', 'fourthVar.someKey');
|
||||
expect(missingVars).to.not.contain('secondVar', 'fourthVar.otherKey.nextKey');
|
||||
expect(missingVars).toContain('thirdVar');
|
||||
expect(missingVars).toContain('fourthVar.someKey');
|
||||
expect(missingVars).not.toContain('secondVar');
|
||||
expect(missingVars).not.toContain('fourthVar.otherKey.nextKey');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
1
test/testresult/index.html
Normal file
1
test/testresult/index.html
Normal file
@ -0,0 +1 @@
|
||||
<head></head>analyzed
|
1
test/testresult/index2.html
Normal file
1
test/testresult/index2.html
Normal file
@ -0,0 +1 @@
|
||||
A second hbs file!
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smarthbs',
|
||||
version: '3.0.2',
|
||||
description: 'handlebars with better fs support'
|
||||
}
|
14
ts/index.ts
14
ts/index.ts
@ -1,10 +1,10 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
export type TTemplateStringType = 'filePath' | 'code';
|
||||
|
||||
export let handlebars = 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';
|
||||
export * from './smarthbs.compile.js';
|
||||
import './smarthbs.helpers.js';
|
||||
export * from './smarthbs.partials.js';
|
||||
export * from './smarthbs.template.js';
|
||||
export * from './smarthbs.variables.js';
|
||||
export * from './smarthbs.postprocess.js';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
/**
|
||||
* compiles a directory and outputs it
|
||||
|
@ -1,10 +1,10 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
/**
|
||||
* Helper:
|
||||
* Allows you to analyze a context
|
||||
*/
|
||||
plugins.handlebars.registerHelper('__analyze', analyzeContext => {
|
||||
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
|
||||
if (typeof analyzeContext === 'string') {
|
||||
if (plugins.handlebars.partials[analyzeContext]) {
|
||||
console.log(`The analyzed partial ${analyzeContext} looks like this`);
|
||||
@ -20,7 +20,7 @@ plugins.handlebars.registerHelper('__analyze', analyzeContext => {
|
||||
* Helper:
|
||||
* logs all registered partials to console
|
||||
*/
|
||||
plugins.handlebars.registerHelper('__allPartialsLog', analyzeContext => {
|
||||
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
|
||||
console.log(plugins.handlebars.partials);
|
||||
return 'analyzed';
|
||||
});
|
||||
|
@ -1,11 +1,11 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
/**
|
||||
* registers a directory of partials to make them available within handlebars compilation
|
||||
*/
|
||||
export let registerPartialDir = (dirPathArg: string): Promise<any> => {
|
||||
let done = plugins.smartpromise.defer();
|
||||
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
|
||||
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(
|
||||
|
@ -1,7 +1,15 @@
|
||||
import * as handlebars from 'handlebars';
|
||||
import lodashUniq from 'lodash.uniq';
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { handlebars, lodashUniq, path, smartfile, smartpromise };
|
||||
export { smartpath, smartfile, smartpromise };
|
||||
|
||||
// third party
|
||||
import handlebars from 'handlebars';
|
||||
|
||||
export { handlebars };
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
let safeSyntaxBeginRegex = /{-{/g;
|
||||
let safeSyntaxEndRegex = /}-}/g;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
/**
|
||||
* get a template for a file on disk
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This file contains code that makes it easy to search handlebar templates for variables.
|
||||
// Why? To get a clue if you are missing some.
|
||||
|
||||
import * as plugins from './smarthbs.plugins';
|
||||
import * as plugins from './smarthbs.plugins.js';
|
||||
|
||||
// the curly regex objects
|
||||
let tripleCurlyRegex = /{{{\s*[\w\.]+\s*}}}/g;
|
||||
@ -26,12 +26,15 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
|
||||
}
|
||||
|
||||
// make sure we are clean from curly brackets
|
||||
varNameArray = varNameArray.map(x => {
|
||||
varNameArray = varNameArray.map((x) => {
|
||||
return x.match(nameInCurlsRegex)[0];
|
||||
});
|
||||
|
||||
// make sure are uniq
|
||||
varNameArray = plugins.lodashUniq(varNameArray);
|
||||
function uniqueArray(input: string[]): string[] {
|
||||
return Array.from(new Set(input));
|
||||
}
|
||||
varNameArray = uniqueArray(varNameArray);
|
||||
return varNameArray;
|
||||
};
|
||||
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
Reference in New Issue
Block a user