Skip to content

Commit

Permalink
use specific fns instead of massive paths obj (#1005)
Browse files Browse the repository at this point in the history
* use specific fns instead of massive paths obj

* lint
  • Loading branch information
goastler authored Jan 31, 2024
1 parent 8968ba9 commit d279e40
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 143 deletions.
244 changes: 138 additions & 106 deletions dev/config/src/projectInfo.ts
Original file line number Diff line number Diff line change
@@ -1,108 +1,140 @@
import fs from 'fs'

export const getContractNames = () => {
return ['captcha', 'common', 'proxy']
}

export type Paths = {
root: string
dev: string
demos: string
contract: string
protocol: string
packages: string
config: string
scripts: string
protocolCli: string
protocolDist: string
clientExample: string
clientExampleServer: string
clientBundleExample: string
dappExample: string
common: string
api: string
cli: string
util: string
database: string
datasets: string
datasetsFs: string
env: string
fileServer: string
procaptcha: string
procaptchaReact: string
procaptchaBundle: string
provider: string
server: string
typesDatabase: string
typesEnv: string
types: string
contractPackagesDir: string
}

export const getPaths = (): Paths => {
const root = new URL('../../..', import.meta.url).pathname.slice(0, -1)
const dev = `${root}/dev`
const packages = `${root}/packages`
const protocol = `${root}/protocol`
const demos = `${root}/demos`
const contract = `${packages}/contract`
const types = `${packages}/types`
const config = `${dev}/config`
const scripts = `${dev}/scripts`
const protocolCli = `${protocol}/dist/cli`
const protocolDist = `${protocol}/target/ink`
const clientExample = `${demos}/client-example`
const clientExampleServer = `${demos}/client-example-server`
const clientBundleExample = `${demos}/client-bundle-example`
const dappExample = `${demos}/dapp-example`
const common = `${packages}/common`
const api = `${packages}/api`
const cli = `${packages}/cli`
const util = `${packages}/util`
const database = `${packages}/database`
const datasets = `${packages}/datasets`
const datasetsFs = `${packages}/datasets-fs`
const env = `${packages}/env`
const fileServer = `${packages}/file-server`
const procaptcha = `${packages}/procaptcha`
const procaptchaReact = `${packages}/procaptcha-react`
const procaptchaBundle = `${packages}/procaptcha-bundle`
const provider = `${packages}/provider`
const server = `${packages}/server`
const typesDatabase = `${packages}/types-database`
const typesEnv = `${packages}/types-env`
const contractPackagesDir = `${root}/contracts`

return {
contractPackagesDir,
root,
dev,
demos,
contract,
protocol,
packages,
config,
scripts,
protocolCli,
protocolDist,
clientExample,
clientExampleServer,
clientBundleExample,
dappExample,
common,
api,
cli,
util,
database,
datasets,
datasetsFs,
env,
fileServer,
procaptcha,
procaptchaReact,
procaptchaBundle,
provider,
server,
typesDatabase,
typesEnv,
types,
}
return fs.readdirSync(getProtocolContractsDir()).filter((name) => {
// test is dir
return fs.statSync(`${getProtocolContractsDir()}/${name}`).isDirectory()
})
}

export const getRootDir = () => {
return new URL('../../..', import.meta.url).pathname.slice(0, -1)
}

export const getDevDir = () => {
return `${getRootDir()}/dev`
}

export const getDemosDir = () => {
return `${getRootDir()}/demos`
}

export const getContractDir = () => {
return `${getRootDir()}/packages/contract`
}

export const getProtocolDir = () => {
return `${getRootDir()}/protocol`
}

export const getPackagesDir = () => {
return `${getRootDir()}/packages`
}

export const getConfigPkgDir = () => {
return `${getDevDir()}/config`
}

export const getScriptsPkgDir = () => {
return `${getDevDir()}/scripts`
}

export const getProtocolCliDir = () => {
return `${getProtocolDir()}/dist/cli`
}

export const getProtocolDistDir = () => {
return `${getProtocolDir()}/target/ink`
}

export const getClientExampleDir = () => {
return `${getDemosDir()}/client-example`
}

export const getClientExampleServerDir = () => {
return `${getDemosDir()}/client-example-server`
}

export const getClientBundleExampleDir = () => {
return `${getDemosDir()}/client-bundle-example`
}

export const getDappExampleDir = () => {
return `${getDemosDir()}/dapp-example`
}

export const getCommonPkgDir = () => {
return `${getPackagesDir()}/common`
}

export const getApiPkgDir = () => {
return `${getPackagesDir()}/api`
}

export const getCliPkgDir = () => {
return `${getPackagesDir()}/cli`
}

export const getUtilPkgDir = () => {
return `${getPackagesDir()}/util`
}

export const getDatabasePkgDir = () => {
return `${getPackagesDir()}/database`
}

export const getDatasetsPkgDir = () => {
return `${getPackagesDir()}/datasets`
}

export const getDatasetsFsPkgDir = () => {
return `${getPackagesDir()}/datasets-fs`
}

export const getEnvPkgDir = () => {
return `${getPackagesDir()}/env`
}

export const getFileServerPkgDir = () => {
return `${getPackagesDir()}/file-server`
}

export const getProcaptchaPkgDir = () => {
return `${getPackagesDir()}/procaptcha`
}

export const getProcaptchaReactPkgDir = () => {
return `${getPackagesDir()}/procaptcha-react`
}

export const getProcaptchaBundlePkgDir = () => {
return `${getPackagesDir()}/procaptcha-bundle`
}

export const getProviderPkgDir = () => {
return `${getPackagesDir()}/provider`
}

export const getServerPkgDir = () => {
return `${getPackagesDir()}/server`
}

export const getTypesDatabasePkgDir = () => {
return `${getPackagesDir()}/types-database`
}

export const getTypesEnvPkgDir = () => {
return `${getPackagesDir()}/types-env`
}

export const getTypesPkgDir = () => {
return `${getPackagesDir()}/types`
}

export const getContractsDir = () => {
return `${getRootDir()}/contracts`
}

export const getProtocolContractsDir = () => {
return `${getProtocolDir()}/contracts`
}
29 changes: 0 additions & 29 deletions dev/config/src/tests/paths.test.ts

This file was deleted.

11 changes: 5 additions & 6 deletions dev/scripts/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { LogLevel, getLogger } from '@prosopo/common'
import { deployDapp, deployProtocol } from '../contract/deploy/index.js'
import { exec } from '../util/index.js'
import { getContractNames, getPaths } from '@prosopo/config'
import { getContractNames, getContractsDir, getProtocolDistDir, getScriptsPkgDir } from '@prosopo/config'
import { getEnv, loadEnv } from '@prosopo/cli'
import { getLogLevel } from '@prosopo/common'
import { hideBin } from 'yargs/helpers'
Expand All @@ -25,7 +25,6 @@ import path from 'path'
import setVersion from '../scripts/setVersion.js'
import yargs from 'yargs'

const paths = getPaths()
const rootDir = path.resolve('.')

loadEnv(rootDir)
Expand Down Expand Up @@ -106,8 +105,8 @@ export async function processArgs(args: string[]) {
(yargs) => yargs,
async (argv) => {
const env = getEnv()
const paths = getPaths()
await exec(`cp -v ${paths.scripts}/env.${env} ${paths.scripts}/.env.${env}`)
const scripts = getScriptsPkgDir()
await exec(`cp -v ${scripts}/env.${env} ${scripts}/.env.${env}`)
},
[]
)
Expand Down Expand Up @@ -154,9 +153,9 @@ export async function processArgs(args: string[]) {
handler: async (argv) => {
const contracts = getContractNames()
for (const contract of contracts) {
const inDir = `${paths.protocolDist}/${contract}`
const inDir = `${getProtocolDistDir()}/${contract}`
await exec(
`node dist/cli/index.js import_contract --in=${inDir} --out=${paths.contractPackagesDir}/${contract}/src`
`node dist/cli/index.js import_contract --in=${inDir} --out=${getContractsDir()}/${contract}/src`
)
}
},
Expand Down
4 changes: 2 additions & 2 deletions dev/scripts/src/scripts/setVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLogLevel, getLogger } from '@prosopo/common'
import { getPaths } from '@prosopo/config'
import { getRootDir } from '@prosopo/config'
import { loadEnv } from '@prosopo/cli'
import { parse, stringify } from '@iarna/toml'
import fs from 'fs'
Expand Down Expand Up @@ -53,7 +53,7 @@ const find = (pth: string, filter: (pth: string) => boolean): string[] => {
export default async function setVersion(version: string, ignore?: string[]) {
log.info('Setting version to ', version)
version = parseVersion(version)
const root = getPaths().root
const root = getRootDir()
const ignorePaths = ['node_modules', 'cargo-cache', ...(ignore ?? [])]
log.debug('Ignoring paths: ', ignorePaths)
// walk through all files finding .json or .toml
Expand Down

0 comments on commit d279e40

Please sign in to comment.