Skip to content

Commit

Permalink
fix(twig engine): startup and running problems (#1478)
Browse files Browse the repository at this point in the history
* fix: missing schema entry for twig engine

* fix: twig php engine loading

* fix: error message if partial could not be found

---------

Co-authored-by: Josef Bredreck <[email protected]>
  • Loading branch information
mfranzke and JosefBredereck authored Feb 1, 2023
1 parent e721091 commit e5a1904
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "6.0.0",
"main": "./src/index.js",
"dependencies": {
"@pattern-lab/engine-handlebars": "^6.0.0",
"@pattern-lab/engine-mustache": "^6.0.0",
"@pattern-lab/live-server": "^6.0.0",
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function (partialName, patternlab, reportWarning = true) {
}
if (reportWarning) {
logger.warning(
`Could not find pattern referenced with partial syntax ${partialName}.
`Could not find pattern referenced with partial syntax "${partialName}" from "${patternlab.config.paths.source.patterns}".
This can occur when a pattern was renamed, moved, or no longer exists but it still referenced within a different template or within data as a link.`
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/edition-twig/patternlab-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"engines": {
"twig": {
"twig-php": {
"package": "@pattern-lab/engine-twig-php",
"fileExtensions": [
"twig"
Expand Down
13 changes: 7 additions & 6 deletions packages/engine-twig-php/lib/engine_twig_php.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ const engine_twig_php = {
usePatternLabConfig: function (config) {
patternLabConfig = config;

if (!config.engines.twig) {
if (!config.engines['twig-php']) {
console.error('Missing "twig" in Pattern Lab config file; exiting...');
process.exit(1);
}

const { namespaces, alterTwigEnv, relativeFrom, ...rest } =
config.engines.twig;
config.engines['twig-php'];

// since package is a reserved word in node, we need to delete it from the config object like this
delete rest.package;
delete rest.fileExtensions;

// Schema on config object being passed in:
// https://github.com/basaltinc/twig-renderer/blob/master/config.schema.json
Expand Down Expand Up @@ -221,10 +225,7 @@ const engine_twig_php = {

// then tease out the folder name itself (including the # prefix)
// ex. atoms
const folderName = fullFolderPath.substring(
fullFolderPath.lastIndexOf('/') + 1,
fullFolderPath.length
);
const folderName = path.parse(fullFolderPath).base;

// finally, return the Twig path we created from the full file path
// ex. atoms/buttons/button.twig
Expand Down
2 changes: 1 addition & 1 deletion packages/starterkit-twig-demo/patternlab-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"engines": {
"twig": {
"twig-php": {
"package": "@pattern-lab/engine-twig-php",
"fileExtensions": [
"twig"
Expand Down

0 comments on commit e5a1904

Please sign in to comment.