Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
d50c8a1260 | |||
b3702d56bc | |||
ff0faa719b | |||
400e228ffc | |||
25871fc970 | |||
eb990a8ec2 | |||
f5194b76bd | |||
6b5e9ac617 | |||
60854250eb | |||
53de92ac1a | |||
6cb4fff0a5 | |||
45710ded00 | |||
aa87ed9427 | |||
f3594447ac | |||
a3f18c17ed | |||
c5ec7e9c24 | |||
98875a2ece | |||
5b42cf93cb | |||
e0ab34c466 | |||
beb3013e2c | |||
5d1c0a6f1e | |||
fc450816e6 | |||
5fac35c75f | |||
dde29629b7 | |||
4347f800e6 | |||
59161f1eeb | |||
b9a346c5d7 | |||
fa961f86b8 | |||
ff679c1787 | |||
35e3c9ae48 | |||
bf0007ff3a | |||
3ab780e600 | |||
d0662f809f | |||
e20bf7f610 | |||
0a97ec4d07 | |||
69e09c8b4c | |||
0e92554d0a | |||
648afbcf21 | |||
7998c99f27 |
123
.gitlab-ci.yml
123
.gitlab-ci.yml
@ -3,69 +3,148 @@ image: hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .yarn/
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- 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:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
||||
export * from './smartscaf.classes.smartscaf';
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./smartscaf.classes.smartscaf"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9
|
50
dist/smartscaf.classes.smartscaf.d.ts
vendored
50
dist/smartscaf.classes.smartscaf.d.ts
vendored
@ -1,50 +0,0 @@
|
||||
import { Smartfile } from 'smartfile';
|
||||
export interface ScafTemplateContructorOptions {
|
||||
name?: string;
|
||||
description?: string;
|
||||
sourceDir?: string;
|
||||
}
|
||||
export declare class ScafTemplate {
|
||||
name: string;
|
||||
description: string;
|
||||
templateSmartfileArray: Smartfile[];
|
||||
requiredVariables: string[];
|
||||
defaultVariables: any;
|
||||
suppliedVariables: any;
|
||||
missingVariables: string[];
|
||||
/**
|
||||
* read a template from a directory
|
||||
*/
|
||||
readTemplateFromDir(dirPathArg: string): Promise<void>;
|
||||
/**
|
||||
* supply the variables to render the teplate with
|
||||
* @param variablesArg gets merged with this.suppliedVariables
|
||||
*/
|
||||
supplyVariables(variablesArg: any): Promise<void>;
|
||||
/**
|
||||
* Will ask for the missing variables by cli interaction
|
||||
*/
|
||||
askCliForMissingVariables(): Promise<void>;
|
||||
/**
|
||||
* finds all variables in a Template in as string
|
||||
* e.g. myobject.someKey and myobject.someOtherKey
|
||||
*/
|
||||
private _findVariablesInTemplate();
|
||||
/**
|
||||
* checks if supplied Variables satisfy the template
|
||||
*/
|
||||
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();
|
||||
}
|
124
dist/smartscaf.classes.smartscaf.js
vendored
124
dist/smartscaf.classes.smartscaf.js
vendored
@ -1,124 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartscaf.plugins");
|
||||
const helpers = require("./smartscaf.helpers");
|
||||
class ScafTemplate {
|
||||
constructor() {
|
||||
this.suppliedVariables = {};
|
||||
this.missingVariables = [];
|
||||
}
|
||||
/**
|
||||
* read a template from a directory
|
||||
*/
|
||||
readTemplateFromDir(dirPathArg) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let dirPath = plugins.path.resolve(dirPathArg);
|
||||
this.templateSmartfileArray = yield plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*');
|
||||
yield this._findVariablesInTemplate();
|
||||
yield this._checkSuppliedVariables();
|
||||
yield this._checkDefaultVariables();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* supply the variables to render the teplate with
|
||||
* @param variablesArg gets merged with this.suppliedVariables
|
||||
*/
|
||||
supplyVariables(variablesArg) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.suppliedVariables = plugins.lodash.merge(this.suppliedVariables, variablesArg);
|
||||
this.missingVariables = yield this._checkSuppliedVariables();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Will ask for the missing variables by cli interaction
|
||||
*/
|
||||
askCliForMissingVariables() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.missingVariables = yield this._checkSuppliedVariables();
|
||||
let localSmartInteract = new plugins.smartinteract.SmartInteract();
|
||||
for (let missingVariable of this.missingVariables) {
|
||||
localSmartInteract.addQuestions([{
|
||||
name: missingVariable,
|
||||
type: 'input',
|
||||
default: (() => {
|
||||
if (this.defaultVariables[missingVariable]) {
|
||||
return this.defaultVariables[missingVariable];
|
||||
}
|
||||
else {
|
||||
return 'undefined variable';
|
||||
}
|
||||
})(),
|
||||
message: `What is the value of ${missingVariable}?`
|
||||
}]);
|
||||
}
|
||||
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);
|
||||
}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* finds all variables in a Template in as string
|
||||
* e.g. myobject.someKey and myobject.someOtherKey
|
||||
*/
|
||||
_findVariablesInTemplate() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* checks if supplied Variables satisfy the template
|
||||
*/
|
||||
_checkSuppliedVariables() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let missingVars = [];
|
||||
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||
let localMissingVars = yield plugins.smarthbs.checkVarsSatisfaction(templateSmartfile.contents.toString(), this.suppliedVariables);
|
||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars);
|
||||
}
|
||||
missingVars = plugins.lodash.uniq(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;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBOEM7QUFDOUMsK0NBQThDO0FBVzlDO0lBQUE7UUFNRSxzQkFBaUIsR0FBUSxFQUFFLENBQUE7UUFDM0IscUJBQWdCLEdBQWEsRUFBRSxDQUFBO0lBd0dqQyxDQUFDO0lBdEdDOztPQUVHO0lBQ0csbUJBQW1CLENBQUUsVUFBa0I7O1lBQzNDLElBQUksT0FBTyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1lBQzlDLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxNQUFNLE9BQU8sQ0FBQyxTQUFTLENBQUMsR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tCLENBQzVELGlCQUFpQixDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsQ0FDdEMsQ0FBQTtnQkFDRCxJQUFJLENBQUMsZ0JBQWdCLEdBQUcsYUFBYSxDQUFBO1lBQ3ZDLENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDTixJQUFJLENBQUMsZ0JBQWdCLEdBQUcsRUFBRSxDQUFBO1lBQzVCLENBQUM7UUFDSCxDQUFDO0tBQUE7Q0FDRjtBQS9HRCxvQ0ErR0MifQ==
|
4
dist/smartscaf.helpers.d.ts
vendored
4
dist/smartscaf.helpers.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 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>;
|
36
dist/smartscaf.helpers.js
vendored
36
dist/smartscaf.helpers.js
vendored
@ -1,36 +0,0 @@
|
||||
"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 });
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
else if (!referencePointer[varName] && varNameNext) {
|
||||
referencePointer[varName] = {};
|
||||
referencePointer = referencePointer[varName];
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7O0dBRUc7QUFDUSxRQUFBLGVBQWUsR0FBRyxDQUFPLFNBQVMsRUFBRSxZQUFvQixFQUFFLFFBQWdCO0lBQ25GLElBQUksYUFBYSxHQUFHLFlBQVksQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDM0MsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUE7SUFDaEMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsS0FBSyxhQUFhLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7UUFDaEQsSUFBSSxPQUFPLEdBQUcsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBRTlCLDZCQUE2QjtRQUM3QixJQUFJLFdBQVcsR0FBVyxDQUFDO1lBQ3pCLEVBQUUsQ0FBQyxDQUFDLGFBQWEsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUN6QixNQUFNLENBQUMsYUFBYSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQTtZQUM3QixDQUFDO1lBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNiLENBQUMsQ0FBQyxFQUFFLENBQUE7UUFFSixzQ0FBc0M7UUFDdEMsRUFBRSxDQUFDLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7WUFDL0MsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLEdBQUcsUUFBUSxDQUFBO1FBQ3RDLENBQUM7UUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsSUFBSSxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQ3JELGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQTtZQUM5QixnQkFBZ0IsR0FBRyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUM5QyxDQUFDO0lBQ0gsQ0FBQztBQUNILENBQUMsQ0FBQSxDQUFBIn0=
|
9
dist/smartscaf.plugins.d.ts
vendored
9
dist/smartscaf.plugins.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
import 'typings-global';
|
||||
import * as lodash from 'lodash';
|
||||
import * as path from 'path';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smarthbs from 'smarthbs';
|
||||
import * as smartinteract from 'smartinteract';
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartyaml from 'smartyaml';
|
||||
export { lodash, path, smartfile, smarthbs, smartinteract, smartq, smartyaml };
|
18
dist/smartscaf.plugins.js
vendored
18
dist/smartscaf.plugins.js
vendored
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
const lodash = require("lodash");
|
||||
exports.lodash = lodash;
|
||||
const path = require("path");
|
||||
exports.path = path;
|
||||
const smartfile = require("smartfile");
|
||||
exports.smartfile = smartfile;
|
||||
const smarthbs = require("smarthbs");
|
||||
exports.smarthbs = smarthbs;
|
||||
const smartinteract = require("smartinteract");
|
||||
exports.smartinteract = smartinteract;
|
||||
const smartq = require("smartq");
|
||||
exports.smartq = smartq;
|
||||
const smartyaml = require("smartyaml");
|
||||
exports.smartyaml = smartyaml;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFTOUIsd0JBQU07QUFSUiw2QkFBNEI7QUFTMUIsb0JBQUk7QUFSTix1Q0FBc0M7QUFTcEMsOEJBQVM7QUFSWCxxQ0FBb0M7QUFTbEMsNEJBQVE7QUFSViwrQ0FBOEM7QUFTNUMsc0NBQWE7QUFSZixpQ0FBZ0M7QUFTOUIsd0JBQU07QUFSUix1Q0FBc0M7QUFTcEMsOEJBQVMifQ==
|
@ -3,8 +3,17 @@
|
||||
"coverageTreshold": 30
|
||||
},
|
||||
"npmci": {
|
||||
"globalNpmTools": [
|
||||
"npmts"
|
||||
]
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartscaf",
|
||||
"shortDescription": "scaffold projects quickly",
|
||||
"npmPackagename": "@pushrocks/smartscaf",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
1817
package-lock.json
generated
Normal file
1817
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "smartscaf",
|
||||
"version": "1.0.2",
|
||||
"name": "@pushrocks/smartscaf",
|
||||
"version": "3.0.3",
|
||||
"private": false,
|
||||
"description": "scaffold projects quickly",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -23,16 +25,21 @@
|
||||
"npm"
|
||||
],
|
||||
"devDependencies": {
|
||||
"tapbundle": "^1.0.12"
|
||||
"@gitzone/tsbuild": "^2.1.8",
|
||||
"@gitzone/tsrun": "^1.1.17",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^11.9.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/lodash": "^4.14.64",
|
||||
"lodash": "^4.17.4",
|
||||
"smartfile": "^4.2.11",
|
||||
"smarthbs": "^1.0.12",
|
||||
"smartinteract": "^1.0.4",
|
||||
"smartq": "^1.1.1",
|
||||
"smartyaml": "^1.0.2",
|
||||
"typings-global": "^1.0.16"
|
||||
"@pushrocks/lik": "^3.0.4",
|
||||
"@pushrocks/smartfile": "^6.0.12",
|
||||
"@pushrocks/smartfm": "^2.0.1",
|
||||
"@pushrocks/smarthbs": "^2.0.3",
|
||||
"@pushrocks/smartinteract": "^2.0.4",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartyaml": "^2.0.3",
|
||||
"@types/lodash": "^4.14.121",
|
||||
"lodash": "^4.17.11"
|
||||
}
|
||||
}
|
||||
|
36
readme.md
36
readme.md
@ -1,29 +1,35 @@
|
||||
# smartscaf
|
||||
# @pushrocks/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/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartscaf)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartscaf)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartscaf)
|
||||
* [docs (typedoc)](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/)
|
||||
[](https://gitlab.com/pushrocks/smartscaf/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartscaf/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartscaf)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartscaf)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.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)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://)
|
||||
|
||||
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://maintainedby.lossless.com)
|
||||
|
41
test/test.ts
41
test/test.ts
@ -1,28 +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';
|
||||
|
||||
process.env.CI = 'true'
|
||||
process.env.CI = 'true';
|
||||
|
||||
let testScafTemplate: smartscaf.ScafTemplate
|
||||
let testScafTemplate: smartscaf.ScafTemplate;
|
||||
|
||||
tap.test('should create new Smartscaf instance', async () => {
|
||||
testScafTemplate = new smartscaf.ScafTemplate()
|
||||
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate)
|
||||
})
|
||||
testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
|
||||
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate);
|
||||
});
|
||||
|
||||
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
||||
await testScafTemplate.readTemplateFromDir('./test/test_template')
|
||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(4)
|
||||
})
|
||||
await testScafTemplate.readTemplateFromDir();
|
||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(6);
|
||||
});
|
||||
|
||||
tap.test('smartfile -> should accept variables', async () => {
|
||||
await testScafTemplate.supplyVariables({})
|
||||
console.log(testScafTemplate.missingVariables)
|
||||
})
|
||||
await testScafTemplate.supplyVariables({});
|
||||
console.log(testScafTemplate.missingVariables);
|
||||
});
|
||||
|
||||
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();
|
||||
|
1
test/test_output/changedname.md
Normal file
1
test/test_output/changedname.md
Normal file
@ -0,0 +1 @@
|
||||
# some undefined variable
|
1
test/test_output/hello.md
Normal file
1
test/test_output/hello.md
Normal file
@ -0,0 +1 @@
|
||||
# param1 10
|
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
|
10
test/test_template/.smartscaf.yml
Normal file
10
test/test_template/.smartscaf.yml
Normal file
@ -0,0 +1,10 @@
|
||||
defaults:
|
||||
templateVar1: from default yaml
|
||||
templateVar2: this is another value from yml
|
||||
templateObject.value1: wow
|
||||
templateObject.value2: here
|
||||
node_version: '10'
|
||||
|
||||
dependencies:
|
||||
merge:
|
||||
- ../test_template_2
|
@ -1,2 +0,0 @@
|
||||
templateVar1: from default yaml
|
||||
templateVar2: this is another value from yml
|
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 {{templateVar2}}
|
||||
# this is a {{templateObject.value1}}
|
||||
# this is a {{templateObject.value2}}
|
||||
# this is a {{templateVar3}}
|
||||
|
@ -1 +1,4 @@
|
||||
---
|
||||
fileName: changedname.md
|
||||
---
|
||||
# some {{wow}}
|
1
test/test_template_2/hello.md
Normal file
1
test/test_template_2/hello.md
Normal file
@ -0,0 +1 @@
|
||||
# param1 {{node_version}}
|
@ -1 +1 @@
|
||||
export * from './smartscaf.classes.smartscaf'
|
||||
export * from './smartscaf.classes.smartscaf';
|
||||
|
@ -1,102 +1,170 @@
|
||||
import * as plugins from './smartscaf.plugins'
|
||||
import * as helpers from './smartscaf.helpers'
|
||||
import * as plugins from './smartscaf.plugins';
|
||||
import * as helpers from './smartscaf.helpers';
|
||||
|
||||
// interfaces
|
||||
import { Smartfile } from 'smartfile'
|
||||
import { Smartfile } from '@pushrocks/smartfile';
|
||||
|
||||
export interface ScafTemplateContructorOptions {
|
||||
name?: string,
|
||||
description?: string
|
||||
sourceDir?: string
|
||||
name?: string;
|
||||
description?: string;
|
||||
sourceDir?: string;
|
||||
}
|
||||
|
||||
export class ScafTemplate {
|
||||
name: string
|
||||
description: string
|
||||
templateSmartfileArray: Smartfile[]
|
||||
requiredVariables: string[]
|
||||
defaultVariables: any
|
||||
suppliedVariables: any = {}
|
||||
missingVariables: string[] = []
|
||||
static async createTemplateFromDir() {}
|
||||
|
||||
/**
|
||||
* the name of the template
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* the descriptions of the template
|
||||
*/
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* the location on disk of the template
|
||||
*/
|
||||
dirPath: string;
|
||||
|
||||
/**
|
||||
* the files of the template as array of Smartfiles
|
||||
*/
|
||||
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
|
||||
*/
|
||||
async readTemplateFromDir (dirPathArg: string) {
|
||||
let dirPath = plugins.path.resolve(dirPathArg)
|
||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*')
|
||||
await this._findVariablesInTemplate()
|
||||
await this._checkSuppliedVariables()
|
||||
await this._checkDefaultVariables()
|
||||
async readTemplateFromDir() {
|
||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
|
||||
await this._resolveTemplateDependencies();
|
||||
await this._findVariablesInTemplate();
|
||||
await this._checkSuppliedVariables();
|
||||
await this._checkDefaultVariables();
|
||||
}
|
||||
|
||||
/**
|
||||
* supply the variables to render the teplate with
|
||||
* @param variablesArg gets merged with this.suppliedVariables
|
||||
*/
|
||||
async supplyVariables (variablesArg) {
|
||||
this.suppliedVariables = plugins.lodash.merge(this.suppliedVariables, variablesArg)
|
||||
this.missingVariables = await this._checkSuppliedVariables()
|
||||
async supplyVariables(variablesArg) {
|
||||
this.suppliedVariables = {
|
||||
...this.suppliedVariables,
|
||||
...variablesArg
|
||||
};
|
||||
this.missingVariables = await this._checkSuppliedVariables();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will ask for the missing variables by cli interaction
|
||||
*/
|
||||
async askCliForMissingVariables () {
|
||||
this.missingVariables = await this._checkSuppliedVariables()
|
||||
let localSmartInteract = new plugins.smartinteract.SmartInteract()
|
||||
async askCliForMissingVariables() {
|
||||
this.missingVariables = await this._checkSuppliedVariables();
|
||||
let localSmartInteract = new plugins.smartinteract.SmartInteract();
|
||||
for (let missingVariable of this.missingVariables) {
|
||||
localSmartInteract.addQuestions([{
|
||||
name: missingVariable,
|
||||
type: 'input',
|
||||
default: (() => {
|
||||
if (this.defaultVariables[missingVariable]) {
|
||||
return this.defaultVariables[missingVariable]
|
||||
} else {
|
||||
return 'undefined variable'
|
||||
}
|
||||
})(),
|
||||
message: `What is the value of ${missingVariable}?`
|
||||
}])
|
||||
localSmartInteract.addQuestions([
|
||||
{
|
||||
name: missingVariable,
|
||||
type: 'input',
|
||||
default: (() => {
|
||||
if (this.defaultVariables && this.defaultVariables[missingVariable]) {
|
||||
return this.defaultVariables[missingVariable];
|
||||
} else {
|
||||
return 'undefined variable';
|
||||
}
|
||||
})(),
|
||||
message: `What is the value of ${missingVariable}?`
|
||||
}
|
||||
]);
|
||||
}
|
||||
let answerBucket = await localSmartInteract.runQueue()
|
||||
answerBucket.answerMap.forEach(async answer => {
|
||||
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value)
|
||||
})
|
||||
let answerBucket = await localSmartInteract.runQueue();
|
||||
await answerBucket.answerMap.forEach(async answer => {
|
||||
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* writes a file to disk
|
||||
* @param destinationDirArg
|
||||
*/
|
||||
async writeToDisk(destinationDirArg) {
|
||||
const smartfileArrayToWrite: Smartfile[] = [];
|
||||
for (let 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);
|
||||
|
||||
// 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);
|
||||
smartfileArrayToWrite.push(smartfile);
|
||||
}
|
||||
|
||||
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* finds all variables in a Template in as string
|
||||
* e.g. myobject.someKey and myobject.someOtherKey
|
||||
*/
|
||||
private async _findVariablesInTemplate () {
|
||||
let templateVariables: string[] = []
|
||||
private async _findVariablesInTemplate() {
|
||||
let templateVariables: string[] = [];
|
||||
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(templateSmartfile.contents.toString())
|
||||
templateVariables = plugins.lodash.concat(templateVariables, localTemplateVariables)
|
||||
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
|
||||
templateSmartfile.contents.toString()
|
||||
);
|
||||
templateVariables = [...templateVariables, ...localTemplateVariables];
|
||||
}
|
||||
templateVariables = plugins.lodash.uniq(templateVariables)
|
||||
templateVariables = templateVariables.filter((value, index, self) => {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if supplied Variables satisfy the template
|
||||
*/
|
||||
private async _checkSuppliedVariables () {
|
||||
let missingVars: string[] = []
|
||||
private async _checkSuppliedVariables() {
|
||||
let missingVars: string[] = [];
|
||||
for (let templateSmartfile of this.templateSmartfileArray) {
|
||||
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
|
||||
templateSmartfile.contents.toString(),
|
||||
this.suppliedVariables
|
||||
)
|
||||
missingVars = plugins.lodash.concat(missingVars, localMissingVars)
|
||||
);
|
||||
|
||||
// combine with other missingVars
|
||||
missingVars = [...missingVars, ...localMissingVars];
|
||||
}
|
||||
missingVars = plugins.lodash.uniq(missingVars)
|
||||
return missingVars
|
||||
|
||||
// dedupe
|
||||
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
|
||||
* checks the smartscaf.yml default values at the root of a template
|
||||
* allows 2 ways of notation in YAML:
|
||||
* >> myObject.myKey.someDeeperKey: someValue
|
||||
* >> myObject.yourKey.yourDeeperKey: yourValue
|
||||
@ -107,18 +175,60 @@ export class ScafTemplate {
|
||||
* >> - yourKey:
|
||||
* >> - yourDeeperKey: yourValue
|
||||
*/
|
||||
private async _checkDefaultVariables () {
|
||||
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === 'defaults.yml'
|
||||
})[0]
|
||||
private async _checkDefaultVariables() {
|
||||
let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||
});
|
||||
|
||||
if (defaultsSmartfile) {
|
||||
let defaultObject = await plugins.smartyaml.yamlStringToObject(
|
||||
defaultsSmartfile.contents.toString()
|
||||
)
|
||||
this.defaultVariables = defaultObject
|
||||
} else {
|
||||
this.defaultVariables = {}
|
||||
if (smartscafSmartfile) {
|
||||
const smartscafObject = await plugins.smartyaml.yamlStringToObject(
|
||||
smartscafSmartfile.contents.toString()
|
||||
);
|
||||
const defaultObject = smartscafObject.defaults;
|
||||
this.defaultVariables = defaultObject;
|
||||
}
|
||||
|
||||
// safeguard against non existent defaults
|
||||
if (!this.defaultVariables) {
|
||||
console.log('this template does not specify defaults');
|
||||
this.defaultVariables = {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
console.log(`Now resolving ${dependency}`);
|
||||
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
|
||||
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
|
||||
console.log(
|
||||
`dependency ${dependency} resolves to ${templatePathToMerge} which ist NOT a directory`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
|
||||
templatePathToMerge,
|
||||
'**/*'
|
||||
);
|
||||
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +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
|
||||
let varNamesArray = varStringArg.split('.');
|
||||
let referencePointer = objectArg;
|
||||
for (let i = 0; i !== varNamesArray.length; i++) {
|
||||
let varName = varNamesArray[i]
|
||||
let varName = varNamesArray[i];
|
||||
|
||||
// is there a next variable ?
|
||||
let varNameNext: string = (() => {
|
||||
if (varNamesArray[i + 1]) {
|
||||
return varNamesArray[i + 1]
|
||||
return varNamesArray[i + 1];
|
||||
}
|
||||
return null
|
||||
})()
|
||||
return null;
|
||||
})();
|
||||
|
||||
// build the tree in suppliedVariables
|
||||
if (!referencePointer[varName] && !varNameNext) {
|
||||
referencePointer[varName] = valueArg
|
||||
referencePointer[varName] = valueArg;
|
||||
referencePointer = null;
|
||||
} else if (!referencePointer[varName] && varNameNext) {
|
||||
referencePointer[varName] = {}
|
||||
referencePointer = referencePointer[varName]
|
||||
referencePointer[varName] = {};
|
||||
referencePointer = referencePointer[varName];
|
||||
} else if (referencePointer[varName] && varNameNext) {
|
||||
referencePointer = referencePointer[varName];
|
||||
} else {
|
||||
throw new Error('Something is strange!');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,18 +1,10 @@
|
||||
import 'typings-global'
|
||||
import * as lodash from 'lodash'
|
||||
import * as path from 'path'
|
||||
import * as smartfile from 'smartfile'
|
||||
import * as smarthbs from 'smarthbs'
|
||||
import * as smartinteract from 'smartinteract'
|
||||
import * as smartq from 'smartq'
|
||||
import * as smartyaml from 'smartyaml'
|
||||
import * as path from 'path';
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartfm from '@pushrocks/smartfm';
|
||||
import * as smarthbs from '@pushrocks/smarthbs';
|
||||
import * as smartinteract from '@pushrocks/smartinteract';
|
||||
import * as smartq from '@pushrocks/smartpromise';
|
||||
import * as smartyaml from '@pushrocks/smartyaml';
|
||||
|
||||
export {
|
||||
lodash,
|
||||
path,
|
||||
smartfile,
|
||||
smarthbs,
|
||||
smartinteract,
|
||||
smartq,
|
||||
smartyaml
|
||||
}
|
||||
export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Reference in New Issue
Block a user