@lowdefy/build
Version:
98 lines (94 loc) • 3.29 kB
JavaScript
/*
Copyright 2020-2026 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/ import operators from '@lowdefy/operators-js/operators/build';
import { resolve, WalkContext } from './buildRefs/walker.js';
import getRefContent from './buildRefs/getRefContent.js';
import makeRefDefinition from './buildRefs/makeRefDefinition.js';
import evaluateStaticOperators from './buildRefs/evaluateStaticOperators.js';
import collectDynamicIdentifiers from './collectDynamicIdentifiers.js';
import validateOperatorsDynamic from './validateOperatorsDynamic.js';
import fetchModules from './fetchModules.js';
import { resolveLocalManifest, resolveFullManifest } from './registerModules.js';
import resolveModuleDependencies from './resolveModuleDependencies.js';
validateOperatorsDynamic({
operators
});
const dynamicIdentifiers = collectDynamicIdentifiers({
operators
});
async function parseLowdefyYaml({ context }) {
const refDef = makeRefDefinition('lowdefy.yaml', null, context.refMap);
const content = await getRefContent({
context,
refDef,
referencedFrom: null
});
const ctx = new WalkContext({
buildContext: context,
refId: refDef.id,
sourceRefId: null,
vars: {},
path: '',
currentFile: refDef.path,
refChain: new Set(refDef.path ? [
refDef.path
] : []),
operators,
env: process.env,
dynamicIdentifiers,
shouldStop: (path)=>{
if (path.startsWith('modules')) return false;
return 'preserve';
}
});
let config = await resolve(content, ctx);
config = evaluateStaticOperators({
context,
input: config,
refDef
});
return config ?? {};
}
async function buildModuleDefs({ context }) {
const lowdefyConfig = await parseLowdefyYaml({
context
});
context.plugins = lowdefyConfig.plugins ?? [];
const moduleEntries = lowdefyConfig.modules ?? [];
if (moduleEntries.length === 0) {
return;
}
const resolvedPaths = await fetchModules({
moduleEntries,
context
});
// Step 1: Local resolve — concrete arrays, preserved content, exports/deps extracted
for (const entry of moduleEntries){
await resolveLocalManifest({
entry,
resolvedPaths: resolvedPaths[entry.id],
context
});
}
// Step 2: Auto-wire and validate dependency wiring
resolveModuleDependencies({
context
});
// Step 3: Full resolve — cross-module refs, preserved content
for (const entryId of Object.keys(context.modules)){
await resolveFullManifest({
entryId,
context
});
}
}
export default buildModuleDefs;