mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-22 18:29:26 +00:00
feature: common: cloudfunc: migrate to ESM
This commit is contained in:
parent
a063353a27
commit
64654e8d5c
19 changed files with 78 additions and 88 deletions
|
|
@ -7,7 +7,7 @@ import {tryToCatch} from 'try-to-catch';
|
|||
import {createSimport} from 'simport';
|
||||
import parse from 'yargs-parser';
|
||||
import exit from '../server/exit.js';
|
||||
import {createConfig, configPath} from '../server/config.js';
|
||||
import {createConfig, configPath} from '../server/config.mjs';
|
||||
import * as env from '../server/env.mjs';
|
||||
import prefixer from '../server/prefixer.js';
|
||||
import * as validate from '../server/validate.mjs';
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const {
|
|||
apiURL,
|
||||
formatMsg,
|
||||
buildFromJSON,
|
||||
} = require('../common/cloudfunc');
|
||||
} = require('../common/cloudfunc.mjs');
|
||||
|
||||
const {loadModule} = require('./load-module.mjs');
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const isDev = process.env.NODE_ENV === 'development';
|
|||
|
||||
module.exports = async (config) => {
|
||||
globalThis.Util = require('../common/util');
|
||||
globalThis.CloudFunc = require('../common/cloudfunc');
|
||||
globalThis.CloudFunc = require('../common/cloudfunc.mjs');
|
||||
|
||||
globalThis.DOM = require('./dom');
|
||||
globalThis.CloudCmd = require('./client');
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
/* global CloudCmd */
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
const {encode, decode} = require('../../common/entity');
|
||||
const {getTitle, FS} = require('../../common/cloudfunc');
|
||||
const {getTitle, FS} = require('../../common/cloudfunc.mjs');
|
||||
|
||||
let Title;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
const philip = require('philip');
|
||||
|
||||
const Images = require('./images');
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
const {FS} = require('../../common/cloudfunc.mjs');
|
||||
const DOM = require('.');
|
||||
const Dialog = require('./dialog');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const {FS} = require('../../../common/cloudfunc');
|
||||
const {FS} = require('../../../common/cloudfunc.mjs');
|
||||
const _sendRequest = require('./send-request');
|
||||
|
||||
const imgPosition = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const load = require('./load');
|
|||
const Images = require('./images');
|
||||
const {alert} = require('./dialog');
|
||||
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
const {FS} = require('../../common/cloudfunc.mjs');
|
||||
|
||||
const {getCurrentDirPath: getPathWhenRootEmpty} = require('.');
|
||||
const loadFile = wraptile(_loadFile);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const clipboard = require('@cloudcmd/clipboard');
|
|||
|
||||
const getRange = require('./get-range');
|
||||
const uploadFiles = require('../dom/upload-files');
|
||||
const {FS} = require('../../common/cloudfunc');
|
||||
const {FS} = require('../../common/cloudfunc.mjs');
|
||||
|
||||
const getIndex = currify(require('./get-index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const Images = require('../../dom/images');
|
|||
const Events = require('../../dom/events');
|
||||
const Files = require('../../dom/files');
|
||||
|
||||
const {getTitle} = require('../../../common/cloudfunc');
|
||||
const {getTitle} = require('../../../common/cloudfunc.mjs');
|
||||
const {Dialog, setTitle} = DOM;
|
||||
|
||||
const Name = 'Config';
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const {promisify} = require('es6-promisify');
|
|||
const {tryToCatch} = require('try-to-catch');
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
const load = require('load.js');
|
||||
const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc');
|
||||
const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc.mjs');
|
||||
|
||||
const {time, timeEnd} = require('../../common/util');
|
||||
const getEditor = () => editor;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const exec = require('execon');
|
|||
const wrap = require('wraptile');
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
|
||||
const {FS} = require('../../../common/cloudfunc');
|
||||
const {FS} = require('../../../common/cloudfunc.mjs');
|
||||
const {getIdBySrc} = require('../../dom/load');
|
||||
const RESTful = require('../../dom/rest');
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const _modal = require('@cloudcmd/modal');
|
|||
const _createElement = require('@cloudcmd/create-element');
|
||||
|
||||
const {time} = require('../../../common/util');
|
||||
const {FS} = require('../../../common/cloudfunc');
|
||||
const {FS} = require('../../../common/cloudfunc.mjs');
|
||||
|
||||
const {
|
||||
isImage,
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
'use strict';
|
||||
import rendy from 'rendy';
|
||||
import currify from 'currify';
|
||||
import store from 'fullstore';
|
||||
import {encode} from './entity.js';
|
||||
|
||||
const rendy = require('rendy');
|
||||
const currify = require('currify');
|
||||
const store = require('fullstore');
|
||||
const {encode} = require('./entity');
|
||||
|
||||
const getHeaderField = currify(_getHeaderField);
|
||||
export const getHeaderField = currify(_getHeaderField);
|
||||
|
||||
/* КОНСТАНТЫ (общие для клиента и сервера)*/
|
||||
/* название программы */
|
||||
const NAME = 'Cloud Commander';
|
||||
const FS = '/fs';
|
||||
|
||||
export const FS = '/fs';
|
||||
|
||||
const Path = store();
|
||||
|
||||
Path('/');
|
||||
|
|
@ -22,14 +22,10 @@ const filterOutDotFiles = ({showDotFiles}) => ({name}) => {
|
|||
return !name.startsWith('.');
|
||||
};
|
||||
|
||||
module.exports.FS = FS;
|
||||
module.exports.apiURL = '/api/v1';
|
||||
module.exports.MAX_FILE_SIZE = 500 * 1024;
|
||||
module.exports.getHeaderField = getHeaderField;
|
||||
module.exports.getPathLink = getPathLink;
|
||||
module.exports.getDotDot = getDotDot;
|
||||
export const apiURL = '/api/v1';
|
||||
export const MAX_FILE_SIZE = 500 * 1024;
|
||||
|
||||
module.exports.formatMsg = (msg, name, status) => {
|
||||
export const formatMsg = (msg, name, status) => {
|
||||
status = status || 'ok';
|
||||
name = name || '';
|
||||
|
||||
|
|
@ -43,7 +39,7 @@ module.exports.formatMsg = (msg, name, status) => {
|
|||
* Функция возвращает заголовок веб страницы
|
||||
* @path
|
||||
*/
|
||||
module.exports.getTitle = (options) => {
|
||||
export const getTitle = (options) => {
|
||||
options = options || {};
|
||||
|
||||
const {path = Path(), name} = options;
|
||||
|
|
@ -62,7 +58,7 @@ module.exports.getTitle = (options) => {
|
|||
* возвращаеться массив каталогов
|
||||
* @param url - адрес каталога
|
||||
*/
|
||||
function getPathLink(url, prefix, template) {
|
||||
export function getPathLink(url, prefix, template) {
|
||||
if (!url)
|
||||
throw Error('url could not be empty!');
|
||||
|
||||
|
|
@ -108,9 +104,7 @@ function getPathLink(url, prefix, template) {
|
|||
return lines.join('');
|
||||
}
|
||||
|
||||
module.exports._getDataName = _getDataName;
|
||||
|
||||
function _getDataName(name) {
|
||||
export function _getDataName(name) {
|
||||
const encoded = btoa(encodeURI(name));
|
||||
return `data-name="js-file-${encoded}" `;
|
||||
}
|
||||
|
|
@ -119,7 +113,7 @@ function _getDataName(name) {
|
|||
* @param params - информация о файлах
|
||||
*
|
||||
*/
|
||||
module.exports.buildFromJSON = (params) => {
|
||||
export const buildFromJSON = (params) => {
|
||||
const {
|
||||
prefix,
|
||||
template,
|
||||
|
|
@ -262,7 +256,8 @@ function getAttribute(type) {
|
|||
return 'target="_blank" ';
|
||||
}
|
||||
|
||||
module.exports._getSize = getSize;
|
||||
export const _getSize = getSize;
|
||||
|
||||
function getSize({size, type}) {
|
||||
if (type === 'directory')
|
||||
return '<dir>';
|
||||
|
|
@ -285,7 +280,7 @@ function _getHeaderField(sort, order, name) {
|
|||
return `${name}${arrow}`;
|
||||
}
|
||||
|
||||
function getDotDot(path) {
|
||||
export function getDotDot(path) {
|
||||
// убираем последний слеш и каталог в котором мы сейчас находимся
|
||||
const lastSlash = path.substr(path, path.lastIndexOf('/'));
|
||||
const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
|
||||
|
|
@ -1,20 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const {join} = require('node:path');
|
||||
const {readFileSync} = require('node:fs');
|
||||
|
||||
const test = require('supertape');
|
||||
const montag = require('montag');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const {
|
||||
import {readFileSync} from 'node:fs';
|
||||
import test from 'supertape';
|
||||
import montag from 'montag';
|
||||
import cheerio from 'cheerio';
|
||||
import {
|
||||
_getSize,
|
||||
getPathLink,
|
||||
buildFromJSON,
|
||||
_getDataName,
|
||||
} = require('./cloudfunc');
|
||||
} from './cloudfunc.mjs';
|
||||
|
||||
const templatePath = join(__dirname, '../tmpl/fs');
|
||||
const templatePath = new URL('../tmpl/fs', import.meta.url).pathname;
|
||||
|
||||
const template = {
|
||||
pathLink: readFileSync(`${templatePath}/pathLink.hbs`, 'utf8'),
|
||||
|
|
@ -14,12 +14,12 @@ import dword from 'dword';
|
|||
import deepword from 'deepword';
|
||||
import nomine from 'nomine';
|
||||
import fileop from '@cloudcmd/fileop';
|
||||
import cloudfunc from '../common/cloudfunc.js';
|
||||
import * as cloudfunc from '../common/cloudfunc.mjs';
|
||||
import authentication from './auth.js';
|
||||
import {createConfig, configPath} from './config.js';
|
||||
import {createConfig, configPath} from './config.mjs';
|
||||
import modulas from './modulas.mjs';
|
||||
import userMenu from './user-menu.mjs';
|
||||
import rest from './rest/index.js';
|
||||
import rest from './rest/index.mjs';
|
||||
import route from './route.mjs';
|
||||
import * as validate from './validate.mjs';
|
||||
import prefixer from './prefixer.js';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
'use strict';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {dirname} from 'node:path';
|
||||
import {createRequire} from 'node:module';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const require = createRequire(import.meta.url);
|
||||
const DIR_SERVER = `${__dirname}/`;
|
||||
const DIR_COMMON = '../common/';
|
||||
|
||||
const path = require('node:path');
|
||||
|
||||
const fs = require('node:fs');
|
||||
|
|
@ -21,7 +26,7 @@ const {tryCatch} = require('try-catch');
|
|||
const criton = require('criton');
|
||||
const exit = require(`${DIR_SERVER}exit`);
|
||||
|
||||
const CloudFunc = require(`${DIR_COMMON}cloudfunc`);
|
||||
const CloudFunc = require('../common/cloudfunc.mjs');
|
||||
const isUndefined = (a) => typeof a === 'undefined';
|
||||
const DIR = `${DIR_SERVER}../`;
|
||||
const HOME = homedir();
|
||||
|
|
@ -36,7 +41,6 @@ const key = (a) => Object
|
|||
.pop();
|
||||
|
||||
const ConfigPath = path.join(DIR, 'json/config.json');
|
||||
const ConfigHome = path.join(HOME, '.cloudcmd.json');
|
||||
|
||||
const connection = currify(_connection);
|
||||
const connectionWrapped = wraptile(_connection);
|
||||
|
|
@ -65,8 +69,7 @@ function read(filename) {
|
|||
};
|
||||
}
|
||||
|
||||
module.exports.createConfig = createConfig;
|
||||
module.exports.configPath = ConfigHome;
|
||||
export const configPath = path.join(HOME, '.cloudcmd.json');
|
||||
|
||||
const manageListen = currify((manage, socket, auth) => {
|
||||
if (!manage('configDialog'))
|
||||
|
|
@ -84,7 +87,7 @@ function initWrite(filename, configManager) {
|
|||
return resolve;
|
||||
}
|
||||
|
||||
function createConfig({configPath} = {}) {
|
||||
export function createConfig({configPath} = {}) {
|
||||
const config = {};
|
||||
const changeEmitter = new Emitter();
|
||||
|
||||
|
|
@ -237,7 +240,8 @@ function traverse([manage, json]) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports._cryptoPass = cryptoPass;
|
||||
export const _cryptoPass = cryptoPass;
|
||||
|
||||
function cryptoPass(manage, json) {
|
||||
const algo = manage('algo');
|
||||
|
||||
|
|
@ -1,26 +1,21 @@
|
|||
'use strict';
|
||||
import path from 'node:path';
|
||||
import _fs from 'node:fs';
|
||||
import process from 'node:process';
|
||||
import jaguar from 'jaguar';
|
||||
import onezip from 'onezip';
|
||||
import inly from 'inly';
|
||||
import wraptile from 'wraptile';
|
||||
import currify from 'currify';
|
||||
import pullout from 'pullout';
|
||||
import json from 'jonny';
|
||||
import ponse from 'ponse';
|
||||
import copymitter from 'copymitter';
|
||||
import _moveFiles from '@cloudcmd/move-files';
|
||||
import root from '../root.js';
|
||||
import * as CloudFunc from '../../common/cloudfunc.mjs';
|
||||
import markdown from '../markdown/index.js';
|
||||
import info from './info.js';
|
||||
|
||||
const path = require('node:path');
|
||||
const _fs = require('node:fs');
|
||||
|
||||
const process = require('node:process');
|
||||
|
||||
const jaguar = require('jaguar');
|
||||
const onezip = require('onezip');
|
||||
const inly = require('inly');
|
||||
const wraptile = require('wraptile');
|
||||
const currify = require('currify');
|
||||
const pullout = require('pullout');
|
||||
const json = require('jonny');
|
||||
const ponse = require('ponse');
|
||||
|
||||
const copymitter = require('copymitter');
|
||||
const _moveFiles = require('@cloudcmd/move-files');
|
||||
|
||||
const root = require(`../root`);
|
||||
const CloudFunc = require(`../../common/cloudfunc`);
|
||||
const markdown = require(`../markdown/index.js`);
|
||||
const info = require('./info');
|
||||
const isUndefined = (a) => typeof a === 'undefined';
|
||||
const isRootAll = (root, names) => names.some(isRootWin32(root));
|
||||
const isString = (a) => typeof a === 'string';
|
||||
|
|
@ -37,7 +32,7 @@ const UserError = (msg) => {
|
|||
return error;
|
||||
};
|
||||
|
||||
module.exports = currify(({config, fs = _fs, moveFiles = _moveFiles}, request, response, next) => {
|
||||
export default currify(({config, fs = _fs, moveFiles = _moveFiles}, request, response, next) => {
|
||||
const name = ponse.getPathName(request);
|
||||
const regExp = RegExp(`^${apiURL}`);
|
||||
const is = regExp.test(name);
|
||||
|
|
@ -188,7 +183,8 @@ const getRenameMsg = (from, to) => {
|
|||
return msg;
|
||||
};
|
||||
|
||||
module.exports._onPUT = onPUT;
|
||||
export const _onPUT = onPUT;
|
||||
|
||||
function onPUT({name, fs, moveFiles, config, body}, callback) {
|
||||
checkPut(name, body, callback);
|
||||
|
||||
|
|
@ -368,10 +364,10 @@ const isRootWin32 = currify((root, path) => {
|
|||
return isWin32 && isRoot && isConfig;
|
||||
});
|
||||
|
||||
module.exports._isRootWin32 = isRootWin32;
|
||||
module.exports._isRootAll = isRootAll;
|
||||
export const _isRootWin32 = isRootWin32;
|
||||
export const _isRootAll = isRootAll;
|
||||
|
||||
module.exports._getWin32RootMsg = getWin32RootMsg;
|
||||
export const _getWin32RootMsg = getWin32RootMsg;
|
||||
|
||||
function getWin32RootMsg() {
|
||||
const message = 'Could not copy from/to root on windows!';
|
||||
|
|
@ -388,7 +384,7 @@ function parseData(data) {
|
|||
return json.stringify(data);
|
||||
}
|
||||
|
||||
module.exports._formatMsg = formatMsg;
|
||||
export const _formatMsg = formatMsg;
|
||||
|
||||
function formatMsg(msg, data, status) {
|
||||
const value = parseData(data);
|
||||
|
|
@ -12,7 +12,7 @@ import pipe from 'pipe-io';
|
|||
import {contentType} from 'mime-types';
|
||||
import root from './root.js';
|
||||
import prefixer from './prefixer.js';
|
||||
import CloudFunc from '../common/cloudfunc.js';
|
||||
import * as CloudFunc from '../common/cloudfunc.mjs';
|
||||
import Template from './template.js';
|
||||
import {getColumns} from './columns.mjs';
|
||||
import {getThemes} from './theme.mjs';
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ const test = require('supertape');
|
|||
const readFilesSync = require('@cloudcmd/read-files-sync');
|
||||
|
||||
const {time, timeEnd} = require(`../../common/util`);
|
||||
const CloudFunc = require('../../common/cloudfunc.js');
|
||||
const CloudFunc = require('../../common/cloudfunc.mjs');
|
||||
|
||||
const DIR = `${__dirname}/../../`;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue