Compare commits

..

33 Commits

Author SHA1 Message Date
60854250eb 3.0.0 2018-08-30 22:43:22 +02:00
53de92ac1a BREAKING CHANGE(structure): templates now take their path within the constructor 2018-08-30 22:43:22 +02:00
6cb4fff0a5 2.0.2 2018-08-28 23:57:06 +02:00
45710ded00 2.0.1 2018-08-28 00:20:02 +02:00
aa87ed9427 fix(dependencies): resolve dependencies 2018-08-28 00:20:02 +02:00
f3594447ac 2.0.0 2018-08-27 23:55:14 +02:00
a3f18c17ed BREAKING CHANGE(scope): switch to new @pushrocks scope 2018-08-27 23:55:14 +02:00
c5ec7e9c24 1.0.14 2017-08-09 16:57:39 +02:00
98875a2ece fix variable distribution 2017-08-09 16:57:32 +02:00
5b42cf93cb 1.0.13 2017-08-09 15:31:39 +02:00
e0ab34c466 update dependencies 2017-08-09 15:31:35 +02:00
beb3013e2c 1.0.12 2017-07-28 14:47:46 +02:00
5d1c0a6f1e update dependencies 2017-07-28 14:47:43 +02:00
fc450816e6 1.0.11 2017-06-02 01:03:27 +02:00
5fac35c75f prevent empty defaults.yml causing error 2017-06-02 01:03:24 +02:00
dde29629b7 1.0.10 2017-05-28 00:14:25 +02:00
4347f800e6 update dependencies 2017-05-28 00:14:11 +02:00
59161f1eeb 1.0.9 2017-05-27 23:53:06 +02:00
b9a346c5d7 now supports frontmatter for advanced file templating 2017-05-27 23:52:58 +02:00
fa961f86b8 1.0.8 2017-05-27 03:25:50 +02:00
ff679c1787 add docs 2017-05-27 03:25:42 +02:00
35e3c9ae48 1.0.7 2017-05-27 03:22:00 +02:00
bf0007ff3a fix deep add 2017-05-27 03:21:55 +02:00
3ab780e600 1.0.6 2017-05-27 02:57:25 +02:00
d0662f809f update smartfile 2017-05-27 02:57:22 +02:00
e20bf7f610 1.0.5 2017-05-27 01:47:21 +02:00
0a97ec4d07 fix tests 2017-05-27 01:47:16 +02:00
69e09c8b4c 1.0.4 2017-05-27 01:28:42 +02:00
0e92554d0a update smartfile 2017-05-27 01:28:37 +02:00
648afbcf21 1.0.3 2017-05-26 15:32:54 +02:00
7998c99f27 now works as intended 2017-05-26 15:32:50 +02:00
8e3633827c 1.0.2 2017-05-25 18:32:56 +02:00
eac20873e5 now working 2017-05-25 18:32:53 +02:00
27 changed files with 2019 additions and 1135 deletions

View File

@ -3,69 +3,140 @@ image: hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .yarn/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- trigger - metadata
- pages
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY: testLEGACY:
stage: test stage: test
script: script:
- npmci test legacy - npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
allow_failure: true allow_failure: true
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci test lts - npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci test stable - npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci publish - npmci node install stable
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmci
stage: pages stage: metadata
script: script:
- npmci command yarn global add npmpage - npmci command npm install -g typedoc typescript
- npmci command npmpage - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags: tags:
- docker - docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -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;
} }

View File

@ -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 = Object.assign({}, this.suppliedVariables, variablesArg);
this.missingVariables = yield this._checkSuppliedVariables(); this.missingVariables = yield this._checkSuppliedVariables();
}); });
} }
@ -41,23 +45,59 @@ class ScafTemplate {
this.missingVariables = yield this._checkSuppliedVariables(); this.missingVariables = yield this._checkSuppliedVariables();
let localSmartInteract = new plugins.smartinteract.SmartInteract(); let localSmartInteract = new plugins.smartinteract.SmartInteract();
for (let missingVariable of this.missingVariables) { for (let missingVariable of this.missingVariables) {
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 = 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 = [...templateVariables, ...localTemplateVariables];
} }
templateVariables = templateVariables.filter((value, index, self) => {
return self.indexOf(value) === index;
});
}); });
} }
/** /**
@ -66,14 +106,45 @@ 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 = [
missingVars = plugins.lodash.uniq(missingVars); ...missingVars,
...localMissingVars
];
} }
missingVars = missingVars.filter((value, index, self) => {
return self.indexOf(value) === index;
});
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.ScafTemplate = ScafTemplate; exports.ScafTemplate = ScafTemplate;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZX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BQztZQUN2QyxDQUFDLENBQUMsQ0FBQztZQUNILE9BQU8sV0FBVyxDQUFDO1FBQ3JCLENBQUM7S0FBQTtJQUVEOzs7Ozs7Ozs7OztPQVdHO0lBQ1csc0JBQXNCOztZQUNsQyxJQUFJLGlCQUFpQixHQUFHLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxNQUFNLENBQUMsWUFBWSxDQUFDLEVBQUU7Z0JBQ3hFLE9BQU8sWUFBWSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEtBQUssY0FBYyxDQUFDO1lBQ3pELENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBRU4sSUFBSSxpQkFBaUIsRUFBRTtnQkFDckIsSUFBSSxhQUFhLEdBQUcsTUFBTSxPQUFPLENBQUMsU0FBUyxDQUFDLGtCQUFrQixDQUM1RCxpQkFBaUIsQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLENBQ3RDLENBQUM7Z0JBQ0YsSUFBSSxDQUFDLGdCQUFnQixHQUFHLGFBQWEsQ0FBQzthQUN2QztpQkFBTTtnQkFDTCxJQUFJLENBQUMsZ0JBQWdCLEdBQUcsRUFBRSxDQUFDO2FBQzVCO1FBQ0gsQ0FBQztLQUFBO0NBQ0Y7QUEvSUQsb0NBK0lDIn0=

View File

@ -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>;

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7O0dBRUc7QUFDUSxRQUFBLGVBQWUsR0FBRyxDQUFPLFNBQVMsRUFBRSxZQUFvQixFQUFFLFFBQWdCLEVBQUUsRUFBRTtJQUN2RixJQUFJLGFBQWEsR0FBRyxZQUFZLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQzNDLElBQUksZ0JBQWdCLEdBQUcsU0FBUyxDQUFBO0lBQ2hDLEtBQUssSUFBSSxDQ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8 +1,8 @@
import 'typings-global';
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 { path, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };

View File

@ -1,16 +1,17 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const lodash = require("lodash");
exports.lodash = lodash;
const path = require("path"); 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZCQUE0QjtBQVMxQixvQkFBSTtBQVJOLHVDQUFzQztBQVNwQyw4QkFBUztBQVJYLG1DQUFrQztBQVNoQywwQkFBTztBQVJULHFDQUFvQztBQVNsQyw0QkFBUTtBQVJWLCtDQUE4QztBQVM1QyxzQ0FBYTtBQVJmLGlDQUFnQztBQVM5Qix3QkFBTTtBQVJSLHVDQUFzQztBQVNwQyw4QkFBUyJ9

33
docs/index.md Normal file
View File

@ -0,0 +1,33 @@
# smartscaf
scaffold projects quickly
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartscaf)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartscaf/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartscaf/badges/master/build.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartscaf.svg)](https://www.npmjs.com/package/smartscaf)
[![Dependency Status](https://david-dm.org/pushrocks/smartscaf.svg)](https://david-dm.org/pushrocks/smartscaf)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartscaf/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartscaf/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartscaf/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartscaf)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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 | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://)

View File

@ -3,8 +3,7 @@
"coverageTreshold": 30 "coverageTreshold": 30
}, },
"npmci": { "npmci": {
"globalNpmTools": [ "npmGlobalTools": [],
"npmts" "npmAccessLevel": "public"
]
} }
} }

1475
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,14 @@
{ {
"name": "smartscaf", "name": "@pushrocks/smartscaf",
"version": "1.0.1", "version": "3.0.0",
"private": false,
"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": "(tstest test/)",
"build": "(tsbuild)",
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,15 +26,21 @@
"npm" "npm"
], ],
"devDependencies": { "devDependencies": {
"tapbundle": "^1.0.10" "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.1.12",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.5",
"@types/node": "^10.9.2"
}, },
"dependencies": { "dependencies": {
"@types/lodash": "^4.14.63", "@pushrocks/lik": "^3.0.1",
"lodash": "^4.17.4", "@pushrocks/smartfile": "^6.0.8",
"smartfile": "^4.2.9", "@pushrocks/smartfm": "^2.0.1",
"smarthbs": "^1.0.12", "@pushrocks/smarthbs": "^2.0.0",
"smartinteract": "^1.0.4", "@pushrocks/smartinteract": "^2.0.4",
"smartq": "^1.1.1", "@pushrocks/smartpromise": "^2.0.5",
"typings-global": "^1.0.16" "@pushrocks/smartyaml": "^2.0.3",
"@types/lodash": "^4.14.72",
"lodash": "^4.17.4"
} }
} }

View File

@ -1,13 +1,16 @@
# smartscaf # smartscaf
scaffold projects quickly scaffold projects quickly
## Availabililty ## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartscaf) [![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartscaf) [![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartscaf)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartscaf) [![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartscaf)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartscaf/) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartscaf/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartscaf/badges/master/build.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master) [![build status](https://GitLab.com/pushrocks/smartscaf/badges/master/build.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master) [![coverage report](https://GitLab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartscaf/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartscaf.svg)](https://www.npmjs.com/package/smartscaf) [![npm downloads per month](https://img.shields.io/npm/dm/smartscaf.svg)](https://www.npmjs.com/package/smartscaf)
@ -19,11 +22,12 @@ scaffold projects quickly
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README. For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) > | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://) [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://)

View File

@ -1,26 +1,37 @@
import { expect, tap } from 'tapbundle' import { expect, tap } from '@pushrocks/tapbundle';
import * as path from 'path';
import * as smartscaf from '../dist/index' import * as smartscaf from '../ts/index';
let testScafTemplate: smartscaf.ScafTemplate process.env.CI = 'true'
let testScafTemplate: smartscaf.ScafTemplate;
tap.test('should create new Smartscaf instance', async () => { tap.test('should create new Smartscaf instance', async () => {
testScafTemplate = new smartscaf.ScafTemplate() testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate) expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate);
}) });
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();
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 () => {
await testScafTemplate.supplyVariables({}) await testScafTemplate.supplyVariables({});
console.log(testScafTemplate.missingVariables) console.log(testScafTemplate.missingVariables);
}) });
tap.test('ask cli', async () => { tap.test('ask cli', async () => {
await testScafTemplate.askCliForMissingVariables() await testScafTemplate.askCliForMissingVariables();
}) });
tap.start() 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();

View File

@ -0,0 +1 @@
# some undefined variable

View File

@ -0,0 +1,4 @@
templateVar1: from default yaml
templateVar2: this is another value from yml
templateObject.value1: wow
templateObject.value2: here

View File

@ -0,0 +1 @@
awesome!

View File

@ -0,0 +1,3 @@
# this is a wow
# this is a here
# this is a undefined variable

View 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

View File

@ -0,0 +1,4 @@
templateVar1: from default yaml
templateVar2: this is another value from yml
templateObject.value1: wow
templateObject.value2: here

View File

@ -0,0 +1 @@
awesome!

View File

@ -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}}

View File

@ -1 +1,4 @@
---
fileName: changedname.md
---
# some {{wow}} # some {{wow}}

View File

@ -1 +1 @@
export * from './smartscaf.classes.smartscaf' export * from './smartscaf.classes.smartscaf';

View File

@ -1,79 +1,186 @@
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 '@pushrocks/smartfile';
export interface ScafTemplateContructorOptions { export interface ScafTemplateContructorOptions {
name?: string, name?: string;
description?: string description?: string;
sourceDir?: string sourceDir?: string;
} }
export class ScafTemplate { export class ScafTemplate {
name: string static async createTemplateFromDir() {
description: string
templateSmartfileArray: Smartfile[] }
requiredVariables: string[]
suppliedVariables: any name: string;
missingVariables: string[] = [] description: string;
dirPath: string;
templateSmartfileArray: Smartfile[];
requiredVariables: string[];
defaultVariables: any;
suppliedVariables: any = {};
missingVariables: string[] = [];
constructor(dirPathArg: string) {
this.dirPath = plugins.path.resolve(dirPathArg);
}
/** /**
* read a template from a directory * read a template from a directory
*/ */
async readTemplateFromDir (dirPathArg: string) { async readTemplateFromDir() {
let dirPath = plugins.path.resolve(dirPathArg) this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*') await this._resolveTemplateDependencies();
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 = {
this.missingVariables = await this._checkSuppliedVariables() ...this.suppliedVariables,
...variablesArg
};
this.missingVariables = await this._checkSuppliedVariables();
} }
/** /**
* Will ask for the missing variables by cli interaction * Will ask for the missing variables by cli interaction
*/ */
async askCliForMissingVariables () { async askCliForMissingVariables() {
this.missingVariables = await this._checkSuppliedVariables() this.missingVariables = await this._checkSuppliedVariables();
let localSmartInteract = new plugins.smartinteract.SmartInteract() let localSmartInteract = new plugins.smartinteract.SmartInteract();
for (let missingVariable of this.missingVariables) { for (let missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([{ localSmartInteract.addQuestions([
name: missingVariable, {
type: 'input', name: missingVariable,
default: `undefined ${missingVariable}`, type: 'input',
message: `What is the value of ${missingVariable}?` default: (() => {
}]) if (this.defaultVariables && this.defaultVariables[missingVariable]) {
return this.defaultVariables[missingVariable];
} else {
return 'undefined variable';
}
})(),
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 = 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
const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: "yaml"
});
let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
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 = [...templateVariables, ...localTemplateVariables];
} }
templateVariables = templateVariables.filter((value, index, self) => {
return self.indexOf(value) === index;
});
} }
/** /**
* checks if supplied Variables satisfy the template * checks if supplied Variables satisfy the template
*/ */
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 = [...missingVars, ...localMissingVars];
missingVars = plugins.lodash.uniq(missingVars) }
missingVars = missingVars.filter((value, index, self) => {
return self.indexOf(value) === index;
});
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 = {};
}
}
/**
* resolve template dependencies
*/
private async _resolveTemplateDependencies() {
const dependenciesSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === "dependencies.yml"
});
if(!dependenciesSmartfile) {
console.log('No further template dependencies defined!');
return;
}
console.log('Found template dependencies! Resolving them now!');
console.log('looking at templates to merge!')
const dependencies = await plugins.smartyaml.yamlStringToObject(dependenciesSmartfile.contentBuffer.toString());
for (const dependency of dependencies.merge) {
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
const templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(templatePathToMerge, '**/*');
this.templateSmartfileArray.concat(templateSmartfileArray);
} }
return missingVars
} }
} }

View File

@ -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!');
}
}
};

View File

@ -1,16 +1,10 @@
import 'typings-global' import * as path from 'path';
import * as lodash from 'lodash' import * as lik from '@pushrocks/lik';
import * as path from 'path' import * as smartfile from '@pushrocks/smartfile';
import * as smartfile from 'smartfile' import * as smartfm from '@pushrocks/smartfm';
import * as smarthbs from 'smarthbs' import * as smarthbs from '@pushrocks/smarthbs';
import * as smartinteract from 'smartinteract' import * as smartinteract from '@pushrocks/smartinteract';
import * as smartq from 'smartq' import * as smartq from '@pushrocks/smartpromise';
import * as smartyaml from '@pushrocks/smartyaml';
export { export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
lodash,
path,
smartfile,
smarthbs,
smartinteract,
smartq
}

1002
yarn.lock

File diff suppressed because it is too large Load Diff