diff --git a/src/customizer/Customizer.ts b/src/customizer/Customizer.ts index 98b3669..a51293d 100644 --- a/src/customizer/Customizer.ts +++ b/src/customizer/Customizer.ts @@ -14,6 +14,14 @@ export class Customizer { /** Custom instructions appended to transformPage's instruction block. */ protected customTransformInstructions: string[] = []; + // --- Local data folder --- + // Override in a derived class to change the local project folder name. + + /** Name of the local data folder created in the user's project directory. */ + get localFolder(): string { + return '.synthos'; + } + // --- Content folder paths --- // Override these in a derived class to point to your fork's folders. diff --git a/src/init.ts b/src/init.ts index fdf058c..aa4aa7b 100644 --- a/src/init.ts +++ b/src/init.ts @@ -7,6 +7,7 @@ import { getOutdatedThemes, parseThemeFilename } from "./themes"; import { Customizer } from './customizer'; export interface SynthOSConfig { + localFolder: string; pagesFolder: string; requiredPagesFolder: string; defaultPagesFolder: string; @@ -24,6 +25,7 @@ export function createConfig( customizer?: Customizer ): SynthOSConfig { return { + localFolder: pagesFolder, pagesFolder: path.join(process.cwd(), pagesFolder), requiredPagesFolder: customizer?.requiredPagesFolder ?? path.join(__dirname, '../required-pages'), defaultPagesFolder: customizer?.defaultPagesFolder ?? path.join(__dirname, '../default-pages'), @@ -43,7 +45,7 @@ export async function init(config: SynthOSConfig, includeDefaultPages: boolean = return false; } - console.log(`Initializing .synthos folder...`); + console.log(`Initializing ${config.localFolder} folder...`); // Create pages folder await ensureFolderExists(config.pagesFolder); @@ -54,7 +56,7 @@ export async function init(config: SynthOSConfig, includeDefaultPages: boolean = await saveFile(path.join(config.pagesFolder, 'settings.json.example'), JSON.stringify(DefaultSettings, null, 4)); // Setup default scripts - console.log(`Copying default scripts to .synthos folder...`); + console.log(`Copying default scripts to ${config.localFolder} folder...`); const scriptsFolder = path.join(config.pagesFolder, 'scripts'); await ensureFolderExists(scriptsFolder); switch (process.platform) { @@ -73,17 +75,17 @@ export async function init(config: SynthOSConfig, includeDefaultPages: boolean = break; } - await saveFile(path.join(scriptsFolder, 'example.sh'), '#!/bin/bash\n\n# This is an example script\n\n# You can run this script using the following command:\n# sh .synthos/scripts/example.sh\n\n# This script will print "Hello, World!" to the console\n\necho "Hello, World!"\n'); + await saveFile(path.join(scriptsFolder, 'example.sh'), `#!/bin/bash\n\n# This is an example script\n\n# You can run this script using the following command:\n# sh ${config.localFolder}/scripts/example.sh\n\n# This script will print "Hello, World!" to the console\n\necho "Hello, World!"\n`); // Setup default themes - console.log(`Copying default themes to .synthos folder...`); + console.log(`Copying default themes to ${config.localFolder} folder...`); const themesFolder = path.join(config.pagesFolder, 'themes'); await ensureFolderExists(themesFolder); await copyFiles(config.defaultThemesFolder, themesFolder); // Copy pages if (includeDefaultPages) { - console.log(`Copying default pages to .synthos folder...`); + console.log(`Copying default pages to ${config.localFolder} folder...`); await copyDefaultPages(config.defaultPagesFolder, config.pagesFolder); } @@ -94,7 +96,7 @@ async function repairMissingFolders(config: SynthOSConfig): Promise { // Rebuild scripts folder from defaults if missing const scriptsFolder = path.join(config.pagesFolder, 'scripts'); if (!await checkIfExists(scriptsFolder)) { - console.log(`Restoring default scripts to .synthos folder...`); + console.log(`Restoring default scripts to ${config.localFolder} folder...`); await ensureFolderExists(scriptsFolder); switch (process.platform) { case 'win32': @@ -111,13 +113,13 @@ async function repairMissingFolders(config: SynthOSConfig): Promise { await copyFile(path.join(config.defaultScriptsFolder, 'linux-terminal.json'), scriptsFolder); break; } - await saveFile(path.join(scriptsFolder, 'example.sh'), '#!/bin/bash\n\n# This is an example script\n\n# You can run this script using the following command:\n# sh .synthos/scripts/example.sh\n\n# This script will print "Hello, World!" to the console\n\necho "Hello, World!"\n'); + await saveFile(path.join(scriptsFolder, 'example.sh'), `#!/bin/bash\n\n# This is an example script\n\n# You can run this script using the following command:\n# sh ${config.localFolder}/scripts/example.sh\n\n# This script will print "Hello, World!" to the console\n\necho "Hello, World!"\n`); } // Rebuild themes folder from defaults if missing const themesFolder = path.join(config.pagesFolder, 'themes'); if (!await checkIfExists(themesFolder)) { - console.log(`Restoring default themes to .synthos folder...`); + console.log(`Restoring default themes to ${config.localFolder} folder...`); await ensureFolderExists(themesFolder); await copyFiles(config.defaultThemesFolder, themesFolder); } else { @@ -152,7 +154,7 @@ async function repairMissingFolders(config: SynthOSConfig): Promise { // No pages folder and no flat files — rebuild from defaults const htmlFiles = (await listFiles(config.pagesFolder)).filter(f => f.endsWith('.html')); if (htmlFiles.length === 0) { - console.log(`Restoring default pages to .synthos/pages/ folder...`); + console.log(`Restoring default pages to ${config.localFolder}/pages/ folder...`); await copyDefaultPages(config.defaultPagesFolder, config.pagesFolder); } else { await ensureFolderExists(pagesSubdir); @@ -160,7 +162,7 @@ async function repairMissingFolders(config: SynthOSConfig): Promise { } // Migrate any stray flat .html files from root into pages// - await migrateFlatPages(config.pagesFolder); + await migrateFlatPages(config.pagesFolder, config.localFolder); } function toTitleCase(name: string): string { @@ -171,12 +173,12 @@ function toTitleCase(name: string): string { .replace(/\b\w/g, c => c.toUpperCase()); } -async function migrateFlatPages(pagesFolder: string): Promise { +async function migrateFlatPages(pagesFolder: string, localFolder: string): Promise { const pagesSubdir = path.join(pagesFolder, 'pages'); const htmlFiles = (await listFiles(pagesFolder)).filter(f => f.endsWith('.html')); if (htmlFiles.length === 0) return; - console.log(`Migrating ${htmlFiles.length} page(s) to .synthos/pages/ folder...`); + console.log(`Migrating ${htmlFiles.length} page(s) to ${localFolder}/pages/ folder...`); await ensureFolderExists(pagesSubdir); const now = new Date().toISOString(); diff --git a/src/pages.ts b/src/pages.ts index b243fbf..81634e6 100644 --- a/src/pages.ts +++ b/src/pages.ts @@ -23,7 +23,7 @@ export interface PageInfo { export type PageMetadata = Omit; export async function loadPageMetadata(pagesFolder: string, name: string, fallbackFolder?: string): Promise { - // 1. Try user override: .synthos/pages//page.json + // 1. Try user override: /pages//page.json const metadataPath = path.join(pagesFolder, 'pages', name, 'page.json'); if (await checkIfExists(metadataPath)) { try { diff --git a/src/service/useApiRoutes.ts b/src/service/useApiRoutes.ts index 0407c24..8e00c96 100644 --- a/src/service/useApiRoutes.ts +++ b/src/service/useApiRoutes.ts @@ -794,14 +794,14 @@ Return ONLY the JSON object.`}; // Backup original page to .migrated/ before overwriting const migratedFolder = path.join(config.pagesFolder, '.migrated'); - // Handle legacy flat file (.synthos/pagename.html) + // Handle legacy flat file (/pagename.html) const flatPath = path.join(config.pagesFolder, `${name}.html`); if (await checkIfExists(flatPath)) { await copyFile(flatPath, migratedFolder); await deleteFile(flatPath); } - // Handle folder-based page (.synthos/pages/name/) + // Handle folder-based page (/pages/name/) const folderPath = path.join(config.pagesFolder, 'pages', name); if (await checkIfExists(folderPath)) { await copyFolderRecursive(folderPath, path.join(migratedFolder, name)); diff --git a/src/synthos-cli.ts b/src/synthos-cli.ts index 9e28ae9..a1c31c0 100644 --- a/src/synthos-cli.ts +++ b/src/synthos-cli.ts @@ -17,7 +17,7 @@ export async function run() { default: 4242 }) .option('pages', { - describe: `Include default pages when initializing a new .synthos folder.`, + describe: `Include default pages when initializing a new local folder.`, type: 'boolean', default: true }) @@ -33,7 +33,7 @@ export async function run() { }) .demandOption([]); }, async (args) => { - const config = createConfig('.synthos', { debug: args.debug, debugPageUpdates: args.debugPageUpdates }, customizer); + const config = createConfig(customizer.localFolder, { debug: args.debug, debugPageUpdates: args.debugPageUpdates }, customizer); await init(config, args.pages); await server(config, customizer).listen(args.port, async () => { console.log(`SynthOS server is running on http://localhost:${args.port}`);