Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
c5ec7e9c24 | |||
98875a2ece | |||
5b42cf93cb | |||
e0ab34c466 | |||
beb3013e2c | |||
5d1c0a6f1e | |||
fc450816e6 | |||
5fac35c75f | |||
dde29629b7 | |||
4347f800e6 | |||
59161f1eeb | |||
b9a346c5d7 | |||
fa961f86b8 | |||
ff679c1787 | |||
35e3c9ae48 | |||
bf0007ff3a | |||
3ab780e600 | |||
d0662f809f | |||
e20bf7f610 | |||
0a97ec4d07 | |||
69e09c8b4c | |||
0e92554d0a | |||
648afbcf21 | |||
7998c99f27 | |||
8e3633827c | |||
eac20873e5 |
20
dist/smartscaf.classes.smartscaf.d.ts
vendored
20
dist/smartscaf.classes.smartscaf.d.ts
vendored
@ -9,6 +9,7 @@ export declare class ScafTemplate {
|
|||||||
description: string;
|
description: string;
|
||||||
templateSmartfileArray: Smartfile[];
|
templateSmartfileArray: Smartfile[];
|
||||||
requiredVariables: string[];
|
requiredVariables: string[];
|
||||||
|
defaultVariables: any;
|
||||||
suppliedVariables: any;
|
suppliedVariables: any;
|
||||||
missingVariables: string[];
|
missingVariables: string[];
|
||||||
/**
|
/**
|
||||||
@ -17,19 +18,34 @@ export declare class ScafTemplate {
|
|||||||
readTemplateFromDir(dirPathArg: string): Promise<void>;
|
readTemplateFromDir(dirPathArg: string): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* supply the variables to render the teplate with
|
* supply the variables to render the teplate with
|
||||||
* @param variablesArg
|
* @param variablesArg gets merged with this.suppliedVariables
|
||||||
*/
|
*/
|
||||||
supplyVariables(variablesArg: any): Promise<void>;
|
supplyVariables(variablesArg: any): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Will ask for the missing variables by cli interaction
|
* Will ask for the missing variables by cli interaction
|
||||||
*/
|
*/
|
||||||
askCliForMissingVariables(): Promise<void>;
|
askCliForMissingVariables(): Promise<void>;
|
||||||
|
writeToDisk(destinationDirArg: any): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* finds all variables in a Template
|
* finds all variables in a Template in as string
|
||||||
|
* e.g. myobject.someKey and myobject.someOtherKey
|
||||||
*/
|
*/
|
||||||
private _findVariablesInTemplate();
|
private _findVariablesInTemplate();
|
||||||
/**
|
/**
|
||||||
* checks if supplied Variables satisfy the template
|
* checks if supplied Variables satisfy the template
|
||||||
*/
|
*/
|
||||||
private _checkSuppliedVariables();
|
private _checkSuppliedVariables();
|
||||||
|
/**
|
||||||
|
* checks the default.yml at the root of a template for default variables
|
||||||
|
* allows 2 ways of notation in YAML:
|
||||||
|
* >> myObject.myKey.someDeeperKey: someValue
|
||||||
|
* >> myObject.yourKey.yourDeeperKey: yourValue
|
||||||
|
* or
|
||||||
|
* >> myObject:
|
||||||
|
* >> - someKey:
|
||||||
|
* >> - someDeeperKey: someValue
|
||||||
|
* >> - yourKey:
|
||||||
|
* >> - yourDeeperKey: yourValue
|
||||||
|
*/
|
||||||
|
private _checkDefaultVariables();
|
||||||
}
|
}
|
||||||
|
84
dist/smartscaf.classes.smartscaf.js
vendored
84
dist/smartscaf.classes.smartscaf.js
vendored
@ -9,8 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const plugins = require("./smartscaf.plugins");
|
const plugins = require("./smartscaf.plugins");
|
||||||
|
const helpers = require("./smartscaf.helpers");
|
||||||
class ScafTemplate {
|
class ScafTemplate {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.suppliedVariables = {};
|
||||||
this.missingVariables = [];
|
this.missingVariables = [];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -20,16 +22,18 @@ class ScafTemplate {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let dirPath = plugins.path.resolve(dirPathArg);
|
let dirPath = plugins.path.resolve(dirPathArg);
|
||||||
this.templateSmartfileArray = yield plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*');
|
this.templateSmartfileArray = yield plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*');
|
||||||
this._findVariablesInTemplate();
|
yield this._findVariablesInTemplate();
|
||||||
|
yield this._checkSuppliedVariables();
|
||||||
|
yield this._checkDefaultVariables();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* supply the variables to render the teplate with
|
* supply the variables to render the teplate with
|
||||||
* @param variablesArg
|
* @param variablesArg gets merged with this.suppliedVariables
|
||||||
*/
|
*/
|
||||||
supplyVariables(variablesArg) {
|
supplyVariables(variablesArg) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
this.suppliedVariables = variablesArg;
|
this.suppliedVariables = plugins.lodash.merge(this.suppliedVariables, variablesArg);
|
||||||
this.missingVariables = yield this._checkSuppliedVariables();
|
this.missingVariables = yield this._checkSuppliedVariables();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -44,20 +48,52 @@ class ScafTemplate {
|
|||||||
localSmartInteract.addQuestions([{
|
localSmartInteract.addQuestions([{
|
||||||
name: missingVariable,
|
name: missingVariable,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
default: `undefined ${missingVariable}`,
|
default: (() => {
|
||||||
|
if (this.defaultVariables && this.defaultVariables[missingVariable]) {
|
||||||
|
return this.defaultVariables[missingVariable];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 'undefined variable';
|
||||||
|
}
|
||||||
|
})(),
|
||||||
message: `What is the value of ${missingVariable}?`
|
message: `What is the value of ${missingVariable}?`
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
let answers = yield localSmartInteract.runQueue();
|
let answerBucket = yield localSmartInteract.runQueue();
|
||||||
|
answerBucket.answerMap.forEach((answer) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
writeToDisk(destinationDirArg) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray);
|
||||||
|
for (let smartfile of smartfileArrayToWrite) {
|
||||||
|
// render the template
|
||||||
|
let template = yield plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
|
||||||
|
let renderedTemplateString = template(this.suppliedVariables);
|
||||||
|
// handle frontmatter
|
||||||
|
let parsedTemplate = plugins.smartfm.parse(renderedTemplateString);
|
||||||
|
if (parsedTemplate.data.fileName) {
|
||||||
|
smartfile.updateFileName(parsedTemplate.data.fileName);
|
||||||
|
}
|
||||||
|
smartfile.contents = Buffer.from(parsedTemplate.content);
|
||||||
|
}
|
||||||
|
yield plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* finds all variables in a Template
|
* finds all variables in a Template in as string
|
||||||
|
* e.g. myobject.someKey and myobject.someOtherKey
|
||||||
*/
|
*/
|
||||||
_findVariablesInTemplate() {
|
_findVariablesInTemplate() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
for (let localSmartfile of this.templateSmartfileArray) {
|
let templateVariables = [];
|
||||||
|
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||||
|
let localTemplateVariables = yield plugins.smarthbs.findVarsInHbsString(templateSmartfile.contents.toString());
|
||||||
|
templateVariables = plugins.lodash.concat(templateVariables, localTemplateVariables);
|
||||||
}
|
}
|
||||||
|
templateVariables = plugins.lodash.uniq(templateVariables);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -66,14 +102,40 @@ class ScafTemplate {
|
|||||||
_checkSuppliedVariables() {
|
_checkSuppliedVariables() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let missingVars = [];
|
let missingVars = [];
|
||||||
for (let templateSmartFile of this.templateSmartfileArray) {
|
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||||
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartFile.contents.toString(), this.suppliedVariables);
|
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartfile.contents.toString(), this.suppliedVariables);
|
||||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars);
|
missingVars = plugins.lodash.concat(missingVars, localMissingVars);
|
||||||
missingVars = plugins.lodash.uniq(missingVars);
|
|
||||||
}
|
}
|
||||||
|
missingVars = plugins.lodash.uniq(missingVars);
|
||||||
return missingVars;
|
return missingVars;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* checks the default.yml at the root of a template for default variables
|
||||||
|
* allows 2 ways of notation in YAML:
|
||||||
|
* >> myObject.myKey.someDeeperKey: someValue
|
||||||
|
* >> myObject.yourKey.yourDeeperKey: yourValue
|
||||||
|
* or
|
||||||
|
* >> myObject:
|
||||||
|
* >> - someKey:
|
||||||
|
* >> - someDeeperKey: someValue
|
||||||
|
* >> - yourKey:
|
||||||
|
* >> - yourDeeperKey: yourValue
|
||||||
|
*/
|
||||||
|
_checkDefaultVariables() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
|
||||||
|
return smartfileArg.parsedPath.base === 'defaults.yml';
|
||||||
|
})[0];
|
||||||
|
if (defaultsSmartfile) {
|
||||||
|
let defaultObject = yield plugins.smartyaml.yamlStringToObject(defaultsSmartfile.contents.toString());
|
||||||
|
this.defaultVariables = defaultObject;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.defaultVariables = {};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.Scaf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d.ts
vendored
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* adds a variable in string dot notation to an already more or less expanded object
|
||||||
|
*/
|
||||||
|
export declare let deepAddToObject: (objectArg: any, varStringArg: string, valueArg: string) => Promise<void>;
|
||||||
|
42
dist/smartscaf.helpers.js
vendored
42
dist/smartscaf.helpers.js
vendored
@ -1,3 +1,43 @@
|
|||||||
"use strict";
|
"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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
/**
|
||||||
|
* adds a variable in string dot notation to an already more or less expanded object
|
||||||
|
*/
|
||||||
|
exports.deepAddToObject = (objectArg, varStringArg, valueArg) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let varNamesArray = varStringArg.split('.');
|
||||||
|
let referencePointer = objectArg;
|
||||||
|
for (let i = 0; i !== varNamesArray.length; i++) {
|
||||||
|
let varName = varNamesArray[i];
|
||||||
|
// is there a next variable ?
|
||||||
|
let varNameNext = (() => {
|
||||||
|
if (varNamesArray[i + 1]) {
|
||||||
|
return varNamesArray[i + 1];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})();
|
||||||
|
// build the tree in suppliedVariables
|
||||||
|
if (!referencePointer[varName] && !varNameNext) {
|
||||||
|
referencePointer[varName] = valueArg;
|
||||||
|
referencePointer = null;
|
||||||
|
}
|
||||||
|
else if (!referencePointer[varName] && varNameNext) {
|
||||||
|
referencePointer[varName] = {};
|
||||||
|
referencePointer = referencePointer[varName];
|
||||||
|
}
|
||||||
|
else if (referencePointer[varName] && varNameNext) {
|
||||||
|
referencePointer = referencePointer[varName];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('Something is strange!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7O0dBRUc7QUFDUSxRQUFBLGVBQWUsR0FBRyxDQUFPLFNBQVMsRUFBRSxZQUFvQixFQUFFLFFBQWdCO0lBQ25GLElBQUksYUFBYSxHQUFHLFlBQVksQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDM0MsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUE7SUFDaEMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsS0FBSyxhQUFhLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7UUFDaEQsSUFBSSxPQUFPLEdBQUcsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBRTlCLDZCQUE2QjtRQUM3QixJQUFJLFdBQVcsR0FBVyxDQUFDO1lBQ3pCLEVBQUUsQ0FBQyxDQUFDLGFBQWEsQ0F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vendored
@ -2,7 +2,9 @@ import 'typings-global';
|
|||||||
import * as lodash from 'lodash';
|
import * as lodash from 'lodash';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartfile from 'smartfile';
|
import * as smartfile from 'smartfile';
|
||||||
|
import * as smartfm from 'smartfm';
|
||||||
import * as smarthbs from 'smarthbs';
|
import * as smarthbs from 'smarthbs';
|
||||||
import * as smartinteract from 'smartinteract';
|
import * as smartinteract from 'smartinteract';
|
||||||
import * as smartq from 'smartq';
|
import * as smartq from 'smartq';
|
||||||
export { lodash, path, smartfile, smarthbs, smartinteract, smartq };
|
import * as smartyaml from 'smartyaml';
|
||||||
|
export { lodash, path, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
||||||
|
6
dist/smartscaf.plugins.js
vendored
6
dist/smartscaf.plugins.js
vendored
@ -7,10 +7,14 @@ const path = require("path");
|
|||||||
exports.path = path;
|
exports.path = path;
|
||||||
const smartfile = require("smartfile");
|
const smartfile = require("smartfile");
|
||||||
exports.smartfile = smartfile;
|
exports.smartfile = smartfile;
|
||||||
|
const smartfm = require("smartfm");
|
||||||
|
exports.smartfm = smartfm;
|
||||||
const smarthbs = require("smarthbs");
|
const smarthbs = require("smarthbs");
|
||||||
exports.smarthbs = smarthbs;
|
exports.smarthbs = smarthbs;
|
||||||
const smartinteract = require("smartinteract");
|
const smartinteract = require("smartinteract");
|
||||||
exports.smartinteract = smartinteract;
|
exports.smartinteract = smartinteract;
|
||||||
const smartq = require("smartq");
|
const smartq = require("smartq");
|
||||||
exports.smartq = smartq;
|
exports.smartq = smartq;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFROUIsd0JBQU07QUFQUiw2QkFBNEI7QUFRMUIsb0JBQUk7QUFQTix1Q0FBc0M7QUFRcEMsOEJBQVM7QUFQWCxxQ0FBb0M7QUFRbEMsNEJBQVE7QUFQViwrQ0FBOEM7QUFRNUMsc0NBQWE7QUFQZixpQ0FBZ0M7QUFROUIsd0JBQU0ifQ==
|
const smartyaml = require("smartyaml");
|
||||||
|
exports.smartyaml = smartyaml;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFVOUIsd0JBQU07QUFUUiw2QkFBNEI7QUFVMUIsb0JBQUk7QUFUTix1Q0FBc0M7QUFVcEMsOEJBQVM7QUFUWCxtQ0FBa0M7QUFVaEMsMEJBQU87QUFUVCxxQ0FBb0M7QUFVbEMsNEJBQVE7QUFUViwrQ0FBOEM7QUFVNUMsc0NBQWE7QUFUZixpQ0FBZ0M7QUFVOUIsd0JBQU07QUFUUix1Q0FBc0M7QUFVcEMsOEJBQVMifQ==
|
29
docs/index.md
Normal file
29
docs/index.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# smartscaf
|
||||||
|
scaffold projects quickly
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/smartscaf)
|
||||||
|
[](https://GitLab.com/pushrocks/smartscaf)
|
||||||
|
[](https://github.com/pushrocks/smartscaf)
|
||||||
|
[](https://pushrocks.gitlab.io/smartscaf/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://GitLab.com/pushrocks/smartscaf/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smartscaf/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smartscaf)
|
||||||
|
[](https://david-dm.org/pushrocks/smartscaf)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartscaf/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartscaf)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
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://)
|
21
package.json
21
package.json
@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "smartscaf",
|
"name": "smartscaf",
|
||||||
"version": "1.0.1",
|
"version": "1.0.14",
|
||||||
"description": "scaffold projects quickly",
|
"description": "scaffold projects quickly",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(npmts)",
|
||||||
|
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,15 +24,17 @@
|
|||||||
"npm"
|
"npm"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tapbundle": "^1.0.10"
|
"tapbundle": "^1.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.63",
|
"@types/lodash": "^4.14.72",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"smartfile": "^4.2.9",
|
"smartfile": "^4.2.20",
|
||||||
"smarthbs": "^1.0.12",
|
"smartfm": "^1.0.5",
|
||||||
"smartinteract": "^1.0.4",
|
"smarthbs": "^1.0.16",
|
||||||
"smartq": "^1.1.1",
|
"smartinteract": "^1.0.10",
|
||||||
"typings-global": "^1.0.16"
|
"smartq": "^1.1.6",
|
||||||
|
"smartyaml": "^1.0.2",
|
||||||
|
"typings-global": "^1.0.20"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
test/test.ts
15
test/test.ts
@ -1,6 +1,9 @@
|
|||||||
import { expect, tap } from 'tapbundle'
|
import { expect, tap } from 'tapbundle'
|
||||||
|
import * as path from 'path'
|
||||||
|
|
||||||
import * as smartscaf from '../dist/index'
|
import * as smartscaf from '../ts/index'
|
||||||
|
|
||||||
|
// process.env.CI = 'true'
|
||||||
|
|
||||||
let testScafTemplate: smartscaf.ScafTemplate
|
let testScafTemplate: smartscaf.ScafTemplate
|
||||||
|
|
||||||
@ -11,7 +14,7 @@ tap.test('should create new Smartscaf instance', async () => {
|
|||||||
|
|
||||||
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
||||||
await testScafTemplate.readTemplateFromDir('./test/test_template')
|
await testScafTemplate.readTemplateFromDir('./test/test_template')
|
||||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(3)
|
expect(testScafTemplate.templateSmartfileArray.length).to.equal(5)
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.test('smartfile -> should accept variables', async () => {
|
tap.test('smartfile -> should accept variables', async () => {
|
||||||
@ -23,4 +26,12 @@ tap.test('ask cli', async () => {
|
|||||||
await testScafTemplate.askCliForMissingVariables()
|
await testScafTemplate.askCliForMissingVariables()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('should have valid supplied variables', async () => {
|
||||||
|
console.log(testScafTemplate.suppliedVariables)
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.test('should output ready rendered template', async () => {
|
||||||
|
await testScafTemplate.writeToDisk(path.resolve('./test/test_output'))
|
||||||
|
})
|
||||||
|
|
||||||
tap.start()
|
tap.start()
|
||||||
|
1
test/test_output/changedname.md
Normal file
1
test/test_output/changedname.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# some undefined variable
|
4
test/test_output/defaults.yml
Normal file
4
test/test_output/defaults.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
templateVar1: from default yaml
|
||||||
|
templateVar2: this is another value from yml
|
||||||
|
templateObject.value1: wow
|
||||||
|
templateObject.value2: here
|
1
test/test_output/notemplate.yml
Normal file
1
test/test_output/notemplate.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
awesome!
|
3
test/test_output/template1.md
Normal file
3
test/test_output/template1.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# this is a wow
|
||||||
|
# this is a here
|
||||||
|
# this is a undefined variable
|
3
test/test_output/template2.md
Normal file
3
test/test_output/template2.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# this is a from default yaml
|
||||||
|
# this is a this is another value from yml
|
||||||
|
# this is a undefined variable
|
4
test/test_template/defaults.yml
Normal file
4
test/test_template/defaults.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
templateVar1: from default yaml
|
||||||
|
templateVar2: this is another value from yml
|
||||||
|
templateObject.value1: wow
|
||||||
|
templateObject.value2: here
|
1
test/test_template/notemplate.yml
Normal file
1
test/test_template/notemplate.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
awesome!
|
@ -1,3 +1,3 @@
|
|||||||
# this is a {{templateVar1}}
|
# this is a {{templateObject.value1}}
|
||||||
# this is a {{templateVar2}}
|
# this is a {{templateObject.value2}}
|
||||||
# this is a {{templateVar3}}
|
# this is a {{templateVar3}}
|
||||||
|
@ -1 +1,4 @@
|
|||||||
|
---
|
||||||
|
fileName: changedname.md
|
||||||
|
---
|
||||||
# some {{wow}}
|
# some {{wow}}
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smartscaf.plugins'
|
import * as plugins from './smartscaf.plugins'
|
||||||
|
import * as helpers from './smartscaf.helpers'
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { Smartfile } from 'smartfile'
|
import { Smartfile } from 'smartfile'
|
||||||
@ -14,7 +15,8 @@ export class ScafTemplate {
|
|||||||
description: string
|
description: string
|
||||||
templateSmartfileArray: Smartfile[]
|
templateSmartfileArray: Smartfile[]
|
||||||
requiredVariables: string[]
|
requiredVariables: string[]
|
||||||
suppliedVariables: any
|
defaultVariables: any
|
||||||
|
suppliedVariables: any = {}
|
||||||
missingVariables: string[] = []
|
missingVariables: string[] = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,15 +25,17 @@ export class ScafTemplate {
|
|||||||
async readTemplateFromDir (dirPathArg: string) {
|
async readTemplateFromDir (dirPathArg: string) {
|
||||||
let dirPath = plugins.path.resolve(dirPathArg)
|
let dirPath = plugins.path.resolve(dirPathArg)
|
||||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*')
|
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*')
|
||||||
this._findVariablesInTemplate()
|
await this._findVariablesInTemplate()
|
||||||
|
await this._checkSuppliedVariables()
|
||||||
|
await this._checkDefaultVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* supply the variables to render the teplate with
|
* supply the variables to render the teplate with
|
||||||
* @param variablesArg
|
* @param variablesArg gets merged with this.suppliedVariables
|
||||||
*/
|
*/
|
||||||
async supplyVariables (variablesArg) {
|
async supplyVariables (variablesArg) {
|
||||||
this.suppliedVariables = variablesArg
|
this.suppliedVariables = plugins.lodash.merge(this.suppliedVariables, variablesArg)
|
||||||
this.missingVariables = await this._checkSuppliedVariables()
|
this.missingVariables = await this._checkSuppliedVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,20 +49,56 @@ export class ScafTemplate {
|
|||||||
localSmartInteract.addQuestions([{
|
localSmartInteract.addQuestions([{
|
||||||
name: missingVariable,
|
name: missingVariable,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
default: `undefined ${missingVariable}`,
|
default: (() => {
|
||||||
|
if (this.defaultVariables && this.defaultVariables[missingVariable]) {
|
||||||
|
return this.defaultVariables[missingVariable]
|
||||||
|
} else {
|
||||||
|
return 'undefined variable'
|
||||||
|
}
|
||||||
|
})(),
|
||||||
message: `What is the value of ${missingVariable}?`
|
message: `What is the value of ${missingVariable}?`
|
||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
let answers = await localSmartInteract.runQueue()
|
let answerBucket = await localSmartInteract.runQueue()
|
||||||
|
answerBucket.answerMap.forEach(async answer => {
|
||||||
|
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeToDisk (destinationDirArg) {
|
||||||
|
let smartfileArrayToWrite = plugins.lodash.cloneDeep(this.templateSmartfileArray)
|
||||||
|
for (let smartfile of smartfileArrayToWrite) {
|
||||||
|
|
||||||
|
// render the template
|
||||||
|
let template = await plugins.smarthbs.getTemplateForString(
|
||||||
|
smartfile.contents.toString()
|
||||||
|
)
|
||||||
|
let renderedTemplateString = template(this.suppliedVariables)
|
||||||
|
|
||||||
|
// handle frontmatter
|
||||||
|
let parsedTemplate = plugins.smartfm.parse(renderedTemplateString)
|
||||||
|
if (parsedTemplate.data.fileName) {
|
||||||
|
smartfile.updateFileName(parsedTemplate.data.fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
smartfile.contents = Buffer.from(parsedTemplate.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* finds all variables in a Template
|
* finds all variables in a Template in as string
|
||||||
|
* e.g. myobject.someKey and myobject.someOtherKey
|
||||||
*/
|
*/
|
||||||
private async _findVariablesInTemplate () {
|
private async _findVariablesInTemplate () {
|
||||||
for (let localSmartfile of this.templateSmartfileArray) {
|
let templateVariables: string[] = []
|
||||||
|
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||||
|
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(templateSmartfile.contents.toString())
|
||||||
|
templateVariables = plugins.lodash.concat(templateVariables, localTemplateVariables)
|
||||||
}
|
}
|
||||||
|
templateVariables = plugins.lodash.uniq(templateVariables)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,14 +106,41 @@ export class ScafTemplate {
|
|||||||
*/
|
*/
|
||||||
private async _checkSuppliedVariables () {
|
private async _checkSuppliedVariables () {
|
||||||
let missingVars: string[] = []
|
let missingVars: string[] = []
|
||||||
for (let templateSmartFile of this.templateSmartfileArray) {
|
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||||
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
|
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
|
||||||
templateSmartFile.contents.toString(),
|
templateSmartfile.contents.toString(),
|
||||||
this.suppliedVariables
|
this.suppliedVariables
|
||||||
)
|
)
|
||||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
|
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
|
||||||
missingVars = plugins.lodash.uniq(missingVars)
|
|
||||||
}
|
}
|
||||||
|
missingVars = plugins.lodash.uniq(missingVars)
|
||||||
return missingVars
|
return missingVars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks the default.yml at the root of a template for default variables
|
||||||
|
* allows 2 ways of notation in YAML:
|
||||||
|
* >> myObject.myKey.someDeeperKey: someValue
|
||||||
|
* >> myObject.yourKey.yourDeeperKey: yourValue
|
||||||
|
* or
|
||||||
|
* >> myObject:
|
||||||
|
* >> - someKey:
|
||||||
|
* >> - someDeeperKey: someValue
|
||||||
|
* >> - yourKey:
|
||||||
|
* >> - yourDeeperKey: yourValue
|
||||||
|
*/
|
||||||
|
private async _checkDefaultVariables () {
|
||||||
|
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
|
||||||
|
return smartfileArg.parsedPath.base === 'defaults.yml'
|
||||||
|
})[0]
|
||||||
|
|
||||||
|
if (defaultsSmartfile) {
|
||||||
|
let defaultObject = await plugins.smartyaml.yamlStringToObject(
|
||||||
|
defaultsSmartfile.contents.toString()
|
||||||
|
)
|
||||||
|
this.defaultVariables = defaultObject
|
||||||
|
} else {
|
||||||
|
this.defaultVariables = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,33 @@
|
|||||||
import * as plugins from './smartscaf.plugins'
|
import * as plugins from './smartscaf.plugins'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a variable in string dot notation to an already more or less expanded object
|
||||||
|
*/
|
||||||
|
export let deepAddToObject = async (objectArg, varStringArg: string, valueArg: string) => {
|
||||||
|
let varNamesArray = varStringArg.split('.')
|
||||||
|
let referencePointer = objectArg
|
||||||
|
for (let i = 0; i !== varNamesArray.length; i++) {
|
||||||
|
let varName = varNamesArray[i]
|
||||||
|
|
||||||
|
// is there a next variable ?
|
||||||
|
let varNameNext: string = (() => {
|
||||||
|
if (varNamesArray[i + 1]) {
|
||||||
|
return varNamesArray[i + 1]
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
})()
|
||||||
|
|
||||||
|
// build the tree in suppliedVariables
|
||||||
|
if (!referencePointer[varName] && !varNameNext) {
|
||||||
|
referencePointer[varName] = valueArg
|
||||||
|
referencePointer = null
|
||||||
|
} else if (!referencePointer[varName] && varNameNext) {
|
||||||
|
referencePointer[varName] = {}
|
||||||
|
referencePointer = referencePointer[varName]
|
||||||
|
} else if (referencePointer[varName] && varNameNext) {
|
||||||
|
referencePointer = referencePointer[varName]
|
||||||
|
} else {
|
||||||
|
throw new Error('Something is strange!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,15 +2,19 @@ import 'typings-global'
|
|||||||
import * as lodash from 'lodash'
|
import * as lodash from 'lodash'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as smartfile from 'smartfile'
|
import * as smartfile from 'smartfile'
|
||||||
|
import * as smartfm from 'smartfm'
|
||||||
import * as smarthbs from 'smarthbs'
|
import * as smarthbs from 'smarthbs'
|
||||||
import * as smartinteract from 'smartinteract'
|
import * as smartinteract from 'smartinteract'
|
||||||
import * as smartq from 'smartq'
|
import * as smartq from 'smartq'
|
||||||
|
import * as smartyaml from 'smartyaml'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lodash,
|
lodash,
|
||||||
path,
|
path,
|
||||||
smartfile,
|
smartfile,
|
||||||
|
smartfm,
|
||||||
smarthbs,
|
smarthbs,
|
||||||
smartinteract,
|
smartinteract,
|
||||||
smartq
|
smartq,
|
||||||
|
smartyaml
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user