From 1cecba6f13d27f7666d75f10df2169bc51829c07 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 11 Oct 2019 21:56:11 +0200 Subject: [PATCH] fix(core): update --- .vscode/launch.json | 29 +++++++ .vscode/settings.json | 20 +++++ package-lock.json | 134 +++++++++++++++++++++++++----- package.json | 5 +- test/test_template/.smartscaf.yml | 3 + ts/interfaces/index.ts | 1 + ts/interfaces/smartscaf.ts | 7 ++ ts/smartscaf.classes.smartscaf.ts | 110 +++++++++++++++--------- ts/smartscaf.plugins.ts | 3 +- 9 files changed, 248 insertions(+), 64 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 ts/interfaces/index.ts create mode 100644 ts/interfaces/smartscaf.ts diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..112db52 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "current file", + "type": "node", + "request": "launch", + "args": [ + "${relativeFile}" + ], + "runtimeArgs": ["-r", "@gitzone/tsrun"], + "cwd": "${workspaceRoot}", + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": "test.ts", + "type": "node", + "request": "launch", + "args": [ + "test/test.ts" + ], + "runtimeArgs": ["-r", "@gitzone/tsrun"], + "cwd": "${workspaceRoot}", + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6763058 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "json.schemas": [ + { + "fileMatch": ["/npmextra.json"], + "schema": { + "type": "object", + "properties": { + "npmci": { + "type": "object", + "description": "settings for npmci" + }, + "gitzone": { + "type": "object", + "description": "settings for gitzone" + } + } + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index acb0597..93ba415 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,26 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.5.5", + "resolved": "https://verdaccio.lossless.one/@babel%2fcode-frame/-/code-frame-7.5.5.tgz", + "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==", + "dev": true, + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/highlight": { + "version": "7.5.0", + "resolved": "https://verdaccio.lossless.one/@babel%2fhighlight/-/highlight-7.5.0.tgz", + "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", + "dev": true, + "requires": { + "chalk": "^2.0.0", + "esutils": "^2.0.2", + "js-tokens": "^4.0.0" + } + }, "@gitzone/tsbuild": { "version": "2.1.17", "resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.17.tgz", @@ -147,7 +167,6 @@ "version": "1.0.15", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartexit/-/smartexit-1.0.15.tgz", "integrity": "sha512-pvJBmF13spcDN+O8rSpYlKBOObyfW+omZKQr3hhSMT1VHMEYV8e/njsA19Cg4C2DfLPv+cRFFgPn27zJpleRsQ==", - "dev": true, "requires": { "@pushrocks/lik": "^3.0.5", "@pushrocks/smartdelay": "^2.0.3", @@ -239,14 +258,12 @@ "@pushrocks/smartlog-interfaces": { "version": "2.0.5", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog-interfaces/-/smartlog-interfaces-2.0.5.tgz", - "integrity": "sha512-eLNlRpDwy3E+6v/B6fo/NiAo+UxBO3SxKgIIsgUGbWfVpsyUi0PG2xfVCdhJlhL1AsRRvKglfHSOB8qKE+XCLw==", - "dev": true + "integrity": "sha512-eLNlRpDwy3E+6v/B6fo/NiAo+UxBO3SxKgIIsgUGbWfVpsyUi0PG2xfVCdhJlhL1AsRRvKglfHSOB8qKE+XCLw==" }, "@pushrocks/smartlog-source-ora": { "version": "1.0.8", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog-source-ora/-/smartlog-source-ora-1.0.8.tgz", "integrity": "sha512-yPFACo/1gHx2o43qYLJ6LB5AUvSFB42abYynySpaIZfQKzdz09eJB/LMbVdOKPObwk7bcma5owyK5lPHicG9Ig==", - "dev": true, "requires": { "@pushrocks/smartlog-interfaces": "^2.0.5", "ora": "^3.4.0" @@ -307,7 +324,6 @@ "version": "2.0.25", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartshell/-/smartshell-2.0.25.tgz", "integrity": "sha512-sYVHOhBRdr+CkjS+o1SDtB5058ZYxTPAYuexx2ydl2g+57KNdEcSRWN/2mOv5+NFH+tvvgtnUjC3AclC9CwJ4A==", - "dev": true, "requires": { "@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartexit": "^1.0.15", @@ -571,10 +587,9 @@ } }, "@types/which": { - "version": "1.3.1", - "resolved": "https://verdaccio.lossless.one/@types%2fwhich/-/which-1.3.1.tgz", - "integrity": "sha512-ZrJDWpvg75LTGX4XwuneY9s6bF3OeZcGTpoGh3zDV9ytzcHMFsRrMIaLBRJZQMBoGyKs6unBQfVdrLZiYfb1zQ==", - "dev": true + "version": "1.3.2", + "resolved": "https://verdaccio.lossless.one/@types%2fwhich/-/which-1.3.2.tgz", + "integrity": "sha512-8oDqyLC7eD4HM307boe2QWKyuzdzWBj56xI/imSl2cpL+U3tCMaTAkMJ4ee5JBZ/FsOJlvRGeIShiZDAl1qERA==" }, "@types/yargs": { "version": "12.0.13", @@ -661,6 +676,12 @@ "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://verdaccio.lossless.one/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, "camelcase": { "version": "5.3.1", "resolved": "https://verdaccio.lossless.one/camelcase/-/camelcase-5.3.1.tgz", @@ -728,8 +749,7 @@ "cli-spinners": { "version": "2.2.0", "resolved": "https://verdaccio.lossless.one/cli-spinners/-/cli-spinners-2.2.0.tgz", - "integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==", - "dev": true + "integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==" }, "cli-width": { "version": "2.2.0", @@ -761,8 +781,7 @@ "clone": { "version": "1.0.4", "resolved": "https://verdaccio.lossless.one/clone/-/clone-1.0.4.tgz", - "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=", - "dev": true + "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" }, "code-point-at": { "version": "1.1.0", @@ -794,8 +813,7 @@ "commander": { "version": "2.20.1", "resolved": "https://verdaccio.lossless.one/commander/-/commander-2.20.1.tgz", - "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==", - "optional": true + "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==" }, "concat-map": { "version": "0.0.1", @@ -850,7 +868,6 @@ "version": "1.0.3", "resolved": "https://verdaccio.lossless.one/defaults/-/defaults-1.0.3.tgz", "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", - "dev": true, "requires": { "clone": "^1.0.2" } @@ -890,6 +907,12 @@ "resolved": "https://verdaccio.lossless.one/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, + "esutils": { + "version": "2.0.3", + "resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true + }, "execa": { "version": "1.0.0", "resolved": "https://verdaccio.lossless.one/execa/-/execa-1.0.0.tgz", @@ -1116,7 +1139,12 @@ "isexe": { "version": "2.0.0", "resolved": "https://verdaccio.lossless.one/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://verdaccio.lossless.one/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true }, "js-yaml": { @@ -1179,7 +1207,6 @@ "version": "2.2.0", "resolved": "https://verdaccio.lossless.one/log-symbols/-/log-symbols-2.2.0.tgz", "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", - "dev": true, "requires": { "chalk": "^2.0.1" } @@ -1254,6 +1281,23 @@ "resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://verdaccio.lossless.one/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, "moment": { "version": "2.24.0", "resolved": "https://verdaccio.lossless.one/moment/-/moment-2.24.0.tgz", @@ -1332,7 +1376,6 @@ "version": "3.4.0", "resolved": "https://verdaccio.lossless.one/ora/-/ora-3.4.0.tgz", "integrity": "sha512-eNwHudNbO1folBP3JsZ19v9azXWtQZjICdr3Q0TDPIaeBQ3mXLrh54wM+er0+hSp+dWKf+Z8KM58CYzEyIYxYg==", - "dev": true, "requires": { "chalk": "^2.4.2", "cli-cursor": "^2.1.0", @@ -1417,6 +1460,12 @@ "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "dev": true }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://verdaccio.lossless.one/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, "pathval": { "version": "1.1.0", "resolved": "https://verdaccio.lossless.one/pathval/-/pathval-1.1.0.tgz", @@ -1455,6 +1504,15 @@ "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "dev": true }, + "resolve": { + "version": "1.12.0", + "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz", + "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, "restore-cursor": { "version": "2.0.0", "resolved": "https://verdaccio.lossless.one/restore-cursor/-/restore-cursor-2.0.0.tgz", @@ -1670,6 +1728,42 @@ "resolved": "https://verdaccio.lossless.one/tslib/-/tslib-1.10.0.tgz", "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" }, + "tslint": { + "version": "5.20.0", + "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz", + "integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^4.0.1", + "glob": "^7.1.1", + "js-yaml": "^3.13.1", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.29.0" + } + }, + "tslint-config-prettier": { + "version": "1.18.0", + "resolved": "https://verdaccio.lossless.one/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz", + "integrity": "sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==", + "dev": true + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://verdaccio.lossless.one/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "type-detect": { "version": "4.0.8", "resolved": "https://verdaccio.lossless.one/type-detect/-/type-detect-4.0.8.tgz", @@ -1706,7 +1800,6 @@ "version": "1.0.1", "resolved": "https://verdaccio.lossless.one/wcwidth/-/wcwidth-1.0.1.tgz", "integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=", - "dev": true, "requires": { "defaults": "^1.0.3" } @@ -1715,7 +1808,6 @@ "version": "1.3.1", "resolved": "https://verdaccio.lossless.one/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, "requires": { "isexe": "^2.0.0" } diff --git a/package.json b/package.json index 46803ee..d3b8d13 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ "@gitzone/tsrun": "^1.2.8", "@gitzone/tstest": "^1.0.28", "@pushrocks/tapbundle": "^3.0.13", - "@types/node": "^12.7.9" + "@types/node": "^12.7.9", + "tslint": "^5.20.0", + "tslint-config-prettier": "^1.18.0" }, "dependencies": { "@pushrocks/lik": "^3.0.11", @@ -38,6 +40,7 @@ "@pushrocks/smarthbs": "^2.0.8", "@pushrocks/smartinteract": "^2.0.4", "@pushrocks/smartpromise": "^3.0.6", + "@pushrocks/smartshell": "^2.0.25", "@pushrocks/smartyaml": "^2.0.3" }, "files": [ diff --git a/test/test_template/.smartscaf.yml b/test/test_template/.smartscaf.yml index d131f47..31eee84 100644 --- a/test/test_template/.smartscaf.yml +++ b/test/test_template/.smartscaf.yml @@ -8,3 +8,6 @@ defaults: dependencies: merge: - ../test_template_2 + +runafter: + - npm install \ No newline at end of file diff --git a/ts/interfaces/index.ts b/ts/interfaces/index.ts new file mode 100644 index 0000000..bba25a5 --- /dev/null +++ b/ts/interfaces/index.ts @@ -0,0 +1 @@ +export * from './smartscaf'; \ No newline at end of file diff --git a/ts/interfaces/smartscaf.ts b/ts/interfaces/smartscaf.ts new file mode 100644 index 0000000..83e1ffa --- /dev/null +++ b/ts/interfaces/smartscaf.ts @@ -0,0 +1,7 @@ +export interface ISmartscafFile { + defaults: {[key:string]: string}; + dependencies: { + merge: string[]; + }; + runafter: string[]; +} \ No newline at end of file diff --git a/ts/smartscaf.classes.smartscaf.ts b/ts/smartscaf.classes.smartscaf.ts index bcee9a2..23e2775 100644 --- a/ts/smartscaf.classes.smartscaf.ts +++ b/ts/smartscaf.classes.smartscaf.ts @@ -1,4 +1,5 @@ import * as plugins from './smartscaf.plugins'; +import * as interfaces from './interfaces'; import * as helpers from './smartscaf.helpers'; // interfaces @@ -11,31 +12,37 @@ export interface ScafTemplateContructorOptions { } export class ScafTemplate { - static async createTemplateFromDir() {} + public static async createTemplateFromDir() {} /** * the name of the template */ - name: string; + public name: string; /** * the descriptions of the template */ - description: string; + public description: string; /** * the location on disk of the template */ - dirPath: string; + public dirPath: string; + public destinationPath: string; + + /** + * smartscafFile + */ + public smartscafFile: interfaces.ISmartscafFile; /** * the files of the template as array of Smartfiles */ - templateSmartfileArray: Smartfile[]; - requiredVariables: string[]; - defaultVariables: any; - suppliedVariables: any = {}; - missingVariables: string[] = []; + public templateSmartfileArray: Smartfile[]; + public requiredVariables: string[]; + public defaultVariables: any; + public suppliedVariables: any = {}; + public missingVariables: string[] = []; constructor(dirPathArg: string) { this.dirPath = plugins.path.resolve(dirPathArg); @@ -44,8 +51,30 @@ export class ScafTemplate { /** * read a template from a directory */ - async readTemplateFromDir() { + public async readTemplateFromDir() { this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*'); + + // read .smartscaf.yml file + let smartscafFile: interfaces.ISmartscafFile = { + defaults: {}, + dependencies: { + merge: [] + }, + runafter: [] + }; + + const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => { + return smartfileArg.parsedPath.base === '.smartscaf.yml'; + }); + + if (smartscafSmartfile) { + smartscafFile = { + ...smartscafFile, + ...await plugins.smartyaml.yamlStringToObject(smartscafSmartfile.contentBuffer.toString()) + }; + } + this.smartscafFile = smartscafFile; + await this._resolveTemplateDependencies(); await this._findVariablesInTemplate(); await this._checkSuppliedVariables(); @@ -56,7 +85,7 @@ export class ScafTemplate { * supply the variables to render the teplate with * @param variablesArg gets merged with this.suppliedVariables */ - async supplyVariables(variablesArg) { + public async supplyVariables(variablesArg) { this.suppliedVariables = { ...this.suppliedVariables, ...variablesArg @@ -67,10 +96,10 @@ export class ScafTemplate { /** * Will ask for the missing variables by cli interaction */ - async askCliForMissingVariables() { + public async askCliForMissingVariables() { this.missingVariables = await this._checkSuppliedVariables(); - let localSmartInteract = new plugins.smartinteract.SmartInteract(); - for (let missingVariable of this.missingVariables) { + const localSmartInteract = new plugins.smartinteract.SmartInteract(); + for (const missingVariable of this.missingVariables) { localSmartInteract.addQuestions([ { name: missingVariable, @@ -86,7 +115,7 @@ export class ScafTemplate { } ]); } - let answerBucket = await localSmartInteract.runQueue(); + const answerBucket = await localSmartInteract.runQueue(); await answerBucket.answerMap.forEach(async answer => { await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value); }); @@ -96,23 +125,24 @@ export class ScafTemplate { * writes a file to disk * @param destinationDirArg */ - async writeToDisk(destinationDirArg) { + public async writeToDisk(destinationDirArg) { + this.destinationPath = destinationDirArg; const smartfileArrayToWrite: Smartfile[] = []; - for (let smartfile of this.templateSmartfileArray) { + for (const smartfile of this.templateSmartfileArray) { // lets filter out template files if (smartfile.path === '.smartscaf.yml') { continue; } // render the template - let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString()); - let renderedTemplateString = template(this.suppliedVariables); + const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString()); + const renderedTemplateString = template(this.suppliedVariables); // handle frontmatter const smartfmInstance = new plugins.smartfm.Smartfm({ fmType: 'yaml' }); - let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any; + const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any; if (parsedTemplate.data.fileName) { smartfile.updateFileName(parsedTemplate.data.fileName); } @@ -122,6 +152,7 @@ export class ScafTemplate { } await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg); + await this.runScripts(); } /** @@ -130,8 +161,8 @@ export class ScafTemplate { */ private async _findVariablesInTemplate() { let templateVariables: string[] = []; - for (let templateSmartfile of this.templateSmartfileArray) { - let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString( + for (const templateSmartfile of this.templateSmartfileArray) { + const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString( templateSmartfile.contents.toString() ); templateVariables = [...templateVariables, ...localTemplateVariables]; @@ -146,8 +177,8 @@ export class ScafTemplate { */ private async _checkSuppliedVariables() { let missingVars: string[] = []; - for (let templateSmartfile of this.templateSmartfileArray) { - let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction( + for (const templateSmartfile of this.templateSmartfileArray) { + const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction( templateSmartfile.contents.toString(), this.suppliedVariables ); @@ -176,7 +207,7 @@ export class ScafTemplate { * >> - yourDeeperKey: yourValue */ private async _checkDefaultVariables() { - let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => { + const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => { return smartfileArg.parsedPath.base === '.smartscaf.yml'; }); @@ -199,23 +230,8 @@ export class ScafTemplate { * resolve template dependencies */ private async _resolveTemplateDependencies() { - const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => { - return smartfileArg.parsedPath.base === '.smartscaf.yml'; - }); - if (!smartscafSmartfile) { - console.log('No further template dependencies defined!'); - return; - } - console.log('Found template dependencies! Resolving them now!'); console.log('looking at templates to merge!'); - const smartscafYamlObject = await plugins.smartyaml.yamlStringToObject( - smartscafSmartfile.contentBuffer.toString() - ); - if (!smartscafYamlObject) { - console.log('Something seems strange about the supplied dependencies.yml file.'); - return; - } - for (const dependency of smartscafYamlObject.dependencies.merge) { + for (const dependency of this.smartscafFile.dependencies.merge) { console.log(`Now resolving ${dependency}`); const templatePathToMerge = plugins.path.join(this.dirPath, dependency); if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) { @@ -231,4 +247,16 @@ export class ScafTemplate { this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray); } } + + private async runScripts () { + if (!this.destinationPath) { + throw new Error('cannot run scripts without an destinationdir'); + } + const smartshellInstance = new plugins.smartshell.Smartshell({ + executor: 'bash' + }); + for (const command of this.smartscafFile.runafter) { + await smartshellInstance.exec(`cd ${this.destinationPath} && ${command}`); + } + } } diff --git a/ts/smartscaf.plugins.ts b/ts/smartscaf.plugins.ts index ccd581b..0b868fa 100644 --- a/ts/smartscaf.plugins.ts +++ b/ts/smartscaf.plugins.ts @@ -6,5 +6,6 @@ import * as smarthbs from '@pushrocks/smarthbs'; import * as smartinteract from '@pushrocks/smartinteract'; import * as smartq from '@pushrocks/smartpromise'; import * as smartyaml from '@pushrocks/smartyaml'; +import * as smartshell from '@pushrocks/smartshell'; -export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml }; +export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml, smartshell };