Skip to content

Commit

Permalink
fix: 🐛 template identities
Browse files Browse the repository at this point in the history
  • Loading branch information
lenconda committed Sep 15, 2021
1 parent 440fab1 commit df5f24f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/dollie-core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const TEMPLATE_CACHE_PATHNAME_PREFIX = '/template';
const EXTEND_TEMPLATE_LABEL_PREFIX = 'extend:';
const EXTEND_TEMPLATE_PATHNAME_PREFIX = '/extends';
const MAIN_TEMPLATE_PATHNAME_PREFIX = '/main';
const TEMPLATE_FILE_PREFIX = '__template.';
const TEMPLATE_FILE_IDENTITY = '__template.';
const TEMPLATE_CONFIG_FILE_NAMES = [
'dollie.js',
'.dollie.js',
Expand All @@ -16,7 +16,7 @@ export {
EXTEND_TEMPLATE_LABEL_PREFIX,
EXTEND_TEMPLATE_PATHNAME_PREFIX,
MAIN_TEMPLATE_PATHNAME_PREFIX,
TEMPLATE_FILE_PREFIX,
TEMPLATE_FILE_IDENTITY,
TEMPLATE_CONFIG_FILE_NAMES,
EXTEND_TEMPLATE_PREFIX,
};
14 changes: 6 additions & 8 deletions packages/dollie-core/src/generators/module.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ModulePropsIncompatibleError,
} from '../errors';
import {
TEMPLATE_CACHE_PATHNAME_PREFIX, MAIN_TEMPLATE_PATHNAME_PREFIX,
TEMPLATE_CACHE_PATHNAME_PREFIX,
} from '../constants';
import {
readTemplateEntities,
Expand All @@ -43,7 +43,6 @@ import {
FileContent,
} from '@dollie/utils';
import ejs from 'ejs';
import path from 'path';

class ModuleGenerator extends Generator implements Generator {
private modulePathname: string;
Expand All @@ -52,7 +51,6 @@ class ModuleGenerator extends Generator implements Generator {
private moduleProps: InquirerAnswers = {};
private fileTable: FileTable = {};
private projectMergeTable: MergeTable = {};
private threeFactorCompareTable: FileTable = {};

public constructor(
templateId: string,
Expand Down Expand Up @@ -178,6 +176,7 @@ class ModuleGenerator extends Generator implements Generator {
absoluteOriginalPathname,
isBinary,
isDirectory,
isTemplateFile,
} = entity;

if (isDirectory) {
Expand All @@ -192,8 +191,9 @@ class ModuleGenerator extends Generator implements Generator {
continue;
}

const content = ejs.render(contentBuffer.toString(), this.moduleProps);
this.threeFactorCompareTable[entityPathname] = content;
const content = isTemplateFile
? ejs.render(contentBuffer.toString(), this.moduleProps)
: contentBuffer.toString();

if (!_.isArray(this.cacheTable[entityPathname])) {
this.cacheTable[entityPathname] = [diff(content)];
Expand All @@ -208,9 +208,7 @@ class ModuleGenerator extends Generator implements Generator {
}

public mergeTemplateFiles() {
for (const entityPathname of Object.keys(this.cacheTable)) {

}
super.mergeTemplateFiles(false);
}

public resolveConflicts() {
Expand Down
6 changes: 3 additions & 3 deletions packages/dollie-core/src/utils/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import fs from 'fs';
import {
TEMPLATE_CACHE_PATHNAME_PREFIX,
TEMPLATE_FILE_PREFIX,
TEMPLATE_FILE_IDENTITY,
} from '../constants';
import {
LoaderConfig,
Expand Down Expand Up @@ -98,9 +98,9 @@ const readTemplateEntities = (
let relativePathname = initialRelativePathname;
let absolutePathname = initialAbsolutePathname;

if (initialEntityName.startsWith(TEMPLATE_FILE_PREFIX)) {
if (initialEntityName.startsWith(TEMPLATE_FILE_IDENTITY)) {
isTemplateFile = true;
entityName = initialEntityName.slice(TEMPLATE_FILE_PREFIX.length);
entityName = initialEntityName.slice(TEMPLATE_FILE_IDENTITY.length);
relativePathname = `${relativeDirectoryPathname ? `${relativeDirectoryPathname}/` : ''}${entityName}`;
absolutePathname = `${absoluteDirectoryPathname ? `${absoluteDirectoryPathname}/` : ''}${entityName}`;
}
Expand Down

0 comments on commit df5f24f

Please sign in to comment.