fix(smartscaf): migrate file handling to SmartFileFactory and tighten TypeScript compatibility
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-04-30 - 4.0.22 - fix(smartscaf)
|
||||
migrate file handling to SmartFileFactory and tighten TypeScript compatibility
|
||||
|
||||
- replace deprecated smartfile fs and memory helpers with SmartFileFactory virtual directory APIs
|
||||
- initialize class properties and add explicit typings to satisfy stricter TypeScript settings
|
||||
- update test imports and tooling dependencies for newer tstest and smartfile ecosystem versions
|
||||
|
||||
## 2026-03-24 - 4.0.21 - fix(smartconfig)
|
||||
correct smartconfig package key and add npmjs registry for public releases
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Task Venture Capital GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+13
-14
@@ -7,7 +7,7 @@
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --verbose --logfile --timeout 60)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
@@ -31,21 +31,21 @@
|
||||
"cli tool"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.6.4",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.4",
|
||||
"@push.rocks/tapbundle": "^6.0.3",
|
||||
"@types/node": "^22.14.1"
|
||||
"@git.zone/tsbuild": "^4.4.0",
|
||||
"@git.zone/tsrun": "^2.0.2",
|
||||
"@git.zone/tstest": "^3.6.3",
|
||||
"@types/node": "^25.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/lik": "^6.2.2",
|
||||
"@push.rocks/smartfile": "^11.2.5",
|
||||
"@push.rocks/lik": "^6.4.1",
|
||||
"@push.rocks/smartfile": "^13.1.3",
|
||||
"@push.rocks/smartfm": "^2.2.2",
|
||||
"@push.rocks/smarthbs": "^3.0.3",
|
||||
"@push.rocks/smartfs": "^1.5.1",
|
||||
"@push.rocks/smarthbs": "^3.0.5",
|
||||
"@push.rocks/smartinteract": "^2.0.16",
|
||||
"@push.rocks/smartobject": "^1.0.12",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartshell": "^3.3.0",
|
||||
"@push.rocks/smartshell": "^3.3.8",
|
||||
"@push.rocks/smartyaml": "^3.0.4"
|
||||
},
|
||||
"files": [
|
||||
@@ -57,6 +57,8 @@
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
".smartconfig.json",
|
||||
"license",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
@@ -64,8 +66,5 @@
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6",
|
||||
"pnpm": {
|
||||
"overrides": {}
|
||||
}
|
||||
"packageManager": "pnpm@10.28.2"
|
||||
}
|
||||
|
||||
Generated
+2107
-4478
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as smartscaf from '../ts/index.js';
|
||||
@@ -34,4 +34,4 @@ tap.test('should output ready rendered template', async () => {
|
||||
await testScafTemplate.writeToDisk(path.resolve('./test/test_output'));
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartscaf',
|
||||
version: '4.0.21',
|
||||
version: '4.0.22',
|
||||
description: 'A project aimed at quickly scaffolding projects with support for TypeScript, smart file handling, and template rendering.'
|
||||
}
|
||||
|
||||
@@ -15,31 +15,37 @@ export class ScafTemplate {
|
||||
/**
|
||||
* the name of the template
|
||||
*/
|
||||
public name: string;
|
||||
public name = '';
|
||||
|
||||
/**
|
||||
* the descriptions of the template
|
||||
*/
|
||||
public description: string;
|
||||
public description = '';
|
||||
|
||||
/**
|
||||
* the location on disk of the template
|
||||
*/
|
||||
public dirPath: string;
|
||||
public destinationPath: string;
|
||||
public destinationPath?: string;
|
||||
|
||||
/**
|
||||
* smartscafFile
|
||||
*/
|
||||
public smartscafFile: interfaces.ISmartscafFile;
|
||||
public smartscafFile: interfaces.ISmartscafFile = {
|
||||
defaults: {},
|
||||
dependencies: {
|
||||
merge: [],
|
||||
},
|
||||
runafter: [],
|
||||
};
|
||||
|
||||
/**
|
||||
* the files of the template as array of Smartfiles
|
||||
*/
|
||||
public templateSmartfileArray: plugins.smartfile.SmartFile[];
|
||||
public requiredVariables: string[];
|
||||
public defaultVariables: any;
|
||||
public suppliedVariables: any = {};
|
||||
public templateSmartfileArray: plugins.smartfile.SmartFile[] = [];
|
||||
public requiredVariables: string[] = [];
|
||||
public defaultVariables: Record<string, unknown> = {};
|
||||
public suppliedVariables: Record<string, unknown> = {};
|
||||
public missingVariables: string[] = [];
|
||||
|
||||
constructor(dirPathArg: string) {
|
||||
@@ -50,10 +56,10 @@ export class ScafTemplate {
|
||||
* read a template from a directory
|
||||
*/
|
||||
public async readTemplateFromDir() {
|
||||
this.templateSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
|
||||
const templateVirtualDirectory = await plugins.smartFileFactory.virtualDirectoryFromPath(
|
||||
this.dirPath,
|
||||
'**/*',
|
||||
);
|
||||
this.templateSmartfileArray = templateVirtualDirectory.listFiles();
|
||||
|
||||
// read .smartscaf.yml file
|
||||
let smartscafFile: interfaces.ISmartscafFile = {
|
||||
@@ -90,7 +96,7 @@ export class ScafTemplate {
|
||||
* supply the variables to render the teplate with
|
||||
* @param variablesArg gets merged with this.suppliedVariables
|
||||
*/
|
||||
public async supplyVariables(variablesArg) {
|
||||
public async supplyVariables(variablesArg: Record<string, unknown>) {
|
||||
this.suppliedVariables = {
|
||||
...this.suppliedVariables,
|
||||
...variablesArg,
|
||||
@@ -168,11 +174,11 @@ export class ScafTemplate {
|
||||
// Postprocess: convert {-{ back to {{
|
||||
const finalContent = await plugins.smarthbs.postprocess(parsedTemplate.content);
|
||||
|
||||
renderedFiles.push(new plugins.smartfile.SmartFile({
|
||||
path: finalPath,
|
||||
contentBuffer: Buffer.from(finalContent),
|
||||
base: smartfile.base,
|
||||
}));
|
||||
renderedFiles.push(plugins.smartFileFactory.fromBuffer(
|
||||
finalPath,
|
||||
Buffer.from(finalContent),
|
||||
smartfile.base,
|
||||
));
|
||||
}
|
||||
|
||||
return renderedFiles;
|
||||
@@ -182,7 +188,7 @@ export class ScafTemplate {
|
||||
* writes a file to disk
|
||||
* @param destinationDirArg
|
||||
*/
|
||||
public async writeToDisk(destinationDirArg) {
|
||||
public async writeToDisk(destinationDirArg: string) {
|
||||
this.destinationPath = destinationDirArg;
|
||||
const smartfileArrayToWrite: plugins.smartfile.SmartFile[] = [];
|
||||
for (const smartfile of this.templateSmartfileArray) {
|
||||
@@ -214,10 +220,10 @@ export class ScafTemplate {
|
||||
smartfileArrayToWrite.push(smartfile);
|
||||
}
|
||||
|
||||
await plugins.smartfile.memory.smartfileArrayToFs(
|
||||
const virtualDirectoryToWrite = plugins.smartFileFactory.virtualDirectoryFromFileArray(
|
||||
smartfileArrayToWrite,
|
||||
destinationDirArg,
|
||||
);
|
||||
await virtualDirectoryToWrite.saveToDisk(destinationDirArg);
|
||||
await this.runScripts();
|
||||
}
|
||||
|
||||
@@ -302,17 +308,16 @@ export class ScafTemplate {
|
||||
for (const dependency of this.smartscafFile.dependencies.merge) {
|
||||
console.log(`Now resolving ${dependency}`);
|
||||
const templatePathToMerge = plugins.path.join(this.dirPath, dependency);
|
||||
if (!plugins.smartfile.fs.isDirectory(templatePathToMerge)) {
|
||||
if (!(await plugins.smartFs.directory(templatePathToMerge).exists())) {
|
||||
console.log(
|
||||
`dependency ${dependency} resolves to ${templatePathToMerge} which ist NOT a directory`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const templateSmartfileArray =
|
||||
await plugins.smartfile.fs.fileTreeToObject(
|
||||
templatePathToMerge,
|
||||
'**/*',
|
||||
);
|
||||
const templateVirtualDirectoryToMerge = await plugins.smartFileFactory.virtualDirectoryFromPath(
|
||||
templatePathToMerge,
|
||||
);
|
||||
const templateSmartfileArray = templateVirtualDirectoryToMerge.listFiles();
|
||||
this.templateSmartfileArray = this.templateSmartfileArray.concat(
|
||||
templateSmartfileArray,
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as path from 'path';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartfm from '@push.rocks/smartfm';
|
||||
import * as smartfs from '@push.rocks/smartfs';
|
||||
import * as smarthbs from '@push.rocks/smarthbs';
|
||||
import * as smartinteract from '@push.rocks/smartinteract';
|
||||
import * as smartobject from '@push.rocks/smartobject';
|
||||
@@ -9,11 +10,15 @@ import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartyaml from '@push.rocks/smartyaml';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export const smartFileFactory = smartfile.SmartFileFactory.nodeFs();
|
||||
export const smartFs = smartFileFactory.getSmartFs() as smartfs.SmartFs;
|
||||
|
||||
export {
|
||||
path,
|
||||
lik,
|
||||
smartfile,
|
||||
smartfm,
|
||||
smartfs,
|
||||
smarthbs,
|
||||
smartinteract,
|
||||
smartobject,
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
"types": ["node"]
|
||||
},
|
||||
"exclude": ["dist_*/**/*.d.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user