@itemconsulting/preset-enonic-xp
Advanced tools
export default function loader(source: string): string; | ||
export declare function getDependencyFilePaths(source: string, resourcePath: string): string[]; |
@@ -1,25 +0,12 @@ | ||
import { sep, join } from "path"; | ||
import { urlToRequest, getHashDigest } from "loader-utils"; | ||
import { getHashDigest } from "loader-utils"; | ||
import { getDependencyFilePaths, getPathRelativeToResources } from "./storybook-loader-utils.js"; | ||
export default function loader(source) { | ||
const requires = getDependencyFilePaths(source, this.resourcePath) | ||
const pathRegex = /\[#import "(.*?)".*?]/gi; | ||
const requires = getDependencyFilePaths(source, this.resourcePath, pathRegex) | ||
.map((path) => `require("${escapePathForWindows(path)}");`) | ||
.join("\n"); | ||
return `${requires}\nexport default "${escapePathForWindows(this.resourcePath)}?hash=${getHashDigest(source)}";`; | ||
return `${requires}\nexport default "${getPathRelativeToResources(this.resourcePath)}"; /* hash=${getHashDigest(source)} */`; | ||
} | ||
export function getDependencyFilePaths(source, resourcePath) { | ||
const resourcesDir = join("src", "main", "resources"); | ||
const srcDirIndex = resourcePath.indexOf(resourcesDir); | ||
const baseDirPath = resourcePath.substring(0, srcDirIndex + resourcesDir.length); | ||
const pathRegex = /\[#import "(.*?)".*?]/gi; | ||
const importFilePaths = []; | ||
for (const match of source.matchAll(pathRegex)) { | ||
const url = match[1]; | ||
const isAbsolutePath = url.substring(0, sep.length) === sep; | ||
const fullImportFile = urlToRequest(url, isAbsolutePath ? baseDirPath : undefined); | ||
importFilePaths.push(fullImportFile); | ||
} | ||
return importFilePaths; | ||
} | ||
function escapePathForWindows(path) { | ||
return path.replace(/\\/g, "\\\\"); | ||
} |
@@ -17,2 +17,11 @@ import { logger } from "@storybook/node-logger"; | ||
}, | ||
{ | ||
test: /\.html$/, | ||
use: [ | ||
{ | ||
loader: resolve(__dirname, "thymeleaf-loader.js"), | ||
options: {}, | ||
}, | ||
], | ||
}, | ||
]; | ||
@@ -19,0 +28,0 @@ } |
{ | ||
"name": "@itemconsulting/preset-enonic-xp", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Preset for using Storybook with Enonic XP", | ||
@@ -23,11 +23,11 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.18.1", | ||
"@typescript-eslint/parser": "^6.18.1", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.2", | ||
"prettier": "^3.1.1", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"prettier": "^3.2.5", | ||
"typescript": "^5.3.3", | ||
"webpack": "^5.89.0" | ||
"webpack": "^5.90.1" | ||
} | ||
} |
6164
32.3%11
57.14%81
65.31%