Compare commits

..

8 Commits

Author SHA1 Message Date
ff0faa719b 3.0.2 2019-01-27 18:55:39 +01:00
400e228ffc fix(core): update 2019-01-27 18:55:38 +01:00
25871fc970 3.0.1 2018-10-04 17:00:33 +02:00
eb990a8ec2 fix(core): update 2018-10-04 17:00:33 +02:00
f5194b76bd Merge branch 'master' into 'master'
update

See merge request pushrocks/smartscaf!1
2018-10-04 14:48:20 +00:00
6b5e9ac617 update 2018-10-04 16:04:42 +02:00
60854250eb 3.0.0 2018-08-30 22:43:22 +02:00
53de92ac1a BREAKING CHANGE(structure): templates now take their path within the constructor 2018-08-30 22:43:22 +02:00
11 changed files with 776 additions and 219 deletions

View File

@ -26,6 +26,7 @@ mirror:
snyk: snyk:
stage: security stage: security
script: script:
- npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
@ -33,24 +34,39 @@ snyk:
- docker - docker
- notpriv - 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 # 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: testLTS:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install lts - npmci node install lts
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -62,6 +78,7 @@ testLTS:
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
@ -118,6 +135,7 @@ pages:
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags: tags:
@ -130,13 +148,3 @@ pages:
paths: paths:
- public - public
allow_failure: true 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

777
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartscaf", "name": "@pushrocks/smartscaf",
"version": "2.0.2", "version": "3.0.2",
"private": false, "private": false,
"description": "scaffold projects quickly", "description": "scaffold projects quickly",
"main": "dist/index.js", "main": "dist/index.js",
@ -26,21 +26,21 @@
"npm" "npm"
], ],
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.6",
"@gitzone/tsrun": "^1.1.12", "@gitzone/tsrun": "^1.1.17",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.18",
"@pushrocks/tapbundle": "^3.0.5", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.9.2" "@types/node": "^10.12.18"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.1", "@pushrocks/lik": "^3.0.4",
"@pushrocks/smartfile": "^6.0.8", "@pushrocks/smartfile": "^6.0.12",
"@pushrocks/smartfm": "^2.0.1", "@pushrocks/smartfm": "^2.0.1",
"@pushrocks/smarthbs": "^2.0.0", "@pushrocks/smarthbs": "^2.0.0",
"@pushrocks/smartinteract": "^2.0.4", "@pushrocks/smartinteract": "^2.0.4",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartyaml": "^2.0.3", "@pushrocks/smartyaml": "^2.0.3",
"@types/lodash": "^4.14.72", "@types/lodash": "^4.14.120",
"lodash": "^4.17.4" "lodash": "^4.17.11"
} }
} }

View File

@ -3,18 +3,18 @@ import * as path from 'path';
import * as smartscaf from '../ts/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 () => { tap.test('should create new Smartscaf instance', async () => {
testScafTemplate = new smartscaf.ScafTemplate(); testScafTemplate = new smartscaf.ScafTemplate('./test/test_template');
expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate); expect(testScafTemplate).to.be.instanceof(smartscaf.ScafTemplate);
}); });
tap.test('Smartscaf instance -> should read a template directory', async () => { tap.test('Smartscaf instance -> should read a template directory', async () => {
await testScafTemplate.readTemplateFromDir('./test/test_template'); await testScafTemplate.readTemplateFromDir();
expect(testScafTemplate.templateSmartfileArray.length).to.equal(5); expect(testScafTemplate.templateSmartfileArray.length).to.equal(6);
}); });
tap.test('smartfile -> should accept variables', async () => { tap.test('smartfile -> should accept variables', async () => {

View File

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

View File

@ -0,0 +1 @@
# param1 10

View 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

View File

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

View File

@ -0,0 +1 @@
# param1 {{node_version}}

View File

@ -11,26 +11,45 @@ export interface ScafTemplateContructorOptions {
} }
export class ScafTemplate { export class ScafTemplate {
static async createTemplateFromDir() {}
/**
* the name of the template
*/
name: string; name: string;
/**
* the descriptions of the template
*/
description: string; description: string;
/**
* the location on disk of the template
*/
dirPath: string;
/**
* the files of the template as array of Smartfiles
*/
templateSmartfileArray: Smartfile[]; templateSmartfileArray: Smartfile[];
requiredVariables: string[]; requiredVariables: string[];
defaultVariables: any; defaultVariables: any;
suppliedVariables: any = {}; suppliedVariables: any = {};
missingVariables: string[] = []; missingVariables: string[] = [];
dependencies: ScafTemplate[]; constructor(dirPathArg: string) {
this.dirPath = plugins.path.resolve(dirPathArg);
}
/** /**
* read a template from a directory * read a template from a directory
*/ */
async readTemplateFromDir(dirPathArg: string) { async readTemplateFromDir() {
let dirPath = plugins.path.resolve(dirPathArg); this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*');
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(dirPath, '**/*'); await this._resolveTemplateDependencies();
await this._findVariablesInTemplate(); await this._findVariablesInTemplate();
await this._checkSuppliedVariables(); await this._checkSuppliedVariables();
await this._checkDefaultVariables(); await this._checkDefaultVariables();
await this._resolveTemplateDependencies();
} }
/** /**
@ -68,21 +87,30 @@ export class ScafTemplate {
]); ]);
} }
let answerBucket = await localSmartInteract.runQueue(); 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); await helpers.deepAddToObject(this.suppliedVariables, answer.name, answer.value);
}); });
} }
/**
* writes a file to disk
* @param destinationDirArg
*/
async writeToDisk(destinationDirArg) { async writeToDisk(destinationDirArg) {
let smartfileArrayToWrite = this.templateSmartfileArray; const smartfileArrayToWrite: Smartfile[] = [];
for (let smartfile of smartfileArrayToWrite) { for (let smartfile of this.templateSmartfileArray) {
// lets filter out template files
if (smartfile.path === '.smartscaf.yml') {
continue;
}
// render the template // render the template
let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString()); let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
let renderedTemplateString = template(this.suppliedVariables); let renderedTemplateString = template(this.suppliedVariables);
// handle frontmatter // handle frontmatter
const smartfmInstance = new plugins.smartfm.Smartfm({ const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: "yaml" fmType: 'yaml'
}); });
let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any; let parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
if (parsedTemplate.data.fileName) { if (parsedTemplate.data.fileName) {
@ -90,6 +118,7 @@ export class ScafTemplate {
} }
smartfile.contents = Buffer.from(parsedTemplate.content); smartfile.contents = Buffer.from(parsedTemplate.content);
smartfileArrayToWrite.push(smartfile);
} }
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg); await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
@ -122,8 +151,12 @@ export class ScafTemplate {
templateSmartfile.contents.toString(), templateSmartfile.contents.toString(),
this.suppliedVariables this.suppliedVariables
); );
// combine with other missingVars
missingVars = [...missingVars, ...localMissingVars]; missingVars = [...missingVars, ...localMissingVars];
} }
// dedupe
missingVars = missingVars.filter((value, index, self) => { missingVars = missingVars.filter((value, index, self) => {
return self.indexOf(value) === index; 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: * allows 2 ways of notation in YAML:
* >> myObject.myKey.someDeeperKey: someValue * >> myObject.myKey.someDeeperKey: someValue
* >> myObject.yourKey.yourDeeperKey: yourValue * >> myObject.yourKey.yourDeeperKey: yourValue
@ -143,16 +176,21 @@ export class ScafTemplate {
* >> - yourDeeperKey: yourValue * >> - yourDeeperKey: yourValue
*/ */
private async _checkDefaultVariables() { private async _checkDefaultVariables() {
let defaultsSmartfile = this.templateSmartfileArray.filter(smartfileArg => { let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === 'defaults.yml'; return smartfileArg.parsedPath.base === '.smartscaf.yml';
})[0]; });
if (defaultsSmartfile) { if (smartscafSmartfile) {
let defaultObject = await plugins.smartyaml.yamlStringToObject( const smartscafObject = await plugins.smartyaml.yamlStringToObject(
defaultsSmartfile.contents.toString() smartscafSmartfile.contents.toString()
); );
const defaultObject = smartscafObject.defaults;
this.defaultVariables = defaultObject; this.defaultVariables = defaultObject;
} else { }
// safeguard against non existent defaults
if (!this.defaultVariables) {
console.log('this template does not specify defaults');
this.defaultVariables = {}; this.defaultVariables = {};
} }
} }
@ -161,14 +199,36 @@ export class ScafTemplate {
* resolve template dependencies * resolve template dependencies
*/ */
private async _resolveTemplateDependencies() { private async _resolveTemplateDependencies() {
const dependencies = this.templateSmartfileArray.find(smartfileArg => { const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === "dependencies.yml" return smartfileArg.parsedPath.base === '.smartscaf.yml';
}); });
if(!dependencies) { if (!smartscafSmartfile) {
console.log('No further template dependencies defined!'); console.log('No further template dependencies defined!');
return; 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);
}
} }
} }

View File

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