Files
portal/scripts/local-content.mjs
T

20 lines
1010 B
JavaScript

// Prepare a disposable content repository for Sveltia's local folder picker.
import { cpSync, existsSync, mkdirSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
const root = fileURLToPath(new URL('../', import.meta.url));
const local = join(root, '.tmp/content');
if (!existsSync(local)) {
mkdirSync(local, { recursive: true });
cpSync(join(root, 'sample-content/pages'), join(local, 'pages'), { recursive: true });
cpSync(join(root, 'sample-content/uploads'), join(local, 'uploads'), { recursive: true });
}
if (!existsSync(join(local, '.git'))) {
execFileSync('git', ['init', '--quiet', '--initial-branch=main', local], { stdio: 'inherit' });
}
execFileSync(process.execPath, [join(root, 'scripts/content.mjs'), local], { stdio: 'inherit' });
console.log(`In Sveltia, choose Work with Local Repository and select: ${local}`);
console.log('After saving, run: npm run content:sync -- .tmp/content');