Compare commits

..

19 Commits

Author SHA1 Message Date
909cceb1a5 4.0.0 2022-06-25 03:19:16 +02:00
5f1bc8dc29 BREAKING CHANGE(core): switch to esm 2022-06-25 03:19:16 +02:00
d33f943fc6 3.0.10 2020-01-31 14:51:06 +00:00
e4c2d86dbc fix(core): update 2020-01-31 14:51:05 +00:00
088bed779f 3.0.9 2019-10-11 21:56:11 +02:00
1cecba6f13 fix(core): update 2019-10-11 21:56:11 +02:00
324b93a419 3.0.8 2019-10-02 12:50:14 +02:00
4be3fc27b3 fix(core): update 2019-10-02 12:50:14 +02:00
655a8a72ff 3.0.7 2019-09-10 18:23:53 +02:00
80a77d5f06 fix(core): update 2019-09-10 18:23:53 +02:00
6296411b50 3.0.6 2019-09-10 18:18:30 +02:00
e7690d4020 fix(core): update 2019-09-10 18:18:30 +02:00
b85a29cfc1 3.0.5 2019-09-10 18:03:33 +02:00
d559b0f402 fix(core): update 2019-09-10 18:03:33 +02:00
7433c1dba4 3.0.4 2019-09-10 18:00:13 +02:00
c8f6b0296d update 2019-09-10 18:00:03 +02:00
0cffae9eaa update dependencies 2019-09-10 17:59:29 +02:00
d50c8a1260 3.0.3 2019-02-17 17:17:47 +01:00
b3702d56bc fix(core): update 2019-02-17 17:17:47 +01:00
28 changed files with 11655 additions and 1722 deletions

19
.gitignore vendored
View File

@ -1,3 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,16 +1,19 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
@ -18,127 +21,113 @@ stages:
mirror:
stage: security
script:
- npmci git mirror
- npmci git mirror
only:
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
snyk:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
- notpriv
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
- docker
allow_failure: true
services:
- docker:stable-dind
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
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
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
- priv
- docker
allow_failure: true
# ====================
# test stage
# ====================
testLTS:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
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 typescript
- npmci npm prepare
- npmci npm install
tags:
- docker
- priv
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
- npmci trigger
only:
- tags
- tags
tags:
- docker
- notpriv
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
@ -146,5 +135,5 @@ pages:
artifacts:
expire_in: 1 week
paths:
- public
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

1
dist/index.d.ts vendored
View File

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

7
dist/index.js vendored
View File

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

View File

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

View File

@ -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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E9BQU8sV0FBVyxDQUFDO1FBQ3JCLENBQUM7S0FBQTtJQUVEOzs7Ozs7Ozs7OztPQVdHO0lBQ1csc0JBQXNCOztZQUNsQyxJQUFJLGlCQUFpQixHQUFHLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxNQUFNLENBQUMsWUFBWSxDQUFDLEVBQUU7Z0JBQ3hFLE9BQU8sWUFBWSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEtBQUssY0FBYyxDQUFDO1lBQ3pELENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBRU4sSUFBSSxpQkFBaUIsRUFBRTtnQkFDckIsSUFBSSxhQUFhLEdBQUcsTUFBTSxPQUFPLENBQUMsU0FBUyxDQUFDLGtCQUFrQixDQUM1RCxpQkFBaUIsQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLENBQ3RDLENBQUM7Z0JBQ0YsSUFBSSxDQUFDLGdCQUFnQixHQUFHLGFBQWEsQ0FBQzthQUN2QztpQkFBTTtnQkFDTCxJQUFJLENBQUMsZ0JBQWdCLEdBQUcsRUFBRSxDQUFDO2FBQzVCO1FBQ0gsQ0FBQztLQUFBO0NBQ0Y7QUEvSUQsb0NBK0lDIn0=

View File

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

View File

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

View File

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

View File

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

View File

@ -1,33 +0,0 @@
# 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

@ -5,5 +5,16 @@
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartscaf",
"description": "scaffold projects quickly",
"npmPackagename": "@pushrocks/smartscaf",
"license": "MIT"
}
}
}

12513
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
{
"name": "@pushrocks/smartscaf",
"version": "3.0.2",
"version": "4.0.0",
"private": false,
"description": "scaffold projects quickly",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)",
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)"
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -26,21 +26,39 @@
"npm"
],
"devDependencies": {
"@gitzone/tsbuild": "^2.1.6",
"@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18"
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsrun": "^1.2.37",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^18.0.0",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartfile": "^6.0.12",
"@pushrocks/smartfm": "^2.0.1",
"@pushrocks/smarthbs": "^2.0.0",
"@pushrocks/smartinteract": "^2.0.4",
"@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartyaml": "^2.0.3",
"@types/lodash": "^4.14.120",
"lodash": "^4.17.11"
}
"@pushrocks/lik": "^6.0.0",
"@pushrocks/smartfile": "^10.0.2",
"@pushrocks/smartfm": "^2.0.4",
"@pushrocks/smarthbs": "^2.0.8",
"@pushrocks/smartinteract": "^2.0.11",
"@pushrocks/smartparam": "^1.1.6",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartshell": "^2.0.30",
"@pushrocks/smartyaml": "^2.0.5"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"type": "module",
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -1,25 +1,27 @@
# smartscaf
# @pushrocks/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/)
## 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
[![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/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartscaf/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartscaf/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartscaf)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartscaf)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartscaf)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartscaf)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartscaf)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
@ -31,3 +33,14 @@ 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
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)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,7 +1,7 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as path from 'path';
import * as smartscaf from '../ts/index';
import * as smartscaf from '../ts/index.js';
process.env.CI = 'true';
@ -9,12 +9,12 @@ let testScafTemplate: smartscaf.ScafTemplate;
tap.test('should create new Smartscaf instance', async () => {
testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate);
expect(testScafTemplate).toBeInstanceOf(smartscaf.ScafTemplate);
});
tap.test('Smartscaf instance -> should read a template directory', async () => {
await testScafTemplate.readTemplateFromDir();
expect(testScafTemplate.templateSmartfileArray.length).to.equal(6);
expect(testScafTemplate.templateSmartfileArray.length).toEqual(6);
});
tap.test('smartfile -> should accept variables', async () => {

View File

@ -8,3 +8,6 @@ defaults:
dependencies:
merge:
- ../test_template_2
runafter:
- npm install

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartscaf',
version: '4.0.0',
description: 'scaffold projects quickly'
}

View File

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

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './smartscaf.js';

View File

@ -0,0 +1,7 @@
export interface ISmartscafFile {
defaults: { [key: string]: string };
dependencies: {
merge: string[];
};
runafter: string[];
}

View File

@ -1,5 +1,5 @@
import * as plugins from './smartscaf.plugins';
import * as helpers from './smartscaf.helpers';
import * as plugins from './smartscaf.plugins.js';
import * as interfaces from './interfaces/index.js';
// interfaces
import { Smartfile } from '@pushrocks/smartfile';
@ -11,31 +11,37 @@ export interface ScafTemplateContructorOptions {
}
export class ScafTemplate {
static async createTemplateFromDir() {}
public static async createTemplateFromDir() {}
/**
* the name of the template
*/
name: string;
public name: string;
/**
* the descriptions of the template
*/
description: string;
public description: string;
/**
* the location on disk of the template
*/
dirPath: string;
public dirPath: string;
public destinationPath: string;
/**
* smartscafFile
*/
public smartscafFile: interfaces.ISmartscafFile;
/**
* the files of the template as array of Smartfiles
*/
templateSmartfileArray: Smartfile[];
requiredVariables: string[];
defaultVariables: any;
suppliedVariables: any = {};
missingVariables: string[] = [];
public templateSmartfileArray: Smartfile[];
public requiredVariables: string[];
public defaultVariables: any;
public suppliedVariables: any = {};
public missingVariables: string[] = [];
constructor(dirPathArg: string) {
this.dirPath = plugins.path.resolve(dirPathArg);
@ -44,8 +50,32 @@ export class ScafTemplate {
/**
* read a template from a directory
*/
async readTemplateFromDir() {
public async readTemplateFromDir() {
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
// read .smartscaf.yml file
let smartscafFile: interfaces.ISmartscafFile = {
defaults: {},
dependencies: {
merge: [],
},
runafter: [],
};
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
if (smartscafSmartfile) {
smartscafFile = {
...smartscafFile,
...(await plugins.smartyaml.yamlStringToObject(
smartscafSmartfile.contentBuffer.toString()
)),
};
}
this.smartscafFile = smartscafFile;
await this._resolveTemplateDependencies();
await this._findVariablesInTemplate();
await this._checkSuppliedVariables();
@ -56,10 +86,10 @@ export class ScafTemplate {
* supply the variables to render the teplate with
* @param variablesArg gets merged with this.suppliedVariables
*/
async supplyVariables(variablesArg) {
public async supplyVariables(variablesArg) {
this.suppliedVariables = {
...this.suppliedVariables,
...variablesArg
...variablesArg,
};
this.missingVariables = await this._checkSuppliedVariables();
}
@ -67,10 +97,10 @@ export class ScafTemplate {
/**
* Will ask for the missing variables by cli interaction
*/
async askCliForMissingVariables() {
public async askCliForMissingVariables() {
this.missingVariables = await this._checkSuppliedVariables();
let localSmartInteract = new plugins.smartinteract.SmartInteract();
for (let missingVariable of this.missingVariables) {
const localSmartInteract = new plugins.smartinteract.SmartInteract();
for (const missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([
{
name: missingVariable,
@ -82,37 +112,39 @@ export class ScafTemplate {
return 'undefined variable';
}
})(),
message: `What is the value of ${missingVariable}?`
}
message: `What is the value of ${missingVariable}?`,
},
]);
}
let answerBucket = await localSmartInteract.runQueue();
await answerBucket.answerMap.forEach(async answer => {
await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
});
const answerBucket = await localSmartInteract.runQueue();
const answers = answerBucket.getAllAnswers();
for (const answer of answers) {
await plugins.smartparam.smartAdd(this.suppliedVariables, answer.name, answer.value);
}
}
/**
* writes a file to disk
* @param destinationDirArg
*/
async writeToDisk(destinationDirArg) {
public async writeToDisk(destinationDirArg) {
this.destinationPath = destinationDirArg;
const smartfileArrayToWrite: Smartfile[] = [];
for (let smartfile of this.templateSmartfileArray) {
for (const smartfile of this.templateSmartfileArray) {
// lets filter out template files
if (smartfile.path === '.smartscaf.yml') {
continue;
}
// render the template
let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
let renderedTemplateString = template(this.suppliedVariables);
const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
const renderedTemplateString = template(this.suppliedVariables);
// handle frontmatter
const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: 'yaml'
fmType: 'yaml',
});
let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
if (parsedTemplate.data.fileName) {
smartfile.updateFileName(parsedTemplate.data.fileName);
}
@ -122,6 +154,7 @@ export class ScafTemplate {
}
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
await this.runScripts();
}
/**
@ -130,8 +163,8 @@ export class ScafTemplate {
*/
private async _findVariablesInTemplate() {
let templateVariables: string[] = [];
for (let templateSmartfile of this.templateSmartfileArray) {
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
for (const templateSmartfile of this.templateSmartfileArray) {
const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
templateSmartfile.contents.toString()
);
templateVariables = [...templateVariables, ...localTemplateVariables];
@ -146,8 +179,8 @@ export class ScafTemplate {
*/
private async _checkSuppliedVariables() {
let missingVars: string[] = [];
for (let templateSmartfile of this.templateSmartfileArray) {
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
for (const templateSmartfile of this.templateSmartfileArray) {
const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
templateSmartfile.contents.toString(),
this.suppliedVariables
);
@ -176,7 +209,7 @@ export class ScafTemplate {
* >> - yourDeeperKey: yourValue
*/
private async _checkDefaultVariables() {
let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
@ -199,23 +232,8 @@ export class ScafTemplate {
* resolve template dependencies
*/
private async _resolveTemplateDependencies() {
const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
if (!smartscafSmartfile) {
console.log('No further template dependencies defined!');
return;
}
console.log('Found template dependencies! Resolving them now!');
console.log('looking at templates to merge!');
const smartscafYamlObject = await plugins.smartyaml.yamlStringToObject(
smartscafSmartfile.contentBuffer.toString()
);
if (!smartscafYamlObject) {
console.log('Something seems strange about the supplied dependencies.yml file.');
return;
}
for (const dependency of smartscafYamlObject.dependencies.merge) {
for (const dependency of this.smartscafFile.dependencies.merge) {
console.log(`Now resolving ${dependency}`);
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
@ -231,4 +249,16 @@ export class ScafTemplate {
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray);
}
}
private async runScripts() {
if (!this.destinationPath) {
throw new Error('cannot run scripts without an destinationdir');
}
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
});
for (const command of this.smartscafFile.runafter) {
await smartshellInstance.exec(`cd ${this.destinationPath} && ${command}`);
}
}
}

View File

@ -1,33 +0,0 @@
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

@ -4,7 +4,20 @@ 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 smartparam from '@pushrocks/smartparam';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartyaml from '@pushrocks/smartyaml';
import * as smartshell from '@pushrocks/smartshell';
export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
export {
path,
lik,
smartfile,
smartfm,
smarthbs,
smartinteract,
smartparam,
smartpromise,
smartyaml,
smartshell,
};

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}

View File

@ -1,17 +0,0 @@
{
"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"
}