Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to nx workspace #1483

Draft
wants to merge 21 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: extend pattern lab global types and descriptions
  • Loading branch information
JosefBredereck committed Feb 26, 2023
commit 4b3a7d173dfc31eba8154ad3607886df036fd898
2 changes: 1 addition & 1 deletion packages/engine-handlebars/src/lib/engine-handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class EngineHandlebars implements PatternLabEngine {
return partial;
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-liquid/src/lib/engine-liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class EngineLiquid implements PatternLabEngine {
return foundPatternPartial.split(':')[0];
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-mustache/src/lib/engine-mustache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class EngineMustache implements PatternLabEngine {
return foundPatternPartial.split(':')[0];
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-nunjucks/src/lib/engine-nunjucks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class EngineNunjucks implements PatternLabEngine {
return '';
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-twig-php/src/lib/engine-twig-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class EngineTwigPhp implements PatternLabEngine {
}
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const metaFilePath = path.resolve(config.paths.source.meta, fileName);
try {
fs.statSync(metaFilePath);
Expand Down
8 changes: 3 additions & 5 deletions packages/engine-twig/src/lib/engine-twig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ export class EngineTwig implements PatternLabEngine {
/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g;

renderPattern(pattern: Pattern, data: PatternData, _partials?: PatternPartial): Promise<string> {
let patternPath = pattern.basePattern ? pattern.basePattern.relPath : pattern.relPath;
let patternPath = pattern.basePattern?.relPath || pattern.relPath;
if (this.metaPath && patternPath.lastIndexOf(this.metaPath) === 0) {
patternPath = patternPath.substring(this.metaPath.length + 1);
}
return Promise.resolve(this.engine.render(patternPath, data));
}

registerPartial(pattern: Pattern): void {
console.log(
`registerPartial(${pattern.name} - ${pattern.patternPartial} - ${pattern.patternPath} - ${pattern.relPath})`,
);
console.log(`registerPartial(${pattern.name} - ${pattern.patternPartial} - ${pattern.relPath})`);
patternLabLoader.registerPartial(pattern);
}

Expand Down Expand Up @@ -148,7 +146,7 @@ export class EngineTwig implements PatternLabEngine {
}
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const metaFilePath = path.resolve(config.paths.source.meta, fileName);
try {
fs.statSync(metaFilePath);
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-underscore/src/lib/engine-underscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class EngineUnderscore implements PatternLabEngine {
return partialIDWithQuotes.replace(edgeQuotesMatcher, '');
}

spawnFile(config: PatternLabConfig, fileName: string): void {
private spawnFile(config: PatternLabConfig, fileName: string): void {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);
try {
Expand Down
79 changes: 78 additions & 1 deletion packages/types/src/lib/interfaces/engine.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,101 @@ import { PatternLabConfig } from './pattern-lab-config.interface';
import { Pattern, PatternData, PatternPartial } from './pattern.interface';

export interface PatternLabEngine {
/**
* The unique name of the engine used to key out the engine in the pattern lab instance
*/
engineName: string;

/**
* The file extensions that this engine can render and by which patterns are loaded.
* e.g. ['.hbs', '.handlebars']
*/
engineFileExtension: string[];

/**
* Defines if the engine should look out for partials directly on the include sub pattern mechanism
* @deprecated is only used by mustache engine and will be removed in the future
* in favor of default behavior https://github.com/pattern-lab/patternlab-node/issues/1180
*/
expandPartials: boolean;

/**
* Render the pattern template with the given data and partials
* @param pattern the pattern to render
* @param data additional data to pass to the pattern template
* @param partials partials to pass to the pattern template or which need to be added to the engine)
* @returns the rendered pattern
*/
renderPattern: (pattern: Pattern, data: PatternData, partials?: PatternPartial) => Promise<string>;

/**
* Register a pattern to the engine so that it can be used in the render process later on
* @param pattern the pattern to register
*/
registerPartial: (pattern: Pattern) => void;

/**
* Fin all partials in the given pattern
* @param pattern the pattern to search for partials
* @returns the partials found in the pattern
*/
findPartials: (pattern: Pattern) => RegExpMatchArray | null;

/**
* Fin all partials with pattern parameters in the given pattern
* @param pattern the pattern to search for partials
* @returns the partials found in the pattern
* @deprecated is only used by mustache engine and will be removed in the future in favor
* of default behavior https://github.com/pattern-lab/patternlab-node/issues/1180
*/
findPartialsWithPatternParameters: (pattern: Pattern) => RegExpMatchArray | null;

/**
* Fin all list items in the given pattern
* @param pattern the pattern to search for list items
* @returns the list items found in the pattern
* @deprecated this feature is not supported anymore and will be removed in the future
* https://github.com/pattern-lab/patternlab-node/issues/1178
*/
findListItems: (pattern: Pattern) => RegExpMatchArray | null;

/**
* Fin a specific partial in the given pattern
* @param partialString the partial to search for
* @returns the pattern partial found in the pattern
*/
findPartial: (partialString: string) => string;
spawnFile: (config: PatternLabConfig, fileName: string) => void;

/**
*
* @param config
* @returns
*/
spawnMeta: (config: PatternLabConfig) => void;

/**
*
* @param config
* @returns
*/
usePatternLabConfig: (config: PatternLabConfig) => void;
}

interface PatternEngineConfigBase {
/**
* The name of the npm package to load the engine from
*/
package: string;

/**
* The file extensions that this engine can render and by which patterns are loaded.
* e.g. ['.hbs', '.handlebars']
*/
fileExtensions: string[];

/**
* The location of extensions that should be loaded by the engine
*/
extend?: string | string[];
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './engine.interface';
export * from './pattern.interface';
export * from './pattern-lab.interface';
export * from './pattern-lab-config.interface';
16 changes: 16 additions & 0 deletions packages/types/src/lib/interfaces/pattern-lab.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PatternLabConfig } from './pattern-lab-config.interface';
import { PatternData } from './pattern.interface';

export interface PatternLab {
/**
* The configuration for this instance of Pattern Lab
*/
config: PatternLabConfig;

/**
* The data for this instance of Pattern Lab.
* Functions as global data for all patterns if no local
* pattern specific data is provided.
*/
data: PatternData;
}
Loading