Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
172 changes: 103 additions & 69 deletions syncify/options/define/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,142 +121,176 @@ async function setSchemaJson () {

const { shared } = $.section;
const warn = warnOption('Section Schema');
const files = [ ...$.paths.blocks.input, ...$.paths.sections.input ];
const files = [ ...$.paths.blocks.input, ...$.paths.sections.input, ...$.paths.config.input ];

for (const file of files) {
function buildSettingsCache (file: string, settings: SchemaSettings[]) {

const read = await readFile(file, 'utf8');
const hash = checksum(read);
const refs = [];

if (has(file, $.cache.schema) && $.cache.checksum[file] === hash) continue;
for (const setting of settings) {

$.cache.checksum[file] = hash;
if (has('$ref', setting)) {

const data = read.toString();
const indices = GetSchemaIndices(data);
const [ key, prop ] = setting.$ref.split('.');

if (indices === null) {
warn('Liquid Parse Error', relative($.cwd, file));
continue;
}
if (shared.has(key)) {

try {
if (!$.cache.schema[shared.get(key).uri].has(file)) {

$.cache.schema[shared.get(key).uri].add(file);

if (has('settings', shared.get(key).schema[prop])) {

refs.push((shared.get(key).schema[prop] as SettingsGroup).settings);

const schema = parse<SchemaSectionTag>(data.slice(indices.begin, indices.ender));
const schemaProp = hasProp(schema);
continue;

function buildSettingsCache (file: string, settings: SchemaSettings[]) {
}

refs.push(shared.get(key).schema[prop]);

}

const refs = [];
}

for (const setting of settings) {
}
}

if (has('$ref', setting)) {
for (const settings of refs) {

const [ key, prop ] = setting.$ref.split('.');
buildSettingsCache(file, settings);

if (shared.has(key)) {
}

if (!$.cache.schema[shared.get(key).uri].has(file)) {
}

$.cache.schema[shared.get(key).uri].add(file);
function buildBlockCache (file: string, blocks: SchemaBlocks[]) {

if (has('settings', shared.get(key).schema[prop])) {
const blockRefs: SchemaBlocks[] = [];
const settingsRefs = [];

refs.push((shared.get(key).schema[prop] as SettingsGroup).settings);
for (const block of blocks) {

continue;
const blockProp = hasProp(block);

}
if (blockProp('$ref')) {

refs.push(shared.get(key).schema[prop]);
const [ key, prop ] = block.$ref.split('.');

}
if (shared.has(key)) {

}
if (!$.cache.schema[shared.get(key).uri].has(file)) {

}
}
$.cache.schema[shared.get(key).uri].add(file);

for (const settings of refs) {
blockRefs.push(shared.get(key).schema[prop] as SchemaBlocks);

buildSettingsCache(file, settings);
};

}

}

function buildBlockCache (file: string, blocks: SchemaBlocks[]) {
if (blockProp('settings')) {

const blockRefs: SchemaBlocks[] = [];
const settingsRefs = [];
settingsRefs.push(block.settings);

for (const block of blocks) {
}
}

const blockProp = hasProp(block);
for (const block of blockRefs) {

if (blockProp('$ref')) {
buildBlockCache(file, [ block ]);

const [ key, prop ] = block.$ref.split('.');
}

if (shared.has(key)) {
for (const settings of settingsRefs) {

if (!$.cache.schema[shared.get(key).uri].has(file)) {
buildSettingsCache(file, settings);

$.cache.schema[shared.get(key).uri].add(file);
}

blockRefs.push(shared.get(key).schema[prop] as SchemaBlocks);
}

};
for (const file of files) {

}
const read = await readFile(file, 'utf8');
const hash = checksum(read);

}
if (has(file, $.cache.schema) && $.cache.checksum[file] === hash) continue;

if (blockProp('settings')) {
$.cache.checksum[file] = hash;

settingsRefs.push(block.settings);
const data = read.toString();

}
}
if (file.includes('/config/') && file.includes('settings_schema.json')) {

for (const block of blockRefs) {
const schema = parse(data);

buildBlockCache(file, [ block ]);
schema.slice(1).forEach((setting: {name: string, settings: any[]}) => {
if (has('settings', setting) && isArray(setting.settings)) {

}
try {

for (const settings of settingsRefs) {
buildSettingsCache(file, setting.settings);

buildSettingsCache(file, settings);
} catch (e) {

if (has(file, $.cache.sections)) {

delete $.cache.sections[file];

}

warn('Config Parse Error', relative($.cwd, file));
}

}
});

}
continue;

if (schemaProp('settings')) {
}

if (file.includes('/sections/') || file.includes('/blocks/')) {

buildSettingsCache(file, schema.settings);
const indices = GetSchemaIndices(data);

if (indices === null) {
warn('Liquid Parse Error', relative($.cwd, file));
continue;
}

if (schemaProp('blocks')) {
try {

buildBlockCache(file, schema.blocks);
const schema = parse<SchemaSectionTag>(data.slice(indices.begin, indices.ender));
const schemaProp = hasProp(schema);

}
if (schemaProp('settings')) {

} catch (e) {
buildSettingsCache(file, schema.settings);

if (has(file, $.cache.sections)) {
}

delete $.cache.sections[file];
if (schemaProp('blocks')) {

}
buildBlockCache(file, schema.blocks);

warn('JSON Parse Error', relative($.cwd, file));
}

}
} catch (e) {

if (has(file, $.cache.sections)) {

delete $.cache.sections[file];

}

warn('JSON Parse Error', relative($.cwd, file));

}

};

}

Expand Down
31 changes: 29 additions & 2 deletions syncify/transform/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'node:path';

import { readFile, writeFile } from 'fs-extra';

import { evaluate, ParseEvaluate, stringify } from '@syncify/json';
import { evaluate, parse, ParseEvaluate, stringify } from '@syncify/json';
import { timer } from '@syncify/timer';

import { log } from '~cli/log';
Expand All @@ -14,6 +14,7 @@ import { themeFilesGet, themeFilesUpsertMap } from '~http/themeFiles';
import { runChecksum } from '~process/cache';
import { prompt } from '~prompt';
import { theme } from '~prompts/enquirer';
import { InjectSettings } from '~schema';
import { tailwindParse } from '~style';
import * as u from '~utils';

Expand Down Expand Up @@ -261,7 +262,7 @@ export async function JsonTransform (file: File): Promise<string> {

if (!u.isString(read)) return;

const local = read.trim();
let local = read.trim();

file.size = u.byteSize(local);

Expand All @@ -270,8 +271,34 @@ export async function JsonTransform (file: File): Promise<string> {
return;
}

if (file.name === 'settings_schema') {

const schemaFiles = u.values($.cache.schema);

for (const schemaFile of schemaFiles) {
schemaFile.delete(file.input);
}

const settings = parse(local);

settings.slice(1).forEach((schema: {name: string, settings: any[]}) => {
if (u.has('settings', schema) && u.isArray(schema.settings)) {
schema.settings = InjectSettings(file, schema.settings);
}
});

local = stringify(settings);

}

if ($.mode.build === false && isDiff(file.type)) {

if (file.name === 'settings_schema') {
file.value = await jsonCompile(file, local);
}

file.value = await jsonCompare(file, local);

} else {
file.value = await jsonCompile(file, local);
}
Expand Down
Loading