gpreview
Version:
Preview Ghost themes locally without a full Ghost installation
59 lines • 2.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
const server_1 = require("../server/server");
const watcher_1 = require("../utils/watcher");
const program = new commander_1.Command();
program
.name('gpreview')
.description('Preview Ghost themes with mock data')
.version('1.0.0')
.argument('[theme-path]', 'Path to Ghost theme directory', '.')
.option('-p, --port <number>', 'Port to run server on', '3000')
.option('-d, --data <path>', 'Path to custom mock data JSON file')
.option('-w, --watch', 'Watch theme files for changes and auto-reload')
.action(async (themePath, options) => {
try {
const resolvedThemePath = path_1.default.resolve(themePath);
if (!(0, fs_1.existsSync)(resolvedThemePath)) {
console.error(chalk_1.default.red(`❌ Theme directory not found: ${resolvedThemePath}`));
process.exit(1);
}
if (options.data) {
const dataPath = path_1.default.resolve(options.data);
if (!(0, fs_1.existsSync)(dataPath)) {
console.error(chalk_1.default.red(`❌ Data file not found: ${dataPath}`));
process.exit(1);
}
}
const server = new server_1.PreviewServer(resolvedThemePath, {
port: parseInt(options.port, 10),
dataPath: options.data,
});
await server.start();
if (options.watch) {
console.log(chalk_1.default.blue('👁 Watching for theme changes...'));
const watcher = (0, watcher_1.createFileWatcher)(resolvedThemePath, () => {
console.log(chalk_1.default.yellow('🔄 Theme files changed. Please restart the server.'));
});
process.on('SIGINT', () => {
watcher.close();
process.exit(0);
});
}
}
catch (error) {
console.error(chalk_1.default.red('❌ Error starting preview server:'));
console.error(error);
process.exit(1);
}
});
program.parse();
//# sourceMappingURL=index.js.map