Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
60854250eb | |||
53de92ac1a |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartscaf",
|
||||
"version": "2.0.2",
|
||||
"version": "3.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -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",
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user