From 34cfe010f78a74af7fe4bd841c0dd9e03a96a1e1 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 19 Mar 2017 17:14:28 +0100 Subject: [PATCH] clean up --- dist/index.d.ts | 18 +++-------- dist/index.js | 63 +++++-------------------------------- dist/smarthbs.compile.d.ts | 4 +++ dist/smarthbs.compile.js | 27 ++++++++++++++++ dist/smarthbs.helpers.d.ts | 2 ++ dist/smarthbs.helpers.js | 5 +++ dist/smarthbs.partials.d.ts | 4 +++ dist/smarthbs.partials.js | 23 ++++++++++++++ dist/smarthbs.plugins.d.ts | 6 ++++ dist/smarthbs.plugins.js | 12 +++++++ dist/smarthbs.template.d.ts | 5 +++ dist/smarthbs.template.js | 19 +++++++++++ ts/index.ts | 57 +++------------------------------ ts/smarthbs.compile.ts | 21 +++++++++++++ ts/smarthbs.helpers.ts | 4 +++ ts/smarthbs.partials.ts | 21 +++++++++++++ ts/smarthbs.plugins.ts | 12 +++++++ ts/smarthbs.template.ts | 9 ++++++ 18 files changed, 191 insertions(+), 121 deletions(-) create mode 100644 dist/smarthbs.compile.d.ts create mode 100644 dist/smarthbs.compile.js create mode 100644 dist/smarthbs.helpers.d.ts create mode 100644 dist/smarthbs.helpers.js create mode 100644 dist/smarthbs.partials.d.ts create mode 100644 dist/smarthbs.partials.js create mode 100644 dist/smarthbs.plugins.d.ts create mode 100644 dist/smarthbs.plugins.js create mode 100644 dist/smarthbs.template.d.ts create mode 100644 dist/smarthbs.template.js create mode 100644 ts/smarthbs.compile.ts create mode 100644 ts/smarthbs.helpers.ts create mode 100644 ts/smarthbs.partials.ts create mode 100644 ts/smarthbs.plugins.ts create mode 100644 ts/smarthbs.template.ts diff --git a/dist/index.d.ts b/dist/index.d.ts index df0e5b6..0a86845 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,15 +1,5 @@ -/// -import 'typings-global'; export declare type TTemplateStringType = 'filePath' | 'code'; -/** - * registers a directory of partials to make them available within handlebars compilation - */ -export declare let registerPartialDir: (dirPathArg: string) => Promise<{}>; -/** - * compiles a directory and outputs it - */ -export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise; -/** - * get a template for a file on disk - */ -export declare let getTemplateForFile: (filePathArg: string) => Promise; +export * from './smarthbs.compile'; +export * from './smarthbs.helpers'; +export * from './smarthbs.partials'; +export * from './smarthbs.template'; diff --git a/dist/index.js b/dist/index.js index ac29c50..5cd8290 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,57 +1,10 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} 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); - let hbsFileString = smartfile.fs.toStringSync(path.join(dirPathArg, hbsFilePath)); - if (parsedPath.dir === '') { - parsedPath.name = '/' + parsedPath.name; - } - let partialName = `partials${parsedPath.dir}${parsedPath.name}`; - handlebars.registerPartial(partialName, hbsFileString); - done.resolve(); - } - }); - return done.promise; -}; -/** - * compiles a directory and outputs it - */ -exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () { - let hbsFilePathArray = smartfile.fs.listFilesSync(originDirPathArg, /.hbs/); - let data = smartfile.fs.toObjectSync(path.join(originDirPathArg, dataFileNameArg)); - for (let hbsFilePath of hbsFilePathArray) { - let parsedPath = path.parse(hbsFilePath); - let hbsFileString = smartfile.fs.toStringSync(path.join(originDirPathArg, hbsFilePath)); - let template = handlebars.compile(hbsFileString); - let output = template(data); - console.log('hi ' + output + ' hi'); - smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html')); - } -}); -/** - * get a template for a file on disk - */ -exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, function* () { - let filePathAbsolute = path.resolve(filePathArg); - return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute)); -}); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUF3QztBQUN4Qyx1Q0FBc0M7QUFDdEMsaUNBQWdDO0FBQ2hDLDZCQUE0QjtBQUc1Qjs7R0FFRztBQUNRLFFBQUEsa0JBQWtCLEdBQUcsQ0FBQyxVQUFrQjtJQUNqRCxJQUFJLElBQUksR0FBRyxNQUFNLENBQUMsS0FBSyxFQUFFLENBQUE7SUFDekIsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDLElBQUksQ0FBQyxlQUFlO1FBQ3BFLEdBQUcsQ0FBQyxDQUFDLElBQUksV0FBVyxJQUFJLGVBQWUsQ0FBQyxDQUFDLENBQUM7WUFDeEMsSUFBSSxVQUFVLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUN4QyxJQUFJLGFBQWEsR0FBRyx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0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUE7UUFDeEMsSUFBSSxhQUFhLEdBQUcsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxXQUFXLENBQUMsQ0FBQyxDQUFBO1FBQ3ZGLElBQUksUUFBUSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDaEQsSUFBSSxNQUFNLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsS0FBSyxHQUFHLE1BQU0sR0FBRyxLQUFLLENBQUMsQ0FBQTtRQUNuQyxTQUFTLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxNQUFNLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxxQkFBcUIsRUFBRSxVQUFVLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUE7SUFDaEcsQ0FBQztBQUNILENBQUMsQ0FBQSxDQUFBO0FBRUQ7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQU8sV0FBbUI7SUFDeEQsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFBO0lBQ2hELE1BQU0sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQTtBQUN4RSxDQUFDLENBQUEsQ0FBQSJ9 \ No newline at end of file +__export(require("./smarthbs.compile")); +__export(require("./smarthbs.helpers")); +__export(require("./smarthbs.partials")); +__export(require("./smarthbs.template")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUdBLHdDQUFrQztBQUNsQyx3Q0FBa0M7QUFDbEMseUNBQW1DO0FBQ25DLHlDQUFtQyJ9 \ No newline at end of file diff --git a/dist/smarthbs.compile.d.ts b/dist/smarthbs.compile.d.ts new file mode 100644 index 0000000..71c15a8 --- /dev/null +++ b/dist/smarthbs.compile.d.ts @@ -0,0 +1,4 @@ +/** + * compiles a directory and outputs it + */ +export declare let compileDirectory: (originDirPathArg: string, destinationDirPathArg: string, dataFileNameArg: string) => Promise; diff --git a/dist/smarthbs.compile.js b/dist/smarthbs.compile.js new file mode 100644 index 0000000..cc540c0 --- /dev/null +++ b/dist/smarthbs.compile.js @@ -0,0 +1,27 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const plugins = require("./smarthbs.plugins"); +/** + * compiles a directory and outputs it + */ +exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () { + 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'); + plugins.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ENBQUMsYUFBYSxDQUFDLENBQUE7UUFDeEQsSUFBSSxNQUFNLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQzNCLE9BQU8sQ0FBQyxHQUFHLENBQUMsS0FBSyxHQUFHLE1BQU0sR0FBRyxLQUFLLENBQUMsQ0FBQTtRQUNuQyxPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHFCQUFxQixFQUFFLFVBQVUsQ0FBQyxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQTtJQUNoSCxDQUFDO0FBQ0gsQ0FBQyxDQUFBLENBQUEifQ== \ No newline at end of file diff --git a/dist/smarthbs.helpers.d.ts b/dist/smarthbs.helpers.d.ts new file mode 100644 index 0000000..2117d55 --- /dev/null +++ b/dist/smarthbs.helpers.d.ts @@ -0,0 +1,2 @@ +/// +export declare let registerHelper: typeof Handlebars.registerHelper; diff --git a/dist/smarthbs.helpers.js b/dist/smarthbs.helpers.js new file mode 100644 index 0000000..706063a --- /dev/null +++ b/dist/smarthbs.helpers.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const plugins = require("./smarthbs.plugins"); +exports.registerHelper = plugins.handlebars.registerHelper; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBNkM7QUFFbEMsUUFBQSxjQUFjLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxjQUFjLENBQUEifQ== \ No newline at end of file diff --git a/dist/smarthbs.partials.d.ts b/dist/smarthbs.partials.d.ts new file mode 100644 index 0000000..dacef7e --- /dev/null +++ b/dist/smarthbs.partials.d.ts @@ -0,0 +1,4 @@ +/** + * registers a directory of partials to make them available within handlebars compilation + */ +export declare let registerPartialDir: (dirPathArg: string) => Promise<{}>; diff --git a/dist/smarthbs.partials.js b/dist/smarthbs.partials.js new file mode 100644 index 0000000..c317a8c --- /dev/null +++ b/dist/smarthbs.partials.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const plugins = require("./smarthbs.plugins"); +/** + * registers a directory of partials to make them available within handlebars compilation + */ +exports.registerPartialDir = (dirPathArg) => { + let done = plugins.smartq.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.name = '/' + parsedPath.name; + } + let partialName = `partials${parsedPath.dir}${parsedPath.name}`; + plugins.handlebars.registerPartial(partialName, hbsFileString); + done.resolve(); + } + }); + return done.promise; +}; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGFydGlhbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy5wYXJ0aWFscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDhDQUE2QztBQUU3Qzs7R0FFRztBQUNRLFFBQUEsa0JBQWtCLEdBQUcsQ0FBQyxVQUFrQjtJQUNqRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBRSxDQUFBO0lBQ2pDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxVQUFVLEVBQUUsVUFBVSxDQUFDLENBQUMsSUFBSSxDQUFDLGVBQWU7UUFDNUUsR0FBRyxDQUFDLENBQUMsSUFBSSxXQUFXLElBQUksZUFBZSxDQUFDLENBQUMsQ0FBQztZQUN4QyxJQUFJLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQTtZQUNoRCxJQUFJLGFBQWEsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUE7WUFDakcsRUFBRSxDQUFDLENBQUMsVUFBVSxDQUFDLEdBQUcsS0FBSyxFQUFFLENBQUMsQ0FBQyxDQUFDO2dCQUMxQixVQUFVLENBQUMsSUFBSSxHQUFHLEdBQUcsR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFBO1lBQ3pDLENBQUM7WUFDRCxJQUFJLFdBQVcsR0FBRyxXQUFXLFVBQVUsQ0FBQyxHQUFHLEdBQUcsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFBO1lBQy9ELE9BQU8sQ0FBQyxVQUFVLENBQUMsZUFBZSxDQUFDLFdBQVcsRUFBRSxhQUFhLENBQUMsQ0FBQTtZQUM5RCxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDaEIsQ0FBQztJQUNILENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0= \ No newline at end of file diff --git a/dist/smarthbs.plugins.d.ts b/dist/smarthbs.plugins.d.ts new file mode 100644 index 0000000..5e4d0e1 --- /dev/null +++ b/dist/smarthbs.plugins.d.ts @@ -0,0 +1,6 @@ +import 'typings-global'; +import * as handlebars from 'handlebars'; +import * as smartfile from 'smartfile'; +import * as smartq from 'smartq'; +import * as path from 'path'; +export { handlebars, smartfile, smartq, path }; diff --git a/dist/smarthbs.plugins.js b/dist/smarthbs.plugins.js new file mode 100644 index 0000000..55d4515 --- /dev/null +++ b/dist/smarthbs.plugins.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("typings-global"); +const handlebars = require("handlebars"); +exports.handlebars = handlebars; +const smartfile = require("smartfile"); +exports.smartfile = smartfile; +const smartq = require("smartq"); +exports.smartq = smartq; +const path = require("path"); +exports.path = path; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aGJzLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIseUNBQXdDO0FBTXRDLGdDQUFVO0FBTFosdUNBQXNDO0FBTXBDLDhCQUFTO0FBTFgsaUNBQWdDO0FBTTlCLHdCQUFNO0FBTFIsNkJBQTRCO0FBTTFCLG9CQUFJIn0= \ No newline at end of file diff --git a/dist/smarthbs.template.d.ts b/dist/smarthbs.template.d.ts new file mode 100644 index 0000000..a0a8cd7 --- /dev/null +++ b/dist/smarthbs.template.d.ts @@ -0,0 +1,5 @@ +/// +/** + * get a template for a file on disk + */ +export declare let getTemplateForFile: (filePathArg: string) => Promise; diff --git a/dist/smarthbs.template.js b/dist/smarthbs.template.js new file mode 100644 index 0000000..f0fc097 --- /dev/null +++ b/dist/smarthbs.template.js @@ -0,0 +1,19 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const plugins = require("./smarthbs.plugins"); +/** + * get a template for a file on disk + */ +exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, function* () { + let filePathAbsolute = plugins.path.resolve(filePathArg); + return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute)); +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRoYnMudGVtcGxhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGhicy50ZW1wbGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsOENBQTZDO0FBRTdDOztHQUVHO0FBQ1EsUUFBQSxrQkFBa0IsR0FBRyxDQUFPLFdBQW1CO0lBQ3hELElBQUksZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDeEQsTUFBTSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUE7QUFDeEYsQ0FBQyxDQUFBLENBQUEifQ== \ No newline at end of file diff --git a/ts/index.ts b/ts/index.ts index a9c6ff3..6d3ee1b 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,54 +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' +import * as plugins from './smarthbs.plugins' 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) - let hbsFileString = smartfile.fs.toStringSync(path.join(dirPathArg, hbsFilePath)) - if (parsedPath.dir === '') { - parsedPath.name = '/' + parsedPath.name - } - let partialName = `partials${parsedPath.dir}${parsedPath.name}` - handlebars.registerPartial(partialName, hbsFileString) - done.resolve() - } - }) - return done.promise -} - -/** - * compiles a directory and outputs it - */ -export let compileDirectory = async ( - originDirPathArg: string, - destinationDirPathArg: string, - dataFileNameArg: string -) => { - let hbsFilePathArray = smartfile.fs.listFilesSync(originDirPathArg, /.hbs/) - let data = smartfile.fs.toObjectSync(path.join(originDirPathArg, dataFileNameArg)) - for (let hbsFilePath of hbsFilePathArray) { - let parsedPath = path.parse(hbsFilePath) - let hbsFileString = smartfile.fs.toStringSync(path.join(originDirPathArg, hbsFilePath)) - let template = handlebars.compile(hbsFileString) - let output = template(data) - console.log('hi ' + output + ' hi') - smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html')) - } -} - -/** - * get a template for a file on disk - */ -export let getTemplateForFile = async (filePathArg: string) => { - let filePathAbsolute = path.resolve(filePathArg) - return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute)) -} +export * from './smarthbs.compile' +export * from './smarthbs.helpers' +export * from './smarthbs.partials' +export * from './smarthbs.template' diff --git a/ts/smarthbs.compile.ts b/ts/smarthbs.compile.ts new file mode 100644 index 0000000..f624ed6 --- /dev/null +++ b/ts/smarthbs.compile.ts @@ -0,0 +1,21 @@ +import * as plugins from './smarthbs.plugins' + +/** + * compiles a directory and outputs it + */ +export let compileDirectory = async ( + originDirPathArg: string, + destinationDirPathArg: string, + dataFileNameArg: string +) => { + 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') + plugins.smartfile.memory.toFsSync(output, plugins.path.join(destinationDirPathArg, parsedPath.name + '.html')) + } +} diff --git a/ts/smarthbs.helpers.ts b/ts/smarthbs.helpers.ts new file mode 100644 index 0000000..ac93dd3 --- /dev/null +++ b/ts/smarthbs.helpers.ts @@ -0,0 +1,4 @@ +import * as plugins from './smarthbs.plugins' + +export let registerHelper = plugins.handlebars.registerHelper + diff --git a/ts/smarthbs.partials.ts b/ts/smarthbs.partials.ts new file mode 100644 index 0000000..527097a --- /dev/null +++ b/ts/smarthbs.partials.ts @@ -0,0 +1,21 @@ +import * as plugins from './smarthbs.plugins' + +/** + * registers a directory of partials to make them available within handlebars compilation + */ +export let registerPartialDir = (dirPathArg: string) => { + let done = plugins.smartq.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.name = '/' + parsedPath.name + } + let partialName = `partials${parsedPath.dir}${parsedPath.name}` + plugins.handlebars.registerPartial(partialName, hbsFileString) + done.resolve() + } + }) + return done.promise +} diff --git a/ts/smarthbs.plugins.ts b/ts/smarthbs.plugins.ts new file mode 100644 index 0000000..a8ba1ac --- /dev/null +++ b/ts/smarthbs.plugins.ts @@ -0,0 +1,12 @@ +import 'typings-global' +import * as handlebars from 'handlebars' +import * as smartfile from 'smartfile' +import * as smartq from 'smartq' +import * as path from 'path' + +export { + handlebars, + smartfile, + smartq, + path +} diff --git a/ts/smarthbs.template.ts b/ts/smarthbs.template.ts new file mode 100644 index 0000000..83e88e3 --- /dev/null +++ b/ts/smarthbs.template.ts @@ -0,0 +1,9 @@ +import * as plugins from './smarthbs.plugins' + +/** + * get a template for a file on disk + */ +export let getTemplateForFile = async (filePathArg: string) => { + let filePathAbsolute = plugins.path.resolve(filePathArg) + return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute)) +}