fix(ScafTemplate): Use interactive shell for post-scaffold scripts; update CI workflows and package metadata

This commit is contained in:
2025-08-17 15:56:11 +00:00
parent b2ba770b78
commit abc7cbc5ea
21 changed files with 187 additions and 77 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartscaf',
version: '4.0.17',
version: '4.0.18',
description: 'A project aimed at quickly scaffolding projects with support for TypeScript, smart file handling, and template rendering.'
}

View File

@@ -50,7 +50,10 @@ export class ScafTemplate {
* read a template from a directory
*/
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 = {
@@ -61,15 +64,17 @@ export class ScafTemplate {
runafter: [],
};
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
const smartscafSmartfile = this.templateSmartfileArray.find(
(smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
},
);
if (smartscafSmartfile) {
smartscafFile = {
...smartscafFile,
...(await plugins.smartyaml.yamlStringToObject(
smartscafSmartfile.contentBuffer.toString()
smartscafSmartfile.contentBuffer.toString(),
)),
};
}
@@ -105,7 +110,10 @@ export class ScafTemplate {
name: missingVariable,
type: 'input',
default: (() => {
if (this.defaultVariables && this.defaultVariables[missingVariable]) {
if (
this.defaultVariables &&
this.defaultVariables[missingVariable]
) {
return this.defaultVariables[missingVariable];
} else {
return 'undefined variable';
@@ -118,7 +126,11 @@ export class ScafTemplate {
const answerBucket = await localSmartInteract.runQueue();
const answers = answerBucket.getAllAnswers();
for (const answer of answers) {
await plugins.smartobject.smartAdd(this.suppliedVariables, answer.name, answer.value);
await plugins.smartobject.smartAdd(
this.suppliedVariables,
answer.name,
answer.value,
);
}
}
@@ -136,23 +148,32 @@ export class ScafTemplate {
}
// render the template
const template = await plugins.smarthbs.getTemplateForString(smartfile.contents.toString());
const template = await plugins.smarthbs.getTemplateForString(
smartfile.contents.toString(),
);
const renderedTemplateString = template(this.suppliedVariables);
// handle frontmatter
const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: 'yaml',
});
const parsedTemplate = smartfmInstance.parse(renderedTemplateString) as any;
const parsedTemplate = smartfmInstance.parse(
renderedTemplateString,
) as any;
if (parsedTemplate.data.fileName) {
smartfile.updateFileName(parsedTemplate.data.fileName);
}
smartfile.contents = Buffer.from(await plugins.smarthbs.postprocess(parsedTemplate.content));
smartfile.contents = Buffer.from(
await plugins.smarthbs.postprocess(parsedTemplate.content),
);
smartfileArrayToWrite.push(smartfile);
}
await plugins.smartfile.memory.smartfileArrayToFs(smartfileArrayToWrite, destinationDirArg);
await plugins.smartfile.memory.smartfileArrayToFs(
smartfileArrayToWrite,
destinationDirArg,
);
await this.runScripts();
}
@@ -164,7 +185,7 @@ export class ScafTemplate {
let templateVariables: string[] = [];
for (const templateSmartfile of this.templateSmartfileArray) {
const localTemplateVariables = await plugins.smarthbs.findVarsInHbsString(
templateSmartfile.contents.toString()
templateSmartfile.contents.toString(),
);
templateVariables = [...templateVariables, ...localTemplateVariables];
}
@@ -181,7 +202,7 @@ export class ScafTemplate {
for (const templateSmartfile of this.templateSmartfileArray) {
const localMissingVars = await plugins.smarthbs.checkVarsSatisfaction(
templateSmartfile.contents.toString(),
this.suppliedVariables
this.suppliedVariables,
);
// combine with other missingVars
@@ -208,13 +229,15 @@ export class ScafTemplate {
* >> - yourDeeperKey: yourValue
*/
private async _checkDefaultVariables() {
const smartscafSmartfile = this.templateSmartfileArray.find((smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
});
const smartscafSmartfile = this.templateSmartfileArray.find(
(smartfileArg) => {
return smartfileArg.parsedPath.base === '.smartscaf.yml';
},
);
if (smartscafSmartfile) {
const smartscafObject = await plugins.smartyaml.yamlStringToObject(
smartscafSmartfile.contents.toString()
smartscafSmartfile.contents.toString(),
);
const defaultObject = smartscafObject.defaults;
this.defaultVariables = defaultObject;
@@ -237,15 +260,18 @@ export class ScafTemplate {
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`
`dependency ${dependency} resolves to ${templatePathToMerge} which ist NOT a directory`,
);
continue;
}
const templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
templatePathToMerge,
'**/*'
const templateSmartfileArray =
await plugins.smartfile.fs.fileTreeToObject(
templatePathToMerge,
'**/*',
);
this.templateSmartfileArray = this.templateSmartfileArray.concat(
templateSmartfileArray,
);
this.templateSmartfileArray = this.templateSmartfileArray.concat(templateSmartfileArray);
}
}
@@ -257,7 +283,9 @@ export class ScafTemplate {
executor: 'bash',
});
for (const command of this.smartscafFile.runafter) {
await smartshellInstance.execInteractive(`cd ${this.destinationPath} && ${command}`);
await smartshellInstance.execInteractive(
`cd ${this.destinationPath} && ${command}`,
);
}
}
}