Compare commits

..

6 Commits

Author SHA1 Message Date
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
11 changed files with 616 additions and 499 deletions

View File

@ -81,6 +81,7 @@ codequality:
allow_failure: true allow_failure: true
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:

23
.snyk Normal file
View File

@ -0,0 +1,23 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.5
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-JSYAML-173999:
- '@pushrocks/smartfm > gray-matter > js-yaml':
reason: None given
expires: '2019-10-10T16:23:38.993Z'
- '@pushrocks/smartyaml > js-yaml':
reason: None given
expires: '2019-10-10T16:23:38.993Z'
SNYK-JS-JSYAML-174129:
- '@pushrocks/smartfm > gray-matter > js-yaml':
reason: None given
expires: '2019-10-10T16:23:38.993Z'
- '@pushrocks/smartyaml > js-yaml':
reason: None given
expires: '2019-10-10T16:23:38.993Z'
SNYK-JS-LODASH-450202:
- '@pushrocks/smartinteract > inquirer > lodash':
reason: None given
expires: '2019-10-10T16:23:38.993Z'
patch: {}

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

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

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

@ -0,0 +1,20 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone"
}
}
}
}
]
}

893
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": "3.0.6", "version": "3.0.9",
"private": false, "private": false,
"description": "scaffold projects quickly", "description": "scaffold projects quickly",
"main": "dist/index.js", "main": "dist/index.js",
@ -27,17 +27,20 @@
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.4" "@types/node": "^12.7.9",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.11", "@pushrocks/lik": "^3.0.11",
"@pushrocks/smartfile": "^7.0.4", "@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartfm": "^2.0.4", "@pushrocks/smartfm": "^2.0.4",
"@pushrocks/smarthbs": "^2.0.8", "@pushrocks/smarthbs": "^2.0.8",
"@pushrocks/smartinteract": "^2.0.4", "@pushrocks/smartinteract": "^2.0.4",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartshell": "^2.0.25",
"@pushrocks/smartyaml": "^2.0.3" "@pushrocks/smartyaml": "^2.0.3"
}, },
"files": [ "files": [

View File

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

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

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

View File

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

View File

@ -1,4 +1,5 @@
import * as plugins from './smartscaf.plugins'; import * as plugins from './smartscaf.plugins';
import * as interfaces from './interfaces';
import * as helpers from './smartscaf.helpers'; import * as helpers from './smartscaf.helpers';
// interfaces // interfaces
@ -11,31 +12,37 @@ export interface ScafTemplateContructorOptions {
} }
export class ScafTemplate { export class ScafTemplate {
static async createTemplateFromDir() {} public static async createTemplateFromDir() {}
/** /**
* the name of the template * the name of the template
*/ */
name: string; public name: string;
/** /**
* the descriptions of the template * the descriptions of the template
*/ */
description: string; public description: string;
/** /**
* the location on disk of the template * 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 * the files of the template as array of Smartfiles
*/ */
templateSmartfileArray: Smartfile[]; public templateSmartfileArray: Smartfile[];
requiredVariables: string[]; public requiredVariables: string[];
defaultVariables: any; public defaultVariables: any;
suppliedVariables: any = {}; public suppliedVariables: any = {};
missingVariables: string[] = []; public missingVariables: string[] = [];
constructor(dirPathArg: string) { constructor(dirPathArg: string) {
this.dirPath = plugins.path.resolve(dirPathArg); this.dirPath = plugins.path.resolve(dirPathArg);
@ -44,8 +51,30 @@ export class ScafTemplate {
/** /**
* read a template from a directory * read a template from a directory
*/ */
async readTemplateFromDir() { public async readTemplateFromDir() {
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(this.dirPath, '**/*'); 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._resolveTemplateDependencies();
await this._findVariablesInTemplate(); await this._findVariablesInTemplate();
await this._checkSuppliedVariables(); await this._checkSuppliedVariables();
@ -56,7 +85,7 @@ export class ScafTemplate {
* supply the variables to render the teplate with * supply the variables to render the teplate with
* @param variablesArg gets merged with this.suppliedVariables * @param variablesArg gets merged with this.suppliedVariables
*/ */
async supplyVariables(variablesArg) { public async supplyVariables(variablesArg) {
this.suppliedVariables = { this.suppliedVariables = {
...this.suppliedVariables, ...this.suppliedVariables,
...variablesArg ...variablesArg
@ -67,10 +96,10 @@ export class ScafTemplate {
/** /**
* Will ask for the missing variables by cli interaction * Will ask for the missing variables by cli interaction
*/ */
async askCliForMissingVariables() { public async askCliForMissingVariables() {
this.missingVariables = await this._checkSuppliedVariables(); this.missingVariables = await this._checkSuppliedVariables();
let localSmartInteract = new plugins.smartinteract.SmartInteract(); const localSmartInteract = new plugins.smartinteract.SmartInteract();
for (let missingVariable of this.missingVariables) { for (const missingVariable of this.missingVariables) {
localSmartInteract.addQuestions([ localSmartInteract.addQuestions([
{ {
name: missingVariable, name: missingVariable,
@ -86,7 +115,7 @@ export class ScafTemplate {
} }
]); ]);
} }
let answerBucket = await localSmartInteract.runQueue(); const answerBucket = await localSmartInteract.runQueue();
await 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);
}); });
@ -96,23 +125,24 @@ export class ScafTemplate {
* writes a file to disk * writes a file to disk
* @param destinationDirArg * @param destinationDirArg
*/ */
async writeToDisk(destinationDirArg) { public async writeToDisk(destinationDirArg) {
this.destinationPath = destinationDirArg;
const smartfileArrayToWrite: Smartfile[] = []; const smartfileArrayToWrite: Smartfile[] = [];
for (let smartfile of this.templateSmartfileArray) { for (const smartfile of this.templateSmartfileArray) {
// lets filter out template files // lets filter out template files
if (smartfile.path === '.smartscaf.yml') { if (smartfile.path === '.smartscaf.yml') {
continue; continue;
} }
// render the template // render the template
let template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString()); const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
let renderedTemplateString = template(this.suppliedVariables); const 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; const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
if (parsedTemplate.data.fileName) { if (parsedTemplate.data.fileName) {
smartfile.updateFileName(parsedTemplate.data.fileName); smartfile.updateFileName(parsedTemplate.data.fileName);
} }
@ -122,6 +152,7 @@ export class ScafTemplate {
} }
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg); await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
await this.runScripts();
} }
/** /**
@ -130,8 +161,8 @@ export class ScafTemplate {
*/ */
private async _findVariablesInTemplate() { private async _findVariablesInTemplate() {
let templateVariables: string[] = []; let templateVariables: string[] = [];
for (let templateSmartfile of this.templateSmartfileArray) { for (const templateSmartfile of this.templateSmartfileArray) {
let localTemplateVariables = await plugins.smarthbs.findVarsInHbsString( const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
templateSmartfile.contents.toString() templateSmartfile.contents.toString()
); );
templateVariables = [...templateVariables, ...localTemplateVariables]; templateVariables = [...templateVariables, ...localTemplateVariables];
@ -146,8 +177,8 @@ export class ScafTemplate {
*/ */
private async _checkSuppliedVariables() { private async _checkSuppliedVariables() {
let missingVars: string[] = []; let missingVars: string[] = [];
for (let templateSmartfile of this.templateSmartfileArray) { for (const templateSmartfile of this.templateSmartfileArray) {
let localMissingVars = await plugins.smarthbs.checkVarsSatisfaction( const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
templateSmartfile.contents.toString(), templateSmartfile.contents.toString(),
this.suppliedVariables this.suppliedVariables
); );
@ -176,7 +207,7 @@ export class ScafTemplate {
* >> - yourDeeperKey: yourValue * >> - yourDeeperKey: yourValue
*/ */
private async _checkDefaultVariables() { private async _checkDefaultVariables() {
let smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => { const smartscafSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === '.smartscaf.yml'; return smartfileArg.parsedPath.base === '.smartscaf.yml';
}); });
@ -199,23 +230,8 @@ export class ScafTemplate {
* resolve template dependencies * resolve template dependencies
*/ */
private async _resolveTemplateDependencies() { 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!'); console.log('looking at templates to merge!');
const smartscafYamlObject = await plugins.smartyaml.yamlStringToObject( for (const dependency of this.smartscafFile.dependencies.merge) {
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}`); console.log(`Now resolving ${dependency}`);
const templatePathToMerge = plugins.path.join(this.dirPath, dependency); const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) { if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
@ -231,4 +247,16 @@ export class ScafTemplate {
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray); 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

@ -6,5 +6,6 @@ import * as smarthbs from '@pushrocks/smarthbs';
import * as smartinteract from '@pushrocks/smartinteract'; import * as smartinteract from '@pushrocks/smartinteract';
import * as smartq from '@pushrocks/smartpromise'; import * as smartq from '@pushrocks/smartpromise';
import * as smartyaml from '@pushrocks/smartyaml'; 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, smartq, smartyaml, smartshell };