Skip to content

Commit

Permalink
feat(dev-cli): auto-set memory-limit flag based on module requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterFarber committed Aug 28, 2024
1 parent 17f5917 commit a1ea58d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
50 changes: 49 additions & 1 deletion dev-cli/src/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Deno */

import { Command, basename, resolve } from '../deps.js'
import { Command, basename, resolve, parse } from '../deps.js'
import { hostArgs, tagsArg } from '../utils.js'
import { VERSION } from '../versions.js'

Expand Down Expand Up @@ -42,6 +42,52 @@ function contractSourceArgs (contractWasmPath) {
]
}

/**
* Retrieves the memory limit based on the configuration preset or custom memory limit.
* @returns {string} The memory limit
*/
async function GetMemoryLimit () {
let memoryLimit = '256-mb'

const configPath = `${Deno.cwd()}/config.yml`
let config = null
try {
config = parse(await Deno.readTextFile(configPath))
} catch {
return memoryLimit
}

if (config) {
switch (config.preset) {
case 'xs':
memoryLimit = '64-mb'
break
case 'sm':
memoryLimit = '128-mb'
break
case 'md':
memoryLimit = '256-mb'
break
case 'lg':
memoryLimit = '256-mb'
break
case 'xl':
memoryLimit = '512-mb'
break
case 'xxl':
memoryLimit = '4096-mb'
break
default:
memoryLimit = '256-mb'
break
}
}
if (config?.memory_limit) {
memoryLimit = `${config.memoryLimit}-b`
}
return memoryLimit
}

/**
* TODO:
* - Validate existence of wallet
Expand All @@ -50,6 +96,8 @@ function contractSourceArgs (contractWasmPath) {
* - require confirmation and bypass with --yes
*/
export async function publish ({ wallet, host, tag, value }, contractWasmPath) {
tag.push('Memory-Limit')
value.push(await GetMemoryLimit())
const cmdArgs = [
...walletArgs(wallet),
...hostArgs(host),
Expand Down
1 change: 1 addition & 0 deletions dev-cli/src/deps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Command } from 'https://deno.land/x/[email protected]/command/mod.ts'
export { basename, resolve } from 'https://deno.land/[email protected]/path/mod.ts'
export { copy } from 'https://deno.land/[email protected]/fs/copy.ts'
export { parse } from 'jsr:@std/yaml'

0 comments on commit a1ea58d

Please sign in to comment.