Skip to content

Commit

Permalink
fix: check for template.json (#440)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordy Quak <[email protected]>
  • Loading branch information
jrquak and Jordy Quak authored Jun 5, 2023
1 parent 0041fbf commit d934690
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/bb-components-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
readFileSync,
remove,
} from 'fs-extra';
import fs from 'fs';
import ts, { JsxEmit, ModuleKind, ScriptTarget } from 'typescript';
import extractComponentCompatibility from './components/compatibility';
import { doTranspile } from './components/transformers';
Expand Down Expand Up @@ -386,9 +387,15 @@ void (async (): Promise<void> => {
readPartialPrefabs(),
]);

const existingComponents: Component[] = JSON.parse(
readFileSync(`${distDir}/templates.json`, 'utf8'),
);
const templatesPath = path.join(distDir, 'templates.json');
let existingComponents: Component[] = [];

if (fs.existsSync(templatesPath)) {
const templatesData = fs.readFileSync(templatesPath, 'utf8');
existingComponents = JSON.parse(templatesData);
} else {
console.warn('templates.json file not found: building template.json');
}

const validStyleTypes = styles.map(({ type }) => type);
const prefabs = jsPrefabs
Expand Down Expand Up @@ -416,9 +423,18 @@ void (async (): Promise<void> => {
{},
);

const componentNames = existingComponents.map(({ name }) => name);
let finalComponents: Component[];
if (fs.existsSync(templatesPath)) {
const templatesData = fs.readFileSync(templatesPath, 'utf8');
finalComponents = JSON.parse(templatesData);
} else {
// Here we have to build templates
finalComponents = components;
}

const componentNames = finalComponents.map(({ name }) => name);

checkNameReferences(prefabs, existingComponents);
checkNameReferences(prefabs, finalComponents);

const componentStyleMap: ComponentStyleMap = components.reduce((acc, c) => {
return c.styleType
Expand Down

0 comments on commit d934690

Please sign in to comment.