Compare commits

..

2 Commits

Author SHA1 Message Date
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
4 changed files with 25 additions and 13 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartscaf",
"version": "2.0.2",
"version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartscaf",
"version": "2.0.2",
"version": "3.0.0",
"private": false,
"description": "scaffold projects quickly",
"main": "dist/index.js",

View File

@ -8,12 +8,12 @@ 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');
await testScafTemplate.readTemplateFromDir();
expect(testScafTemplate.templateSmartfileArray.length).to.equal(5);
});

View File

@ -11,26 +11,32 @@ export interface ScafTemplateContructorOptions {
}
export class ScafTemplate {
static async createTemplateFromDir() {
}
name: string;
description: string;
dirPath: string;
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();
}
/**
@ -161,14 +167,20 @@ export class ScafTemplate {
* resolve template dependencies
*/
private async _resolveTemplateDependencies() {
const dependencies = this.templateSmartfileArray.find(smartfileArg => {
const dependenciesSmartfile = this.templateSmartfileArray.find(smartfileArg => {
return smartfileArg.parsedPath.base === "dependencies.yml"
});
if(!dependencies) {
if(!dependenciesSmartfile) {
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 dependencies = await plugins.smartyaml.yamlStringToObject(dependenciesSmartfile.contentBuffer.toString());
for (const dependency of dependencies.merge) {
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
const templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(templatePathToMerge, '**/*');
this.templateSmartfileArray.concat(templateSmartfileArray);
}
}
}