Merge branch 'master' into 'master'

fixed async readPartialDir

Closes #1

See merge request !1
This commit is contained in:
Phil Kunz 2017-03-14 18:33:04 +00:00
commit 8041ccdada
8 changed files with 38 additions and 21 deletions

View File

@ -1,5 +1,5 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmts
image: hosttoday/ht-docker-node:npmci
stages:
- test

2
dist/index.d.ts vendored
View File

@ -4,7 +4,7 @@ export declare type TTemplateStringType = 'filePath' | 'code';
/**
* registers a directory of partials to make them available within handlebars compilation
*/
export declare let registerPartialDir: (dirPathArg: string) => void;
export declare let registerPartialDir: (dirPathArg: string) => Promise<{}>;
/**
* compiles a directory and outputs it
*/

7
dist/index.js vendored
View File

@ -7,14 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const handlebars = require("handlebars");
const smartfile = require("smartfile");
const smartq = require("smartq");
const path = require("path");
/**
* registers a directory of partials to make them available within handlebars compilation
*/
exports.registerPartialDir = (dirPathArg) => {
let done = smartq.defer();
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = path.parse(hbsFilePath);
@ -24,8 +27,10 @@ exports.registerPartialDir = (dirPathArg) => {
}
let partialName = `partials${parsedPath.dir}${parsedPath.name}`;
handlebars.registerPartial(partialName, hbsFileString);
done.resolve();
}
});
return done.promise;
};
/**
* compiles a directory and outputs it
@ -49,4 +54,4 @@ exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, fu
let filePathAbsolute = path.resolve(filePathArg);
return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute));
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW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QUFBO1FBQ3ZGLElBQUksUUFBUSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDaEQsSUFBSSxNQUFNLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsS0FBSyxHQUFHLE1BQU0sR0FBRyxLQUFLLENBQUMsQ0FBQTtRQUNuQyxTQUFTLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxxQkFBcUIsRUFBRSxVQUFVLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUE7SUFDaEcsQ0FBQztBQUNILENBQUMsQ0FBQSxDQUFBO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQU8sV0FBbUI7SUFDeEQsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQ2hELE1BQU0sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQTtBQUN4RSxDQUFDLENBQUEsQ0FBQSJ9

7
npmextra.json Normal file
View File

@ -0,0 +1,7 @@
{
"npmci": {
"globalNpmTools": [
"npmts"
]
}
}

View File

@ -21,10 +21,10 @@
},
"homepage": "https://gitlab.com/pkunz/smarthbs#README",
"dependencies": {
"@types/handlebars": "^4.0.31",
"@types/handlebars": "^4.0.32",
"handlebars": "^4.0.6",
"smartfile": "^4.1.4",
"smartq": "^1.0.4",
"smartfile": "^4.1.8",
"smartq": "^1.1.1",
"typings-global": "^1.0.14"
},
"devDependencies": {

View File

@ -1,4 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-test");
const smarthbs = require("../dist/index");
const path = require("path");
@ -13,4 +14,4 @@ describe('smarthbs', function () {
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQiwwQ0FBeUM7QUFDekMsNkJBQTRCO0FBRTVCLElBQUksVUFBVSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLGVBQWUsQ0FBQyxDQUFBO0FBQ3RELElBQUksY0FBYyxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFBO0FBQ3RELElBQUksYUFBYSxHQUFHLElBQUksQ0FBRSxJQUFJLENBQUMsU0FBUyxFQUFFLFlBQVksQ0FBQyxDQUFBO0FBQ3ZELFFBQVEsQ0FBQyxVQUFVLEVBQUU7SUFFakIsRUFBRSxDQUFDLHdCQUF3QixFQUFFO1FBQ3pCLFFBQVEsQ0FBQyxrQkFBa0IsQ0FBQyxjQUFjLENBQUMsQ0FBQTtJQUMvQyxDQUFDLENBQUMsQ0FBQTtJQUVGLEVBQUUsQ0FBQyw0QkFBNEIsRUFBRTtRQUM3QixRQUFRLENBQUMsZ0JBQWdCLENBQUMsVUFBVSxFQUFFLGFBQWEsRUFBRSxXQUFXLENBQUMsQ0FBQTtJQUNyRSxDQUFDLENBQUMsQ0FBQTtBQUVOLENBQUMsQ0FBQyxDQUFBIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3QkFBcUI7QUFDckIsMENBQXlDO0FBQ3pDLDZCQUE0QjtBQUU1QixJQUFJLFVBQVUsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBRSxlQUFlLENBQUMsQ0FBQTtBQUN0RCxJQUFJLGNBQWMsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxVQUFVLENBQUMsQ0FBQTtBQUN0RCxJQUFJLGFBQWEsR0FBRyxJQUFJLENBQUUsSUFBSSxDQUFDLFNBQVMsRUFBRSxZQUFZLENBQUMsQ0FBQTtBQUN2RCxRQUFRLENBQUMsVUFBVSxFQUFFO0lBRWpCLEVBQUUsQ0FBQyx3QkFBd0IsRUFBRTtRQUN6QixRQUFRLENBQUMsa0JBQWtCLENBQUMsY0FBYyxDQUFDLENBQUE7SUFDL0MsQ0FBQyxDQUFDLENBQUE7SUFFRixFQUFFLENBQUMsNEJBQTRCLEVBQUU7UUFDN0IsUUFBUSxDQUFDLGdCQUFnQixDQUFDLFVBQVUsRUFBRSxhQUFhLEVBQUUsV0FBVyxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7QUFFTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,6 +1,7 @@
import 'typings-global'
import * as handlebars from 'handlebars'
import * as smartfile from 'smartfile'
import * as smartq from 'smartq'
import * as path from 'path'
export type TTemplateStringType = 'filePath' | 'code'
@ -8,6 +9,7 @@ export type TTemplateStringType = 'filePath' | 'code'
* registers a directory of partials to make them available within handlebars compilation
*/
export let registerPartialDir = (dirPathArg: string) => {
let done = smartq.defer()
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
for (let hbsFilePath of hbsFileArrayArg) {
let parsedPath = path.parse(hbsFilePath)
@ -17,8 +19,10 @@ export let registerPartialDir = (dirPathArg: string) => {
}
let partialName = `partials${parsedPath.dir}${parsedPath.name}`
handlebars.registerPartial(partialName, hbsFileString)
done.resolve()
}
})
return done.promise
}
/**

View File

@ -8,9 +8,9 @@
dependencies:
"@types/node" "*"
"@types/handlebars@^4.0.31":
version "4.0.31"
resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.0.31.tgz#a7fba66fafe42713aee88eeca8db91192efe6e72"
"@types/handlebars@^4.0.32":
version "4.0.32"
resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.0.32.tgz#637e8d945a9354aab47df7125005490fe9f8e592"
"@types/mocha@^2.2.31":
version "2.2.39"
@ -201,9 +201,9 @@ isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
js-yaml@^3.7.0:
version "3.8.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.1.tgz#782ba50200be7b9e5a8537001b7804db3ad02628"
js-yaml@^3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.2.tgz#02d3e2c0f6beab20248d412c352203827d786721"
dependencies:
argparse "^1.0.7"
esprima "^3.1.1"
@ -329,31 +329,31 @@ shelljs@^0.7.4:
interpret "^1.0.0"
rechoir "^0.6.2"
smartfile@^4.1.4:
version "4.1.6"
resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.1.6.tgz#d71026aefef99233c56766c3c6c11afc41a19b3a"
smartfile@^4.1.8:
version "4.1.8"
resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.1.8.tgz#4f568537de0cd1174ce3086036ac9df26f860330"
dependencies:
"@types/fs-extra" "0.x.x"
"@types/vinyl" "^2.0.0"
fs-extra "^2.0.0"
glob "^7.1.1"
js-yaml "^3.7.0"
js-yaml "^3.8.2"
require-reload "0.2.2"
smartpath "^3.2.7"
smartq "^1.0.4"
smartpath "^3.2.8"
smartq "^1.1.1"
smartrequest "^1.0.4"
typings-global "^1.0.14"
vinyl "^2.0.1"
vinyl-file "^3.0.0"
smartpath@^3.2.7:
smartpath@^3.2.8:
version "3.2.8"
resolved "https://registry.yarnpkg.com/smartpath/-/smartpath-3.2.8.tgz#4834bd3a8bae2295baacadba23c87a501952f940"
dependencies:
home "^1.0.1"
typings-global "^1.0.14"
smartq@^1.0.4, smartq@^1.1.0:
smartq@^1.1.0, smartq@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.1.tgz#efb358705260d41ae18aef7ffd815f7b6fe17dd3"
dependencies: