Inline getting the workspace paths.

pull/5370/head
Evan Sangaline 9 months ago committed by Aniket
parent 53aa914b7e
commit 6e41b58927
  1. 49
      libs/remix-ws-templates/src/script-templates/sindri/utils.ts

@ -22,15 +22,28 @@ const getSindriManifest = async () => {
return JSON.parse(sindriJson) return JSON.parse(sindriJson)
} }
const normalizePath = (path: string): string => {
while (path.startsWith('/') || path.startsWith('./')) {
path = path.replace(/^(\.\/|\/)/, '')
}
return path
}
/** /**
* Create a map of file paths to `File` objects for either all or a subset of files in the workspace. * Compile the circuit.
* *
* @param {RegExp | null} includeRegex - A regular expression to limit the included files to those * @param {string | string[] | null} tags - The tag or tags to use when compiling the circuit.
* whose paths match. If not specified, then all paths are included. * @returns {CircuitInfoResponse} compiled circuit
* @param {RegExp | null} excludeRegex - A regular expression to exclude files whose paths match.
* @returns {Promise<{[path: string]: File}>} A map of file paths to `File` objects.
*/ */
const getWorkspaceFilesByPath = async (includeRegex: RegExp | null = null, excludeRegex: RegExp | null = null): Promise<{[path: string]: File}> => { export const compile = async (tags: string | string[] | null = ['latest']): CircuitInfoResponse => {
await authorize()
const sindriManifest = await getSindriManifest()
// Create a map from file paths to `File` objects for (almost) all files in the workspace.
// We exclude `.deps/` files because these are resolved to more intuitive locations so they can
// be used by the circuit without specifying a complex import path. We'll merge the dependencies
// into the files at their expected import paths in a later step.
const excludeRegex = /^\.deps\//
const filesByPath: {[path: string]: File} = {} const filesByPath: {[path: string]: File} = {}
interface Workspace { interface Workspace {
children?: Workspace children?: Workspace
@ -40,35 +53,13 @@ const getWorkspaceFilesByPath = async (includeRegex: RegExp | null = null, exclu
const childQueue: Array<[string, Workspace]> = Object.entries(workspace) const childQueue: Array<[string, Workspace]> = Object.entries(workspace)
while (childQueue.length > 0) { while (childQueue.length > 0) {
const [path, child] = childQueue.pop() const [path, child] = childQueue.pop()
if ('content' in child && (includeRegex === null || includeRegex.test(path)) && (excludeRegex === null || !excludeRegex.test(path))) { if ('content' in child && !excludeRegex.test(path)) {
filesByPath[path] = new File([child.content], path) filesByPath[path] = new File([child.content], path)
} }
if ('children' in child) { if ('children' in child) {
childQueue.push(...Object.entries(child.children)) childQueue.push(...Object.entries(child.children))
} }
} }
return filesByPath
}
const normalizePath = (path: string): string => {
while (path.startsWith('/') || path.startsWith('./')) {
path = path.replace(/^(\.\/|\/)/, '')
}
return path
}
/**
* Compile the circuit.
*
* @param {string | string[] | null} tags - The tag or tags to use when compiling the circuit.
* @returns {CircuitInfoResponse} compiled circuit
*/
export const compile = async (tags: string | string[] | null = ['latest']): CircuitInfoResponse => {
await authorize()
const sindriManifest = await getSindriManifest()
// Create a map from file paths to `File` objects for all files in the workspace.
const filesByPath = await getWorkspaceFilesByPath(null, /^\.deps\//)
// Merge any of the circuit's resolved dependencies into the files at their expected import paths. // Merge any of the circuit's resolved dependencies into the files at their expected import paths.
if (sindriManifest.circuitType === 'circom') { if (sindriManifest.circuitType === 'circom') {

Loading…
Cancel
Save