generated from polymech/site-template
stuff like that :)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define repositories to commit to
|
||||
# . refers to the current directory (polymech/site2)
|
||||
# ../polymech-astro refers to the sibling directory
|
||||
REPOS=("." "../polymech-astro")
|
||||
|
||||
# Store the optional commit message
|
||||
MSG="$1"
|
||||
|
||||
# Iterate over each repository
|
||||
for repo in "${REPOS[@]}"; do
|
||||
echo "--------------------------------------------------"
|
||||
echo "Processing repository: $repo"
|
||||
echo "--------------------------------------------------"
|
||||
|
||||
# Execute in a subshell to preserve current directory
|
||||
(
|
||||
cd "$repo" || { echo "Failed to enter $repo"; exit 1; }
|
||||
|
||||
# Add all changes
|
||||
git add -A .
|
||||
|
||||
# Commit
|
||||
if [ -n "$MSG" ]; then
|
||||
git commit -m "$MSG"
|
||||
else
|
||||
# If no message provided, let git open the editor
|
||||
git commit
|
||||
fi
|
||||
|
||||
# Pushing changes
|
||||
git push
|
||||
)
|
||||
done
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { quicktype, InputData, jsonInputForTargetLanguage } from 'quicktype-core';
|
||||
|
||||
const CONFIG_PATH = path.resolve('./app-config.json');
|
||||
const OUTPUT_SCHEMA_PATH = path.resolve('./src/app/config.schema.ts');
|
||||
const OUTPUT_DTS_PATH = path.resolve('./src/app/config.d.ts');
|
||||
|
||||
async function main() {
|
||||
console.log(`Reading config from ${CONFIG_PATH}...`);
|
||||
const configContent = fs.readFileSync(CONFIG_PATH, 'utf8');
|
||||
|
||||
// 1. Generate TypeScript Definitions (d.ts) FIRST
|
||||
console.log('Generating TypeScript definitions...');
|
||||
|
||||
const tsInput = jsonInputForTargetLanguage("ts");
|
||||
await tsInput.addSource({
|
||||
name: "AppConfig",
|
||||
samples: [configContent]
|
||||
});
|
||||
|
||||
const tsInputData = new InputData();
|
||||
tsInputData.addInput(tsInput);
|
||||
|
||||
const tsResult = await quicktype({
|
||||
inputData: tsInputData,
|
||||
lang: "ts",
|
||||
rendererOptions: {
|
||||
"just-types": "true",
|
||||
"acronym-style": "original"
|
||||
}
|
||||
});
|
||||
|
||||
const tsCode = tsResult.lines.join('\n');
|
||||
fs.writeFileSync(OUTPUT_DTS_PATH, tsCode);
|
||||
console.log(`Wrote TypeScript definitions to ${OUTPUT_DTS_PATH}`);
|
||||
|
||||
// 2. Generate Zod Schema from Types using ts-to-zod
|
||||
console.log('Generating Zod schema from types...');
|
||||
|
||||
try {
|
||||
const { execSync } = await import('child_process');
|
||||
// ts-to-zod <input> <output>
|
||||
// Use relative paths to avoid Windows path concatenation issues with ts-to-zod
|
||||
const relDts = path.relative(process.cwd(), OUTPUT_DTS_PATH);
|
||||
const relSchema = path.relative(process.cwd(), OUTPUT_SCHEMA_PATH);
|
||||
|
||||
execSync(`npx ts-to-zod "${relDts}" "${relSchema}"`, { stdio: 'inherit', cwd: process.cwd() });
|
||||
|
||||
// Append export type AppConfig
|
||||
fs.appendFileSync(OUTPUT_SCHEMA_PATH, `\nexport type AppConfig = z.infer<typeof appConfigSchema>;\n`);
|
||||
|
||||
console.log(`Wrote Zod schema to ${OUTPUT_SCHEMA_PATH}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to generate Zod schema:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Error fetching/generating config:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import handler from 'serve-handler';
|
||||
import http from 'http';
|
||||
import { PRODUCT_ROOT, FILE_SERVER_DEV } from '../src/app/config';
|
||||
|
||||
// Parse host and port from FILE_SERVER_DEV
|
||||
const [host, portStr] = FILE_SERVER_DEV.split(':');
|
||||
const port = parseInt(portStr, 10);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const server = http.createServer((request: any, response: any) => {
|
||||
return handler(request, response, {
|
||||
public: PRODUCT_ROOT(),
|
||||
headers: [
|
||||
{
|
||||
source: '**/*',
|
||||
headers: [{ key: 'Access-Control-Allow-Origin', value: '*' }]
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(port, host, () => {
|
||||
console.log(`Running at http://${host}:${port}`);
|
||||
console.log(`Serving files from: ${PRODUCT_ROOT()}`);
|
||||
});
|
||||
Reference in New Issue
Block a user