Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
60854250eb | |||
53de92ac1a | |||
6cb4fff0a5 | |||
45710ded00 | |||
aa87ed9427 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartscaf",
|
"name": "@pushrocks/smartscaf",
|
||||||
"version": "2.0.0",
|
"version": "3.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartscaf",
|
"name": "@pushrocks/smartscaf",
|
||||||
"version": "2.0.0",
|
"version": "3.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "scaffold projects quickly",
|
"description": "scaffold projects quickly",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -33,6 +33,7 @@
|
|||||||
"@types/node": "^10.9.2"
|
"@types/node": "^10.9.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@pushrocks/lik": "^3.0.1",
|
||||||
"@pushrocks/smartfile": "^6.0.8",
|
"@pushrocks/smartfile": "^6.0.8",
|
||||||
"@pushrocks/smartfm": "^2.0.1",
|
"@pushrocks/smartfm": "^2.0.1",
|
||||||
"@pushrocks/smarthbs": "^2.0.0",
|
"@pushrocks/smarthbs": "^2.0.0",
|
||||||
|
@ -8,12 +8,12 @@ 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(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,20 +11,29 @@ export interface ScafTemplateContructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ScafTemplate {
|
export class ScafTemplate {
|
||||||
|
static async createTemplateFromDir() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
dirPath: string;
|
||||||
templateSmartfileArray: Smartfile[];
|
templateSmartfileArray: Smartfile[];
|
||||||
requiredVariables: string[];
|
requiredVariables: string[];
|
||||||
defaultVariables: any;
|
defaultVariables: any;
|
||||||
suppliedVariables: any = {};
|
suppliedVariables: any = {};
|
||||||
missingVariables: string[] = [];
|
missingVariables: string[] = [];
|
||||||
|
|
||||||
|
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();
|
||||||
@ -153,4 +162,25 @@ export class ScafTemplate {
|
|||||||
this.defaultVariables = {};
|
this.defaultVariables = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resolve template dependencies
|
||||||
|
*/
|
||||||
|
private async _resolveTemplateDependencies() {
|
||||||
|
const dependenciesSmartfile = this.templateSmartfileArray.find(smartfileArg => {
|
||||||
|
return smartfileArg.parsedPath.base === "dependencies.yml"
|
||||||
|
});
|
||||||
|
if(!dependenciesSmartfile) {
|
||||||
|
console.log('No further template dependencies defined!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartfm from '@pushrocks/smartfm';
|
import * as smartfm from '@pushrocks/smartfm';
|
||||||
import * as smarthbs from '@pushrocks/smarthbs';
|
import * as smarthbs from '@pushrocks/smarthbs';
|
||||||
@ -6,4 +7,4 @@ 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';
|
||||||
|
|
||||||
export { path, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
export { path, lik, smartfile, smartfm, smarthbs, smartinteract, smartq, smartyaml };
|
||||||
|
Reference in New Issue
Block a user