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
|
|
@ -21,7 +21,7 @@ import modulas from './modulas.js';
|
|||
import userMenu from './user-menu.mjs';
|
||||
import rest from './rest/index.js';
|
||||
import route from './route.mjs';
|
||||
import validate from './validate.js';
|
||||
import * as validate from './validate.mjs';
|
||||
import prefixer from './prefixer.js';
|
||||
import terminal from './terminal.js';
|
||||
import distribute from './distribute/index.js';
|
||||
|
|
@ -64,7 +64,7 @@ function cloudcmd(params) {
|
|||
if (/root/.test(name))
|
||||
validate.root(value, config);
|
||||
|
||||
if (/editor|packer|columns/.test(name))
|
||||
if (/editor|packer|themes/.test(name))
|
||||
validate[name](value);
|
||||
|
||||
if (/prefix/.test(name))
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
const fullstore = require('fullstore');
|
||||
const process = require('node:process');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const {nanomemoize} = require('nano-memoize');
|
||||
const readFilesSync = require('@cloudcmd/read-files-sync');
|
||||
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 {nanomemoize} = nanomemoizeDefault;
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const isMap = (a) => /\.map$/.test(a);
|
||||
const not = (fn) => (a) => !fn(a);
|
||||
|
||||
|
|
@ -19,9 +20,9 @@ const defaultColumns = {
|
|||
const _isDev = fullstore(process.env.NODE_ENV === 'development');
|
||||
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
|
||||
|
||||
module.exports.isDev = _isDev;
|
||||
export const isDev = _isDev;
|
||||
|
||||
module.exports.getColumns = ({isDev = _isDev()} = {}) => {
|
||||
export const getColumns = ({isDev = _isDev()} = {}) => {
|
||||
const columns = readFilesSyncMemo(isDev);
|
||||
|
||||
return {
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
'use strict';
|
||||
import {dirname} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'supertape';
|
||||
import fs from 'node:fs';
|
||||
import {getColumns, isDev} from './columns.mjs';
|
||||
|
||||
const test = require('supertape');
|
||||
const fs = require('node:fs');
|
||||
const {getColumns, isDev} = require('./columns');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
test('columns: prod', (t) => {
|
||||
const columns = getColumns({
|
||||
|
|
@ -13,8 +13,9 @@ import {contentType} from 'mime-types';
|
|||
import root from './root.js';
|
||||
import prefixer from './prefixer.js';
|
||||
import CloudFunc from '../common/cloudfunc.js';
|
||||
import {getColumns} from './columns.js';
|
||||
import Template from './template.js';
|
||||
import {getColumns} from './columns.mjs';
|
||||
import {getThemes} from './theme.mjs';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const {stringify} = JSON;
|
||||
|
|
@ -164,6 +165,7 @@ function indexProcessing(config, options) {
|
|||
prefix: getPrefix(config),
|
||||
config: stringify(config('*')),
|
||||
columns: getColumns()[config('columns')],
|
||||
themes: getThemes()[config('theme')],
|
||||
});
|
||||
|
||||
return data;
|
||||
|
|
|
|||
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');
|
||||
});
|
||||
31
server/themes.spec.mjs
Normal file
31
server/themes.spec.mjs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {dirname} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import test from 'supertape';
|
||||
import fs from 'node:fs';
|
||||
import {getThemes, isDev} from './theme.mjs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
test('themes: dev', (t) => {
|
||||
const themes = getThemes({
|
||||
isDev: true,
|
||||
});
|
||||
|
||||
const css = fs.readFileSync(`${__dirname}/../css/themes/dark.css`, 'utf8');
|
||||
|
||||
t.equal(themes.dark, css);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('themes: no args', (t) => {
|
||||
const currentIsDev = isDev();
|
||||
isDev(true);
|
||||
const themes = getThemes();
|
||||
|
||||
const css = fs.readFileSync(`${__dirname}/../css/themes/light.css`, 'utf8');
|
||||
isDev(currentIsDev);
|
||||
|
||||
t.equal(themes.light, css);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
'use strict';
|
||||
import {statSync as _statSync} from 'node:fs';
|
||||
import tryCatch from 'try-catch';
|
||||
import _exit from './exit.js';
|
||||
import {getColumns as _getColumns} from './columns.mjs';
|
||||
import {getThemes as _getThemes} from './theme.mjs';
|
||||
|
||||
const {statSync: _statSync} = require('node:fs');
|
||||
const tryCatch = require('try-catch');
|
||||
|
||||
const _exit = require('./exit');
|
||||
const {getColumns: _getColumns} = require('./columns');
|
||||
const isString = (a) => typeof a === 'string';
|
||||
|
||||
module.exports.root = (dir, config, {exit = _exit, statSync = _statSync} = {}) => {
|
||||
export const root = (dir, config, {exit = _exit, statSync = _statSync} = {}) => {
|
||||
if (!isString(dir))
|
||||
throw Error('dir should be a string');
|
||||
|
||||
|
|
@ -23,21 +22,21 @@ module.exports.root = (dir, config, {exit = _exit, statSync = _statSync} = {}) =
|
|||
return exit('cloudcmd --root: %s', error.message);
|
||||
};
|
||||
|
||||
module.exports.editor = (name, {exit = _exit} = {}) => {
|
||||
export const editor = (name, {exit = _exit} = {}) => {
|
||||
const reg = /^(dword|edward|deepword)$/;
|
||||
|
||||
if (!reg.test(name))
|
||||
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
|
||||
};
|
||||
|
||||
module.exports.packer = (name, {exit = _exit} = {}) => {
|
||||
export const packer = (name, {exit = _exit} = {}) => {
|
||||
const reg = /^(tar|zip)$/;
|
||||
|
||||
if (!reg.test(name))
|
||||
exit('cloudcmd --packer: could be "tar" or "zip" only');
|
||||
};
|
||||
|
||||
module.exports.columns = (type, {exit = _exit, getColumns = _getColumns} = {}) => {
|
||||
export const columns = (type, {exit = _exit, getColumns = _getColumns} = {}) => {
|
||||
const addQuotes = (a) => `"${a}"`;
|
||||
const all = Object
|
||||
.keys(getColumns())
|
||||
|
|
@ -51,3 +50,18 @@ module.exports.columns = (type, {exit = _exit, getColumns = _getColumns} = {}) =
|
|||
if (!all.includes(type))
|
||||
exit(`cloudcmd --columns: can be only one of: ${names}`);
|
||||
};
|
||||
|
||||
export const theme = (type, {exit = _exit, getThemes = _getThemes} = {}) => {
|
||||
const addQuotes = (a) => `"${a}"`;
|
||||
const all = Object
|
||||
.keys(getThemes())
|
||||
.concat('');
|
||||
|
||||
const names = all
|
||||
.filter(Boolean)
|
||||
.map(addQuotes)
|
||||
.join(', ');
|
||||
|
||||
if (!all.includes(type))
|
||||
exit(`cloudcmd --theme: can be only one of: ${names}`);
|
||||
};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import {test, stub} from 'supertape';
|
||||
import tryCatch from 'try-catch';
|
||||
import validate from './validate.js';
|
||||
import * as validate from './validate.mjs';
|
||||
import cloudcmd from './cloudcmd.mjs';
|
||||
|
||||
test('validate: root: bad', (t) => {
|
||||
|
|
@ -102,3 +102,32 @@ test('validate: columns: wrong', (t) => {
|
|||
t.calledWith(exit, [msg], 'should call exit');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate: theme', (t) => {
|
||||
const exit = stub();
|
||||
|
||||
validate.theme('dark', {
|
||||
exit,
|
||||
});
|
||||
|
||||
t.notCalled(exit, 'should not call exit');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('validate: theme: wrong', (t) => {
|
||||
const getThemes = stub().returns({
|
||||
light: '',
|
||||
dark: '',
|
||||
});
|
||||
|
||||
const exit = stub();
|
||||
const msg = 'cloudcmd --theme: can be only one of: "light", "dark"';
|
||||
|
||||
validate.theme('hello', {
|
||||
exit,
|
||||
getThemes,
|
||||
});
|
||||
|
||||
t.calledWith(exit, [msg], 'should call exit');
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue