Skip to content

Commit

Permalink
v0.9.15
Browse files Browse the repository at this point in the history
- fix: file collection containing file with name of template file not generating file
- upd: make useTemplate function accept an options object instead of raw boolean
towards bridge-core/editor#132
  • Loading branch information
solvedDev committed Jul 23, 2022
1 parent faffe51 commit 6ef58c9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
6 changes: 5 additions & 1 deletion dist/Plugins/BuiltIn/GeneratorScripts/Module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export interface IModuleOpts {
fileSystem: FileSystem;
console: Console;
}
interface IUseTemplateOptions {
omitTemplate?: boolean;
}
export declare function createModule({ generatorPath, omitUsedTemplates, fileSystem, console, }: IModuleOpts): {
useTemplate: (filePath: string, omitTemplate?: boolean) => Promise<any>;
useTemplate: (filePath: string, { omitTemplate }?: IUseTemplateOptions) => Promise<any>;
createCollection: () => Collection;
};
export {};
6 changes: 3 additions & 3 deletions dist/dash-compiler.bundled.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7661,7 +7661,7 @@ function createModule({
console: console2
}) {
return {
useTemplate: (filePath, omitTemplate = true) => {
useTemplate: (filePath, { omitTemplate = true } = {}) => {
const templatePath = pathBrowserify.join(pathBrowserify.dirname(generatorPath), filePath);
if (omitTemplate)
omitUsedTemplates.add(templatePath);
Expand Down Expand Up @@ -7747,13 +7747,13 @@ const GeneratorScriptsPlugin = ({
}
return module.__default__;
}
},
finalizeBuild(filePath, fileContent) {
if (fileCollection.get(filePath)) {
if (filePath.endsWith(".json") && typeof fileContent !== "string")
return JSON.stringify(fileContent, null, " ");
return fileContent;
}
},
finalizeBuild(filePath, fileContent) {
if (omitUsedTemplates.has(filePath))
return null;
if (isGeneratorScript(filePath)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/dash-compiler.bundled.umd.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/dash-compiler.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ function createModule({
console: console2
}) {
return {
useTemplate: (filePath, omitTemplate = true) => {
useTemplate: (filePath, { omitTemplate = true } = {}) => {
const templatePath = join(dirname(generatorPath), filePath);
if (omitTemplate)
omitUsedTemplates.add(templatePath);
Expand Down Expand Up @@ -1575,13 +1575,13 @@ const GeneratorScriptsPlugin = ({
}
return module.__default__;
}
},
finalizeBuild(filePath, fileContent) {
if (fileCollection.get(filePath)) {
if (filePath.endsWith(".json") && typeof fileContent !== "string")
return JSON.stringify(fileContent, null, " ");
return fileContent;
}
},
finalizeBuild(filePath, fileContent) {
if (omitUsedTemplates.has(filePath))
return null;
if (isGeneratorScript(filePath)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/dash-compiler.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-compiler",
"version": "0.9.14",
"version": "0.9.15",
"description": "A fast compiler for Minecraft Add-Ons",
"scripts": {
"build:types": "tsc --project tsconfig.json",
Expand Down
9 changes: 8 additions & 1 deletion src/Plugins/BuiltIn/GeneratorScripts/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ export interface IModuleOpts {
console: Console
}

interface IUseTemplateOptions {
omitTemplate?: boolean
}

export function createModule({
generatorPath,
omitUsedTemplates,
fileSystem,
console,
}: IModuleOpts) {
return {
useTemplate: (filePath: string, omitTemplate = true) => {
useTemplate: (
filePath: string,
{ omitTemplate = true }: IUseTemplateOptions = {}
) => {
const templatePath = join(dirname(generatorPath), filePath)
if (omitTemplate) omitUsedTemplates.add(templatePath)

Expand Down
7 changes: 5 additions & 2 deletions src/Plugins/BuiltIn/GeneratorScripts/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export const GeneratorScriptsPlugin: TCompilerPluginFactory<{}> = ({

return module.__default__
}
},

finalizeBuild(filePath, fileContent) {
// 1. Handle generated virtual files
if (fileCollection.get(filePath)) {
if (
filePath.endsWith('.json') &&
Expand All @@ -105,11 +108,11 @@ export const GeneratorScriptsPlugin: TCompilerPluginFactory<{}> = ({
return JSON.stringify(fileContent, null, '\t')
return fileContent
}
},

finalizeBuild(filePath, fileContent) {
// 2. Omit unused template
if (omitUsedTemplates.has(filePath)) return null

// 3. Handle transformed generator script
if (isGeneratorScript(filePath)) {
if (fileContent === null) return null

Expand Down

0 comments on commit 6ef58c9

Please sign in to comment.