mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: dark theme: add (#332)
This commit is contained in:
parent
35622082a9
commit
6bc4f3ec26
23 changed files with 186 additions and 51 deletions
33
server/theme.mjs
Normal file
33
server/theme.mjs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import path, {dirname} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import process from 'node:process';
|
||||
import fs from 'node:fs';
|
||||
import fullstore from 'fullstore';
|
||||
import nanomemoizeDefault from 'nano-memoize';
|
||||
import readFilesSync from '@cloudcmd/read-files-sync';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const isMap = (a) => /\.map$/.test(a);
|
||||
const not = (fn) => (a) => !fn(a);
|
||||
|
||||
const _isDev = fullstore(process.env.NODE_ENV === 'development');
|
||||
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
||||
|
||||
export const isDev = _isDev;
|
||||
|
||||
export const getThemes = ({isDev = _isDev()} = {}) => {
|
||||
return readFilesSyncMemo(isDev);
|
||||
};
|
||||
|
||||
const {nanomemoize} = nanomemoizeDefault;
|
||||
|
||||
const readFilesSyncMemo = nanomemoize((isDev) => {
|
||||
const dist = getDist(isDev);
|
||||
const themesDir = path.join(__dirname, '..', dist, 'themes');
|
||||
const names = fs
|
||||
.readdirSync(themesDir)
|
||||
.filter(not(isMap));
|
||||
|
||||
return readFilesSync(themesDir, names, 'utf8');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue