chore: cloudcmd

This commit is contained in:
coderiaser 2026-01-15 22:14:01 +02:00
parent 6e778a35ba
commit 4b84d20bb0
17 changed files with 121 additions and 132 deletions

View file

@ -12,11 +12,11 @@ const {initSortPanel, sortPanel} = require('./sort.mjs');
const isDev = process.env.NODE_ENV === 'development';
module.exports = async (config) => {
window.Util = require('../common/util');
window.CloudFunc = require('../common/cloudfunc');
globalThis.Util = require('../common/util');
globalThis.CloudFunc = require('../common/cloudfunc');
window.DOM = require('./dom');
window.CloudCmd = require('./client');
globalThis.DOM = require('./dom');
globalThis.CloudCmd = require('./client');
await register(config);
@ -29,13 +29,13 @@ module.exports = async (config) => {
globalThis.CloudCmd.init(prefix, config);
if (window.CloudCmd.config('menu') === 'aleman')
if (globalThis.CloudCmd.config('menu') === 'aleman')
setTimeout(() => {
import('https://esm.sh/@putout/processor-html');
import('https://esm.sh/@putout/bundle');
}, 100);
};
window.CloudCmd = module.exports;
globalThis.CloudCmd = module.exports;
function getPrefix(prefix) {
if (!prefix)
@ -51,7 +51,7 @@ const onUpdateFound = wraptile(async (config) => {
if (isDev)
return;
const {DOM} = window;
const {DOM} = globalThis;
const prefix = getPrefix(config.prefix);
await load.js(`${prefix}/dist/cloudcmd.common.js`);
@ -60,7 +60,7 @@ const onUpdateFound = wraptile(async (config) => {
console.log('cloudcmd: sw: updated');
DOM.Events.removeAll();
window.CloudCmd(config);
globalThis.CloudCmd(config);
});
async function register(config) {

View file

@ -11,10 +11,10 @@ const returns = wraptile(id);
const {_CURRENT_FILE} = currentFile;
test('current-file: setCurrentName: setAttribute', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const {setAttribute} = current;
@ -23,17 +23,17 @@ test('current-file: setCurrentName: setAttribute', (t) => {
t.calledWith(setAttribute, ['data-name', 'js-file-aGVsbG8='], 'should call setAttribute');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const {setAttribute} = current;
@ -42,8 +42,8 @@ test('current-file: setCurrentName: setAttribute: cyrillic', (t) => {
t.calledWith(setAttribute, ['data-name', 'js-file-JUQwJUIwJUQwJUI5'], 'should call setAttribute');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
@ -59,12 +59,12 @@ test('current-file: getCurrentName', (t) => {
});
test('current-file: emit', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const emit = stub();
global.DOM = getDOM();
global.CloudCmd = getCloudCmd({
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd({
emit,
});
@ -74,22 +74,22 @@ test('current-file: emit', (t) => {
t.calledWith(emit, ['current-file', current], 'should call emit');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: setCurrentName: return', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const link = {};
global.DOM = getDOM({
globalThis.DOM = getDOM({
link,
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
@ -97,19 +97,19 @@ test('current-file: setCurrentName: return', (t) => {
t.equal(result, link, 'should return link');
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.end();
});
test('current-file: getParentDirPath: result', (t) => {
const {DOM} = global;
const {DOM} = globalThis;
const getCurrentDirPath = returns('/D/Films/+++favorite films/');
const getCurrentDirName = returns('+++favorite films');
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentDirPath,
getCurrentDirName,
});
@ -117,55 +117,55 @@ test('current-file: getParentDirPath: result', (t) => {
const result = currentFile.getParentDirPath();
const expected = '/D/Films/';
global.DOM = DOM;
globalThis.DOM = DOM;
t.equal(result, expected, 'should return parent dir path');
t.end();
});
test('current-file: isCurrentFile: no', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const result = currentFile.isCurrentFile();
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.notOk(result);
t.end();
});
test('current-file: isCurrentFile', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
const isContainClass = stub();
global.DOM = getDOM({
globalThis.DOM = getDOM({
isContainClass,
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = {};
currentFile.isCurrentFile(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(isContainClass, [current, _CURRENT_FILE], 'should call isContainClass');
t.end();
});
test('current-file: getCurrentType', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const {getByDataName} = global.DOM;
const {getByDataName} = globalThis.DOM;
getByDataName.returns({
className: 'mini-icon directory',
@ -175,87 +175,87 @@ test('current-file: getCurrentType', (t) => {
currentFile.getCurrentType(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(getByDataName, ['js-type', current]);
t.end();
});
test('current-file: isCurrentIsDir: getCurrentType', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const {getCurrentType} = global.DOM;
const {getCurrentType} = globalThis.DOM;
const current = create();
currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.calledWith(getCurrentType, [current]);
t.end();
});
test('current-file: isCurrentIsDir: directory', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('directory'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.ok(result);
t.end();
});
test('current-file: isCurrentIsDir: directory-link', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('directory-link'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.ok(result);
t.end();
});
test('current-file: isCurrentIsDir: file', (t) => {
const {DOM, CloudCmd} = global;
const {DOM, CloudCmd} = globalThis;
global.DOM = getDOM({
globalThis.DOM = getDOM({
getCurrentType: stub().returns('file'),
});
global.CloudCmd = getCloudCmd();
globalThis.CloudCmd = getCloudCmd();
const current = create();
const result = currentFile.isCurrentIsDir(current);
global.DOM = DOM;
global.CloudCmd = CloudCmd;
globalThis.DOM = DOM;
globalThis.CloudCmd = CloudCmd;
t.notOk(result);
t.end();

View file

@ -416,7 +416,7 @@ module.exports.shrinkSelection = () => {
* setting history wrapper
*/
module.exports.setHistory = (data, title, url) => {
const ret = window.history;
const ret = globalThis.history;
const {prefix} = CloudCmd;
url = prefix + url;
@ -554,7 +554,7 @@ module.exports.getPanel = (options) => {
* then always work with passive
* panel
*/
if (window.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
if (globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH)
panel = DOM.getByDataName('js-left');
if (!panel)

View file

@ -5,7 +5,7 @@ require('css-modules-require-hook/preset');
const {test, stub} = require('supertape');
const {getCSSVar, goToDirectory} = require('./index');
global.CloudCmd = {};
globalThis.CloudCmd = {};
test('cloudcmd: client: dom: goToDirectory', async (t) => {
const path = '';
@ -25,14 +25,14 @@ test('cloudcmd: client: dom: getCSSVar', (t) => {
const body = {};
const getPropertyValue = stub().returns(0);
global.getComputedStyle = stub().returns({
globalThis.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {
body,
});
delete global.getComputedStyle;
delete globalThis.getComputedStyle;
t.notOk(result);
t.end();
@ -42,14 +42,14 @@ test('cloudcmd: client: dom: getCSSVar: 1', (t) => {
const body = {};
const getPropertyValue = stub().returns(1);
global.getComputedStyle = stub().returns({
globalThis.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {
body,
});
delete global.getComputedStyle;
delete globalThis.getComputedStyle;
t.ok(result);
t.end();

View file

@ -7,58 +7,58 @@ const storage = require('./storage');
const {stringify} = JSON;
test('cloudcmd: client: storage: set', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const setItem = stub();
global.localStorage = {
globalThis.localStorage = {
setItem,
};
await storage.set('hello', 'world');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(setItem, ['hello', 'world'], 'should call setItem');
t.end();
});
test('cloudcmd: client: storage: get', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const getItem = stub().returns('world');
global.localStorage = {
globalThis.localStorage = {
getItem,
};
const result = await storage.get('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.equal(result, 'world');
t.end();
});
test('cloudcmd: client: storage: getJson', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const expected = {
hello: 'world',
};
const getItem = stub().returns(stringify(expected));
global.localStorage = {
globalThis.localStorage = {
getItem,
};
const result = await storage.getJson('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.deepEqual(result, expected);
t.end();
});
test('cloudcmd: client: storage: setJson', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const data = {
hello: 'world',
};
@ -66,42 +66,42 @@ test('cloudcmd: client: storage: setJson', async (t) => {
const expected = stringify(data);
const setItem = stub();
global.localStorage = {
globalThis.localStorage = {
setItem,
};
await storage.setJson('hello', data);
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(setItem, ['hello', expected]);
t.end();
});
test('cloudcmd: client: storage: remove', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const removeItem = stub();
global.localStorage = {
globalThis.localStorage = {
removeItem,
};
await storage.remove('hello');
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWith(removeItem, ['hello'], 'should call removeItem');
t.end();
});
test('cloudcmd: client: storage: clear', async (t) => {
const {localStorage} = global;
const {localStorage} = globalThis;
const clear = stub();
global.localStorage = {
globalThis.localStorage = {
clear,
};
await storage.clear();
global.localStorage = localStorage;
globalThis.localStorage = localStorage;
t.calledWithNoArgs(clear, 'should call clear');
t.end();

View file

@ -42,4 +42,3 @@ export const getJsonFromFileTable = () => {
return fileTable;
};

View file

@ -12,8 +12,8 @@ const {getDOM, getCloudCmd} = require('./vim/globals.fixture');
const test = autoGlobals(supertape);
const {stub} = supertape;
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
test('cloudcmd: client: key: enable vim', async (t) => {
const vim = stub();

View file

@ -5,7 +5,7 @@ const dir = './';
const {getDOM} = require('./globals.fixture');
global.DOM = getDOM();
globalThis.DOM = getDOM();
const {_next, _previous} = require(`${dir}find`);

View file

@ -10,13 +10,13 @@ const pathVim = join(dir, 'vim');
const {getDOM, getCloudCmd} = require('./globals.fixture');
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const vim = require(pathVim);
const {assign} = Object;
const {DOM} = global;
const {DOM} = globalThis;
const {Buffer} = DOM;
const pathFind = join(dir, 'vim', 'find');
const {reRequire, stopAll} = mockRequire;
@ -595,7 +595,7 @@ test('cloudcmd: client: key: N', (t) => {
test('cloudcmd: client: key: make directory', async (t) => {
const vim = reRequire(pathVim);
const {DOM} = global;
const {DOM} = globalThis;
assign(DOM, {
promptNewDir: stub(),
@ -615,7 +615,7 @@ test('cloudcmd: client: key: make directory', async (t) => {
test('cloudcmd: client: key: make file', (t) => {
const vim = reRequire(pathVim);
const {DOM} = global;
const {DOM} = globalThis;
assign(DOM, {
promptNewFile: stub(),
@ -634,7 +634,7 @@ test('cloudcmd: client: key: make file', (t) => {
});
test.skip('cloudcmd: client: vim: terminal', (t) => {
const {CloudCmd} = global;
const {CloudCmd} = globalThis;
assign(CloudCmd, {
Terminal: {
@ -652,10 +652,10 @@ test.skip('cloudcmd: client: vim: terminal', (t) => {
});
test.skip('cloudcmd: client: vim: edit', async (t) => {
global.DOM = getDOM();
global.CloudCmd = getCloudCmd();
globalThis.DOM = getDOM();
globalThis.CloudCmd = getCloudCmd();
const {CloudCmd} = global;
const {CloudCmd} = globalThis;
assign(CloudCmd, {
EditFileVim: {

View file

@ -32,7 +32,7 @@ module.exports.init = async () => {
CloudCmd.Listeners = module.exports;
const unselect = (event) => {
const isMac = /Mac/.test(window.navigator.platform);
const isMac = /Mac/.test(globalThis.navigator.platform);
const {
shiftKey,
metaKey,
@ -246,7 +246,7 @@ function onClick(event) {
}
function toggleSelect(key, files) {
const isMac = /Mac/.test(window.navigator.platform);
const isMac = /Mac/.test(globalThis.navigator.platform);
if (!key)
throw Error('key should not be undefined!');
@ -480,7 +480,7 @@ function pop() {
function resize() {
Events.add('resize', () => {
const is = window.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH;
const is = globalThis.innerWidth < CloudCmd.MIN_ONE_PANEL_WIDTH;
if (!is)
return;

View file

@ -1,10 +1,9 @@
/* global CloudCmd */
import exec from 'execon';
import {tryToCatch} from 'try-to-catch';
import {js} from 'load.js';
import {js as loadJS} from 'load.js';
import pascalCase from 'just-pascal-case';
const loadJS = js;
const noJS = (a) => a.replace(/.js$/, '');
/**
@ -50,9 +49,8 @@ export const loadModule = (params) => {
const [e, a] = await tryToCatch(m);
if (e)
return console.error(e);
return;
return await a.show(...args);
};
};

View file

@ -14,7 +14,7 @@ export const createCloudMenu = async (fm, options, menuData) => {
async function loadMenu() {
if (CloudCmd.config('menu') === 'aleman') {
const {host, protocol} = window.location;
const {host, protocol} = globalThis.location;
const url = `${protocol}//${host}/node_modules/aleman/menu/menu.js`;
const {createMenu} = await import(/* webpackIgnore: true */url);

View file

@ -33,7 +33,7 @@ const loadAll = async () => {
const [e] = await tryToCatch(load.parallel, [js, css]);
if (e) {
const src = e.target.src.replace(window.location.href, '');
const src = e.target.src.replace(globalThis.location.href, '');
return Dialog.alert(`file ${src} could not be loaded`);
}

View file

@ -32,7 +32,7 @@ const loadAll = async () => {
const [e] = await tryToCatch(loadParallel, [js, css]);
if (e) {
const src = e.target.src.replace(window.location.href, '');
const src = e.target.src.replace(globalThis.location.href, '');
return Dialog.alert(`file ${src} could not be loaded`);
}

View file

@ -22,12 +22,9 @@ test('cloudcmd: client: view: types: detectType', async (t) => {
headers: [],
});
const originalFetch = global.fetch;
global.fetch = fetch;
globalThis.fetch = fetch;
await _detectType('/hello');
global.fetch = originalFetch;
const expected = ['/hello', {
method: 'HEAD',
}];
@ -37,17 +34,13 @@ test('cloudcmd: client: view: types: detectType', async (t) => {
});
test('cloudcmd: client: view: types: detectType: found', async (t) => {
const originalFetch = global.fetch;
global.fetch = stub().returns({
globalThis.fetch = stub().returns({
headers: [
['content-type', 'image/png'],
],
});
const result = await _detectType('/hello');
global.fetch = originalFetch;
t.equal(result, '.png');
t.end();
});

View file

@ -7,7 +7,7 @@ const sortPrevious = fullstore();
const {getPanel} = DOM;
export const initSortPanel = () => {
const {sort, order} = CloudCmd;
const {sort} = CloudCmd;
const position = DOM.getPanelPosition();
sortPrevious(sort[position]);
@ -34,4 +34,3 @@ export const sortPanel = (name, panel = getPanel()) => {
noCurrent,
});
};

View file

@ -50,14 +50,14 @@ const getRequest = (a, request) => {
return createRequest('/');
};
self.addEventListener('install', wait(onInstall));
self.addEventListener('fetch', respondWith(onFetch));
self.addEventListener('activate', wait(onActivate));
globalThis.addEventListener('install', wait(onInstall));
globalThis.addEventListener('fetch', respondWith(onFetch));
globalThis.addEventListener('activate', wait(onActivate));
async function onActivate() {
console.info(`cloudcmd: sw: activate: ${NAME}`);
await self.clients.claim();
await globalThis.clients.claim();
const keys = await caches.keys();
const deleteCache = caches.delete.bind(caches);
@ -67,7 +67,7 @@ async function onActivate() {
async function onInstall() {
console.info(`cloudcmd: sw: install: ${NAME}`);
await self.skipWaiting();
await globalThis.skipWaiting();
}
async function onFetch(event) {