#!/usr/bin/env node 'use strict'; const fs = require('fs-extra'); const path = require('path'); const endent = require('endent'); // Update theme names list in codemirror-editing-hook.js async function getThemes() { const p = path.join(__dirname, '..', 'vendor/codemirror/theme/'); const files = await fs.readdir(p); return files .filter(name => name.endsWith('.css')) .map(name => name.replace('.css', '')) .sort(); } async function updateHook(themes) { const fileName = path.join(__dirname, '..', 'edit/codemirror-themes.js'); fs.writeFile(fileName, endent` /* exported CODEMIRROR_THEMES */ // this file is generated by update-codemirror-themes.js 'use strict'; const CODEMIRROR_THEMES = ${JSON.stringify(themes, null, 2)}; `.replace(/"/g, "'") + '\n'); } function exit(err) { if (err) { console.error(err); } process.exit(err ? 1 : 0); } getThemes() .then(themes => updateHook(themes)) .then(() => console.log('\x1b[32m%s\x1b[0m', 'codemirror themes list updated')) .catch(exit);