-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { deepMapWithKeys } from '~/utils' | ||
import { expressionRegex } from './expressions' | ||
import { parseTemplateExpression } from './expressions' | ||
|
||
export const symbolRegex = /@@stax:([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})@@/g | ||
|
||
export function symbolizer(attributes: Record<string, any>, symbols: Record<string, any>): Record<string, any> { | ||
return deepMapWithKeys(attributes, (_path, key, value) => { | ||
return [symbolize(symbols, key), symbolize(symbols, value)] | ||
}) | ||
} | ||
|
||
function symbolize(symbols: Record<string, any>, value: any): any { | ||
if (!value || typeof(value) !== 'string') return value | ||
|
||
const matches = value.match(expressionRegex) | ||
if (!matches) return value | ||
|
||
let result = value | ||
for (const match of matches) { | ||
const expression = parseTemplateExpression(match) | ||
|
||
if (expression) { | ||
const uuid = crypto.randomUUID() | ||
value = `@@stax:${uuid}@@` | ||
symbols[uuid] = expression | ||
|
||
if (result == match) | ||
result = value | ||
else | ||
result = result.replace(match, value) | ||
} | ||
} | ||
return result | ||
} |
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,29 +1,34 @@ | ||
import { describe, it, expect, beforeEach } from 'bun:test' | ||
import { mkdirSync,rmSync } from 'fs' | ||
import { rmSync, mkdirSync } from 'fs' | ||
import { resolve } from '~/utils' | ||
import { dump } from '~/yamler' | ||
import Staxfile from '~/staxfile' | ||
import path from 'path' | ||
|
||
const fixturesDir = resolve('tests/fixtures') | ||
const cacheDir = resolve('tmp/tests-staxfile-cache') | ||
|
||
describe('Staxfile', () => { | ||
// let staxfile | ||
// const cacheDir = path.join(__dirname, '../../tmp/tests-staxfile-cache') | ||
let staxfile | ||
|
||
beforeEach(async () => { | ||
rmSync(cacheDir, { recursive: true, force: true }) | ||
mkdirSync(cacheDir, { recursive: true }) | ||
|
||
// beforeEach(() => { | ||
// rmSync(cacheDir, { recursive: true, force: true }) | ||
// mkdirSync(cacheDir, { recursive: true }) | ||
// staxfile = new Staxfile({ app: 'some_service', context: 'tests', source: './tests/fixtures', staxfile: './tests/fixtures/some_service.staxfile' }, { cacheDir }) | ||
// }) | ||
const config = { | ||
app: 'rails_app', | ||
context: 'tests', | ||
source: './tests/fixtures', | ||
staxfile: path.join(fixturesDir, 'rails_app.staxfile'), | ||
cache: true | ||
} | ||
staxfile = new Staxfile(config, { cacheDir }) | ||
await staxfile.load() | ||
}) | ||
|
||
// it('compiles', async () => { | ||
// await staxfile.compile({ force: true }) | ||
// // console.log(staxfile.config) | ||
// expect(staxfile.config.app).toBe('some_service') | ||
// expect(staxfile.config.staxfile).toBe(resolve('./tests/fixtures/some_service.staxfile')) | ||
// expect(staxfile.config.source).toBe(resolve('./tests/fixtures')) | ||
// expect(staxfile.config.workspace).toBe('/workspaces/some_service') | ||
// expect(staxfile.config.workspace_volume).toBe('some_service-workspace') | ||
// expect(staxfile.config.vars.rails_server_port).toBe(3000) | ||
// expect(staxfile.config.vars.ubuntu_version).toBe(24.04) | ||
// expect(staxfile.config.vars.ruby_version).toBe('2.0.1') | ||
// }) | ||
it('loads the correct app name', async () => { | ||
// console.log(staxfile) | ||
// console.log(dump(staxfile.compose)) | ||
// console.log(staxfile) | ||
}) | ||
}) |
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