mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: client: dom: rest: migrate to ESM
This commit is contained in:
parent
c704ffe47a
commit
e4d0ece093
9 changed files with 48 additions and 51 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/* global CloudCmd*/
|
||||
import tryToPromiseAll from '../../common/try-to-promise-all.js';
|
||||
import * as Storage from '#dom/storage';
|
||||
import tryToPromiseAll from '../../common/try-to-promise-all.js';
|
||||
|
||||
const CLASS = 'cut-file';
|
||||
const COPY = 'copy';
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import itype from 'itype';
|
||||
import {promisify} from 'es6-promisify';
|
||||
import * as load from '#dom/load';
|
||||
import RESTful from './rest.js';
|
||||
import * as RESTful from '#dom/rest';
|
||||
|
||||
const Promises = {};
|
||||
const FILES_JSON = 'config|modules';
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import * as Files from '#dom/files';
|
|||
import * as Dialog from '#dom/dialog';
|
||||
import * as Events from '#dom/events';
|
||||
import {getExt} from '#common/util';
|
||||
import * as Images from './images.mjs';
|
||||
import RESTful from './rest.js';
|
||||
import * as Storage from '#dom/storage';
|
||||
import * as Images from './images.mjs';
|
||||
import * as RESTful from '#dom/rest';
|
||||
import renameCurrent from './operations/rename-current.js';
|
||||
import * as CurrentFile from './current-file.mjs';
|
||||
import * as DOMTree from './dom-tree.mjs';
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const capitalize = require('just-capitalize');
|
|||
|
||||
const _Dialog = require('#dom/dialog');
|
||||
const Storage = require('#dom/storage');
|
||||
const RESTful = require('../rest');
|
||||
const RESTful = require('#dom/rest');
|
||||
|
||||
const _currentFile = require('../current-file.mjs');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const {tryToCatch} = require('try-to-catch');
|
||||
|
||||
const {encode} = require('../../common/entity');
|
||||
|
||||
const Images = require('./images.mjs');
|
||||
const IO = require('./io');
|
||||
const Dialog = require('#dom/dialog');
|
||||
|
||||
const handleError = (promise) => async (...args) => {
|
||||
const [e, data] = await tryToCatch(promise, ...args);
|
||||
|
||||
if (!e)
|
||||
return [e, data];
|
||||
|
||||
const encoded = encode(e.message);
|
||||
|
||||
Images.show.error(encoded);
|
||||
Dialog.alert(encoded);
|
||||
|
||||
return [e, data];
|
||||
};
|
||||
|
||||
module.exports.delete = handleError(IO.delete);
|
||||
module.exports.patch = handleError(IO.patch);
|
||||
module.exports.write = handleError(IO.write);
|
||||
module.exports.createDirectory = handleError(IO.createDirectory);
|
||||
module.exports.read = handleError(IO.read);
|
||||
module.exports.copy = handleError(IO.copy);
|
||||
module.exports.pack = handleError(IO.pack);
|
||||
module.exports.extract = handleError(IO.extract);
|
||||
module.exports.move = handleError(IO.move);
|
||||
module.exports.rename = handleError(IO.rename);
|
||||
|
||||
module.exports.Config = {
|
||||
read: handleError(IO.Config.read),
|
||||
write: handleError(IO.Config.write),
|
||||
};
|
||||
|
||||
module.exports.Markdown = {
|
||||
read: handleError(IO.Markdown.read),
|
||||
render: handleError(IO.Markdown.render),
|
||||
};
|
||||
40
client/dom/rest.mjs
Normal file
40
client/dom/rest.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import {tryToCatch} from 'try-to-catch';
|
||||
import * as Dialog from '#dom/dialog';
|
||||
import {encode} from '../../common/entity.js';
|
||||
import * as Images from './images.mjs';
|
||||
import IO from './io/index.js';
|
||||
|
||||
const handleError = (promise) => async (...args) => {
|
||||
const [e, data] = await tryToCatch(promise, ...args);
|
||||
|
||||
if (!e)
|
||||
return [e, data];
|
||||
|
||||
const encoded = encode(e.message);
|
||||
|
||||
Images.show.error(encoded);
|
||||
Dialog.alert(encoded);
|
||||
|
||||
return [e, data];
|
||||
};
|
||||
|
||||
export const remove = handleError(IO.delete);
|
||||
export const patch = handleError(IO.patch);
|
||||
export const write = handleError(IO.write);
|
||||
export const createDirectory = handleError(IO.createDirectory);
|
||||
export const read = handleError(IO.read);
|
||||
export const copy = handleError(IO.copy);
|
||||
export const pack = handleError(IO.pack);
|
||||
export const extract = handleError(IO.extract);
|
||||
export const move = handleError(IO.move);
|
||||
export const rename = handleError(IO.rename);
|
||||
|
||||
export const Config = {
|
||||
read: handleError(IO.Config.read),
|
||||
write: handleError(IO.Config.write),
|
||||
};
|
||||
|
||||
export const Markdown = {
|
||||
read: handleError(IO.Markdown.read),
|
||||
render: handleError(IO.Markdown.render),
|
||||
};
|
||||
|
|
@ -6,7 +6,7 @@ CloudCmd.Markdown = exports;
|
|||
const createElement = require('@cloudcmd/create-element');
|
||||
|
||||
const Images = require('../dom/images.mjs');
|
||||
const {Markdown} = require('../dom/rest');
|
||||
const {Markdown} = require('#dom/rest');
|
||||
const {alert} = require('#dom/dialog');
|
||||
|
||||
module.exports.init = async () => {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const createElement = require('@cloudcmd/create-element');
|
|||
|
||||
const {FS} = require('../../../common/cloudfunc.mjs');
|
||||
const {getIdBySrc} = require('#dom/load');
|
||||
const RESTful = require('../../dom/rest');
|
||||
const RESTful = require('#dom/rest');
|
||||
|
||||
const {config, Key} = CloudCmd;
|
||||
|
||||
|
|
|
|||
|
|
@ -224,6 +224,7 @@
|
|||
"#dom/files": "./client/dom/files.mjs",
|
||||
"#dom/upload-files": "./client/dom/upload-files.mjs",
|
||||
"#dom/storage": "./client/dom/storage.mjs",
|
||||
"#dom/rest": "./client/dom/rest.mjs",
|
||||
"#common/util": "./common/util.mjs"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue