diff --git a/dist/smartscaf.classes.smartscaf.d.ts b/dist/smartscaf.classes.smartscaf.d.ts index a30d5bd..ef72da5 100644 --- a/dist/smartscaf.classes.smartscaf.d.ts +++ b/dist/smartscaf.classes.smartscaf.d.ts @@ -7,14 +7,19 @@ export interface ScafTemplateContructorOptions { export declare class ScafTemplate { name: string; description: string; - templateObject: Smartfile[]; - requiredVariables: any[]; - constructor(); + templateSmartfileArray: Smartfile[]; + requiredVariables: string[]; + suppliedVariables: any; + missingVariables: string[]; /** * read a template from a directory */ - readTemplateFromDir(dirArg: string): Promise; - writeWithVariables(variablesArg: any): Promise; + readTemplateFromDir(dirPathArg: string): Promise; + /** + * supply the variables to render the teplate with + * @param variablesArg + */ + supplyVariables(variablesArg: any): Promise; /** * finds all variables in a Template */ diff --git a/dist/smartscaf.classes.smartscaf.js b/dist/smartscaf.classes.smartscaf.js index 6e36949..0ac7450 100644 --- a/dist/smartscaf.classes.smartscaf.js +++ b/dist/smartscaf.classes.smartscaf.js @@ -10,18 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const plugins = require("./smartscaf.plugins"); class ScafTemplate { - constructor() { } + constructor() { + this.missingVariables = []; + } /** * read a template from a directory */ - readTemplateFromDir(dirArg) { + readTemplateFromDir(dirPathArg) { return __awaiter(this, void 0, void 0, function* () { - this.templateObject = yield plugins.smartfile.fs.fileTreeToObject(dirArg, '**/*'); + let dirPath = plugins.path.resolve(dirPathArg); + this.templateSmartfileArray = yield plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*'); + this._findVariablesInTemplate(); }); } - writeWithVariables(variablesArg) { + /** + * supply the variables to render the teplate with + * @param variablesArg + */ + supplyVariables(variablesArg) { return __awaiter(this, void 0, void 0, function* () { - yield this._checkSuppliedVariables(variablesArg); + this.suppliedVariables = variablesArg; + this.missingVariables = yield this._checkSuppliedVariables(variablesArg); }); } /** @@ -29,6 +38,8 @@ class ScafTemplate { */ _findVariablesInTemplate() { return __awaiter(this, void 0, void 0, function* () { + for (let localSmartfile of this.templateSmartfileArray) { + } }); } /** @@ -36,8 +47,15 @@ class ScafTemplate { */ _checkSuppliedVariables(variablesArg) { return __awaiter(this, void 0, void 0, function* () { + let missingVars = []; + for (let templateSmartFile of this.templateSmartfileArray) { + console.log(templateSmartFile); + let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartFile.contents.toString(), variablesArg); + missingVars = plugins.lodash.concat(missingVars, localMissingVars); + } + return missingVars; }); } } exports.ScafTemplate = ScafTemplate; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBOEM7QUFXOUM7SUFLRSxnQkFBZSxDQUFDO0lBRWhCOztPQUVHO0lBQ0csbUJBQW1CLENBQUUsTUFBYzs7WUFDdkMsSUFBSSxDQUFDLGNBQWMsR0FBRyxNQUFNLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGdCQUFnQixDQUFDLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQTtRQUNuRixDQUFDO0tBQUE7SUFFSyxrQkFBa0IsQ0FBRSxZQUFZOztZQUNwQyxNQUFNLElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNsRCxDQUFDO0tBQUE7SUFFRDs7T0FFRztJQUNXLHdCQUF3Qjs7UUFFdEMsQ0FBQztLQUFBO0lBRUQ7O09BRUc7SUFDVyx1QkFBdUIsQ0FBRSxZQUFZOztRQUVuRCxDQUFDO0tBQUE7Q0FDRjtBQS9CRCxvQ0ErQkMifQ== \ No newline at end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FlBQVk7O1lBQ2hELElBQUksV0FBVyxHQUFhLEVBQUUsQ0FBQTtZQUM5QixHQUFHLENBQUMsQ0FBQyxJQUFJLGlCQUFpQixJQUFJLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxDQUFDLENBQUM7Z0JBQzFELE9BQU8sQ0FBQyxHQUFHLENBQUMsaUJBQWlCLENBQUMsQ0FBQTtnQkFDOUIsSUFBSSxnQkFBZ0IsR0FBRyxNQUFNLE9BQU8sQ0FBQyxRQUFRLENBQUMscUJBQXFCLENBQ2pFLGlCQUFpQixDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsRUFDckMsWUFBWSxDQUNiLENBQUE7Z0JBQ0QsV0FBVyxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsTUFBTSxDQUFDLFdBQVcsRUFBRSxnQkFBZ0IsQ0FBQyxDQUFBO1lBQ3BFLENBQUM7WUFFRCxNQUFNLENBQUMsV0FBVyxDQUFBO1FBQ3BCLENBQUM7S0FBQTtDQUNGO0FBbkRELG9DQW1EQyJ9 \ No newline at end of file diff --git a/dist/smartscaf.plugins.d.ts b/dist/smartscaf.plugins.d.ts index ac896dc..6c8e75e 100644 --- a/dist/smartscaf.plugins.d.ts +++ b/dist/smartscaf.plugins.d.ts @@ -1,4 +1,7 @@ +import 'typings-global'; +import * as lodash from 'lodash'; +import * as path from 'path'; import * as smartfile from 'smartfile'; import * as smarthbs from 'smarthbs'; import * as smartq from 'smartq'; -export { smartfile, smarthbs, smartq }; +export { lodash, path, smartfile, smarthbs, smartq }; diff --git a/dist/smartscaf.plugins.js b/dist/smartscaf.plugins.js index aa5acac..64b41e2 100644 --- a/dist/smartscaf.plugins.js +++ b/dist/smartscaf.plugins.js @@ -1,9 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +require("typings-global"); +const lodash = require("lodash"); +exports.lodash = lodash; +const path = require("path"); +exports.path = path; const smartfile = require("smartfile"); exports.smartfile = smartfile; const smarthbs = require("smarthbs"); exports.smarthbs = smarthbs; const smartq = require("smartq"); exports.smartq = smartq; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHVDQUFzQztBQUtwQyw4QkFBUztBQUpYLHFDQUFvQztBQUtsQyw0QkFBUTtBQUpWLGlDQUFnQztBQUs5Qix3QkFBTSJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFPOUIsd0JBQU07QUFOUiw2QkFBNEI7QUFPMUIsb0JBQUk7QUFOTix1Q0FBc0M7QUFPcEMsOEJBQVM7QUFOWCxxQ0FBb0M7QUFPbEMsNEJBQVE7QUFOVixpQ0FBZ0M7QUFPOUIsd0JBQU0ifQ== \ No newline at end of file diff --git a/package.json b/package.json index 8ffe408..15ba7fe 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,11 @@ "tapbundle": "^1.0.10" }, "dependencies": { - "smartfile": "^4.1.10", - "smarthbs": "^1.0.8", - "smartq": "^1.1.1" + "@types/lodash": "^4.14.63", + "lodash": "^4.17.4", + "smartfile": "^4.2.9", + "smarthbs": "^1.0.11", + "smartq": "^1.1.1", + "typings-global": "^1.0.16" } } diff --git a/test/test.ts b/test/test.ts index 1af5813..404e515 100644 --- a/test/test.ts +++ b/test/test.ts @@ -10,7 +10,13 @@ tap.test('should create new Smartscaf instance', async () => { }) tap.test('Smartscaf instance -> should read a template directory', async () => { - testScafTemplate.readTemplateFromDir('./test/test_template') + await testScafTemplate.readTemplateFromDir('./test/test_template') + expect(testScafTemplate.templateSmartfileArray.length).to.equal(3) +}) + +tap.test('smartfile -> should accept variables', async () => { + await testScafTemplate.supplyVariables({}) + console.log(testScafTemplate.missingVariables) }) tap.start() diff --git a/test/test_template/template1.md b/test/test_template/template1.md new file mode 100644 index 0000000..d9ff40c --- /dev/null +++ b/test/test_template/template1.md @@ -0,0 +1,3 @@ +# this is a {{templateVar1}} +# this is a {{templateVar2}} +# this is a {{templateVar3}} diff --git a/test/test_template/template2.md b/test/test_template/template2.md new file mode 100644 index 0000000..d9ff40c --- /dev/null +++ b/test/test_template/template2.md @@ -0,0 +1,3 @@ +# this is a {{templateVar1}} +# this is a {{templateVar2}} +# this is a {{templateVar3}} diff --git a/test/test_template/template3.md b/test/test_template/template3.md new file mode 100644 index 0000000..aa14a5b --- /dev/null +++ b/test/test_template/template3.md @@ -0,0 +1 @@ +# some {{wow}} \ No newline at end of file diff --git a/ts/smartscaf.classes.smartscaf.ts b/ts/smartscaf.classes.smartscaf.ts index 8bed4ba..281e362 100644 --- a/ts/smartscaf.classes.smartscaf.ts +++ b/ts/smartscaf.classes.smartscaf.ts @@ -15,12 +15,14 @@ export class ScafTemplate { templateSmartfileArray: Smartfile[] requiredVariables: string[] suppliedVariables: any + missingVariables: string[] = [] /** * read a template from a directory */ - async readTemplateFromDir (dirArg: string) { - this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirArg, '**/*') + async readTemplateFromDir (dirPathArg: string) { + let dirPath = plugins.path.resolve(dirPathArg) + this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*') this._findVariablesInTemplate() } @@ -29,22 +31,33 @@ export class ScafTemplate { * @param variablesArg */ async supplyVariables (variablesArg) { - await this._checkSuppliedVariables(variablesArg) + this.suppliedVariables = variablesArg + this.missingVariables = await this._checkSuppliedVariables(variablesArg) } /** * finds all variables in a Template */ - private async _findVariablesInTemplate () { + private async _findVariablesInTemplate() { for (let localSmartfile of this.templateSmartfileArray) { - + } } /** * checks if supplied Variables satisfy the template */ - private async _checkSuppliedVariables (variablesArg) { + private async _checkSuppliedVariables(variablesArg) { + let missingVars: string[] = [] + for (let templateSmartFile of this.templateSmartfileArray) { + console.log(templateSmartFile) + let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction( + templateSmartFile.contents.toString(), + variablesArg + ) + missingVars = plugins.lodash.concat(missingVars, localMissingVars) + } + return missingVars } } diff --git a/ts/smartscaf.plugins.ts b/ts/smartscaf.plugins.ts index c59565a..3499274 100644 --- a/ts/smartscaf.plugins.ts +++ b/ts/smartscaf.plugins.ts @@ -1,8 +1,13 @@ +import 'typings-global' +import * as lodash from 'lodash' +import * as path from 'path' import * as smartfile from 'smartfile' import * as smarthbs from 'smarthbs' import * as smartq from 'smartq' export { + lodash, + path, smartfile, smarthbs, smartq diff --git a/yarn.lock b/yarn.lock index 74b41dc..8c6eb81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -29,9 +29,13 @@ version "4.0.32" resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.0.32.tgz#637e8d945a9354aab47df7125005490fe9f8e592" +"@types/lodash@^4.14.63": + version "4.14.63" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.63.tgz#5ac475f55bfdc62bc88c4239dbc482f2f3bead93" + "@types/node@*": - version "7.0.14" - resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.14.tgz#1470fa002a113316ac9d9ad163fc738c7a0de2a4" + version "7.0.15" + resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.15.tgz#628429289604c5f7e56c13f3a0422f3e59df1a17" "@types/promises-a-plus@*": version "0.0.27" @@ -223,7 +227,7 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -handlebars@^4.0.6: +handlebars@^4.0.7: version "4.0.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.7.tgz#e97325aeb8ea0b9e12b9c4dd73c4c312ad0ede59" dependencies: @@ -306,6 +310,10 @@ left-pad@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a" +lodash@^4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + longest@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" @@ -447,9 +455,9 @@ smartdelay@^1.0.1: dependencies: typings-global "^1.0.14" -smartfile@^4.1.10, smartfile@^4.1.8: - version "4.2.1" - resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.2.1.tgz#2ec85f803f771a1ddff377a438ae87aab25f3e6e" +smartfile@^4.2.9: + version "4.2.9" + resolved "https://registry.yarnpkg.com/smartfile/-/smartfile-4.2.9.tgz#afcd1160049cbe26a86e42e842c86e8b748e69e7" dependencies: "@types/fs-extra" "2.x.x" "@types/vinyl" "^2.0.0" @@ -464,15 +472,17 @@ smartfile@^4.1.10, smartfile@^4.1.8: vinyl "^2.0.2" vinyl-file "^3.0.0" -smarthbs@^1.0.8: - version "1.0.8" - resolved "https://registry.yarnpkg.com/smarthbs/-/smarthbs-1.0.8.tgz#9ff4fc2fc0643c83a80a270d3c8ea160d47f5a5d" +smarthbs@^1.0.11: + version "1.0.11" + resolved "https://registry.yarnpkg.com/smarthbs/-/smarthbs-1.0.11.tgz#bb6a0c279fa6a22c4dffc2cc1a08e68e581251a3" dependencies: "@types/handlebars" "^4.0.32" - handlebars "^4.0.6" - smartfile "^4.1.8" + "@types/lodash" "^4.14.63" + handlebars "^4.0.7" + lodash "^4.17.4" + smartfile "^4.2.9" smartq "^1.1.1" - typings-global "^1.0.14" + typings-global "^1.0.16" smartpath@^3.2.8: version "3.2.8"