-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): separate tableOptions, add renderPrototype, fix prototype …
…config
- Loading branch information
Showing
13 changed files
with
376 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { loadStoreConfig, parseStoreConfig } from "./config/loadStoreConfig.js"; | ||
import { renderTablesFromConfig } from "./render-solidity/renderTablesFromConfig.js"; | ||
import { getAllTableOptions } from "./render-solidity/tableOptions.js"; | ||
import { renderTable } from "./render-solidity/renderTable.js"; | ||
|
||
export type { StoreUserConfig, StoreConfig } from "./config/loadStoreConfig.js"; | ||
|
||
export { loadStoreConfig, parseStoreConfig, renderTablesFromConfig, renderTable }; | ||
export { loadStoreConfig, parseStoreConfig, getAllTableOptions, renderTable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import path from "path"; | ||
import { StoreConfig } from "../config/loadStoreConfig.js"; | ||
import { ImportDatum, RenderPrototypeOptions, RenderTableForPrototype } from "./types.js"; | ||
import { TableOptions } from "./tableOptions.js"; | ||
|
||
export interface PrototypeOptions { | ||
outputDirectory: string; | ||
prototypeName: string; | ||
renderOptions: RenderPrototypeOptions; | ||
} | ||
|
||
export function getAllPrototypeOptions( | ||
config: StoreConfig, | ||
allTablesOptions: TableOptions[], | ||
srcDirectory: string | ||
): PrototypeOptions[] { | ||
const options = []; | ||
for (const prototypeName of Object.keys(config.prototypes)) { | ||
const prototypeData = config.prototypes[prototypeName]; | ||
const outputDirectory = path.join(srcDirectory, prototypeData.directory); | ||
|
||
const tablesOptions = allTablesOptions.filter(({ tableName }) => | ||
Object.keys(prototypeData.tables).includes(tableName) | ||
); | ||
const primaryKeys = tablesOptions[0].renderOptions.primaryKeys; | ||
|
||
// list of any symbols that need to be imported | ||
const imports: ImportDatum[] = []; | ||
|
||
const tableConfigs = Object.keys(prototypeData.tables).map((tableName): RenderTableForPrototype => { | ||
const { default: tableDefault } = prototypeData.tables[tableName]; | ||
const tableOptions = tablesOptions.find((val) => val.tableName === tableName); | ||
if (tableOptions === undefined) throw new Error(`No render options found for table ${tableName}`); | ||
|
||
const { | ||
libraryName: tableLibraryName, | ||
structName, | ||
imports: tableImports, | ||
staticRouteData, | ||
} = tableOptions.renderOptions; | ||
|
||
const importTableRelativePath = | ||
"./" + path.relative(outputDirectory, path.join(tableOptions.outputDirectory, tableOptions.tableName)) + ".sol"; | ||
imports.push({ | ||
symbol: tableLibraryName, | ||
path: importTableRelativePath, | ||
pathFromSrc: tableOptions.outputDirectory, | ||
}); | ||
if (structName !== undefined) { | ||
imports.push({ | ||
symbol: tableLibraryName, | ||
path: importTableRelativePath, | ||
pathFromSrc: tableOptions.outputDirectory, | ||
}); | ||
} | ||
for (const importDatum of tableImports) { | ||
imports.push({ | ||
...importDatum, | ||
path: "./" + path.relative(outputDirectory, importDatum.pathFromSrc) + ".sol", | ||
}); | ||
} | ||
|
||
const fields = tableOptions.renderOptions.fields.map((field) => { | ||
return { | ||
...field, | ||
default: typeof tableDefault === "object" ? tableDefault[field.name] : undefined, | ||
}; | ||
}); | ||
|
||
if (staticRouteData === undefined) throw new Error("Prototypes with table id arguments are not supported"); | ||
|
||
return { | ||
libraryName: tableLibraryName, | ||
structName, | ||
staticRouteData, | ||
fields, | ||
default: typeof structName !== "undefined" && typeof tableDefault === "string" ? tableDefault : undefined, | ||
}; | ||
}); | ||
|
||
options.push({ | ||
outputDirectory, | ||
prototypeName, | ||
renderOptions: { | ||
imports, | ||
libraryName: prototypeName, | ||
primaryKeys, | ||
tables: tableConfigs, | ||
}, | ||
}); | ||
} | ||
return options; | ||
} |
Oops, something went wrong.