Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
b85a29cfc1 | |||
d559b0f402 | |||
7433c1dba4 | |||
c8f6b0296d | |||
0cffae9eaa | |||
d50c8a1260 | |||
b3702d56bc | |||
ff0faa719b | |||
400e228ffc | |||
25871fc970 | |||
eb990a8ec2 | |||
f5194b76bd | |||
6b5e9ac617 | |||
60854250eb | |||
53de92ac1a |
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,22 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@ -26,6 +26,7 @@ mirror:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
@ -36,38 +37,29 @@ snyk:
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
@ -86,19 +78,11 @@ release:
|
||||
# ====================
|
||||
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]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -114,12 +98,15 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
@ -130,13 +117,3 @@ pages:
|
||||
paths:
|
||||
- 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
|
||||
|
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
|
51
dist/smartscaf.classes.smartscaf.d.ts
vendored
51
dist/smartscaf.classes.smartscaf.d.ts
vendored
@ -1,51 +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>;
|
||||
writeToDisk(destinationDirArg: any): 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;
|
||||
}
|
150
dist/smartscaf.classes.smartscaf.js
vendored
150
dist/smartscaf.classes.smartscaf.js
vendored
@ -1,150 +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 = Object.assign({}, 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 && 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);
|
||||
}));
|
||||
});
|
||||
}
|
||||
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 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 = [...templateVariables, ...localTemplateVariables];
|
||||
}
|
||||
templateVariables = templateVariables.filter((value, index, self) => {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 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 = [
|
||||
...missingVars,
|
||||
...localMissingVars
|
||||
];
|
||||
}
|
||||
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
|
||||
*/
|
||||
_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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzY2FmLmNsYXNzZXMuc21hcnRzY2FmLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBK0M7QUFDL0MsK0NBQStDO0FBVy9DO0lBQUE7UUFNRSxzQkFBaUIsR0FBUSxFQUFFLENBQUM7UUFDNUIscUJBQWdCLEdBQWEsRUFBRSxDQUFDO0lBd0lsQyxDQUFDO0lBdElDOztPQUVHO0lBQ0csbUJBQW1CLENBQUMsVUFBa0I7O1lBQzFDLElBQUksT0FBTyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO1lBQy9DLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxNQUFNLE9BQU8sQ0FBQyxTQUFTLENBQU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UMsZ0JBQWdCLEdBQUcsRUFBRSxDQUFDO2FBQzVCO1FBQ0gsQ0FBQztLQUFBO0NBQ0Y7QUEvSUQsb0NBK0lDIn0=
|
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>;
|
43
dist/smartscaf.helpers.js
vendored
43
dist/smartscaf.helpers.js
vendored
@ -1,43 +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;
|
||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7O0dBRUc7QUFDUSxRQUFBLGVBQWUsR0FBRyxDQUFPLFNBQVMsRUFBRSxZQUFvQixFQUFFLFFBQWdCLEVBQUUsRUFBRTtJQUN2RixJQUFJLGFBQWEsR0FBRyxZQUFZLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQzNDLElBQUksZ0JBQWdCLEdBQUcsU0FBUyxDQUFBO0lBQ2hDLEtBQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsS0FBSyxhQUFhLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFO1FBQy9DLElBQUksT0FBTyxHQUFHLGFBQWEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUU5Qiw2QkFBNkI7UUFDN0IsSUFBSSxXQUFXLEdBQVcsQ0FBQyxHQUFHLEVBQUU7WUFDOUIsSUFBSSxhQUFhLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxFQUFFO2dCQUN4QixPQUFPLGFBQWEsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7YUFDNUI7WUFDRCxPQUFPLElBQUksQ0FBQTtRQUNiLENBQUMsQ0FBQyxFQUFFLENBQUE7UUFFSixzQ0FBc0M7UUFDdEMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsV0FBVyxFQUFFO1lBQzlDLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxHQUFHLFFBQVEsQ0FBQTtZQUNwQyxnQkFBZ0IsR0FBRyxJQUFJLENBQUE7U0FDeEI7YUFBTSxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksV0FBVyxFQUFFO1lBQ3BELGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQTtZQUM5QixnQkFBZ0IsR0FBRyxnQkFBZ0IsQ0FBQyxPQUFPLENBQUMsQ0FBQTtTQUM3QzthQUFNLElBQUksZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksV0FBVyxFQUFFO1lBQ25ELGdCQUFnQixHQUFHLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxDQUFBO1NBQzdDO2FBQU07WUFDTCxNQUFNLElBQUksS0FBSyxDQUFDLHVCQUF1QixDQUFDLENBQUE7U0FDekM7S0FDRjtBQUNILENBQUMsQ0FBQSxDQUFBIn0=
|
8
dist/smartscaf.plugins.d.ts
vendored
8
dist/smartscaf.plugins.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
import * as path from 'path';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartfm from 'smartfm';
|
||||
import * as smarthbs from 'smarthbs';
|
||||
import * as smartinteract from 'smartinteract';
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartyaml from 'smartyaml';
|
||||
export { path, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
17
dist/smartscaf.plugins.js
vendored
17
dist/smartscaf.plugins.js
vendored
@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path = require("path");
|
||||
exports.path = path;
|
||||
const smartfile = require("smartfile");
|
||||
exports.smartfile = smartfile;
|
||||
const smartfm = require("smartfm");
|
||||
exports.smartfm = smartfm;
|
||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZCQUE0QjtBQVMxQixvQkFBSTtBQVJOLHVDQUFzQztBQVNwQyw4QkFBUztBQVJYLG1DQUFrQztBQVNoQywwQkFBTztBQVJULHFDQUFvQztBQVNsQyw0QkFBUTtBQVJWLCtDQUE4QztBQVM1QyxzQ0FBYTtBQVJmLGlDQUFnQztBQVM5Qix3QkFBTTtBQVJSLHVDQUFzQztBQVNwQyw4QkFBUyJ9
|
@ -1,33 +0,0 @@
|
||||
# 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://)
|
@ -5,5 +5,15 @@
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartscaf",
|
||||
"shortDescription": "scaffold projects quickly",
|
||||
"npmPackagename": "@pushrocks/smartscaf",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
1316
package-lock.json
generated
1316
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,14 +1,13 @@
|
||||
{
|
||||
"name": "@pushrocks/smartscaf",
|
||||
"version": "2.0.2",
|
||||
"version": "3.0.5",
|
||||
"private": false,
|
||||
"description": "scaffold projects quickly",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)"
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -26,21 +25,30 @@
|
||||
"npm"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@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"
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^3.0.1",
|
||||
"@pushrocks/smartfile": "^6.0.8",
|
||||
"@pushrocks/smartfm": "^2.0.1",
|
||||
"@pushrocks/smarthbs": "^2.0.0",
|
||||
"@pushrocks/lik": "^3.0.11",
|
||||
"@pushrocks/smartfile": "^7.0.4",
|
||||
"@pushrocks/smartfm": "^2.0.4",
|
||||
"@pushrocks/smarthbs": "^2.0.4",
|
||||
"@pushrocks/smartinteract": "^2.0.4",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartyaml": "^2.0.3",
|
||||
"@types/lodash": "^4.14.72",
|
||||
"lodash": "^4.17.4"
|
||||
}
|
||||
"@pushrocks/smartpromise": "^3.0.2",
|
||||
"@pushrocks/smartyaml": "^2.0.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
38
readme.md
38
readme.md
@ -1,25 +1,20 @@
|
||||
# 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/)
|
||||
[](http://standardjs.com/)
|
||||
[](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/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -31,3 +26,10 @@ For further information read the linked docs at the top of this README.
|
||||
> | 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)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
@ -3,18 +3,18 @@ import * as path from 'path';
|
||||
|
||||
import * as smartscaf from '../ts/index';
|
||||
|
||||
process.env.CI = 'true'
|
||||
process.env.CI = 'true';
|
||||
|
||||
let testScafTemplate: smartscaf.ScafTemplate;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
tap.test('Smartscaf instance -> should read a template directory', async () => {
|
||||
await testScafTemplate.readTemplateFromDir('./test/test_template');
|
||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(5);
|
||||
await testScafTemplate.readTemplateFromDir();
|
||||
expect(testScafTemplate.templateSmartfileArray.length).to.equal(6);
|
||||
});
|
||||
|
||||
tap.test('smartfile -> should accept variables', async () => {
|
||||
|
@ -1,4 +0,0 @@
|
||||
templateVar1: from default yaml
|
||||
templateVar2: this is another value from yml
|
||||
templateObject.value1: wow
|
||||
templateObject.value2: here
|
1
test/test_output/hello.md
Normal file
1
test/test_output/hello.md
Normal file
@ -0,0 +1 @@
|
||||
# param1 10
|
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,4 +0,0 @@
|
||||
templateVar1: from default yaml
|
||||
templateVar2: this is another value from yml
|
||||
templateObject.value1: wow
|
||||
templateObject.value2: here
|
1
test/test_template_2/hello.md
Normal file
1
test/test_template_2/hello.md
Normal file
@ -0,0 +1 @@
|
||||
# param1 {{node_version}}
|
@ -11,26 +11,45 @@ export interface ScafTemplateContructorOptions {
|
||||
}
|
||||
|
||||
export class ScafTemplate {
|
||||
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[] = [];
|
||||
|
||||
dependencies: ScafTemplate[];
|
||||
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, '**/*');
|
||||
async readTemplateFromDir() {
|
||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
|
||||
await this._resolveTemplateDependencies();
|
||||
await this._findVariablesInTemplate();
|
||||
await this._checkSuppliedVariables();
|
||||
await this._checkDefaultVariables();
|
||||
await this._resolveTemplateDependencies();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,21 +87,30 @@ export class ScafTemplate {
|
||||
]);
|
||||
}
|
||||
let answerBucket = await localSmartInteract.runQueue();
|
||||
answerBucket.answerMap.forEach(async answer => {
|
||||
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) {
|
||||
let smartfileArrayToWrite = this.templateSmartfileArray;
|
||||
for (let smartfile of smartfileArrayToWrite) {
|
||||
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"
|
||||
fmType: 'yaml'
|
||||
});
|
||||
let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
|
||||
if (parsedTemplate.data.fileName) {
|
||||
@ -90,6 +118,7 @@ export class ScafTemplate {
|
||||
}
|
||||
|
||||
smartfile.contents = Buffer.from(parsedTemplate.content);
|
||||
smartfileArrayToWrite.push(smartfile);
|
||||
}
|
||||
|
||||
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
|
||||
@ -122,8 +151,12 @@ export class ScafTemplate {
|
||||
templateSmartfile.contents.toString(),
|
||||
this.suppliedVariables
|
||||
);
|
||||
|
||||
// combine with other missingVars
|
||||
missingVars = [...missingVars, ...localMissingVars];
|
||||
}
|
||||
|
||||
// dedupe
|
||||
missingVars = missingVars.filter((value, index, self) => {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
@ -131,7 +164,7 @@ export class ScafTemplate {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -143,16 +176,21 @@ export class ScafTemplate {
|
||||
* >> - yourDeeperKey: yourValue
|
||||
*/
|
||||
private async _checkDefaultVariables() {
|
||||
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === 'defaults.yml';
|
||||
})[0];
|
||||
let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||
});
|
||||
|
||||
if (defaultsSmartfile) {
|
||||
let defaultObject = await plugins.smartyaml.yamlStringToObject(
|
||||
defaultsSmartfile.contents.toString()
|
||||
if (smartscafSmartfile) {
|
||||
const smartscafObject = await plugins.smartyaml.yamlStringToObject(
|
||||
smartscafSmartfile.contents.toString()
|
||||
);
|
||||
const defaultObject = smartscafObject.defaults;
|
||||
this.defaultVariables = defaultObject;
|
||||
} else {
|
||||
}
|
||||
|
||||
// safeguard against non existent defaults
|
||||
if (!this.defaultVariables) {
|
||||
console.log('this template does not specify defaults');
|
||||
this.defaultVariables = {};
|
||||
}
|
||||
}
|
||||
@ -161,14 +199,36 @@ export class ScafTemplate {
|
||||
* resolve template dependencies
|
||||
*/
|
||||
private async _resolveTemplateDependencies() {
|
||||
const dependencies = this.templateSmartfileArray.find(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === "dependencies.yml"
|
||||
const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
||||
return smartfileArg.parsedPath.base === '.smartscaf.yml';
|
||||
});
|
||||
if(!dependencies) {
|
||||
if (!smartscafSmartfile) {
|
||||
console.log('No further template dependencies defined!');
|
||||
return;
|
||||
}
|
||||
console.log('Found template dependencies! Resolving them now!')
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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