[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo foxxmd.github.io/komodo-import
compose docker import komodo toml
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: Transform final TOML to have multiline environment

FoxxMD (Aug 14, 2025, 4:22 PM UTC) ed61c712 617c66ce

+72 -2
+16
src/common/utils/utils.ts
··· 1 + import { searchAndReplace } from "@foxxmd/regex-buddy-core"; 2 + import { stripIndents } from "common-tags"; 3 + 1 4 export const isDebugMode = (): boolean => process.env.DEBUG_MODE === 'true'; 2 5 3 6 export function parseBool(value: any, prev: any = false): boolean { ··· 75 78 } 76 79 77 80 return result; 81 + } 82 + 83 + const SINGLE_LINE_ENV_REGEX = new RegExp(/environment = "{1}(.+?)"{1}(?:\n|$)/gms); //new RegExp(/environment = (".+")(?:\\n|$)/g); 84 + export const transformMultiline = (toml: string): string => { 85 + 86 + const transformed = toml.replaceAll(SINGLE_LINE_ENV_REGEX, (match, p1) => { 87 + return stripIndents`environment = """ 88 + ${p1.replaceAll('\\n', '\n').replace(/\n$/, '')} 89 + """ 90 + `.concat('\n'); 91 + }); 92 + 93 + return transformed; 78 94 }
+2 -2
src/index.ts
··· 6 6 import dayjs from 'dayjs'; 7 7 import timezone from 'dayjs/plugin/timezone.js'; 8 8 import utc from 'dayjs/plugin/utc.js'; 9 - import { isDebugMode, isUndefinedOrEmptyString, parseBool } from './common/utils/utils.js'; 9 + import { isDebugMode, isUndefinedOrEmptyString, parseBool, transformMultiline } from './common/utils/utils.js'; 10 10 import { parse, stringify } from 'smol-toml'; 11 11 import { _PartialStackConfig } from 'komodo_client/dist/types.js'; 12 12 import { TomlStack } from './common/infrastructure/tomlObjects.js'; ··· 94 94 let toml: string; 95 95 let logTomlData = isDebugMode(); 96 96 try { 97 - toml = stringify(data); 97 + toml = transformMultiline(stringify(data)); 98 98 } catch (e) { 99 99 logger.error(new Error('Could not produce TOML', {cause: e})); 100 100 logTomlData = true;
+54
tests/util.test.ts
··· 5 5 import withLocalTmpDir from 'with-local-tmp-dir'; 6 6 import { mkdir, writeFile, chmod, constants } from 'node:fs/promises'; 7 7 import path from 'path'; 8 + import { transformMultiline } from '../src/common/utils/utils.js'; 9 + import { stripIndent, stripIndents } from 'common-tags'; 8 10 9 11 describe('#Utils', function () { 10 12 ··· 147 149 it('Should remove trailing slash', function () { 148 150 expect(normalizeWebAddress(`${anIP}:5000/`).normal).to.eq(`http://${anIP}:5000`); 149 151 }); 152 + }); 153 + 154 + }); 155 + 156 + const environmentSample = ` 157 + [[stack]] 158 + name = "newtest" 159 + 160 + [stack.config] 161 + server = "test" 162 + run_directory = "/test" 163 + files_on_host = true 164 + environment = "A_TEST=foowarn\nB_VAR=bar\n" 165 + 166 + [[stack]] 167 + name = "test" 168 + 169 + [stack.config] 170 + server = "test" 171 + run_directory = "/test" 172 + files_on_host = true 173 + environment = "ANOTHER_TEST=foowarn\nBAAAR_VAR=bar\n" 174 + 175 + [[stack]] 176 + name = "testbar" 177 + 178 + [stack.config] 179 + server = "test" 180 + run_directory = "/test" 181 + files_on_host = true`; 182 + 183 + const expectedEnvironments = [ 184 + stripIndents`environment = """ 185 + A_TEST=foowarn 186 + B_VAR=bar 187 + """`, 188 + stripIndents`environment = """ 189 + ANOTHER_TEST=foowarn 190 + BAAAR_VAR=bar 191 + """` 192 + ] 193 + 194 + describe('#TOML', function() { 195 + 196 + it('replaces single line environment with multiline', function() { 197 + 198 + const s = transformMultiline(environmentSample); 199 + 200 + for(const e of expectedEnvironments) { 201 + expect(s).includes(e); 202 + } 203 + 150 204 }); 151 205 152 206 });