fix(build): migrate filesystem access to smartfs and tighten TypeScript compatibility
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smarthbs",
|
||||||
|
"description": "Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.",
|
||||||
|
"npmPackagename": "@push.rocks/smarthbs",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"handlebars",
|
||||||
|
"template engine",
|
||||||
|
"file system",
|
||||||
|
"partials",
|
||||||
|
"template compilation",
|
||||||
|
"smarthbs",
|
||||||
|
"template variables analysis",
|
||||||
|
"dynamic content",
|
||||||
|
"code generation",
|
||||||
|
"typescript",
|
||||||
|
"project management"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {}
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-04-30 - 3.0.5 - fix(build)
|
||||||
|
migrate filesystem access to smartfs and tighten TypeScript compatibility
|
||||||
|
|
||||||
|
- replace legacy smartfile, smartpath, and smartpromise usage with @push.rocks/smartfs across template, partial, and directory compilation flows
|
||||||
|
- update tests and async APIs to await directory compilation and use Node.js fileURLToPath path resolution
|
||||||
|
- enable stricter TypeScript settings with noImplicitAny and add safer typing for helpers and variable analysis
|
||||||
|
|
||||||
## 2025-01-25 - 3.0.4 - fix(metadata)
|
## 2025-01-25 - 3.0.4 - fix(metadata)
|
||||||
Removed CI configuration file .gitlab-ci.yml and updated project metadata
|
Removed CI configuration file .gitlab-ci.yml and updated project metadata
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
+11
-11
@@ -8,7 +8,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --allowimplicitany)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
"partials",
|
"partials",
|
||||||
"template compilation",
|
"template compilation",
|
||||||
"smarthbs",
|
"smarthbs",
|
||||||
"smartfile integration",
|
"smartfs integration",
|
||||||
"template variables analysis",
|
"template variables analysis",
|
||||||
"dynamic content",
|
"dynamic content",
|
||||||
"code generation",
|
"code generation",
|
||||||
@@ -35,17 +35,14 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smarthbs",
|
"homepage": "https://code.foss.global/push.rocks/smarthbs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^10.0.17",
|
"@push.rocks/smartfs": "^1.5.1",
|
||||||
"@pushrocks/smartpath": "^5.0.5",
|
|
||||||
"@pushrocks/smartpromise": "^4.0.2",
|
|
||||||
"handlebars": "^4.7.7"
|
"handlebars": "^4.7.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@gitzone/tsrun": "^1.2.42",
|
"@git.zone/tsrun": "^2.0.2",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@pushrocks/tapbundle": "^5.0.8",
|
"@types/node": "^25.6.0"
|
||||||
"@types/node": "^20.3.1"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@@ -56,10 +53,13 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"packageManager": "pnpm@10.28.2"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+7156
-3692
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -1,10 +1,10 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as smarthbs from '../ts/index.js';
|
import * as smarthbs from '../ts/index.js';
|
||||||
|
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
let hbs_testfilesDir = path.join(dirname, 'hbs_testfiles');
|
let hbs_testfilesDir = path.join(dirname, 'hbs_testfiles');
|
||||||
let testPartialDir = path.join(hbs_testfilesDir, 'partials');
|
let testPartialDir = path.join(hbs_testfilesDir, 'partials');
|
||||||
@@ -15,7 +15,7 @@ tap.test('smarthbs -> should create partials', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('smarthbs -> should compile a directory', async () => {
|
tap.test('smarthbs -> should compile a directory', async () => {
|
||||||
smarthbs.compileDirectory(hbs_testfilesDir, testResultDir, 'data.json');
|
await smarthbs.compileDirectory(hbs_testfilesDir, testResultDir, 'data.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('', async () => {
|
tap.test('', async () => {
|
||||||
@@ -43,4 +43,4 @@ tap.test('', async () => {
|
|||||||
expect(missingVars).not.toContain('fourthVar.otherKey.nextKey');
|
expect(missingVars).not.toContain('fourthVar.otherKey.nextKey');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smarthbs',
|
name: '@push.rocks/smarthbs',
|
||||||
version: '3.0.4',
|
version: '3.0.5',
|
||||||
description: 'Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.'
|
description: 'Enhances Handlebars with advanced filesystem support, template compilation, and efficient management of partials and variables.'
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-16
@@ -8,22 +8,24 @@ export let compileDirectory = async (
|
|||||||
destinationDirPathArg: string,
|
destinationDirPathArg: string,
|
||||||
dataFileNameArg: string
|
dataFileNameArg: string
|
||||||
) => {
|
) => {
|
||||||
let hbsFilePathArray = plugins.smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
|
const originDirPath = plugins.path.resolve(originDirPathArg);
|
||||||
let data = plugins.smartfile.fs.toObjectSync(
|
const destinationDirPath = plugins.path.resolve(destinationDirPathArg);
|
||||||
plugins.path.join(originDirPathArg, dataFileNameArg)
|
const hbsFileArray = await plugins.smartFs.directory(originDirPath)
|
||||||
);
|
.filter((entry) => entry.isFile && entry.name.endsWith('.hbs'))
|
||||||
for (let hbsFilePath of hbsFilePathArray) {
|
.list();
|
||||||
let parsedPath = plugins.path.parse(hbsFilePath);
|
const dataFileString = await plugins.smartFs.file(
|
||||||
let hbsFileString = plugins.smartfile.fs.toStringSync(
|
plugins.path.join(originDirPath, dataFileNameArg)
|
||||||
plugins.path.join(originDirPathArg, hbsFilePath)
|
).encoding('utf8').read() as string;
|
||||||
);
|
const data = JSON.parse(dataFileString) as Record<string, unknown>;
|
||||||
let template = plugins.handlebars.compile(hbsFileString);
|
for (const hbsFile of hbsFileArray) {
|
||||||
let output = template(data);
|
const parsedPath = plugins.path.parse(hbsFile.path);
|
||||||
|
const hbsFileString = await plugins.smartFs.file(hbsFile.path).encoding('utf8').read() as string;
|
||||||
|
const template = plugins.handlebars.compile(hbsFileString);
|
||||||
|
const output = template(data);
|
||||||
console.log('hi ' + output + ' hi');
|
console.log('hi ' + output + ' hi');
|
||||||
await plugins.smartfile.fs.ensureDir(destinationDirPathArg);
|
await plugins.smartFs.directory(destinationDirPath).create();
|
||||||
plugins.smartfile.memory.toFsSync(
|
await plugins.smartFs.file(
|
||||||
output,
|
plugins.path.join(destinationDirPath, parsedPath.name + '.html')
|
||||||
plugins.path.join(destinationDirPathArg, parsedPath.name + '.html')
|
).encoding('utf8').write(output);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import * as plugins from './smarthbs.plugins.js';
|
|||||||
* Helper:
|
* Helper:
|
||||||
* Allows you to analyze a context
|
* Allows you to analyze a context
|
||||||
*/
|
*/
|
||||||
plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
|
plugins.handlebars.registerHelper('__analyze', (analyzeContext: unknown) => {
|
||||||
if (typeof analyzeContext === 'string') {
|
if (typeof analyzeContext === 'string') {
|
||||||
if (plugins.handlebars.partials[analyzeContext]) {
|
if (plugins.handlebars.partials[analyzeContext]) {
|
||||||
console.log(`The analyzed partial ${analyzeContext} looks like this`);
|
console.log(`The analyzed partial ${analyzeContext} looks like this`);
|
||||||
@@ -20,12 +20,15 @@ plugins.handlebars.registerHelper('__analyze', (analyzeContext) => {
|
|||||||
* Helper:
|
* Helper:
|
||||||
* logs all registered partials to console
|
* logs all registered partials to console
|
||||||
*/
|
*/
|
||||||
plugins.handlebars.registerHelper('__allPartialsLog', (analyzeContext) => {
|
plugins.handlebars.registerHelper('__allPartialsLog', (_analyzeContext: unknown) => {
|
||||||
console.log(plugins.handlebars.partials);
|
console.log(plugins.handlebars.partials);
|
||||||
return 'analyzed';
|
return 'analyzed';
|
||||||
});
|
});
|
||||||
|
|
||||||
plugins.handlebars.registerHelper('__compile', (evaluationString, evaluationContext) => {
|
plugins.handlebars.registerHelper('__compile', (evaluationString: unknown, evaluationContext: unknown) => {
|
||||||
let template = plugins.handlebars.compile(evaluationString);
|
if (typeof evaluationString !== 'string') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const template = plugins.handlebars.compile(evaluationString);
|
||||||
return template(evaluationContext);
|
return template(evaluationContext);
|
||||||
});
|
});
|
||||||
|
|||||||
+16
-20
@@ -3,24 +3,20 @@ import * as plugins from './smarthbs.plugins.js';
|
|||||||
/**
|
/**
|
||||||
* registers a directory of partials to make them available within handlebars compilation
|
* registers a directory of partials to make them available within handlebars compilation
|
||||||
*/
|
*/
|
||||||
export let registerPartialDir = (dirPathArg: string): Promise<any> => {
|
export let registerPartialDir = async (dirPathArg: string): Promise<void> => {
|
||||||
let done = plugins.smartpromise.defer();
|
const dirPath = plugins.path.resolve(dirPathArg);
|
||||||
plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then((hbsFileArrayArg) => {
|
const hbsFileArray = await plugins.smartFs.directory(dirPath)
|
||||||
for (let hbsFilePath of hbsFileArrayArg) {
|
.recursive()
|
||||||
let parsedPath = plugins.path.parse(hbsFilePath);
|
.filter((entry) => entry.isFile && entry.name.endsWith('.hbs'))
|
||||||
let hbsFileString = plugins.smartfile.fs.toStringSync(
|
.list();
|
||||||
plugins.path.join(dirPathArg, hbsFilePath)
|
for (const hbsFile of hbsFileArray) {
|
||||||
);
|
const relativeFilePath = plugins.path.relative(dirPath, hbsFile.path);
|
||||||
if (parsedPath.dir === '/') {
|
const parsedPath = plugins.path.parse(relativeFilePath);
|
||||||
parsedPath.dir = '';
|
const hbsFileString = await plugins.smartFs.file(hbsFile.path).encoding('utf8').read() as string;
|
||||||
}
|
const partialDir = parsedPath.dir === '.' || parsedPath.dir === ''
|
||||||
if (parsedPath.dir !== '') {
|
? ''
|
||||||
parsedPath.dir = parsedPath.dir + '/';
|
: `${parsedPath.dir.split(plugins.path.sep).join('/')}/`;
|
||||||
}
|
const partialName = `partials/${partialDir}${parsedPath.name}`;
|
||||||
let partialName = `partials/${parsedPath.dir}${parsedPath.name}`;
|
plugins.handlebars.registerPartial(partialName, hbsFileString);
|
||||||
plugins.handlebars.registerPartial(partialName, hbsFileString);
|
}
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartfs from '@push.rocks/smartfs';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
|
||||||
|
|
||||||
export { smartpath, smartfile, smartpromise };
|
export const smartFs = new smartfs.SmartFs(new smartfs.SmartFsProviderNode());
|
||||||
|
|
||||||
|
export { smartfs };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import handlebars from 'handlebars';
|
import handlebars from 'handlebars';
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import * as plugins from './smarthbs.plugins.js';
|
|||||||
* get a template for a file on disk
|
* get a template for a file on disk
|
||||||
*/
|
*/
|
||||||
export let getTemplateForFile = async (filePathArg: string) => {
|
export let getTemplateForFile = async (filePathArg: string) => {
|
||||||
let filePathAbsolute = plugins.path.resolve(filePathArg);
|
const filePathAbsolute = plugins.path.resolve(filePathArg);
|
||||||
return plugins.handlebars.compile(plugins.smartfile.fs.toStringSync(filePathAbsolute));
|
const fileString = await plugins.smartFs.file(filePathAbsolute).encoding('utf8').read() as string;
|
||||||
|
return plugins.handlebars.compile(fileString);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
|
|||||||
|
|
||||||
// make sure we are clean from curly brackets
|
// make sure we are clean from curly brackets
|
||||||
varNameArray = varNameArray.map((x) => {
|
varNameArray = varNameArray.map((x) => {
|
||||||
return x.match(nameInCurlsRegex)[0];
|
const match = x.match(nameInCurlsRegex);
|
||||||
|
return match ? match[0] : '';
|
||||||
});
|
});
|
||||||
|
|
||||||
// make sure are uniq
|
// make sure are uniq
|
||||||
@@ -44,7 +45,7 @@ export let findVarsInHbsString = async (hbsStringArg: string) => {
|
|||||||
* @param varObjectArg
|
* @param varObjectArg
|
||||||
* @return string array with missing variable names
|
* @return string array with missing variable names
|
||||||
*/
|
*/
|
||||||
export let checkVarsSatisfaction = async (hbsStringArg: string, varObjectArg: any) => {
|
export let checkVarsSatisfaction = async (hbsStringArg: string, varObjectArg: Record<string, unknown>) => {
|
||||||
// required vars as combined deep string with . notation
|
// required vars as combined deep string with . notation
|
||||||
let requiredVarStrings = await findVarsInHbsString(hbsStringArg);
|
let requiredVarStrings = await findVarsInHbsString(hbsStringArg);
|
||||||
|
|
||||||
@@ -55,14 +56,17 @@ export let checkVarsSatisfaction = async (hbsStringArg: string, varObjectArg: an
|
|||||||
// building the
|
// building the
|
||||||
for (let stringVar of requiredVarStrings) {
|
for (let stringVar of requiredVarStrings) {
|
||||||
let splittedVars = stringVar.split('.');
|
let splittedVars = stringVar.split('.');
|
||||||
let requiredPointer = suppliedVarsObject;
|
let requiredPointer: unknown = suppliedVarsObject;
|
||||||
for (let i = 0; i < splittedVars.length; i++) {
|
for (let i = 0; i < splittedVars.length; i++) {
|
||||||
let splitVar = splittedVars[i];
|
let splitVar = splittedVars[i];
|
||||||
let varAvailable = requiredPointer[splitVar] !== undefined;
|
const pointerObject = requiredPointer && typeof requiredPointer === 'object'
|
||||||
|
? requiredPointer as Record<string, unknown>
|
||||||
|
: {};
|
||||||
|
let varAvailable = pointerObject[splitVar] !== undefined;
|
||||||
if (varAvailable && splittedVars.length === i + 1) {
|
if (varAvailable && splittedVars.length === i + 1) {
|
||||||
// ok
|
// ok
|
||||||
} else if (varAvailable) {
|
} else if (varAvailable) {
|
||||||
requiredPointer = requiredPointer[splitVar];
|
requiredPointer = pointerObject[splitVar];
|
||||||
} else {
|
} else {
|
||||||
missingVarsObject.push(stringVar);
|
missingVarsObject.push(stringVar);
|
||||||
i = splittedVars.length;
|
i = splittedVars.length;
|
||||||
|
|||||||
+3
-1
@@ -5,8 +5,10 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist_*/**/*.d.ts"
|
"dist_*/**/*.d.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user